23 #include "main.h" |
23 #include "main.h" |
24 #include "config.h" |
24 #include "config.h" |
25 |
25 |
26 typedef QMap<QString, QVariant> DefaultsMap; |
26 typedef QMap<QString, QVariant> DefaultsMap; |
27 |
27 |
|
28 // |
|
29 // ------------------------------------------------------------------------------------------------- |
|
30 // |
|
31 |
28 static QSettings* getSettingsObject() |
32 static QSettings* getSettingsObject() |
29 { |
33 { |
30 return new QSettings; |
34 return new QSettings; |
31 } |
35 } |
|
36 |
|
37 // |
|
38 // ------------------------------------------------------------------------------------------------- |
|
39 // |
32 |
40 |
33 static DefaultsMap& getDefaults() |
41 static DefaultsMap& getDefaults() |
34 { |
42 { |
35 static DefaultsMap defaults; |
43 static DefaultsMap defaults; |
36 |
44 |
40 } |
48 } |
41 |
49 |
42 return defaults; |
50 return defaults; |
43 } |
51 } |
44 |
52 |
|
53 // |
|
54 // ------------------------------------------------------------------------------------------------- |
|
55 // |
|
56 |
45 void Config::reset() |
57 void Config::reset() |
46 { |
58 { |
47 DefaultsMap& defaults = getDefaults(); |
59 DefaultsMap& defaults = getDefaults(); |
48 |
60 |
49 for (DefaultsMap::iterator it = defaults.begin(); it != defaults.end(); ++it) |
61 for (DefaultsMap::iterator it = defaults.begin(); it != defaults.end(); ++it) |
50 set (it.key(), it.value()); |
62 set (it.key(), it.value()); |
51 } |
63 } |
|
64 |
|
65 // |
|
66 // ------------------------------------------------------------------------------------------------- |
|
67 // |
52 |
68 |
53 QVariant Config::get (const QString& name) |
69 QVariant Config::get (const QString& name) |
54 { |
70 { |
55 QSettings* settings = getSettingsObject(); |
71 QSettings* settings = getSettingsObject(); |
56 DefaultsMap& defaults = getDefaults(); |
72 DefaultsMap& defaults = getDefaults(); |
59 QVariant value = settings->value (name, def); |
75 QVariant value = settings->value (name, def); |
60 settings->deleteLater(); |
76 settings->deleteLater(); |
61 return value; |
77 return value; |
62 } |
78 } |
63 |
79 |
|
80 // |
|
81 // ------------------------------------------------------------------------------------------------- |
|
82 // |
|
83 |
64 bool Config::set (const QString& name, const QVariant& value) |
84 bool Config::set (const QString& name, const QVariant& value) |
65 { |
85 { |
66 QSettings* settings = getSettingsObject(); |
86 QSettings* settings = getSettingsObject(); |
67 settings->setValue (name, value); |
87 settings->setValue (name, value); |
68 settings->deleteLater(); |
88 settings->deleteLater(); |
69 return settings->status() == QSettings::NoError; |
89 return settings->status() == QSettings::NoError; |
70 } |
90 } |
|
91 |
|
92 // |
|
93 // ------------------------------------------------------------------------------------------------- |
|
94 // |
|
95 |
|
96 void Config::sync() |
|
97 { |
|
98 QSettings* settings = getSettingsObject(); |
|
99 settings->sync(); |
|
100 settings->deleteLater(); |
|
101 } |