Skip to content

Commit

Permalink
Make the default icon theme finding more elaborated
Browse files Browse the repository at this point in the history
  • Loading branch information
probonopd authored Aug 21, 2023
1 parent 6ec88d1 commit 86869b1
Showing 1 changed file with 40 additions and 5 deletions.
45 changes: 40 additions & 5 deletions platformthemeplugin/hintsettings.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
#include <QDBusArgument>
#include <QDBusConnection>
#include <QDBusInterface>
#include <QDirIterator>

static const QByteArray s_systemFontName = QByteArrayLiteral("Font");
static const QByteArray s_systemFixedFontName = QByteArrayLiteral("FixedFont");
Expand All @@ -40,14 +41,21 @@ QString resolveSymlink(const QString &path) {
return path;
}

// The default icon theme can be set by the user, e.g.,
// sudo ln -sf /usr/local/share/icons/elementary-xfce /usr/local/share/icons/default
// or
// sudo ln -sf /usr/share/icons/elementary-xfce /usr/share/icons/default
//
// The XDG icon spec is overly complex and provides no clear way how to find the icon theme
// based on the Name= entry. For example, on Ubuntu, the icon theme for KDE is called "Breeze" in index.theme,
// but the folder is called "breeze".
// So we need to read the icon.theme in each subdirectory of iconThemePath and compare the Name= entry with the themeNameFromFile.
// If it matches, we have found the icon theme. The spec is way too complicated, resulting in precious cycles being
// wasted every time an application starts up and the platform theme is loaded.
HintsSettings::HintsSettings(QObject *parent)
: QObject(parent),
m_settings(new QSettings(QSettings::UserScope, "panda", "theme"))
{
// The default icon theme can be set by the user, e.g.,
// sudo ln -sf /usr/local/share/icons/elementary-xfce /usr/local/share/icons/default
// or
// sudo ln -sf /usr/share/icons/elementary-xfce /usr/share/icons/default

const QStringList iconThemePaths = xdgIconThemePaths();

Expand Down Expand Up @@ -75,7 +83,34 @@ HintsSettings::HintsSettings(QObject *parent)
if (line.startsWith("Name=")) {
qDebug() << "line" << line;
QString themeNameFromFile = line.mid(5); // Remove "Name="
defaultIconTheme = themeNameFromFile;
QDir themesDir(resolveSymlink(iconThemePath));
QDirIterator it(themesDir.path(), QDir::Dirs | QDir::NoDotAndDotDot, QDirIterator::NoIteratorFlags);
while (it.hasNext()) {
QString subDir = it.next();
qDebug() << "subDir" << subDir;
QFile subIndexThemeFile(resolveSymlink(subDir + "/index.theme"));
if (subIndexThemeFile.exists()) {
qDebug() << "subIndexThemeFile" << subIndexThemeFile.fileName();
QFile subFile(subIndexThemeFile.fileName());
if (subFile.open(QIODevice::ReadOnly | QIODevice::Text)) {
QTextStream subIn(&subFile);
while (!subIn.atEnd()) {
QString subLine = subIn.readLine();
if (subLine.startsWith("Name=")) {
qDebug() << "Comparing to" << subLine;
QString themeNameFromSubFile = subLine.mid(5); // Remove "Name="
if (themeNameFromFile == themeNameFromSubFile) {
qDebug() << "Found default icon theme" << themeNameFromFile << "in" << subDir;
defaultIconTheme = themeNameFromSubFile;
break;
}
}
}
}
} else {
qDebug() << "subIndexThemeFile" << subIndexThemeFile.fileName() << "does not exist";
}
}
}
}
}
Expand Down

0 comments on commit 86869b1

Please sign in to comment.