|
| 1 | +#include <QDir> |
| 2 | +#include <QString> |
| 3 | +#include <QStandardPaths> |
| 4 | +#include "find-themes.h" |
| 5 | +#include "log.h" |
| 6 | + |
| 7 | +static bool hasOnlyCursorSubdir(QString path) |
| 8 | +{ |
| 9 | + QStringList entries = QDir(path).entryList(QDir::Dirs | QDir::NoDotAndDotDot); |
| 10 | + return entries.contains("cursors") && entries.length() == 1; |
| 11 | +} |
| 12 | + |
| 13 | +static bool hasCursorSubdir(QString path) |
| 14 | +{ |
| 15 | + QStringList entries = QDir(path).entryList(QDir::Dirs | QDir::NoDotAndDotDot); |
| 16 | + return entries.contains("cursors"); |
| 17 | +} |
| 18 | + |
| 19 | +QStringList findIconThemes(enum lab_icon_theme_type type) |
| 20 | +{ |
| 21 | + QStringList paths; |
| 22 | + |
| 23 | + // Setup paths including |
| 24 | + // - $HOME/.icons |
| 25 | + // - $XDG_DATA_HOME/icons |
| 26 | + // - $XDG_DATA_DIRS/icons |
| 27 | + paths.push_back(QString(qgetenv("HOME") + "/.icons")); |
| 28 | + QStringList standardPaths = |
| 29 | + QStandardPaths::standardLocations(QStandardPaths::GenericDataLocation); |
| 30 | + for (const QString &path : std::as_const(standardPaths)) { |
| 31 | + paths.push_back(QString(path + "/icons")); |
| 32 | + } |
| 33 | + |
| 34 | + // Iterate over paths and use any icon-theme which has more than just a |
| 35 | + // "cursors" subdirectory (because that means it's for cursors only) |
| 36 | + QStringList themes; |
| 37 | + themes.push_front(""); |
| 38 | + themes.push_front("Adwaita"); |
| 39 | + for (const QString &path : std::as_const(paths)) { |
| 40 | + QDir dir(path); |
| 41 | + QStringList entries = dir.entryList(QDir::Dirs | QDir::NoDotAndDotDot); |
| 42 | + for (const QString &entry : std::as_const(entries)) { |
| 43 | + switch (type) { |
| 44 | + case LAB_ICON_THEME_TYPE_ICON: |
| 45 | + if (hasOnlyCursorSubdir(QString(path + "/" + entry))) { |
| 46 | + continue; |
| 47 | + } |
| 48 | + themes.push_back(entry); |
| 49 | + break; |
| 50 | + case LAB_ICON_THEME_TYPE_CURSOR: |
| 51 | + if (hasCursorSubdir(QString(path + "/" + entry))) { |
| 52 | + themes.push_back(entry); |
| 53 | + } |
| 54 | + break; |
| 55 | + default: |
| 56 | + break; |
| 57 | + } |
| 58 | + } |
| 59 | + } |
| 60 | + themes.removeDuplicates(); |
| 61 | + themes.sort(Qt::CaseInsensitive); |
| 62 | + return themes; |
| 63 | +} |
| 64 | + |
| 65 | +static bool hasOpenboxOrLabwcSubdir(QString path) |
| 66 | +{ |
| 67 | + QStringList entries = QDir(path).entryList(QDir::Dirs | QDir::NoDotAndDotDot); |
| 68 | + return entries.contains("openbox-3") || entries.contains("labwc"); |
| 69 | +} |
| 70 | + |
| 71 | +QStringList findLabwcThemes(void) |
| 72 | +{ |
| 73 | + QStringList paths; |
| 74 | + |
| 75 | + paths.push_back(QString(qgetenv("HOME") + "/.themes")); |
| 76 | + QStringList standardPaths = |
| 77 | + QStandardPaths::standardLocations(QStandardPaths::GenericDataLocation); |
| 78 | + for (const QString &path : std::as_const(standardPaths)) { |
| 79 | + paths.push_back(QString(path + "/themes")); |
| 80 | + } |
| 81 | + |
| 82 | + QStringList themes; |
| 83 | + themes.push_front("Adwaita"); |
| 84 | + for (const QString &path : std::as_const(paths)) { |
| 85 | + QDir dir(path); |
| 86 | + QStringList entries = dir.entryList(QDir::Dirs | QDir::NoDotAndDotDot); |
| 87 | + for (const QString &entry : std::as_const(entries)) { |
| 88 | + if (hasOpenboxOrLabwcSubdir(QString(path + "/" + entry))) { |
| 89 | + themes.push_back(entry); |
| 90 | + } |
| 91 | + } |
| 92 | + } |
| 93 | + themes.removeDuplicates(); |
| 94 | + themes.sort(Qt::CaseInsensitive); |
| 95 | + return themes; |
| 96 | +} |
0 commit comments