|
19 | 19 | Q_LOGGING_CATEGORY(appitemLog, "org.deepin.dde.shell.dock.taskmanger.appitem") |
20 | 20 |
|
21 | 21 | namespace dock { |
| 22 | +namespace { |
| 23 | +QString desktopIconName(const QSharedPointer<DesktopfileAbstractParser> &parser) |
| 24 | +{ |
| 25 | + if (!parser || !parser->isValied().first) { |
| 26 | + return {}; |
| 27 | + } |
| 28 | + |
| 29 | + return parser->desktopIcon().trimmed(); |
| 30 | +} |
| 31 | + |
| 32 | +QString windowIconName(const QPointer<AbstractWindow> &window) |
| 33 | +{ |
| 34 | + if (window.isNull()) { |
| 35 | + return {}; |
| 36 | + } |
| 37 | + |
| 38 | + return window->icon().trimmed(); |
| 39 | +} |
| 40 | +} |
| 41 | + |
22 | 42 | AppItem::AppItem(QString id, QObject *parent) |
23 | 43 | : AbstractItem(QStringLiteral("AppItem/%1").arg(escapeToObjectPath(id)), parent) |
24 | 44 | , m_id(id) |
@@ -52,21 +72,17 @@ QString AppItem::type() const |
52 | 72 |
|
53 | 73 | QString AppItem::icon() const |
54 | 74 | { |
55 | | - if (!m_currentActiveWindow.isNull()) { |
56 | | - const QString windowIcon = m_currentActiveWindow->icon().trimmed(); |
57 | | - if (!windowIcon.isEmpty()) { |
58 | | - return windowIcon; |
59 | | - } |
| 75 | + const QString windowIcon = windowIconName(m_currentActiveWindow); |
| 76 | + if (!windowIcon.isEmpty()) { |
| 77 | + return windowIcon; |
60 | 78 | } |
61 | 79 |
|
62 | | - if (m_desktopfileParser && m_desktopfileParser->isValied().first) { |
63 | | - const QString desktopIcon = m_desktopfileParser->desktopIcon().trimmed(); |
64 | | - if (!desktopIcon.isEmpty()) { |
65 | | - return desktopIcon; |
66 | | - } |
| 80 | + const QString desktopIcon = desktopIconName(m_desktopfileParser); |
| 81 | + if (!desktopIcon.isEmpty()) { |
| 82 | + return desktopIcon; |
67 | 83 | } |
68 | 84 |
|
69 | | - return QStringLiteral("application-default-icon"); |
| 85 | + return QString::fromLatin1(DEFAULT_APP_ICONNAME); |
70 | 86 | } |
71 | 87 |
|
72 | 88 | QString AppItem::name() const |
@@ -316,7 +332,12 @@ QString AppItem::getCurrentActiveWindowName() const |
316 | 332 |
|
317 | 333 | QString AppItem::getCurrentActiveWindowIcon() const |
318 | 334 | { |
319 | | - return m_currentActiveWindow.isNull() ? this->icon() : m_currentActiveWindow->icon(); |
| 335 | + const QString windowIcon = windowIconName(m_currentActiveWindow); |
| 336 | + if (!windowIcon.isEmpty()) { |
| 337 | + return windowIcon; |
| 338 | + } |
| 339 | + |
| 340 | + return icon(); |
320 | 341 | } |
321 | 342 |
|
322 | 343 | void AppItem::updateCurrentActiveWindow(QPointer<AbstractWindow> window) |
|
0 commit comments