-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathwalcolors.cpp
59 lines (43 loc) · 1.4 KB
/
walcolors.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
#include "walcolors.h"
#include "config.h"
WalColors::WalColors()
{
readAndUpdateColors();
}
void WalColors::readAndUpdateColors(){
QJsonObject walColorsJson = readWalColorsJson();
this->wallpaper = walColorsJson.value("wallpaper").toString();
QJsonObject colorObj = walColorsJson.value("colors").toObject();
if(colorObj.size() == 0) {
colors = QStringList(DEFAULT_COLORS);
return;
}
this->colors.clear();
for(int i=0; i<colorObj.size(); i++){
this->colors.push_back(colorObj.value("color" + QString::number(i)).toString());
}
}
void WalColors::updateWalColors(QString theme, QString backend){
QString program = "/usr/bin/wal";
QStringList arguments;
QProcess *wal = new QProcess();
arguments << "--backend" << backend;
arguments << "-i" << wallpaper;
if(theme == LIGHT_THEME_CODE){
arguments << "-l";
}
wal->start(program, arguments);
wal->waitForFinished();
readAndUpdateColors();
}
QJsonObject WalColors::readWalColorsJson()
{
QFile file(QDir::homePath() + QString(WAL_COLORS_JSON_FILE_NAME));
file.open(QIODevice::ReadOnly | QIODevice::Text);
QString val = file.readAll();
file.close();
QJsonDocument d = QJsonDocument::fromJson(val.toUtf8());
return d.object();
}
QStringList WalColors::getColors(){ return this->colors; }
QString WalColors::getWallpaper(){ return this->wallpaper; }