Commit | Line | Data |
---|---|---|
b2fdd0cf HG |
1 | Taken from nixpkgs, see |
2 | grantleetheme: merge themes across multiple prefixes | |
3 | <https://github.com/NixOS/nixpkgs/commits/master/pkgs/applications/kde/grantleetheme/grantlee-merge-theme-dirs.patch> | |
4 | ||
5 | ||
6 | diff --git a/src/grantleetheme.cpp b/src/grantleetheme.cpp | |
7 | index 27d5bc8..8d43140 100644 | |
8 | --- a/src/grantleetheme.cpp | |
9 | +++ b/src/grantleetheme.cpp | |
10 | @@ -46,7 +46,7 @@ ThemePrivate::ThemePrivate(const ThemePrivate &other) | |
11 | , description(other.description) | |
12 | , name(other.name) | |
13 | , dirName(other.dirName) | |
14 | - , absolutePath(other.absolutePath) | |
15 | + , absolutePaths(other.absolutePaths) | |
16 | , author(other.author) | |
17 | , email(other.email) | |
18 | , loader(other.loader) | |
19 | @@ -64,12 +64,15 @@ void ThemePrivate::setupEngine() | |
20 | ||
21 | void ThemePrivate::setupLoader() | |
22 | { | |
23 | - // Get the parent dir with themes, we set the theme directory separately | |
24 | - QDir dir(absolutePath); | |
25 | - dir.cdUp(); | |
26 | + QStringList templateDirs; | |
27 | + for (const QString& path : absolutePaths) { | |
28 | + QDir dir(path); | |
29 | + dir.cdUp(); | |
30 | + templateDirs << dir.absolutePath(); | |
31 | + } | |
32 | ||
33 | loader = QSharedPointer<GrantleeTheme::QtResourceTemplateLoader>::create(); | |
34 | - loader->setTemplateDirs({ dir.absolutePath() }); | |
35 | + loader->setTemplateDirs(templateDirs); | |
36 | loader->setTheme(dirName); | |
37 | ||
38 | if (!sEngine) { | |
39 | @@ -121,7 +124,7 @@ Theme::Theme(const QString &themePath, const QString &dirName, const QString &de | |
40 | KConfigGroup group(&config, QStringLiteral("Desktop Entry")); | |
41 | if (group.isValid()) { | |
42 | d->dirName = dirName; | |
43 | - d->absolutePath = themePath; | |
44 | + d->absolutePaths = QStringList(themePath); | |
45 | d->name = group.readEntry("Name", QString()); | |
46 | d->description = group.readEntry("Description", QString()); | |
47 | d->themeFileName = group.readEntry("FileName", QString()); | |
48 | @@ -140,7 +143,7 @@ Theme::~Theme() | |
49 | ||
50 | bool Theme::operator==(const Theme &other) const | |
51 | { | |
52 | - return isValid() && other.isValid() && d->absolutePath == other.absolutePath(); | |
53 | + return isValid() && other.isValid() && d->absolutePaths == other.absolutePaths(); | |
54 | } | |
55 | ||
56 | Theme &Theme::operator=(const Theme &other) | |
57 | @@ -184,7 +187,15 @@ QString Theme::dirName() const | |
58 | ||
59 | QString Theme::absolutePath() const | |
60 | { | |
61 | - return d->absolutePath; | |
62 | + if (! d->absolutePaths.isEmpty()) { | |
63 | + return d->absolutePaths.first(); | |
64 | + }; | |
65 | + return QString(); | |
66 | +} | |
67 | + | |
68 | +QStringList Theme::absolutePaths() const | |
69 | +{ | |
70 | + return d->absolutePaths; | |
71 | } | |
72 | ||
73 | QString Theme::author() const | |
74 | @@ -223,6 +231,13 @@ QString Theme::render(const QString &templateName, const QVariantHash &data, con | |
75 | return result; | |
76 | } | |
77 | ||
78 | +void Theme::addThemeDir(const QString& path) | |
79 | +{ | |
80 | + QDir dir(path); | |
81 | + dir.cdUp(); | |
82 | + d->absolutePaths << dir.absolutePath(); | |
83 | +} | |
84 | + | |
85 | void Theme::addPluginPath(const QString &path) | |
86 | { | |
87 | if (!ThemePrivate::sEngine) { | |
88 | diff --git a/src/grantleetheme.h b/src/grantleetheme.h | |
89 | index a25c27b..be38299 100644 | |
90 | --- a/src/grantleetheme.h | |
91 | +++ b/src/grantleetheme.h | |
92 | @@ -48,11 +48,14 @@ public: | |
93 | Q_REQUIRED_RESULT QStringList displayExtraVariables() const; | |
94 | Q_REQUIRED_RESULT QString dirName() const; | |
95 | Q_REQUIRED_RESULT QString absolutePath() const; | |
96 | + Q_REQUIRED_RESULT QStringList absolutePaths() const; | |
97 | Q_REQUIRED_RESULT QString author() const; | |
98 | Q_REQUIRED_RESULT QString authorEmail() const; | |
99 | ||
100 | Q_REQUIRED_RESULT QString render(const QString &templateName, const QVariantHash &data, const QByteArray &applicationDomain = QByteArray()); | |
101 | ||
102 | + void addThemeDir(const QString&); | |
103 | + | |
104 | static void addPluginPath(const QString &path); | |
105 | ||
106 | private: | |
107 | diff --git a/src/grantleetheme_p.h b/src/grantleetheme_p.h | |
108 | index eb73dcb..00510e9 100644 | |
109 | --- a/src/grantleetheme_p.h | |
110 | +++ b/src/grantleetheme_p.h | |
111 | @@ -43,7 +43,7 @@ public: | |
112 | QString description; | |
113 | QString name; | |
114 | QString dirName; | |
115 | - QString absolutePath; | |
116 | + QStringList absolutePaths; | |
117 | QString author; | |
118 | QString email; | |
119 | ||
120 | diff --git a/src/grantleethememanager.cpp b/src/grantleethememanager.cpp | |
121 | index 606d717..dc99041 100644 | |
122 | --- a/src/grantleethememanager.cpp | |
123 | +++ b/src/grantleethememanager.cpp | |
124 | @@ -125,25 +125,18 @@ public: | |
125 | ||
126 | for (const QString &directory : qAsConst(themesDirectories)) { | |
127 | QDirIterator dirIt(directory, QStringList(), QDir::AllDirs | QDir::NoDotAndDotDot); | |
128 | - QStringList alreadyLoadedThemeName; | |
129 | while (dirIt.hasNext()) { | |
130 | dirIt.next(); | |
131 | const QString dirName = dirIt.fileName(); | |
132 | GrantleeTheme::Theme theme = q->loadTheme(dirIt.filePath(), dirName, defaultDesktopFileName); | |
133 | if (theme.isValid()) { | |
134 | QString themeName = theme.name(); | |
135 | - if (alreadyLoadedThemeName.contains(themeName)) { | |
136 | - int i = 2; | |
137 | - const QString originalName(theme.name()); | |
138 | - while (alreadyLoadedThemeName.contains(themeName)) { | |
139 | - themeName = originalName + QStringLiteral(" (%1)").arg(i); | |
140 | - ++i; | |
141 | - } | |
142 | - theme.d->name = themeName; | |
143 | + QMap<QString, GrantleeTheme::Theme>::iterator i = themes.find(dirName); | |
144 | + if (i != themes.end()) { | |
145 | + i.value().addThemeDir(dirIt.filePath()); | |
146 | + } else { | |
147 | + themes.insert(dirName, theme); | |
148 | } | |
149 | - alreadyLoadedThemeName << themeName; | |
150 | - themes.insert(dirName, theme); | |
151 | - //qDebug()<<" theme.name()"<<theme.name(); | |
152 | } | |
153 | } | |
154 | watch->addDir(directory); | |
155 | @@ -366,7 +359,7 @@ QString ThemeManager::pathFromThemes(const QString &themesRelativePath, const QS | |
156 | GrantleeTheme::Theme theme = loadTheme(dirIt.filePath(), dirName, defaultDesktopFileName); | |
157 | if (theme.isValid()) { | |
158 | if (dirName == themeName) { | |
159 | - return theme.absolutePath(); | |
160 | + return theme.absolutePaths().first(); | |
161 | } | |
162 | } | |
163 | } |