-
Notifications
You must be signed in to change notification settings - Fork 6
/
SettingsManager.cc
156 lines (134 loc) · 4.33 KB
/
SettingsManager.cc
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
#include <QFile>
#include <QDir>
#include <QCoreApplication>
#include <SettingsManager.hpp>
static bool getBool(const QSettings &settings, const QString &key) {
return settings.value(key).toBool();
}
SettingsManager::SettingsManager(QObject *parent)
: QObject(parent)
{
m_Settings.sync();
b_isDarkMode = getBool(m_Settings, "V2.isDarkMode");
b_allowSystemNotifications = getBool(m_Settings, "V2.isAllowSystemNotifications");
b_RunOnStartup = getBool(m_Settings, "V2.isRunOnStartup");
b_BTEnabled = getBool(m_Settings, "V2.isDecentralizedUpdateEnabled");
b_ProxyEnabled = getBool(m_Settings, "V2.isProxyEnabled");
/// Get Proxy Settings
m_ProxyHost = m_Settings.value("V2.ProxyHost").toString();
m_ProxyPort = m_Settings.value("V2.ProxyPort").toInt();
m_ProxyType = m_Settings.value("V2.ProxyType").toString();
m_ProxyUser = m_Settings.value("V2.ProxyUser").toString();
m_ProxyPass = m_Settings.value("V2.ProxyPass").toString();
/// Setup Desktop Entry for Startup
auto arguments = QCoreApplication::arguments();
m_DesktopEntry = QString::fromUtf8("[Desktop Entry]\n");
m_DesktopEntry += QString::fromUtf8("Name=AppImageUpdater\n");
m_DesktopEntry += QString::fromUtf8("Type=Application\n");
m_DesktopEntry += QString::fromUtf8("Exec=%1 --minimized\n");
m_DesktopEntry += QString::fromUtf8("Terminal=false\n");
m_DesktopEntry = m_DesktopEntry.arg(
QFileInfo(arguments.at(0)).absolutePath() +
QString::fromUtf8("/") +
QFileInfo(arguments.at(0)).fileName());
}
SettingsManager::~SettingsManager()
{
m_Settings.sync();
}
void SettingsManager::setIsDarkMode(bool value) {
b_isDarkMode = value;
m_Settings.setValue("V2.isDarkMode", b_isDarkMode);
emit isDarkModeChanged();
}
bool SettingsManager::isDarkMode() const {
return b_isDarkMode;
}
void SettingsManager::setASN(bool value) {
b_allowSystemNotifications = value;
m_Settings.setValue("V2.isAllowSystemNotifications", b_allowSystemNotifications);
emit isASNChanged();
}
bool SettingsManager::isASN() const {
return b_allowSystemNotifications;
}
void SettingsManager::setStartup(bool value) {
b_RunOnStartup = value;
m_Settings.setValue("V2.isRunOnStartup", b_RunOnStartup);
if(b_RunOnStartup) {
QFile entryFile(
QDir::homePath() +
QString::fromUtf8("/.config/autostart/AppImageUpdater.desktop"));
if(!entryFile.open(QIODevice::WriteOnly)) {
b_RunOnStartup = false;
m_Settings.setValue("V2.isRunOnStartup", false);
return;
}
entryFile.write(m_DesktopEntry.toLatin1());
entryFile.close();
} else {
QFile::remove(
QDir::homePath() +
QString::fromUtf8("/.config/autostart/AppImageUpdater.desktop"));
}
emit startupChanged();
}
bool SettingsManager::isStartup() const {
return b_RunOnStartup;
}
void SettingsManager::setBTEnabled(bool value) {
b_BTEnabled = value;
m_Settings.setValue("V2.isDecentralizedUpdateEnabled", b_BTEnabled);
emit btEnabledChanged();
}
bool SettingsManager::isBTEnabled() const {
return b_BTEnabled;
}
void SettingsManager::setProxyEnabled(bool value) {
b_ProxyEnabled = value;
m_Settings.setValue("V2.isProxyEnabled", b_ProxyEnabled);
emit proxyChanged();
}
bool SettingsManager::isProxyEnabled() const {
return b_ProxyEnabled;
}
void SettingsManager::setProxyHost(const QString &value) {
m_ProxyHost = value;
m_Settings.setValue("V2.ProxyHost", m_ProxyHost);
emit proxyHostChanged();
}
void SettingsManager::setProxyPort(int port) {
m_ProxyPort = port;
m_Settings.setValue("V2.ProxyPort", m_ProxyPort);
emit proxyPortChanged();
}
void SettingsManager::setProxyType(const QString &value) {
m_ProxyType = value;
m_Settings.setValue("V2.ProxyType", value);
emit proxyTypeChanged();
}
void SettingsManager::setProxyUser(const QString &value) {
m_ProxyUser = value;
m_Settings.setValue("V2.ProxyUser", value);
emit proxyUserChanged();
}
void SettingsManager::setProxyPass(const QString &value) {
m_ProxyPass = value;
m_Settings.setValue("V2.ProxyPass", value);
emit proxyPassChanged();
}
QString SettingsManager::getProxyHost() const {
return m_ProxyHost;
}
int SettingsManager::getProxyPort() const {
return m_ProxyPort;
}
QString SettingsManager::getProxyType() const {
return m_ProxyType;
}
QString SettingsManager::getProxyUser() const {
return m_ProxyUser;
}
QString SettingsManager::getProxyPass() const {
return m_ProxyPass;
}