From a23aaaaa921d818e19b2030076d96f54eb69f1b3 Mon Sep 17 00:00:00 2001 From: Vlad Zahorodnii Date: Mon, 25 Apr 2022 23:09:30 +0300 Subject: [PATCH] Unset iconName when icon can't be loaded --- .../systemtray/statusnotifieritemsource.cpp | 74 ++++++++++--------- 1 file changed, 41 insertions(+), 33 deletions(-) diff --git a/applets/systemtray/statusnotifieritemsource.cpp b/applets/systemtray/statusnotifieritemsource.cpp index 394067010..e09e92419 100644 --- a/applets/systemtray/statusnotifieritemsource.cpp +++ b/applets/systemtray/statusnotifieritemsource.cpp @@ -287,16 +287,17 @@ void StatusNotifierItemSource::refreshCallback(QDBusPendingCallWatcher *call) QIcon overlay; QStringList overlayNames; - // Icon + // Overlay icon { - QIcon icon; - QString iconName; - - // Prefer icon over pixmap. If the icon is unavailable fallback to pixmap. - m_overlayIconName = properties[QStringLiteral("OverlayIconName")].toString(); - if (!m_overlayIconName.isEmpty()) { - overlayNames << m_overlayIconName; - overlay = QIcon(new KIconEngine(m_overlayIconName, iconLoader())); + m_overlayIconName = QString(); + + const QString iconName = properties[QStringLiteral("OverlayIconName")].toString(); + if (!iconName.isEmpty()) { + overlay = QIcon(new KIconEngine(iconName, iconLoader())); + if (!overlay.isNull()) { + m_overlayIconName = iconName; + overlayNames << iconName; + } } if (overlay.isNull()) { KDbusImageVector image; @@ -305,53 +306,60 @@ void StatusNotifierItemSource::refreshCallback(QDBusPendingCallWatcher *call) overlay = imageVectorToPixmap(image); } } + } - // Prefer icon over pixmap. If the icon is unavailable fallback to pixmap. - iconName = properties[QStringLiteral("IconName")].toString(); + // Icon + { + m_icon = QIcon(); + m_iconName = QString(); + + const QString iconName = properties[QStringLiteral("IconName")].toString(); if (!iconName.isEmpty()) { - icon = QIcon(new KIconEngine(iconName, iconLoader(), overlayNames)); - if (!icon.isNull() && !overlay.isNull() && overlayNames.isEmpty()) { - overlayIcon(&icon, &overlay); + m_icon = QIcon(new KIconEngine(iconName, iconLoader(), overlayNames)); + if (!m_icon.isNull()) { + m_iconName = iconName; + if (!overlay.isNull() && overlayNames.isEmpty()) { + overlayIcon(&m_icon, &overlay); + } } } - if (icon.isNull()) { + if (m_icon.isNull()) { KDbusImageVector image; properties[QStringLiteral("IconPixmap")].value() >> image; if (!image.isEmpty()) { - icon = imageVectorToPixmap(image); - if (!icon.isNull() && !overlay.isNull()) { - overlayIcon(&icon, &overlay); + m_icon = imageVectorToPixmap(image); + if (!m_icon.isNull() && !overlay.isNull()) { + overlayIcon(&m_icon, &overlay); } } } - - m_icon = icon; - m_iconName = iconName; } // Attention icon { - QIcon attentionIcon; + m_attentionIcon = QIcon(); + m_attentionIconName = QString(); - m_attentionIconName = properties[QStringLiteral("AttentionIconName")].toString(); - if (!m_attentionIconName.isEmpty()) { - attentionIcon = QIcon(new KIconEngine(m_attentionIconName, iconLoader(), overlayNames)); - if (!attentionIcon.isNull() && !overlay.isNull() && overlayNames.isEmpty()) { - overlayIcon(&attentionIcon, &overlay); + const QString iconName = properties[QStringLiteral("AttentionIconName")].toString(); + if (!iconName.isEmpty()) { + m_attentionIcon = QIcon(new KIconEngine(iconName, iconLoader(), overlayNames)); + if (!m_attentionIcon.isNull()) { + m_attentionIconName = iconName; + if (!overlay.isNull() && overlayNames.isEmpty()) { + overlayIcon(&m_attentionIcon, &overlay); + } } } - if (attentionIcon.isNull()) { + if (m_attentionIcon.isNull()) { KDbusImageVector image; properties[QStringLiteral("AttentionIconPixmap")].value() >> image; if (!image.isEmpty()) { - attentionIcon = imageVectorToPixmap(image); - if (!attentionIcon.isNull() && !overlay.isNull()) { - overlayIcon(&attentionIcon, &overlay); + m_attentionIcon = imageVectorToPixmap(image); + if (!m_attentionIcon.isNull() && !overlay.isNull()) { + overlayIcon(&m_attentionIcon, &overlay); } } } - - m_attentionIcon = attentionIcon; } // ToolTip