-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathdiconic.cpp
109 lines (95 loc) · 3.39 KB
/
diconic.cpp
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
/*
* This file is part LDA, Library for Deepin Toolkit Addons.
* Some components from this project can include sources.
* If they claim a license, then it is specified as the sources
* can have been modified. They are shown at beginnig of files
* or inclusions (when include is replaced by its content).
*
* Copyright (C) 2020 Nicolas B. @n1coc4cola or N1coc4colA on Github.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
*/
#include "diconic.h"
#include <QDir>
#include <QDirIterator>
#include <DThemeManager>
#include <QDebug>
#include <QIcon>
const QString p_assets = ":/assets/images/";
const QString p_bit = ":/icons/deepin/builtin/texts/";
const QString p_bii = ":/icons/deepin/builtin/icons/";
const QString p_lightI = ":/icons/deepin/builtin/light/icons/";
const QString p_darkI = ":/icons/deepin/builtin/dark/icons/";
const QString p_chameleon = ":/chameleon/";
LDA_BEGIN_NAMESPACE
DIconic::DIconic(QObject *parent) : QObject(parent) {}
DIconic::~DIconic()
{
//QObject::~QObject();
}
QIcon *DIconic::fromString(const QString icon_name, IconScopes scope)
{
QStringList dirs;
switch (scope) {
case (int)IconScopes::Assets: dirs << p_assets; break;
case (int)IconScopes::Chameleon: dirs << p_chameleon; break;
case (int)IconScopes::BuiltInIcon: dirs << p_bii; break;
case (int)IconScopes::BuiltInText: dirs << p_bit; break;
case (int)IconScopes::BuiltIn: dirs << p_bii << p_bit; break;
case (int)IconScopes::Dark: dirs << p_darkI; break;
case (int)IconScopes::Light: dirs << p_lightI; break;
case (int)IconScopes::All: dirs << p_assets << p_lightI << p_darkI << p_bit << p_bii << p_chameleon; break;
}
QIcon missing = QIcon::fromTheme(icon_name, QIcon(":/missing.svg"));
int i = 0;
while (i<dirs.length()) {
QDirIterator *it = new QDirIterator(dirs.at(i), QDirIterator::Subdirectories);
while (it->hasNext()) {
QString path = it->next().toUtf8().data();
if (path == QString(dirs.at(i) + icon_name)) {
return new QIcon(path);
}
//path.~QString();
}
//it->~QDirIterator();
i++;
}
//dirs.~QStringList();
qDebug() << "icon " << icon_name << " notfound.";
return new QIcon(missing);
}
QStringList DIconic::listPaths()
{
QStringList dirs;
dirs << p_assets << p_lightI << p_darkI << p_bit << p_bii << p_chameleon;
return dirs;
}
QStringList DIconic::list()
{
QStringList data;
int i = 0;
QStringList dirs = listPaths();
while (i<dirs.length()) {
QDirIterator *it = new QDirIterator(dirs.at(i), QDirIterator::Subdirectories);
while (it->hasNext()) {
data << it->next();
}
//it->~QDirIterator();
i++;
}
//dirs.~QStringList();
return data;
}
LDA_END_NAMESPACE