~ruther/guix-local

ref: 64668f7c15fa639831209f25e313c99a1047de7b guix-local/gnu/packages/patches/kvantum-1.1.5-xdg-dirs-support.patch -rw-r--r-- 21.0 KiB
64668f7c — Rutherther etc: release: Add spare space to the release VM image. a month ago
                                                                                
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
This patch is copied from
https://github.com/tsujan/Kvantum/commit/01989083f9ee75a013c2654e760efd0a1dea4a68.patch
(URL taken from NixOS).
The author of Kvantum refused to allow searching themes from XDG_DATA_DIRS:
https://github.com/tsujan/Kvantum/issues/210.

From 01989083f9ee75a013c2654e760efd0a1dea4a68 Mon Sep 17 00:00:00 2001
From: Mark Sagi-Kazar <mark.sagikazar@gmail.com>
Date: Fri, 1 Apr 2022 21:10:31 +0200
Subject: [PATCH] wip: add xdg dirs support

Signed-off-by: Mark Sagi-Kazar <mark.sagikazar@gmail.com>
---
 Kvantum/kvantummanager/KvCommand.cpp      |  38 ++++-
 Kvantum/kvantummanager/KvantumManager.cpp |  53 +++++-
 Kvantum/style/Kvantum.cpp                 | 199 +++++++++++++++-------
 3 files changed, 224 insertions(+), 66 deletions(-)

diff --git a/Kvantum/kvantummanager/KvCommand.cpp b/Kvantum/kvantummanager/KvCommand.cpp
index 8dd20820..481ed74b 100644
--- a/Kvantum/kvantummanager/KvCommand.cpp
+++ b/Kvantum/kvantummanager/KvCommand.cpp
@@ -18,6 +18,7 @@
 #include "KvCommand.h"
 #include <QDir>
 #include <QSettings>
