From 0b53c4fd5c71f43a240f2d980bac4e0166fffd2a Mon Sep 17 00:00:00 2001 From: Jason Papakostas Date: Sat, 16 Apr 2016 22:21:22 -0500 Subject: [PATCH] fix(Widget::updateIcons): workaround QIcon fallback bug Some builds of Qt appear to have a bug in icon loading: QIcon::hasThemeIcon is sometimes unaware that the icon returned from QIcon::fromTheme was a fallback icon, causing hasThemeIcon to incorrectly return true. In qTox this leads to the tray and window icons using the static qTox logo icon instead of an icon based on the current presence status. This workaround checks for an icon that definitely does not exist to determine if hasThemeIcon can be trusted. On systems with the Qt bug, this workaround will always use our included icons but user themes will be unable to override them. --- src/widget/widget.cpp | 29 ++++++++++++++++++++++++++++- 1 file changed, 28 insertions(+), 1 deletion(-) diff --git a/src/widget/widget.cpp b/src/widget/widget.cpp index ec07319c5..f56706db8 100644 --- a/src/widget/widget.cpp +++ b/src/widget/widget.cpp @@ -445,8 +445,35 @@ void Widget::updateIcons() status = QStringLiteral("offline"); } + // Some builds of Qt appear to have a bug in icon loading: + // QIcon::hasThemeIcon is sometimes unaware that the icon returned + // from QIcon::fromTheme was a fallback icon, causing hasThemeIcon to + // incorrectly return true. + // + // In qTox this leads to the tray and window icons using the static qTox logo + // icon instead of an icon based on the current presence status. + // + // This workaround checks for an icon that definitely does not exist to + // determine if hasThemeIcon can be trusted. + // + // On systems with the Qt bug, this workaround will always use our included + // icons but user themes will be unable to override them. + static bool checkedHasThemeIcon = false; + static bool hasThemeIconBug = false; + + if (!checkedHasThemeIcon) + { + hasThemeIconBug = QIcon::hasThemeIcon("qtox-asjkdfhawjkeghdfjgh"); + checkedHasThemeIcon = true; + + if (hasThemeIconBug) + { + qDebug() << "Detected buggy QIcon::hasThemeIcon. Icon overrides from theme will be ignored."; + } + } + QIcon ico; - if (QIcon::hasThemeIcon("qtox-" + status)) + if (!hasThemeIconBug && QIcon::hasThemeIcon("qtox-" + status)) { ico = QIcon::fromTheme("qtox-" + status); }