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.6
Change-Id: Ia3536141158a4b6c1c4f85db8ad890514cf19e84
Reviewed-by: Axel Spoerl <axel.spoerl@qt.io>
(cherry picked from commit e0c435cbfeaf1b82f759910fbf05d13e55d4f95f)
Reviewed-by: Qt Cherry-pick Bot <cherrypick_bot@qt-project.org>
This commit is contained in:
Alexander Volkov 2021-01-24 18:47:38 +03:00 committed by Qt Cherry-pick Bot
parent 364bffd2c4
commit 79aa84aec2
2 changed files with 22 additions and 1 deletions

View File

@ -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()) {

View File

@ -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);