Skip to content

Commit

Permalink
xdgiconloader: Search for unthemed icons only after the themed ones
Browse files Browse the repository at this point in the history
Unthemed icons should be search only one time, after the hicolor theme.
We are using QIcon::themeSearchPaths() to provide the list of directories
and it doesn't depend on the theme.
  • Loading branch information
luis-pereira committed Apr 12, 2017
1 parent 44cc641 commit bea1939
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 31 deletions.
75 changes: 44 additions & 31 deletions xdgiconloader/xdgiconloader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -432,33 +432,6 @@ QThemeIconInfo XdgIconLoader::findIconHelper(const QString &themeName,
}
}

if (info.entries.isEmpty()) {
// Search for unthemed icons in main dir of search paths
QStringList themeSearchPaths = QIcon::themeSearchPaths();
foreach (QString contentDir, themeSearchPaths) {
QDir currentDir(contentDir);

if (currentDir.exists(iconName + pngext)) {
PixmapEntry *iconEntry = new PixmapEntry;
iconEntry->filename = currentDir.filePath(iconName + pngext);
// Notice we ensure that pixmap entries always come before
// scalable to preserve search order afterwards
info.entries.prepend(iconEntry);
} else if (gSupportsSvg &&
currentDir.exists(iconName + svgext)) {
ScalableEntry *iconEntry = new ScalableEntry;
iconEntry->filename = currentDir.filePath(iconName + svgext);
info.entries.append(iconEntry);
} else if (currentDir.exists(iconName + xpmext)) {
PixmapEntry *iconEntry = new PixmapEntry;
iconEntry->filename = currentDir.filePath(iconName + xpmext);
// Notice we ensure that pixmap entries always come before
// scalable to preserve search order afterwards
info.entries.append(iconEntry);
}
}
}

if (dashFallback && info.entries.isEmpty()) {
// If it's possible - find next fallback for the icon
const int indexOfDash = iconNameFallback.lastIndexOf(QLatin1Char('-'));
Expand All @@ -472,6 +445,41 @@ QThemeIconInfo XdgIconLoader::findIconHelper(const QString &themeName,
return info;
}

QThemeIconInfo XdgIconLoader::unthemedFallback(const QString &iconName) const
{
QThemeIconInfo info;

const QString svgext(QLatin1String(".svg"));
const QString pngext(QLatin1String(".png"));
const QString xpmext(QLatin1String(".xpm"));

// Search for unthemed icons in main dir of search paths
QStringList themeSearchPaths = QIcon::themeSearchPaths();
foreach (QString contentDir, themeSearchPaths) {
QDir currentDir(contentDir);

if (currentDir.exists(iconName + pngext)) {
PixmapEntry *iconEntry = new PixmapEntry;
iconEntry->filename = currentDir.filePath(iconName + pngext);
// Notice we ensure that pixmap entries always come before
// scalable to preserve search order afterwards
info.entries.prepend(iconEntry);
} else if (gSupportsSvg &&
currentDir.exists(iconName + svgext)) {
ScalableEntry *iconEntry = new ScalableEntry;
iconEntry->filename = currentDir.filePath(iconName + svgext);
info.entries.append(iconEntry);
} else if (currentDir.exists(iconName + xpmext)) {
PixmapEntry *iconEntry = new PixmapEntry;
iconEntry->filename = currentDir.filePath(iconName + xpmext);
// Notice we ensure that pixmap entries always come before
// scalable to preserve search order afterwards
info.entries.append(iconEntry);
}
}
return info;
}

QThemeIconInfo XdgIconLoader::pixmapFallback(const QString &iconName) const
{
/*********************************************************************
Expand Down Expand Up @@ -528,11 +536,16 @@ QThemeIconInfo XdgIconLoader::loadIcon(const QString &name) const
if (info.entries.isEmpty()) {
const auto hicolorInfo = findIconHelper(QLatin1String("hicolor"), name, visited, true);
if (hicolorInfo.entries.isEmpty()) {
const auto pixmapInfo = pixmapFallback(name);
if (pixmapInfo.entries.isEmpty()) {
return QThemeIconInfo();
const auto unthemedInfo = unthemedFallback(name);
if (unthemedInfo.entries.isEmpty()) {
const auto pixmapInfo = pixmapFallback(name);
if (pixmapInfo.entries.isEmpty()) {
return QThemeIconInfo();
} else {
return pixmapInfo;
}
} else {
return pixmapInfo;
return unthemedInfo;
}
} else {
return hicolorInfo;
Expand Down
1 change: 1 addition & 0 deletions xdgiconloader/xdgiconloader_p.h
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,7 @@ class XDGICONLOADER_EXPORT XdgIconLoader
const QString &iconName,
QStringList &visited,
bool dashFallback = false) const;
QThemeIconInfo unthemedFallback(const QString &iconName) const;
QThemeIconInfo pixmapFallback(const QString &iconName) const;
mutable QStringList m_iconDirs;
mutable QHash <QString, XdgIconTheme> themeList;
Expand Down

0 comments on commit bea1939

Please sign in to comment.