-
Notifications
You must be signed in to change notification settings - Fork 0
/
settings.cpp
49 lines (38 loc) · 1.14 KB
/
settings.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
#include <QSettings>
#include <QUrl>
#include <QUrlQuery>
#include <QWebEngineProfile>
#include "settings.h"
#include "constants.h"
namespace SettingsPaths {
QString baseUrlPath = "remit/base_url";
QString authTokenPath = "remit/auth_token";
}
QSettings& getInstance() {
static QSettings instance(Constants::configPath() + "/config.ini", QSettings::IniFormat);
return instance;
}
QUrl Settings::remitUrl() {
QUrlQuery authQueryParams;
authQueryParams.addQueryItem("auth_key", value(SettingsPaths::authTokenPath, "").toString());
auto result = remitBaseUrl();
result.setQuery(authQueryParams);
return result;
}
QUrl Settings::remitBaseUrl() {
return QUrl(value(SettingsPaths::baseUrlPath, "https://example.com/").toString());
}
QUrl Settings::githubUrl() {
return QUrl("https://github.com/");
}
QVariant Settings::value(QAnyStringView key, const QVariant& defaultValue)
{
if(!getInstance().contains(key)) {
getInstance().setValue(key, defaultValue);
}
return getInstance().value(key);
}
void Settings::setValue(QAnyStringView key, const QVariant& value)
{
getInstance().setValue(key, value);
}