-
Notifications
You must be signed in to change notification settings - Fork 7
Expand file tree
/
Copy pathsettings.cpp
More file actions
82 lines (70 loc) · 2.67 KB
/
Copy pathsettings.cpp
File metadata and controls
82 lines (70 loc) · 2.67 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
#include "settings.h"
#include <QFile>
#include <QJsonDocument>
#include <QJsonObject>
Settings::Settings() {}
Settings loadSettingsFromFile(const QString &filePath)
{
Settings s;
QFile file(filePath);
if (file.open(QIODevice::ReadOnly)) {
QByteArray saveData = file.readAll();
file.close();
QJsonDocument doc(QJsonDocument::fromJson(saveData));
QJsonObject json = doc.object();
if (json.contains("runOnStartup")) {
s.runOnstartup = json["runOnStartup"].toBool();
}
if (json.contains("notificationBatteryFull")) {
s.batteryLowThreshold = json["notificationBatteryFull"].toInt();
}
if (json.contains("notificationBatteryLow")) {
s.batteryLowThreshold = json["notificationBatteryLow"].toInt();
}
if (json.contains("audioNotification")) {
s.batteryLowThreshold = json["audioNotification"].toInt();
}
if (json.contains("batteryLowThreshold")) {
s.batteryLowThreshold = json["batteryLowThreshold"].toInt();
}
if (json.contains("msecUpdateIntervalTime")) {
s.msecUpdateIntervalTime = json["msecUpdateIntervalTime"].toInt();
}
if (json.contains("styleName")) {
s.styleName = json["styleName"].toString();
}
if (json.contains("lastSelectedVendorID")) {
s.lastSelectedVendorID = json["lastSelectedVendorID"].toString();
}
if (json.contains("lastSelectedProductID")) {
s.lastSelectedProductID = json["lastSelectedProductID"].toString();
}
qDebug() << "Settings Loaded:\t" << json;
qDebug();
}
return s;
}
void saveSettingstoFile(const Settings &settings, const QString &filePath)
{
QJsonObject json;
json["runOnStartup"] = settings.runOnstartup;
json["notificationBatteryFull"] = settings.notificationBatteryFull;
json["notificationBatteryLow"] = settings.notificationBatteryLow;
json["audioNotification"] = settings.audioNotification;
json["batteryLowThreshold"] = settings.batteryLowThreshold;
json["msecUpdateIntervalTime"] = settings.msecUpdateIntervalTime;
json["styleName"] = settings.styleName;
json["lastSelectedVendorID"] = settings.lastSelectedVendorID;
json["lastSelectedProductID"] = settings.lastSelectedProductID;
QJsonDocument doc(json);
QFile file(filePath);
qDebug() << "Saving settings:";
qDebug() << "Destination:\t" << filePath;
if (!file.open(QIODevice::WriteOnly)) {
qWarning("Error:\tCouldn't open save file.");
}
file.write(doc.toJson());
file.close();
//qDebug() << "Content:\t" << json;
qDebug();
}