From addde7843f0bcbf7da8171e5146d8f1822ee0428 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tor=20Arne=20Vestb=C3=B8?= Date: Wed, 10 May 2023 18:46:22 +0200 Subject: [PATCH] Consult QIcon::fallbackThemeName() even when theme name is empty We still need to consult fallbackThemeName() when computing the parent list for an individual theme, as the Freedesktop Theme Icon spec mandates that the "hicolor" theme comes last, but we no longer need to do explicit fallback to fallbackThemeName() if a theme is not found. Pick-to: 6.5 6.6 Change-Id: I6c0b5a45d8258c5b6eaa761402944a735b1606ba Reviewed-by: Axel Spoerl --- src/gui/image/qiconloader.cpp | 15 ++++++++------- tests/auto/gui/image/qicon/tst_qicon.cpp | 4 ++++ 2 files changed, 12 insertions(+), 7 deletions(-) diff --git a/src/gui/image/qiconloader.cpp b/src/gui/image/qiconloader.cpp index 6c5621000e..870f9eb76f 100644 --- a/src/gui/image/qiconloader.cpp +++ b/src/gui/image/qiconloader.cpp @@ -438,9 +438,8 @@ QThemeIconInfo QIconLoader::findIconHelper(const QString &themeName, if (!theme.isValid()) { theme = QIconTheme(themeName); if (!theme.isValid()) { - qCDebug(lcIconLoader) << "Theme" << themeName << "not found;" - << "trying fallback theme" << fallbackThemeName(); - theme = QIconTheme(fallbackThemeName()); + qCDebug(lcIconLoader) << "Theme" << themeName << "not found"; + return info; } } @@ -582,10 +581,12 @@ QThemeIconInfo QIconLoader::loadIcon(const QString &name) const qCDebug(lcIconLoader) << "Loading icon" << name; QThemeIconInfo iconInfo; - if (!themeName().isEmpty()) { - QStringList visited; - iconInfo = findIconHelper(themeName(), name, visited); - } + QStringList visitedThemes; + if (!themeName().isEmpty()) + iconInfo = findIconHelper(themeName(), name, visitedThemes); + + if (iconInfo.entries.empty() && !fallbackThemeName().isEmpty()) + iconInfo = findIconHelper(fallbackThemeName(), name, visitedThemes); if (iconInfo.entries.empty()) iconInfo = lookupFallbackIcon(name); diff --git a/tests/auto/gui/image/qicon/tst_qicon.cpp b/tests/auto/gui/image/qicon/tst_qicon.cpp index 4ae908058e..0d8213a617 100644 --- a/tests/auto/gui/image/qicon/tst_qicon.cpp +++ b/tests/auto/gui/image/qicon/tst_qicon.cpp @@ -732,6 +732,10 @@ void tst_QIcon::fromTheme() // named system icon theme. QIcon::setThemeName(""); // Reset user-theme if (QIcon::themeName().isEmpty()) { + // Test icon from fallback theme even when theme name is empty + QIcon::setFallbackThemeName("fallbacktheme"); + QVERIFY(!QIcon::fromTheme("edit-cut").isNull()); + // Test icon from fallback path even when theme name is empty fallbackIcon = QIcon::fromTheme("red"); QVERIFY(!fallbackIcon.isNull());