-
Notifications
You must be signed in to change notification settings - Fork 0
/
configman.cpp
128 lines (110 loc) · 5.05 KB
/
configman.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
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
#include "configman.h"
void ConfigManager::readConfig() {
QString configPath = QDir::homePath() + "/.config/plainDE/config.json";
if (!QFile::exists(configPath)) {
qDebug() << "~/.config/plainDE/config.json does not exist. "
"Generating new config...";
system("python3 /usr/share/plainDE/tools/genconfig.py");
}
else {
system("python3 /usr/share/plainDE/tools/update-config.py");
}
QFile file(configPath);
file.open(QIODevice::ReadOnly | QIODevice::Text);
QString data = file.readAll();
file.close();
mConfigObj = QJsonDocument::fromJson(data.toUtf8()).object();
}
void ConfigManager::setFields() {
// General settings
mAccent = mConfigObj["accent"].toString();
mAvatar = mConfigObj["avatar"].toString();
mIconTheme = mConfigObj["iconTheme"].toString();
mStylesheet = mConfigObj["theme"].toString();
mTransparent = mStylesheet.contains("transparent");
mCountPanels = mConfigObj["countPanels"].toInt();
mEnableAnimation = mConfigObj["enableAnimation"].toBool();
mSecondsUntilPowerOff = mConfigObj["secondsUntilPowerOff"].toInt();
// Font
mFontFamily = mConfigObj["fontFamily"].toString();
mFontSize = mConfigObj["fontSize"].toInt();
mFont = QFont(mFontFamily, mFontSize);
// App Menu applet settings
mFavApps = mConfigObj["favApps"].toArray();
mMenuIcon = mConfigObj["menuIcon"].toString();
mMenuText = mConfigObj["menuText"].toString();
mMenuIconSize = mConfigObj["menuIconSize"].toInt();
mUseTriangularTabs = mConfigObj["useTriangularTabs"].toBool();
// Date & Time applet settings
mDateFormat = mConfigObj["dateFormat"].toString();
mTimeFormat = mConfigObj["timeFormat"].toString();
// https://code.woboq.org/qt5/qtbase/src/corelib/global/qnamespace.h.html#Qt::DayOfWeek
mFirstDayOfWeek = static_cast<Qt::DayOfWeek>(mConfigObj["firstDayOfWeek"].toInt());
mShowDate = mConfigObj["showDate"].toBool();
mShowWeekNumbers = mConfigObj["showWeekNumbers"].toBool();
// Volume applet settings
mEnableOveramplification = mConfigObj["enableOveramplification"].toBool();
bool pulseaudio = !mConfigObj["volumeAdjustMethod"].toString().compare("PulseAudio");
mVolumeAdjMethod = pulseaudio ? PulseAudio : ALSA;
mDefaultVolume = mConfigObj["defaultVolume"].toInt();
// Keyboard Layout applet settings
mKbToggleMethod = mConfigObj["kbLayoutToggle"].toString();
mKbLayouts = mConfigObj["kbLayouts"].toString();
mUseCountryFlag = mConfigObj["useCountryFlag"].toBool();
// Window List applet settings
mWinListIconSize = mConfigObj["winListIconSize"].toInt();
mWinListShowTitles = mConfigObj["winListShowTitles"].toBool();
// Workspaces applet settings
mShowDesktopNames = mConfigObj["showDesktopNames"].toBool();
// IPv4 applet settings
mNetworkInterface = mConfigObj["ipIfname"].toString();
mIPAddrColor = mConfigObj["ipColor"].toString();
// Sounds
mStartupSound = mConfigObj["logInSound"].toString();
mLogoutSound = mConfigObj["logOutSound"].toString();
// Panels
for (int i = 1; i <= 4; ++i) {
QString currentPanelName = QString("panel%1").arg(QString::number(i));
QJsonObject currentPanelObj = mConfigObj[currentPanelName].toObject();
PanelCfg currentPanel;
if (!mConfigObj[currentPanelName].isNull()) {
currentPanel.applets = currentPanelObj["applets"].toArray();
currentPanel.screen = currentPanelObj["screen"].toString();
currentPanel.backgroundImagePath = currentPanelObj["backgroundImage"].toString();
currentPanel.shift = currentPanelObj["shift"].toInt();
currentPanel.opacity = currentPanelObj["opacity"].toDouble();
currentPanel.margin = currentPanelObj["margin"].toInt();
currentPanel.thickness = currentPanelObj["thickness"].toInt();
currentPanel.launcherIconSize = currentPanelObj["launcherIconSize"].toInt();
currentPanel.expand = currentPanelObj["expand"].toBool();
currentPanel.setOnCenter = currentPanelObj["setOnCenter"].toBool();
currentPanel.spacing = currentPanelObj["spacing"].toInt();
currentPanel.enableAutoHide = currentPanelObj["enableAutoHide"].toBool();
currentPanel.autoHideInterval = currentPanelObj["autoHideInterval"].toInt();
PanelLocation loc;
QString locData = currentPanelObj["location"].toString();
if (!locData.compare("top")) {
loc = Top;
}
else if (!locData.compare("bottom")) {
loc = Bottom;
}
else if (!locData.compare("left")) {
loc = Left;
}
else if (!locData.compare("right")) {
loc = Right;
}
else { // Use 'top' as fallback
loc = Top;
}
currentPanel.location = loc;
}
else {
currentPanel.isNull = true;
}
mPanels.append(currentPanel);
}
}
ConfigManager::ConfigManager() {
}