Sat, 06 Jun 2015 22:20:21 +0300
Removed trailing tabs
20
a5457405cc9b
Use the cfg:: namespace system I made up a while ago instead of using QSettings directly, it's unsafe
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
1 | /* |
30
6b82f6a3ad53
renamed the project to ZCinema
Teemu Piippo <crimsondusk64@gmail.com>
parents:
20
diff
changeset
|
2 | * ZCinema: Zandronum demo launcher |
37
c82a86ea87be
Major rework, lots of internal maintenance, version editor removed
Teemu Piippo <crimsondusk64@gmail.com>
parents:
30
diff
changeset
|
3 | * Copyright (C) 2013-2015 Teemu Piippo |
20
a5457405cc9b
Use the cfg:: namespace system I made up a while ago instead of using QSettings directly, it's unsafe
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
4 | * |
a5457405cc9b
Use the cfg:: namespace system I made up a while ago instead of using QSettings directly, it's unsafe
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
5 | * This program is free software: you can redistribute it and/or modify |
a5457405cc9b
Use the cfg:: namespace system I made up a while ago instead of using QSettings directly, it's unsafe
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
6 | * it under the terms of the GNU General Public License as published by |
a5457405cc9b
Use the cfg:: namespace system I made up a while ago instead of using QSettings directly, it's unsafe
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
7 | * the Free Software Foundation, either version 3 of the License, or |
a5457405cc9b
Use the cfg:: namespace system I made up a while ago instead of using QSettings directly, it's unsafe
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
8 | * (at your option) any later version. |
a5457405cc9b
Use the cfg:: namespace system I made up a while ago instead of using QSettings directly, it's unsafe
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
9 | * |
a5457405cc9b
Use the cfg:: namespace system I made up a while ago instead of using QSettings directly, it's unsafe
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
10 | * This program is distributed in the hope that it will be useful, |
a5457405cc9b
Use the cfg:: namespace system I made up a while ago instead of using QSettings directly, it's unsafe
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
a5457405cc9b
Use the cfg:: namespace system I made up a while ago instead of using QSettings directly, it's unsafe
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
a5457405cc9b
Use the cfg:: namespace system I made up a while ago instead of using QSettings directly, it's unsafe
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
13 | * GNU General Public License for more details. |
a5457405cc9b
Use the cfg:: namespace system I made up a while ago instead of using QSettings directly, it's unsafe
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
14 | * |
a5457405cc9b
Use the cfg:: namespace system I made up a while ago instead of using QSettings directly, it's unsafe
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
15 | * You should have received a copy of the GNU General Public License |
a5457405cc9b
Use the cfg:: namespace system I made up a while ago instead of using QSettings directly, it's unsafe
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
16 | * along with this program. If not, see <http://www.gnu.org/licenses/>. |
a5457405cc9b
Use the cfg:: namespace system I made up a while ago instead of using QSettings directly, it's unsafe
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
17 | */ |
a5457405cc9b
Use the cfg:: namespace system I made up a while ago instead of using QSettings directly, it's unsafe
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
18 | |
37
c82a86ea87be
Major rework, lots of internal maintenance, version editor removed
Teemu Piippo <crimsondusk64@gmail.com>
parents:
30
diff
changeset
|
19 | #include <assert.h> |
20
a5457405cc9b
Use the cfg:: namespace system I made up a while ago instead of using QSettings directly, it's unsafe
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
20 | #include <QDir> |
a5457405cc9b
Use the cfg:: namespace system I made up a while ago instead of using QSettings directly, it's unsafe
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
21 | #include <QTextStream> |
a5457405cc9b
Use the cfg:: namespace system I made up a while ago instead of using QSettings directly, it's unsafe
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
22 | #include <QSettings> |
a5457405cc9b
Use the cfg:: namespace system I made up a while ago instead of using QSettings directly, it's unsafe
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
23 | #include "main.h" |
a5457405cc9b
Use the cfg:: namespace system I made up a while ago instead of using QSettings directly, it's unsafe
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
24 | #include "config.h" |
a5457405cc9b
Use the cfg:: namespace system I made up a while ago instead of using QSettings directly, it's unsafe
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
25 | |
37
c82a86ea87be
Major rework, lots of internal maintenance, version editor removed
Teemu Piippo <crimsondusk64@gmail.com>
parents:
30
diff
changeset
|
26 | typedef QMap<QString, QVariant> DefaultsMap; |
c82a86ea87be
Major rework, lots of internal maintenance, version editor removed
Teemu Piippo <crimsondusk64@gmail.com>
parents:
30
diff
changeset
|
27 | |
39
2c368cf5cc19
Finally done with the new Zandronum version handling
Teemu Piippo <crimsondusk64@gmail.com>
parents:
37
diff
changeset
|
28 | // |
2c368cf5cc19
Finally done with the new Zandronum version handling
Teemu Piippo <crimsondusk64@gmail.com>
parents:
37
diff
changeset
|
29 | // ------------------------------------------------------------------------------------------------- |
2c368cf5cc19
Finally done with the new Zandronum version handling
Teemu Piippo <crimsondusk64@gmail.com>
parents:
37
diff
changeset
|
30 | // |
2c368cf5cc19
Finally done with the new Zandronum version handling
Teemu Piippo <crimsondusk64@gmail.com>
parents:
37
diff
changeset
|
31 | |
37
c82a86ea87be
Major rework, lots of internal maintenance, version editor removed
Teemu Piippo <crimsondusk64@gmail.com>
parents:
30
diff
changeset
|
32 | static QSettings* getSettingsObject() |
c82a86ea87be
Major rework, lots of internal maintenance, version editor removed
Teemu Piippo <crimsondusk64@gmail.com>
parents:
30
diff
changeset
|
33 | { |
c82a86ea87be
Major rework, lots of internal maintenance, version editor removed
Teemu Piippo <crimsondusk64@gmail.com>
parents:
30
diff
changeset
|
34 | return new QSettings; |
c82a86ea87be
Major rework, lots of internal maintenance, version editor removed
Teemu Piippo <crimsondusk64@gmail.com>
parents:
30
diff
changeset
|
35 | } |
20
a5457405cc9b
Use the cfg:: namespace system I made up a while ago instead of using QSettings directly, it's unsafe
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
36 | |
39
2c368cf5cc19
Finally done with the new Zandronum version handling
Teemu Piippo <crimsondusk64@gmail.com>
parents:
37
diff
changeset
|
37 | // |
2c368cf5cc19
Finally done with the new Zandronum version handling
Teemu Piippo <crimsondusk64@gmail.com>
parents:
37
diff
changeset
|
38 | // ------------------------------------------------------------------------------------------------- |
2c368cf5cc19
Finally done with the new Zandronum version handling
Teemu Piippo <crimsondusk64@gmail.com>
parents:
37
diff
changeset
|
39 | // |
2c368cf5cc19
Finally done with the new Zandronum version handling
Teemu Piippo <crimsondusk64@gmail.com>
parents:
37
diff
changeset
|
40 | |
37
c82a86ea87be
Major rework, lots of internal maintenance, version editor removed
Teemu Piippo <crimsondusk64@gmail.com>
parents:
30
diff
changeset
|
41 | static DefaultsMap& getDefaults() |
c82a86ea87be
Major rework, lots of internal maintenance, version editor removed
Teemu Piippo <crimsondusk64@gmail.com>
parents:
30
diff
changeset
|
42 | { |
c82a86ea87be
Major rework, lots of internal maintenance, version editor removed
Teemu Piippo <crimsondusk64@gmail.com>
parents:
30
diff
changeset
|
43 | static DefaultsMap defaults; |
c82a86ea87be
Major rework, lots of internal maintenance, version editor removed
Teemu Piippo <crimsondusk64@gmail.com>
parents:
30
diff
changeset
|
44 | |
c82a86ea87be
Major rework, lots of internal maintenance, version editor removed
Teemu Piippo <crimsondusk64@gmail.com>
parents:
30
diff
changeset
|
45 | if (defaults.isEmpty()) |
c82a86ea87be
Major rework, lots of internal maintenance, version editor removed
Teemu Piippo <crimsondusk64@gmail.com>
parents:
30
diff
changeset
|
46 | { |
c82a86ea87be
Major rework, lots of internal maintenance, version editor removed
Teemu Piippo <crimsondusk64@gmail.com>
parents:
30
diff
changeset
|
47 | // Initialize defaults here. |
20
a5457405cc9b
Use the cfg:: namespace system I made up a while ago instead of using QSettings directly, it's unsafe
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
48 | } |
a5457405cc9b
Use the cfg:: namespace system I made up a while ago instead of using QSettings directly, it's unsafe
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
49 | |
37
c82a86ea87be
Major rework, lots of internal maintenance, version editor removed
Teemu Piippo <crimsondusk64@gmail.com>
parents:
30
diff
changeset
|
50 | return defaults; |
c82a86ea87be
Major rework, lots of internal maintenance, version editor removed
Teemu Piippo <crimsondusk64@gmail.com>
parents:
30
diff
changeset
|
51 | } |
c82a86ea87be
Major rework, lots of internal maintenance, version editor removed
Teemu Piippo <crimsondusk64@gmail.com>
parents:
30
diff
changeset
|
52 | |
39
2c368cf5cc19
Finally done with the new Zandronum version handling
Teemu Piippo <crimsondusk64@gmail.com>
parents:
37
diff
changeset
|
53 | // |
2c368cf5cc19
Finally done with the new Zandronum version handling
Teemu Piippo <crimsondusk64@gmail.com>
parents:
37
diff
changeset
|
54 | // ------------------------------------------------------------------------------------------------- |
2c368cf5cc19
Finally done with the new Zandronum version handling
Teemu Piippo <crimsondusk64@gmail.com>
parents:
37
diff
changeset
|
55 | // |
2c368cf5cc19
Finally done with the new Zandronum version handling
Teemu Piippo <crimsondusk64@gmail.com>
parents:
37
diff
changeset
|
56 | |
37
c82a86ea87be
Major rework, lots of internal maintenance, version editor removed
Teemu Piippo <crimsondusk64@gmail.com>
parents:
30
diff
changeset
|
57 | void Config::reset() |
c82a86ea87be
Major rework, lots of internal maintenance, version editor removed
Teemu Piippo <crimsondusk64@gmail.com>
parents:
30
diff
changeset
|
58 | { |
c82a86ea87be
Major rework, lots of internal maintenance, version editor removed
Teemu Piippo <crimsondusk64@gmail.com>
parents:
30
diff
changeset
|
59 | DefaultsMap& defaults = getDefaults(); |
c82a86ea87be
Major rework, lots of internal maintenance, version editor removed
Teemu Piippo <crimsondusk64@gmail.com>
parents:
30
diff
changeset
|
60 | |
c82a86ea87be
Major rework, lots of internal maintenance, version editor removed
Teemu Piippo <crimsondusk64@gmail.com>
parents:
30
diff
changeset
|
61 | for (DefaultsMap::iterator it = defaults.begin(); it != defaults.end(); ++it) |
c82a86ea87be
Major rework, lots of internal maintenance, version editor removed
Teemu Piippo <crimsondusk64@gmail.com>
parents:
30
diff
changeset
|
62 | set (it.key(), it.value()); |
c82a86ea87be
Major rework, lots of internal maintenance, version editor removed
Teemu Piippo <crimsondusk64@gmail.com>
parents:
30
diff
changeset
|
63 | } |
c82a86ea87be
Major rework, lots of internal maintenance, version editor removed
Teemu Piippo <crimsondusk64@gmail.com>
parents:
30
diff
changeset
|
64 | |
39
2c368cf5cc19
Finally done with the new Zandronum version handling
Teemu Piippo <crimsondusk64@gmail.com>
parents:
37
diff
changeset
|
65 | // |
2c368cf5cc19
Finally done with the new Zandronum version handling
Teemu Piippo <crimsondusk64@gmail.com>
parents:
37
diff
changeset
|
66 | // ------------------------------------------------------------------------------------------------- |
2c368cf5cc19
Finally done with the new Zandronum version handling
Teemu Piippo <crimsondusk64@gmail.com>
parents:
37
diff
changeset
|
67 | // |
2c368cf5cc19
Finally done with the new Zandronum version handling
Teemu Piippo <crimsondusk64@gmail.com>
parents:
37
diff
changeset
|
68 | |
37
c82a86ea87be
Major rework, lots of internal maintenance, version editor removed
Teemu Piippo <crimsondusk64@gmail.com>
parents:
30
diff
changeset
|
69 | QVariant Config::get (const QString& name) |
c82a86ea87be
Major rework, lots of internal maintenance, version editor removed
Teemu Piippo <crimsondusk64@gmail.com>
parents:
30
diff
changeset
|
70 | { |
c82a86ea87be
Major rework, lots of internal maintenance, version editor removed
Teemu Piippo <crimsondusk64@gmail.com>
parents:
30
diff
changeset
|
71 | QSettings* settings = getSettingsObject(); |
c82a86ea87be
Major rework, lots of internal maintenance, version editor removed
Teemu Piippo <crimsondusk64@gmail.com>
parents:
30
diff
changeset
|
72 | DefaultsMap& defaults = getDefaults(); |
c82a86ea87be
Major rework, lots of internal maintenance, version editor removed
Teemu Piippo <crimsondusk64@gmail.com>
parents:
30
diff
changeset
|
73 | DefaultsMap::iterator it = defaults.find (name); |
c82a86ea87be
Major rework, lots of internal maintenance, version editor removed
Teemu Piippo <crimsondusk64@gmail.com>
parents:
30
diff
changeset
|
74 | QVariant def = it != defaults.end() ? *it : QVariant(); |
c82a86ea87be
Major rework, lots of internal maintenance, version editor removed
Teemu Piippo <crimsondusk64@gmail.com>
parents:
30
diff
changeset
|
75 | QVariant value = settings->value (name, def); |
c82a86ea87be
Major rework, lots of internal maintenance, version editor removed
Teemu Piippo <crimsondusk64@gmail.com>
parents:
30
diff
changeset
|
76 | settings->deleteLater(); |
c82a86ea87be
Major rework, lots of internal maintenance, version editor removed
Teemu Piippo <crimsondusk64@gmail.com>
parents:
30
diff
changeset
|
77 | return value; |
c82a86ea87be
Major rework, lots of internal maintenance, version editor removed
Teemu Piippo <crimsondusk64@gmail.com>
parents:
30
diff
changeset
|
78 | } |
c82a86ea87be
Major rework, lots of internal maintenance, version editor removed
Teemu Piippo <crimsondusk64@gmail.com>
parents:
30
diff
changeset
|
79 | |
39
2c368cf5cc19
Finally done with the new Zandronum version handling
Teemu Piippo <crimsondusk64@gmail.com>
parents:
37
diff
changeset
|
80 | // |
2c368cf5cc19
Finally done with the new Zandronum version handling
Teemu Piippo <crimsondusk64@gmail.com>
parents:
37
diff
changeset
|
81 | // ------------------------------------------------------------------------------------------------- |
2c368cf5cc19
Finally done with the new Zandronum version handling
Teemu Piippo <crimsondusk64@gmail.com>
parents:
37
diff
changeset
|
82 | // |
2c368cf5cc19
Finally done with the new Zandronum version handling
Teemu Piippo <crimsondusk64@gmail.com>
parents:
37
diff
changeset
|
83 | |
37
c82a86ea87be
Major rework, lots of internal maintenance, version editor removed
Teemu Piippo <crimsondusk64@gmail.com>
parents:
30
diff
changeset
|
84 | bool Config::set (const QString& name, const QVariant& value) |
c82a86ea87be
Major rework, lots of internal maintenance, version editor removed
Teemu Piippo <crimsondusk64@gmail.com>
parents:
30
diff
changeset
|
85 | { |
c82a86ea87be
Major rework, lots of internal maintenance, version editor removed
Teemu Piippo <crimsondusk64@gmail.com>
parents:
30
diff
changeset
|
86 | QSettings* settings = getSettingsObject(); |
c82a86ea87be
Major rework, lots of internal maintenance, version editor removed
Teemu Piippo <crimsondusk64@gmail.com>
parents:
30
diff
changeset
|
87 | settings->setValue (name, value); |
c82a86ea87be
Major rework, lots of internal maintenance, version editor removed
Teemu Piippo <crimsondusk64@gmail.com>
parents:
30
diff
changeset
|
88 | settings->deleteLater(); |
c82a86ea87be
Major rework, lots of internal maintenance, version editor removed
Teemu Piippo <crimsondusk64@gmail.com>
parents:
30
diff
changeset
|
89 | return settings->status() == QSettings::NoError; |
39
2c368cf5cc19
Finally done with the new Zandronum version handling
Teemu Piippo <crimsondusk64@gmail.com>
parents:
37
diff
changeset
|
90 | } |
2c368cf5cc19
Finally done with the new Zandronum version handling
Teemu Piippo <crimsondusk64@gmail.com>
parents:
37
diff
changeset
|
91 | |
2c368cf5cc19
Finally done with the new Zandronum version handling
Teemu Piippo <crimsondusk64@gmail.com>
parents:
37
diff
changeset
|
92 | // |
2c368cf5cc19
Finally done with the new Zandronum version handling
Teemu Piippo <crimsondusk64@gmail.com>
parents:
37
diff
changeset
|
93 | // ------------------------------------------------------------------------------------------------- |
2c368cf5cc19
Finally done with the new Zandronum version handling
Teemu Piippo <crimsondusk64@gmail.com>
parents:
37
diff
changeset
|
94 | // |
2c368cf5cc19
Finally done with the new Zandronum version handling
Teemu Piippo <crimsondusk64@gmail.com>
parents:
37
diff
changeset
|
95 | |
2c368cf5cc19
Finally done with the new Zandronum version handling
Teemu Piippo <crimsondusk64@gmail.com>
parents:
37
diff
changeset
|
96 | void Config::sync() |
2c368cf5cc19
Finally done with the new Zandronum version handling
Teemu Piippo <crimsondusk64@gmail.com>
parents:
37
diff
changeset
|
97 | { |
2c368cf5cc19
Finally done with the new Zandronum version handling
Teemu Piippo <crimsondusk64@gmail.com>
parents:
37
diff
changeset
|
98 | QSettings* settings = getSettingsObject(); |
2c368cf5cc19
Finally done with the new Zandronum version handling
Teemu Piippo <crimsondusk64@gmail.com>
parents:
37
diff
changeset
|
99 | settings->sync(); |
2c368cf5cc19
Finally done with the new Zandronum version handling
Teemu Piippo <crimsondusk64@gmail.com>
parents:
37
diff
changeset
|
100 | settings->deleteLater(); |
2c368cf5cc19
Finally done with the new Zandronum version handling
Teemu Piippo <crimsondusk64@gmail.com>
parents:
37
diff
changeset
|
101 | } |