-
Notifications
You must be signed in to change notification settings - Fork 26
/
Copy pathsettings.cpp
111 lines (84 loc) · 2.26 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
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
#include <QtCore>
#include "settings.h"
class SettingsPrivate
{
public:
QSettings *settings;
QMap<QString, QString> translations;
QHash<QString, QVariant> defaultValues;
};
/*******************************************************/
Settings::Settings()
{
d = new SettingsPrivate;
addDefaultValues();
d->settings = new QSettings(QSettings::IniFormat,
QSettings::UserScope,
QCoreApplication::organizationName(),
QCoreApplication::applicationName());
qDebug("Configuration file: %s", qPrintable(d->settings->fileName()));
d->settings->setFallbacksEnabled(false);
}
void Settings::addDefaultValues()
{
QHash<QString, QVariant> defaultValues;
defaultValues.insert(SETTING_SKIP_TAGGED, false);
defaultValues.insert(SETTING_MOVE_UNTAGGED, false);
defaultValues.insert(SETTING_TOOLTIPS, true);
addDefaultValues(defaultValues);
}
void Settings::addDefaultValues(const QHash<QString, QVariant> &defaultValues)
{
QHash<QString, QVariant>::const_iterator itEnd = defaultValues.end();
for(QHash<QString, QVariant>::const_iterator it = defaultValues.begin();it != itEnd;++it)
{
d->defaultValues.insert(it.key(), it.value());
}
}
void Settings::fillTranslations()
{
d->translations.insert("en", "English");
// http://www.loc.gov/standards/iso639-2/php/code_list.php
// currently nothing to add
}
Settings::~Settings()
{
delete d->settings;
delete d;
}
QVariant Settings::defaultValue(const QString &key) const
{
return d->defaultValues.value(key);
}
void Settings::remove(const QString &key, Settings::SyncType sync)
{
QSettings *s = settings();
s->beginGroup("settings");
s->remove(key);
s->endGroup();
if(sync == Sync)
s->sync();
}
void Settings::sync()
{
d->settings->sync();
}
QMap<QString, QString> Settings::translations()
{
if(d->translations.isEmpty())
fillTranslations();
return d->translations;
}
Settings* Settings::instance()
{
static Settings *inst = new Settings;
return inst;
}
QHash<QString, QVariant>& Settings::defaultValues()
{
return d->defaultValues;
}
QSettings *Settings::settings() const
{
return d->settings;
}