-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathicontheme.cpp
More file actions
111 lines (101 loc) · 3.47 KB
/
icontheme.cpp
File metadata and controls
111 lines (101 loc) · 3.47 KB
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
#include <QtGlobal>
#include <QDir>
#include <QFileInfo>
#include <QSettings>
#include <QDebug>
#include <QIcon>
#include "icontheme.h"
QStringList IconTheme::base_dirs = QIcon::themeSearchPaths();
IconTheme::IconTheme(const QString &theme_name): theme_name(theme_name)
{
if (theme_name.isNull()) {
return;
}
for (const QString &dir: base_dirs) {
if (!QFileInfo::exists(QString("%1/%2/index.theme").arg(dir).arg(theme_name))) {
continue;
}
base_path = dir + "/" + theme_name;
break;
}
// theme directory not found or doesn't contain index.theme file
if (base_path.isNull()) {
qDebug() << "index.theme not found";
return;
}
QSettings theme_index(base_path + "/index.theme", QSettings::IniFormat);
theme_index.beginGroup("Icon Theme");
display_name = theme_index.value("Name").toString();
parent_themes = theme_index.value("Inherits").toStringList();
QStringList dir_list = theme_index.value("Directories").toStringList();
theme_index.endGroup();
theme_dirs.reserve(dir_list.size());
for (const QString &dir: dir_list) {
theme_index.beginGroup(dir);
int size = theme_index.value("Size", 0).toInt();
QString dir_type = theme_index.value("Type", "Threshold").toString();
Directory::Type type = Directory::Type::Fixed;
if (dir_type == "Scalable") {
type = Directory::Type::Scalable;
} else if (dir_type == "Threshold") {
type = Directory::Type::Threshold;
}
theme_dirs.append(Directory{
size,
theme_index.value("Scale", 1).toInt(),
theme_index.value("Context", "").toString(),
type,
theme_index.value("MaxSize", size).toInt(),
theme_index.value("MinSize", size).toInt(),
theme_index.value("Threshold", 2).toInt(),
dir
});
theme_index.endGroup();
}
// load icons
for (int i = 0, len = theme_dirs.size(); i < len; i++) {
QDir dir(base_path + "/" + theme_dirs[i].path);
for (const QFileInfo &icon: dir.entryInfoList({"*.png", "*.svg", "*.xpm"}, QDir::Files | QDir::Readable)) {
QString icon_name = icon.completeBaseName();
QString ext = icon.suffix();
FileExtension ext_type = FileExtension::XPM;
if (ext == "png")
ext_type = FileExtension::PNG;
else if (ext == "svg")
ext_type = FileExtension::SVG;
theme_icons[icon_name].append({static_cast<uint>(i) , ext_type});
}
}
}
QStringList IconTheme::themes()
{
QSet<QString> themes;
for (QDir dir: base_dirs) {
// skip embedded themes
if (dir.path().startsWith(':'))
continue;
for (const QString& theme: dir.entryList(QDir::Dirs | QDir::Readable |
QDir::NoDotAndDotDot))
{
if (!QFileInfo::exists(dir.filePath(theme + "/index.theme")))
continue;
themes += theme;
}
}
return themes.toList();
}
void IconTheme::add_themes_dir(const QString &path)
{
base_dirs.append(path);
QIcon::setThemeSearchPaths(base_dirs);
}
void IconTheme::add_themes_dirs(const QStringList &paths)
{
base_dirs.append(paths);
QIcon::setThemeSearchPaths(base_dirs);
}
void IconTheme::set_themes_dirs(const QStringList &paths)
{
base_dirs = paths;
QIcon::setThemeSearchPaths(base_dirs);
}