From 062e1bfacdfd8a0c5d0ba1776ebb71cd45b9ca8a Mon Sep 17 00:00:00 2001 From: Alexander Volkov Date: Sun, 24 Jan 2021 18:47:38 +0300 Subject: [PATCH] Don't search more generic icons in Applications and MimeTypes contexts MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit According to the specification https://specifications.freedesktop.org/icon-naming-spec/icon-naming-spec-latest.html#guidelines 1) "the dash “-” character is used to separate levels of specificity in icon names, for all contexts other than MimeTypes" 2) "the “Applications” context should not use this method of falling back to more generic icons" Change-Id: Ia3536141158a4b6c1c4f85db8ad890514cf19e84 Reviewed-by: Axel Spoerl (cherry picked from commit e0c435cbfeaf1b82f759910fbf05d13e55d4f95f) Reviewed-by: Qt Cherry-pick Bot (cherry picked from commit 79aa84aec200b3287e7948aa6c32c1ccb848c4d9) --- src/gui/image/qiconloader.cpp | 18 ++++++++++++++++++ src/gui/image/qiconloader_p.h | 5 ++++- 2 files changed, 22 insertions(+), 1 deletion(-) diff --git a/src/gui/image/qiconloader.cpp b/src/gui/image/qiconloader.cpp index 7383528dc60..35b24663683 100644 --- a/src/gui/image/qiconloader.cpp +++ b/src/gui/image/qiconloader.cpp @@ -392,6 +392,17 @@ QIconTheme::QIconTheme(const QString &themeName) dirInfo.maxSize = indexReader.value(directoryKey + "/MaxSize"_L1, size).toInt(); dirInfo.scale = indexReader.value(directoryKey + "/Scale"_L1, 1).toInt(); + + const QString context = indexReader.value(directoryKey + "/Context"_L1).toString(); + dirInfo.context = [context]() { + if (context == "Applications"_L1) + return QIconDirInfo::Applications; + else if (context == "MimeTypes"_L1) + return QIconDirInfo::MimeTypes; + else + return QIconDirInfo::UnknownContext; + }(); + m_keyList.append(dirInfo); } } @@ -453,6 +464,7 @@ QThemeIconInfo QIconLoader::findIconHelper(const QString &themeName, const QStringList contentDirs = theme.contentDirs(); QStringView iconNameFallback(iconName); + bool searchingGenericFallback = false; // Iterate through all icon's fallbacks in current theme while (info.entries.empty()) { @@ -487,6 +499,11 @@ QThemeIconInfo QIconLoader::findIconHelper(const QString &themeName, QString contentDir = contentDirs.at(i) + u'/'; for (int j = 0; j < subDirs.size() ; ++j) { const QIconDirInfo &dirInfo = subDirs.at(j); + if (searchingGenericFallback && + (dirInfo.context == QIconDirInfo::Applications || + dirInfo.context == QIconDirInfo::MimeTypes)) + continue; + const QString subDir = contentDir + dirInfo.path + u'/'; const QString pngPath = subDir + pngIconName; if (QFile::exists(pngPath)) { @@ -519,6 +536,7 @@ QThemeIconInfo QIconLoader::findIconHelper(const QString &themeName, break; iconNameFallback.truncate(indexOfDash); + searchingGenericFallback = true; } if (info.entries.empty()) { diff --git a/src/gui/image/qiconloader_p.h b/src/gui/image/qiconloader_p.h index 816fb7708cd..cf42e28a481 100644 --- a/src/gui/image/qiconloader_p.h +++ b/src/gui/image/qiconloader_p.h @@ -38,6 +38,7 @@ class QIconLoader; struct QIconDirInfo { enum Type { Fixed, Scalable, Threshold, Fallback }; + enum Context { UnknownContext, Applications, MimeTypes }; QIconDirInfo(const QString &_path = QString()) : path(_path), size(0), @@ -45,7 +46,8 @@ struct QIconDirInfo minSize(0), threshold(0), scale(1), - type(Threshold) {} + type(Threshold), + context(UnknownContext) {} QString path; short size; short maxSize; @@ -53,6 +55,7 @@ struct QIconDirInfo short threshold; short scale; Type type; + Context context; }; Q_DECLARE_TYPEINFO(QIconDirInfo, Q_RELOCATABLE_TYPE);