Changeset View
Changeset View
Standalone View
Standalone View
src/kicontheme.cpp
Show All 25 Lines | |||||
26 | #include <qplatformdefs.h> | 26 | #include <qplatformdefs.h> | ||
27 | 27 | | |||
28 | #include <QCoreApplication> | 28 | #include <QCoreApplication> | ||
29 | #include <QAction> | 29 | #include <QAction> | ||
30 | #include <QMap> | 30 | #include <QMap> | ||
31 | #include <QSet> | 31 | #include <QSet> | ||
32 | #include <QFileInfo> | 32 | #include <QFileInfo> | ||
33 | #include <QDir> | 33 | #include <QDir> | ||
34 | #include <QDirIterator> | ||||
34 | #include <QDebug> | 35 | #include <QDebug> | ||
35 | #include <QResource> | 36 | #include <QResource> | ||
36 | 37 | | |||
37 | #include <klocalizedstring.h> // KLocalizedString::localizedFilePath. Need such functionality in, hmm, QLocale? QStandardPaths? | 38 | #include <klocalizedstring.h> // KLocalizedString::localizedFilePath. Need such functionality in, hmm, QLocale? QStandardPaths? | ||
38 | 39 | | |||
39 | #include <ksharedconfig.h> | 40 | #include <ksharedconfig.h> | ||
40 | 41 | | |||
41 | #include <kconfiggroup.h> | 42 | #include <kconfiggroup.h> | ||
42 | #include <cmath> | 43 | #include <cmath> | ||
43 | 44 | | |||
44 | Q_GLOBAL_STATIC(QString, _themeOverride) | 45 | Q_GLOBAL_STATIC(QString, _themeOverride) | ||
45 | 46 | | |||
46 | // Support for icon themes in RCC files. | 47 | // Support for icon themes in RCC files. | ||
47 | // The intended use case is standalone apps on Windows / MacOS / etc. | 48 | // The intended use case is standalone apps on Windows / MacOS / etc. | ||
48 | // For this reason we use AppDataLocation: BINDIR/data on Windows, Resources on OS X | 49 | // For this reason we use AppDataLocation: BINDIR/data on Windows, Resources on OS X | ||
49 | void initRCCIconTheme() | 50 | void initRCCIconTheme() | ||
50 | { | 51 | { | ||
52 | // old variant: one RCC file that will be enforced as icon theme | ||||
53 | // to be compatible: if this succeeds, we don't try the new variant of looking up multiple rcc files! | ||||
51 | const QString iconThemeRcc = QStandardPaths::locate(QStandardPaths::AppDataLocation, QStringLiteral("icontheme.rcc")); | 54 | const QString iconThemeRcc = QStandardPaths::locate(QStandardPaths::AppDataLocation, QStringLiteral("icontheme.rcc")); | ||
52 | if (!iconThemeRcc.isEmpty()) { | 55 | if (!iconThemeRcc.isEmpty()) { | ||
53 | const QString iconThemeName = QStringLiteral("kf5_rcc_theme"); | 56 | const QString iconThemeName = QStringLiteral("kf5_rcc_theme"); | ||
54 | const QString iconSubdir = QStringLiteral("/icons/") + iconThemeName; | 57 | const QString iconSubdir = QStringLiteral("/icons/") + iconThemeName; | ||
55 | if (QResource::registerResource(iconThemeRcc, iconSubdir)) { | 58 | if (QResource::registerResource(iconThemeRcc, iconSubdir)) { | ||
56 | if (QFileInfo::exists(QLatin1Char(':') + iconSubdir + QStringLiteral("/index.theme"))) { | 59 | if (QFileInfo::exists(QLatin1Char(':') + iconSubdir + QStringLiteral("/index.theme"))) { | ||
57 | // Tell Qt about the theme | 60 | // Tell Qt about the theme | ||
58 | // Note that since qtbase commit a8621a3f8, this means the QPA (i.e. KIconLoader) will NOT be used. | 61 | // Note that since qtbase commit a8621a3f8, this means the QPA (i.e. KIconLoader) will NOT be used. | ||
59 | QIcon::setThemeName(iconThemeName); // Qt looks under :/icons automatically | 62 | QIcon::setThemeName(iconThemeName); // Qt looks under :/icons automatically | ||
60 | // Tell KIconTheme about the theme, in case KIconLoader is used directly | 63 | // Tell KIconTheme about the theme, in case KIconLoader is used directly | ||
61 | *_themeOverride() = iconThemeName; | 64 | *_themeOverride() = iconThemeName; | ||
65 | // stop here, we have found a valid rcc that shall be used! | ||||
66 | return; | ||||
62 | } else { | 67 | } else { | ||
63 | qWarning() << "No index.theme found in" << iconThemeRcc; | 68 | qWarning() << "No index.theme found in" << iconThemeRcc; | ||
64 | QResource::unregisterResource(iconThemeRcc, iconSubdir); | 69 | QResource::unregisterResource(iconThemeRcc, iconSubdir); | ||
65 | } | 70 | } | ||
66 | } else { | 71 | } else { | ||
67 | qWarning() << "Invalid rcc file" << iconThemeRcc; | 72 | qWarning() << "Invalid rcc file" << iconThemeRcc; | ||
68 | } | 73 | } | ||
69 | } | 74 | } | ||
75 | | ||||
76 | // new variant: load all rcc files we find, assume the have internally proper :/icons/<theme>/... naming | ||||
77 | // TODO: we might want to use QLibrary and load the stuff as shared libraries to have mmap on all platforms for the data! | ||||
78 | for (const auto &iconDir : QStandardPaths::locateAll(QStandardPaths::AppDataLocation, QStringLiteral("icons"), QStandardPaths::LocateDirectory)) { | ||||
79 | QDirIterator it(iconDir, QStringList() << QLatin1String("*.rcc"), QDir::Files); | ||||
vonreth: I guess we can use an Initializer here | |||||
80 | while (it.hasNext()) { | ||||
81 | const auto iconFile = it.next(); | ||||
82 | if (!QResource::registerResource(iconFile)) { | ||||
83 | qWarning() << "Invalid rcc file" << iconFile; | ||||
84 | } | ||||
85 | } | ||||
86 | } | ||||
70 | } | 87 | } | ||
71 | Q_COREAPP_STARTUP_FUNCTION(initRCCIconTheme) | 88 | Q_COREAPP_STARTUP_FUNCTION(initRCCIconTheme) | ||
72 | 89 | | |||
73 | // Set the icon theme fallback to breeze | 90 | // Set the icon theme fallback to breeze | ||
74 | // Most of our apps use "lots" of icons that most of the times | 91 | // Most of our apps use "lots" of icons that most of the times | ||
75 | // are only available with breeze, we still honour the user icon | 92 | // are only available with breeze, we still honour the user icon | ||
76 | // theme but if the icon is not found there, we go to breeze | 93 | // theme but if the icon is not found there, we go to breeze | ||
77 | // since it's almost sure it'll be there | 94 | // since it's almost sure it'll be there | ||
▲ Show 20 Lines • Show All 736 Lines • Show Last 20 Lines |
I guess we can use an Initializer here