-
Notifications
You must be signed in to change notification settings - Fork 3
/
settings.cpp
51 lines (43 loc) · 1.18 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
50
51
#include "settings.h"
#include <QSettings>
#include <QDebug>
#define KEY_EFFECTS "EnableEffects"
Settings::Settings(QObject *parent) : QObject(parent)
{
}
void Settings::setValue(Key key, QVariant value)
{
QSettings settings;
QString keyString;
switch(key) {
case EnableEffects:
keyString = KEY_EFFECTS;
break;
default:
qWarning() << Q_FUNC_INFO << "invalid key" << key;
return;
}
settings.setValue(keyString, value);
}
QVariant Settings::getValue(Settings::Key key, QVariant defaultValue)
{
QSettings settings;
QString keyString;
switch(key) {
case EnableEffects:
keyString = KEY_EFFECTS;
break;
default:
qWarning() << Q_FUNC_INFO << "invalid key" << key;
return QVariant();
}
QVariant value = settings.value(keyString, defaultValue);
// Ugly hack because QSettings doesn't store type info,
// and returns stored bools as strings.
// Javascript in turn implicitly converts all non-empty strings to boolean true
// Fuck you very much
if (value.toString() == "true" || value.toString() == "false") {
return value.toBool();
}
return value;
}