commonlib/config.cpp

Mon, 22 Jun 2015 02:30:07 +0300

author
Teemu Piippo <crimsondusk64@gmail.com>
date
Mon, 22 Jun 2015 02:30:07 +0300
changeset 59
bede5aaf49da
parent 56
bdbbde5f754e
permissions
-rw-r--r--

Changed version to 1.1-beta

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>
44
d0bf58f3560f Split the project into two executables (the launcher and the configurator)
Teemu Piippo <crimsondusk64@gmail.com>
parents: 43
diff changeset
23 #include "config.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
24
37
c82a86ea87be Major rework, lots of internal maintenance, version editor removed
Teemu Piippo <crimsondusk64@gmail.com>
parents: 30
diff changeset
25 typedef QMap<QString, QVariant> DefaultsMap;
c82a86ea87be Major rework, lots of internal maintenance, version editor removed
Teemu Piippo <crimsondusk64@gmail.com>
parents: 30
diff changeset
26
39
2c368cf5cc19 Finally done with the new Zandronum version handling
Teemu Piippo <crimsondusk64@gmail.com>
parents: 37
diff changeset
27 //
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
37
c82a86ea87be Major rework, lots of internal maintenance, version editor removed
Teemu Piippo <crimsondusk64@gmail.com>
parents: 30
diff changeset
31 static QSettings* getSettingsObject()
c82a86ea87be Major rework, lots of internal maintenance, version editor removed
Teemu Piippo <crimsondusk64@gmail.com>
parents: 30
diff changeset
32 {
c82a86ea87be Major rework, lots of internal maintenance, version editor removed
Teemu Piippo <crimsondusk64@gmail.com>
parents: 30
diff changeset
33 return new QSettings;
c82a86ea87be Major rework, lots of internal maintenance, version editor removed
Teemu Piippo <crimsondusk64@gmail.com>
parents: 30
diff changeset
34 }
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
35
39
2c368cf5cc19 Finally done with the new Zandronum version handling
Teemu Piippo <crimsondusk64@gmail.com>
parents: 37
diff changeset
36 //
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
37
c82a86ea87be Major rework, lots of internal maintenance, version editor removed
Teemu Piippo <crimsondusk64@gmail.com>
parents: 30
diff changeset
40 static DefaultsMap& getDefaults()
c82a86ea87be Major rework, lots of internal maintenance, version editor removed
Teemu Piippo <crimsondusk64@gmail.com>
parents: 30
diff changeset
41 {
c82a86ea87be Major rework, lots of internal maintenance, version editor removed
Teemu Piippo <crimsondusk64@gmail.com>
parents: 30
diff changeset
42 static DefaultsMap defaults;
c82a86ea87be Major rework, lots of internal maintenance, version editor removed
Teemu Piippo <crimsondusk64@gmail.com>
parents: 30
diff changeset
43
c82a86ea87be Major rework, lots of internal maintenance, version editor removed
Teemu Piippo <crimsondusk64@gmail.com>
parents: 30
diff changeset
44 if (defaults.isEmpty())
c82a86ea87be Major rework, lots of internal maintenance, version editor removed
Teemu Piippo <crimsondusk64@gmail.com>
parents: 30
diff changeset
45 {
c82a86ea87be Major rework, lots of internal maintenance, version editor removed
Teemu Piippo <crimsondusk64@gmail.com>
parents: 30
diff changeset
46 // Initialize defaults here.
56
bdbbde5f754e Added the ability to automatically look up wad paths from other sources (for now just Doomseeker's configuration). By default, ZCinema will automatically do such a lookup if it fails to find a WAD needed for demo playback. This can also be invoked manually in the config prompt.
Teemu Piippo <tsapii@utu.fi>
parents: 46
diff changeset
47 defaults["autoassimilate"] = true;
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 }

mercurial