-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathqsettingsmanager.cpp
More file actions
379 lines (293 loc) · 9.95 KB
/
qsettingsmanager.cpp
File metadata and controls
379 lines (293 loc) · 9.95 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
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
#include "mainwindow.h"
#include "qsettingsmanager.h"
#include "stylesheetgenerator.h"
#include <QSettings>
#include <QCoreApplication>
#include <QStandardPaths>
#include <QUuid>
#include <QDateTime>
#include <QDebug>
QSettingsManager::QSettingsManager()
: settings(QString("%1/%2").arg(QStandardPaths::writableLocation(QStandardPaths::DocumentsLocation),"StopwatchSettings.ini"), QSettings::Format::IniFormat)
, SettingsForHotkeyGroup{
"Hotkeys/Reset",
"Hotkeys/Restore",
"Hotkeys/ToggleOnOff"
}
, SettingsForStopwatchGroup{
"Stopwatch/IsEnabled",
"Stopwatch/LastStopwatchPosition",
"Stopwatch/StopwatchBackgroundColor",
"Stopwatch/StopwatchFont",
"Stopwatch/StopwatchFontColor",
"Stopwatch/StopwatchFontSize",
"Stopwatch/StopwatchPausedFontColor",
"Stopwatch/StopwatchResetFontColor",
"Stopwatch/StopwatchBorderColor",
"Stopwatch/StopwatchBorderThickness",
"Stopwatch/StopwatchBackgroundEnabled",
"Stopwatch/StopwatchRainbowModeIndex",
"Stopwatch/StopwatchFormatModeIndex",
"Stopwatch/StopwatchGradientOneColor",
"Stopwatch/StopwatchGradientTwoColor",
"Stopwatch/StopwatchGradientEnabled",
}
, SettingsForClockGroup{
"System-Clock-Module/ClockFont",
"System-Clock-Module/ClockFontSize",
"System-Clock-Module/ClockFontColor",
"System-Clock-Module/ClockBackgroundColor",
"System-Clock-Module/ClockBackgroundEnabled",
"System-Clock-Module/ClockRainbowModeIndex",
"System-Clock-Module/IsClockEnabled",
"System-Clock-Module/LastClockPosition",
"System-Clock-Module/IsFontSyncedWithStopwatch"}
, SettingsForLoggingGroup{
"Network/UUID",
"Network/LastPingUnix",
"Network/LastUpdateCheckUnix"}
{
setValue("Application", "Version", QString("%1").arg(QCoreApplication::applicationVersion()));
}
void QSettingsManager::setValue(QString groupName, QString valueName, QString value)
{
settings.setValue(QString("%1/%2").arg(groupName, valueName), value);
}
void QSettingsManager::setValue(SettingsForStopwatchGroupIndex e, QString value)
{
settings.setValue(QString("%1").arg(SettingsForStopwatchGroup[e]), value);
}
void QSettingsManager::setValue(SettingsForHotkeyGroupIndex e, QVariantList value)
{
settings.setValue(QString("%1").arg(SettingsForHotkeyGroup[e]), value);
}
void QSettingsManager::setValue(SettingsForHotkeyGroupIndex e, QString value)
{
settings.setValue(QString("%1").arg(SettingsForHotkeyGroup[e]), value);
}
void QSettingsManager::setValue(SettingsForClockGroupIndex e, QString value)
{
settings.setValue(QString("%1").arg(SettingsForClockGroup[e]), value);
}
void QSettingsManager::setValue(Logging e, QVariant value)
{
settings.setValue(QString("%1").arg(SettingsForLoggingGroup[e]), value);
}
const QVariant QSettingsManager::getValue(SettingsForClockGroupIndex e, bool shouldDefaultBeInteger)
{
return settings.value(SettingsForClockGroup[e], false);
}
const QVariant QSettingsManager::getValue(enum Logging e)
{
return settings.value(SettingsForLoggingGroup[e], false);
}
const QVariant QSettingsManager::getValue(enum SettingsForHotkeyGroupIndex e)
{
return settings.value(SettingsForHotkeyGroup[e],false);
}
const QVariant QSettingsManager::getValue(enum SettingsForStopwatchGroupIndex e, bool shouldDefaultBeInteger)
{
if (shouldDefaultBeInteger)
return settings.value(SettingsForStopwatchGroup[e], -1);
return settings.value(SettingsForStopwatchGroup[e], false);
}
const QVariant QSettingsManager::getValue(QString groupName, QString valueName)
{
return settings.value(QString("%1/%2").arg(groupName, valueName),false);
}
bool QSettingsManager::FetchIsStopwatchEnabled()
{
QVariant val = getValue(IsStopwatchEnabled, true);
if (val == -1) return true;
else return val.toBool();
}
bool QSettingsManager::FetchIsGradientEnabled()
{
QVariant val = getValue(StopwatchGradientEnabled, true);
if (val == -1) return true;
else return val.toBool();
}
QString QSettingsManager::FetchStopwatchFontColor()
{
QVariant val = getValue(StopwatchFontColor);
if (val == false) return StylesheetGenerator::DefaultFontHexColor;
else return val.toString();
}
QString QSettingsManager::FetchPausedStopwatchFontColor()
{
QVariant val = getValue(StopwatchPausedFontColor);
if (val == false) return StylesheetGenerator::DefaultPausedFontHexColor;
else return val.toString();
}
QString QSettingsManager::FetchResetStopwatchFontColor()
{
QVariant val = getValue(StopwatchResetFontColor);
if (val == false) return StylesheetGenerator::DefaultPausedFontHexColor;
else return val.toString();
}
QString QSettingsManager::FetchGradientOneFontColor()
{
QVariant val = getValue(StopwatchGradientOneColor);
if (val == false) return StylesheetGenerator::DefaultGradientOneFontHexColor;
else return val.toString();
}
QString QSettingsManager::FetchGradientTwoFontColor()
{
QVariant val = getValue(StopwatchGradientTwoColor);
if (val == false) return StylesheetGenerator::DefaultGradientTwoFontHexColor;
else return val.toString();
}
QString QSettingsManager::FetchStopwatchBackgroundColor()
{
QVariant val = getValue(StopwatchBackgroundColor);
if (val == false) return StylesheetGenerator::DefaultStopwatchBackground;
else return val.toString();
}
QString QSettingsManager::FetchStopwatchBorderColor()
{
QVariant val = getValue(StopwatchBorderColor);
if (val == false) return StylesheetGenerator::DefaultStopwatchBorderColor;
else return val.toString();
}
QString QSettingsManager::FetchStopwatchBorderWidth()
{
QVariant val = getValue(StopwatchBorderThickness);
if (val == false) return StylesheetGenerator::DefaultStopwatchBorderWidth;
else return val.toString();
}
int QSettingsManager::FetchStopwatchRainbowModeIndex()
{
QVariant val = getValue(StopwatchRainbowModeIndex);
if (val == false) return 0;
else return val.toInt();
}
int QSettingsManager::FetchClockRainbowModeIndex()
{
QVariant val = getValue(ClockRainbowModeIndex);
if (val == false) return 0;
else return val.toInt();
}
StopwatchManager::FormatModes QSettingsManager::FetchStopwatchFormatMode()
{
QVariant val = getValue(StopwatchFormatModeIndex);
if (val == false) return StopwatchManager::HourMinuteSecond;
else return static_cast<StopwatchManager::FormatModes>(val.toInt());
}
bool QSettingsManager::FetchIsBackgroundEnabled()
{
QVariant val = getValue(StopwatchBackgroundEnabled, true);
if (val == -1) return true;
else return val.toBool();
}
bool QSettingsManager::FetchIsClockBackgroundEnabled()
{
QVariant val = getValue(ClockBackgroundEnabled, true);
if (val == -1) return true;
else return val.toBool();
}
QString QSettingsManager::FetchStopwatchFont()
{
QVariant val = getValue(StopwatchFont);
if (val == false) return StylesheetGenerator::DefaultFont.toString();
else return val.toString();
}
int QSettingsManager::FetchStopwatchFontSize()
{
QVariant val = getValue(StopwatchFontSize);
if (val == false) return 24;
else return val.toInt();
}
int QSettingsManager::FetchClockFontSize()
{
QVariant val = getValue(ClockFontSize);
if (val == false) return 24;
else return val.toInt();
}
QString QSettingsManager::FetchClockFont()
{
QVariant val = getValue(ClockFont);
if (val == false) return StylesheetGenerator::DefaultFont.toString();
else return val.toString();
}
QString QSettingsManager::FetchClockFontColor()
{
QVariant val = getValue(ClockFontColor);
if (val == false) return StylesheetGenerator::DefaultFontHexColor;
else return val.toString();
}
QString QSettingsManager::FetchClockBackgroundColor()
{
QVariant val = getValue(ClockBackgroundColor);
if (val == false) return StylesheetGenerator::DefaultFontHexColor;
else return val.toString();
}
QPair<float,float> QSettingsManager::FetchStopwatchLastPosition()
{
QVariant val = getValue(LastStopwatchPosition);
if (val == false) return QPair<float,float>(0,0);
QStringList pos = val.toString().split(",");
float x = pos[0].toFloat();
float y = pos[1].toFloat();
return QPair<float,float>(x,y);
}
QPair<float,float> QSettingsManager::FetchSystemClockLastPosition()
{
QVariant val = getValue(LastClockPosition);
if (val == false) return QPair<float,float>(0,100);
QStringList pos = val.toString().split(",");
float x = pos[0].toFloat();
float y = pos[1].toFloat();
return QPair<float,float>(x,y);
}
bool QSettingsManager::CheckIfClockEnabled()
{
QVariant val = getValue(IsClockEnabled, true);
if (val == -1) return true;
else return val.toBool();
}
QString QSettingsManager::FetchUUID()
{
QVariant val = getValue(UUID);
if (val == false) return GenerateUUID();
else return val.toString();
}
int QSettingsManager::FetchLastPingUnix()
{
QVariant val = getValue(LastPingUnix);
if (val == false) return 0;
else return val.toInt();
}
int QSettingsManager::FetchLastUpdateCheckUnix()
{
QVariant val = getValue(LastUpdateCheckUnix);
if (val == false) return 0;
else return val.toInt();
}
bool QSettingsManager::ShouldPostPing()
{
qint64 last = FetchLastPingUnix();
qint64 now = QDateTime::currentSecsSinceEpoch();
return (now - last) > MinutesToSeconds(720);
}
bool QSettingsManager::ShouldCheckUpdate()
{
qint64 last = FetchLastUpdateCheckUnix();
qint64 now = QDateTime::currentSecsSinceEpoch();
return (now - last) > MinutesToSeconds(720);
}
qint64 QSettingsManager::MinutesToSeconds(int minutes)
{
return static_cast<qint64>(minutes) * 60;
}
bool QSettingsManager::FetchIsClockFontSynced()
{
QVariant val = getValue(IsSyncedFontEnabled);
if (val == false) return 0;
else return val.toInt();
}
QString QSettingsManager::GenerateUUID()
{
auto uuid = QUuid::createUuid().toString(QUuid::WithoutBraces).toLower();
setValue(UUID, uuid);
return uuid;
}