+#include <QStandardPaths>
 
 namespace KvManager {
 
@@ -148,6 +149,36 @@ static const QStringList getAllThemes()
 
     /* now add the root themes */
     QStringList rootList;
+    const QStringList xdgKvantumDirs = QStandardPaths::locateAll(QStandardPaths::GenericDataLocation, QString("Kvantum"), QStandardPaths::LocateDirectory);
+    for (const QString &xdgKvantumDir : xdgKvantumDirs)
+    {
+      kv = QDir(xdgKvantumDir);
+      if (kv.exists())
+      {
+          const QStringList folders = kv.entryList (QDir::Dirs | QDir::NoDotAndDotDot, QDir::Name);
+          for (const QString &folder : folders)
+          {
+              QString path = QString ("%1/%2").arg (xdgKvantumDir).arg (folder);
+              if (!folder.contains ("#") && isThemeDir (path))
+              {
+                if (!list.contains (folder) // a user theme with the same name takes priority
+                    && !list.contains (folder + "#")
+                    // a root theme inside 'XDG_DATA_DIRS/Kvantum/' with the same name takes priority
+                    && !rootList.contains (folder))
+                {
+                    rootList << folder;
+                }
+                if (isLightWithDarkDir (path)
+                    && !list.contains (folder + "Dark")
+                    && !list.contains (folder + "Dark" + "#")
+                    && !rootList.contains (folder + "Dark"))
+                {
+                    rootList << (folder + "Dark");
+                }
+              }
+          }
+      }
+    }
     kv = QDir (QString (DATADIR) + QString ("/Kvantum"));
     if (kv.exists())
     {
@@ -158,13 +189,16 @@ static const QStringList getAllThemes()
             if (!folder.contains ("#") && isThemeDir (path))
             {
                 if (!list.contains (folder) // a user theme with the same name takes priority
-                    && !list.contains (folder + "#"))
+                    && !list.contains (folder + "#")
+                    // a root theme inside 'XDG_DATA_DIRS/Kvantum/' with the same name takes priority
+                    && !rootList.contains (folder))
                 {
                     rootList << folder;
                 }
                 if (isLightWithDarkDir (path)
                     && !list.contains (folder + "Dark")
-                    && !list.contains (folder + "Dark" + "#"))
+                    && !list.contains (folder + "Dark" + "#")
+                    && !rootList.contains (folder + "Dark"))
                 {
                     rootList << (folder + "Dark");
                 }
diff --git a/Kvantum/kvantummanager/KvantumManager.cpp b/Kvantum/kvantummanager/KvantumManager.cpp
index 958af9ff..a747ff46 100644
--- a/Kvantum/kvantummanager/KvantumManager.cpp
+++ b/Kvantum/kvantummanager/KvantumManager.cpp
@@ -500,6 +500,22 @@ QString KvantumManager::rootThemeDir (const QString &themeName) const
     {
         return QString();
     }
+    // XDG_DATA_DIRS/Kvantum
+    const QStringList xdgKvantumDirs = QStandardPaths::locateAll(QStandardPaths::GenericDataLocation, QString("Kvantum"), QStandardPaths::LocateDirectory);
+    for (const QString &xdgKvantumDir : xdgKvantumDirs)
+    {
+      QString themeDir = QString ("%1/%2").arg (xdgKvantumDir).arg (themeName);
+      if (fileBelongsToThemeDir (themeName, themeDir))
+          return themeDir;
+      QString lightFolder;
+      if (themeName.size() > 4 && themeName.endsWith ("Dark"))
+      {
+          lightFolder = themeName.left (themeName.size() - 4);
+          themeDir = QString ("%1/%2").arg (xdgKvantumDir).arg (lightFolder);
+          if (fileBelongsToThemeDir (themeName, themeDir))
+              return themeDir;
+      }
+    }
     // /usr/share/Kvantum
     QString themeDir = QString (DATADIR) + QString ("/Kvantum/") + themeName;
     if (fileBelongsToThemeDir (themeName, themeDir))
@@ -1968,6 +1984,36 @@ void KvantumManager::updateThemeList (bool updateAppThemes)
 
     /* now add the root themes */
     QStringList rootList;
+    const QStringList xdgKvantumDirs = QStandardPaths::locateAll(QStandardPaths::GenericDataLocation, QString("Kvantum"), QStandardPaths::LocateDirectory);
+    for (const QString &xdgKvantumDir : xdgKvantumDirs)
+    {
+      kv = QDir(xdgKvantumDir);
+      if (kv.exists())
+      {
+          const QStringList folders = kv.entryList (QDir::Dirs | QDir::NoDotAndDotDot, QDir::Name);
+          for (const QString &folder : folders)
+          {
+              QString path = QString ("%1/%2").arg (xdgKvantumDir).arg (folder);
+              if (!folder.contains ("#") && isThemeDir (path))
+              {
+                if (!list.contains (folder) // a user theme with the same name takes priority
+                    && !list.contains (folder + modifiedSuffix_)
+                    // a root theme inside 'DATADIR/Kvantum/' with the same name takes priority
+                    && !rootList.contains (folder))
+                {
+                    rootList.append (folder);
+                }
+                if (isLightWithDarkDir (path)
+                    && !list.contains (folder + "Dark")
+                    && !list.contains (folder + "Dark" + modifiedSuffix_)
+                    && !rootList.contains (folder + "Dark"))
+                {
+                    rootList.append (folder + "Dark");
+                }
+              }
+          }
+      }
+    }
     kv = QDir (QString (DATADIR) + QString ("/Kvantum"));
     if (kv.exists())
     {
@@ -1978,13 +2024,16 @@ void KvantumManager::updateThemeList (bool updateAppThemes)
             if (!folder.contains ("#") && isThemeDir (path))
             {
                 if (!list.contains (folder) // a user theme with the same name takes priority
-                    && !list.contains (folder + modifiedSuffix_))
+                    && !list.contains (folder + modifiedSuffix_)
+                    // a root theme inside 'DATADIR/Kvantum/' with the same name takes priority
+                    && !rootList.contains (folder))
                 {
                     rootList.append (folder);
                 }
                 if (isLightWithDarkDir (path)
                     && !list.contains (folder + "Dark")
-                    && !list.contains (folder + "Dark" + modifiedSuffix_))
+                    && !list.contains (folder + "Dark" + modifiedSuffix_)
+                    && !rootList.contains (folder + "Dark"))
                 {
                     rootList.append (folder + "Dark");
                 }
diff --git a/Kvantum/style/Kvantum.cpp b/Kvantum/style/Kvantum.cpp
index f198187b..f5c2f443 100644
--- a/Kvantum/style/Kvantum.cpp
+++ b/Kvantum/style/Kvantum.cpp
@@ -642,44 +642,68 @@ void Style::setTheme(const QString &baseThemeName, bool useDark)
       else if (userSvg.isEmpty() // otherwise it's a user theme without config file
                && !themeName.endsWith(QLatin1String("#"))) // root theme names can't have the ending "#"
       { // root theme
-        temp = QString(DATADIR)
-               + QString("/Kvantum/%1/%1.kvconfig").arg(themeName);
-        if (QFile::exists(temp))
-          themeSettings_ = new ThemeConfig(temp);
-        else if (!isThemeDir(QString(DATADIR) + "/Kvantum", themeName) // svg shouldn't be found
-                 && isThemeDir(QString(DATADIR) + "/Kvantum", lightName))
+        temp = QString("");
+        const QStringList xdgKvantumDirs = QStandardPaths::locateAll(QStandardPaths::GenericDataLocation, QString("Kvantum"), QStandardPaths::LocateDirectory);
+        for (const QString &xdgKvantumDir : xdgKvantumDirs)
         {
-          temp = QString(DATADIR)
-                 + QString("/Kvantum/%1/%2.kvconfig").arg(lightName).arg(themeName);
-          if (QFile::exists(temp))
+          temp = xdgKvantumDir
+                 + QString("/%1/%1.kvconfig").arg(themeName);
+          if (QFile::exists(temp)) {
             themeSettings_ = new ThemeConfig(temp);
+            break;
+          }
+          else if (!isThemeDir(xdgKvantumDir, themeName) // svg shouldn't be found
+                   && isThemeDir(xdgKvantumDir, lightName))
+          {
+            temp = xdgKvantumDir
+                   + QString("/%1/%2.kvconfig").arg(lightName).arg(themeName);
+            if (QFile::exists(temp)) {
+              themeSettings_ = new ThemeConfig(temp);
+              break;
+            }
+          }
         }
-
         if (!QFile::exists(temp))
         {
           temp = QString(DATADIR)
-                 + QString("/Kvantum/%1/%1.svg").arg(themeName);
-          if (!QFile::exists(temp)) // otherwise the checked root theme was just an SVG image
+                 + QString("/Kvantum/%1/%1.kvconfig").arg(themeName);
+          if (QFile::exists(temp))
+            themeSettings_ = new ThemeConfig(temp);
+          else if (!isThemeDir(QString(DATADIR) + "/Kvantum", themeName) // svg shouldn't be found
+                   && isThemeDir(QString(DATADIR) + "/Kvantum", lightName))
           {
             temp = QString(DATADIR)
-                   + QString("/themes/%1/Kvantum/%1.kvconfig").arg(themeName);
+                   + QString("/Kvantum/%1/%2.kvconfig").arg(lightName).arg(themeName);
             if (QFile::exists(temp))
               themeSettings_ = new ThemeConfig(temp);
           }
 
-          if (!QFile::exists(temp)
-              && !isThemeDir(QString(DATADIR) + "/themes", themeName)
-              && isThemeDir(QString(DATADIR) + "/themes", lightName))
+          if (!QFile::exists(temp))
           {
             temp = QString(DATADIR)
-                   + QString("/Kvantum/%1/%2.svg").arg(lightName).arg(themeName);
-            if (!QFile::exists(temp))
+                   + QString("/Kvantum/%1/%1.svg").arg(themeName);
+            if (!QFile::exists(temp)) // otherwise the checked root theme was just an SVG image
             {
               temp = QString(DATADIR)
-                     + QString("/themes/%1/Kvantum/%2.kvconfig").arg(lightName).arg(themeName);
+                     + QString("/themes/%1/Kvantum/%1.kvconfig").arg(themeName);
               if (QFile::exists(temp))
                 themeSettings_ = new ThemeConfig(temp);
             }
+
+            if (!QFile::exists(temp)
+                && !isThemeDir(QString(DATADIR) + "/themes", themeName)
+                && isThemeDir(QString(DATADIR) + "/themes", lightName))
+            {
+              temp = QString(DATADIR)
+                     + QString("/Kvantum/%1/%2.svg").arg(lightName).arg(themeName);
+              if (!QFile::exists(temp))
+              {
+                temp = QString(DATADIR)
+                       + QString("/themes/%1/Kvantum/%2.kvconfig").arg(lightName).arg(themeName);
+                if (QFile::exists(temp))
+                  themeSettings_ = new ThemeConfig(temp);
+              }
+            }
           }
         }
       }
@@ -697,33 +721,43 @@ void Style::setTheme(const QString &baseThemeName, bool useDark)
         {
           if (userConfig.isEmpty()) // otherwise it's a user theme without SVG image
           { // root theme
-            temp = QString(DATADIR)
-                   + QString("/Kvantum/%1/%1.svg").arg(themeName);
-            if (QFile::exists(temp))
+            temp = QString("");
+            const QStringList xdgKvantumDirs = QStandardPaths::locateAll(QStandardPaths::GenericDataLocation, QString("Kvantum"), QStandardPaths::LocateDirectory);
+            for (const QString &xdgKvantumDir : xdgKvantumDirs)
             {
-              themeRndr_ = new QSvgRenderer();
-              themeRndr_->load(temp);
+              temp = xdgKvantumDir
+                     + QString("/%1/%1.svg").arg(themeName);
+              if (QFile::exists(temp)) {
+                themeRndr_ = new QSvgRenderer();
+                themeRndr_->load(temp);
+                break;
+              }
+              else if (!isThemeDir(xdgKvantumDir, themeName) // svg shouldn't be found
+                       && isThemeDir(xdgKvantumDir, lightName))
+              {
+                temp = xdgKvantumDir
+                       + QString("/%1/%2.svg").arg(lightName).arg(themeName);
+                if (QFile::exists(temp)) {
+                  themeRndr_ = new QSvgRenderer();
+                  themeRndr_->load(temp);
+                  break;
+                }
+              }
             }
-            else if (!isThemeDir(QString(DATADIR) + "/Kvantum", themeName) // config shouldn't be found
-                     && isThemeDir(QString(DATADIR) + "/Kvantum", lightName))
+            if (!QFile::exists(temp))
             {
               temp = QString(DATADIR)
-                     + QString("/Kvantum/%1/%2.svg").arg(lightName).arg(themeName);
+                     + QString("/Kvantum/%1/%1.svg").arg(themeName);
               if (QFile::exists(temp))
               {
                 themeRndr_ = new QSvgRenderer();
                 themeRndr_->load(temp);
               }
-            }
-
-            if (!QFile::exists(temp))
-            {
-              temp = QString(DATADIR)
-                     + QString("/Kvantum/%1/%1.kvconfig").arg(themeName);
-              if (!QFile::exists(temp)) // otherwise the checked root theme was just a config file
+              else if (!isThemeDir(QString(DATADIR) + "/Kvantum", themeName) // config shouldn't be found
+                       && isThemeDir(QString(DATADIR) + "/Kvantum", lightName))
               {
                 temp = QString(DATADIR)
-                       + QString("/themes/%1/Kvantum/%1.svg").arg(themeName);
+                       + QString("/Kvantum/%1/%2.svg").arg(lightName).arg(themeName);
                 if (QFile::exists(temp))
                 {
                   themeRndr_ = new QSvgRenderer();
@@ -731,22 +765,38 @@ void Style::setTheme(const QString &baseThemeName, bool useDark)
                 }
               }
 
-              if (!QFile::exists(temp)
-                  && !isThemeDir(QString(DATADIR) + "/themes", themeName)
-                  && isThemeDir(QString(DATADIR) + "/themes", lightName))
+              if (!QFile::exists(temp))
               {
                 temp = QString(DATADIR)
-                       + QString("/Kvantum/%1/%2.kvconfig").arg(lightName).arg(themeName);
-                if (!QFile::exists(temp))
+                       + QString("/Kvantum/%1/%1.kvconfig").arg(themeName);
+                if (!QFile::exists(temp)) // otherwise the checked root theme was just a config file
                 {
                   temp = QString(DATADIR)
-                         + QString("/themes/%1/Kvantum/%2.svg").arg(lightName).arg(themeName);
+                         + QString("/themes/%1/Kvantum/%1.svg").arg(themeName);
                   if (QFile::exists(temp))
                   {
                     themeRndr_ = new QSvgRenderer();
                     themeRndr_->load(temp);
                   }
                 }
+
+                if (!QFile::exists(temp)
+                    && !isThemeDir(QString(DATADIR) + "/themes", themeName)
+                    && isThemeDir(QString(DATADIR) + "/themes", lightName))
+                {
+                  temp = QString(DATADIR)
+                         + QString("/Kvantum/%1/%2.kvconfig").arg(lightName).arg(themeName);
+                  if (!QFile::exists(temp))
+                  {
+                    temp = QString(DATADIR)
+                           + QString("/themes/%1/Kvantum/%2.svg").arg(lightName).arg(themeName);
+                    if (QFile::exists(temp))
+                    {
+                      themeRndr_ = new QSvgRenderer();
+                      themeRndr_->load(temp);
+                    }
+                  }
+                }
               }
             }
           }
@@ -756,32 +806,41 @@ void Style::setTheme(const QString &baseThemeName, bool useDark)
           QString _themeName = themeName.left(themeName.length() - 1);
           if (!_themeName.isEmpty() && !_themeName.contains(QLatin1String("#")))
           {
-            temp = QString(DATADIR)
-                   + QString("/Kvantum/%1/%1.svg").arg(_themeName);
-            if (QFile::exists(temp))
+            temp = QString("");
+            const QStringList xdgKvantumDirs = QStandardPaths::locateAll(QStandardPaths::GenericDataLocation, QString("Kvantum"), QStandardPaths::LocateDirectory);
+            for (const QString &xdgKvantumDir : xdgKvantumDirs)
             {
-              themeRndr_ = new QSvgRenderer();
-              themeRndr_->load(temp);
+              temp = xdgKvantumDir
+                     + QString("/%1/%1.svg").arg(_themeName);
+              if (QFile::exists(temp)) {
+                themeRndr_ = new QSvgRenderer();
+                themeRndr_->load(temp);
+                break;
+              }
+              else if (isThemeDir(xdgKvantumDir, lightName))
+              {
+                temp = xdgKvantumDir
+                       + QString("/%1/%2.svg").arg(lightName).arg(_themeName);
+                if (QFile::exists(temp)) {
+                  themeRndr_ = new QSvgRenderer();
+                  themeRndr_->load(temp);
+                  break;
+                }
+              }
             }
-            else if (isThemeDir(QString(DATADIR) + "/Kvantum", lightName))
+            if (!QFile::exists(temp))
             {
               temp = QString(DATADIR)
-                     + QString("/Kvantum/%1/%2.svg").arg(lightName).arg(_themeName);
+                     + QString("/Kvantum/%1/%1.svg").arg(_themeName);
               if (QFile::exists(temp))
               {
                 themeRndr_ = new QSvgRenderer();
                 themeRndr_->load(temp);
               }
-            }
-
-            if (!QFile::exists(temp))
-            {
-              temp = QString(DATADIR)
-                     + QString("/Kvantum/%1/%1.kvconfig").arg(_themeName);
-              if (!QFile::exists(temp)) // otherwise the checked root theme was just a config file
+              else if (isThemeDir(QString(DATADIR) + "/Kvantum", lightName))
               {
                 temp = QString(DATADIR)
-                       + QString("/themes/%1/Kvantum/%1.svg").arg(_themeName);
+                       + QString("/Kvantum/%1/%2.svg").arg(lightName).arg(_themeName);
                 if (QFile::exists(temp))
                 {
                   themeRndr_ = new QSvgRenderer();
@@ -789,22 +848,38 @@ void Style::setTheme(const QString &baseThemeName, bool useDark)
                 }
               }
 
-              if (!QFile::exists(temp)
-                  && !isThemeDir(QString(DATADIR) + "/themes", _themeName)
-                  && isThemeDir(QString(DATADIR) + "/themes", lightName))
+              if (!QFile::exists(temp))
               {
                 temp = QString(DATADIR)
-                       + QString("/Kvantum/%1/%2.kvconfig").arg(lightName).arg(_themeName);
-                if (!QFile::exists(temp))
+                       + QString("/Kvantum/%1/%1.kvconfig").arg(_themeName);
+                if (!QFile::exists(temp)) // otherwise the checked root theme was just a config file
                 {
                   temp = QString(DATADIR)
-                         + QString("/themes/%1/Kvantum/%2.svg").arg(lightName).arg(_themeName);
+                         + QString("/themes/%1/Kvantum/%1.svg").arg(_themeName);
                   if (QFile::exists(temp))
                   {
                     themeRndr_ = new QSvgRenderer();
                     themeRndr_->load(temp);
                   }
                 }
+
+                if (!QFile::exists(temp)
+                    && !isThemeDir(QString(DATADIR) + "/themes", _themeName)
+                    && isThemeDir(QString(DATADIR) + "/themes", lightName))
+                {
+                  temp = QString(DATADIR)
+                         + QString("/Kvantum/%1/%2.kvconfig").arg(lightName).arg(_themeName);
+                  if (!QFile::exists(temp))
+                  {
+                    temp = QString(DATADIR)
+                           + QString("/themes/%1/Kvantum/%2.svg").arg(lightName).arg(_themeName);
+                    if (QFile::exists(temp))
+                    {
+                      themeRndr_ = new QSvgRenderer();
+                      themeRndr_->load(temp);
+                    }
+                  }
+                }
               }
             }
           }