summaryrefslogtreecommitdiffstats
path: root/src/gui/image
diff options
context:
space:
mode:
authorAlexander Volkov <avolkov@astralinux.ru>2021-01-24 18:47:38 +0300
committerAxel Spoerl <axel.spoerl@qt.io>2023-12-18 18:29:20 +0000
commite0c435cbfeaf1b82f759910fbf05d13e55d4f95f (patch)
tree2282250d3094351d344930bcff125edb3d26b462 /src/gui/image
parent8dffb3c5e3cf419d8428b09d433d199e5dbff904 (diff)
Don't search more generic icons in Applications and MimeTypes contexts
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" Pick-to: 6.7 6.6 Change-Id: Ia3536141158a4b6c1c4f85db8ad890514cf19e84 Reviewed-by: Axel Spoerl <axel.spoerl@qt.io>
Diffstat (limited to 'src/gui/image')
-rw-r--r--src/gui/image/qiconloader.cpp18
-rw-r--r--src/gui/image/qiconloader_p.h5
2 files changed, 22 insertions, 1 deletions
diff --git a/src/gui/image/qiconloader.cpp b/src/gui/image/qiconloader.cpp
index a597d1e8b6..e02fa73ba8 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 816fb7708c..cf42e28a48 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);