Tue, 20 Aug 2013 21:15:12 +0300
removed broken config type check
183
f1b8cb53d2a2
Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
1 | /* |
f1b8cb53d2a2
Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
2 | * LDForge: LDraw parts authoring CAD |
f1b8cb53d2a2
Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
3 | * Copyright (C) 2013 Santeri Piippo |
359
bcdfc801658b
more restyle/refactor
Santeri Piippo <crimsondusk64@gmail.com>
parents:
321
diff
changeset
|
4 | * |
183
f1b8cb53d2a2
Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
5 | * This program is free software: you can redistribute it and/or modify |
f1b8cb53d2a2
Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
6 | * it under the terms of the GNU General Public License as published by |
f1b8cb53d2a2
Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
7 | * the Free Software Foundation, either version 3 of the License, or |
f1b8cb53d2a2
Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
8 | * (at your option) any later version. |
359
bcdfc801658b
more restyle/refactor
Santeri Piippo <crimsondusk64@gmail.com>
parents:
321
diff
changeset
|
9 | * |
183
f1b8cb53d2a2
Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
10 | * This program is distributed in the hope that it will be useful, |
f1b8cb53d2a2
Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
f1b8cb53d2a2
Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
f1b8cb53d2a2
Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
13 | * GNU General Public License for more details. |
359
bcdfc801658b
more restyle/refactor
Santeri Piippo <crimsondusk64@gmail.com>
parents:
321
diff
changeset
|
14 | * |
183
f1b8cb53d2a2
Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
15 | * You should have received a copy of the GNU General Public License |
f1b8cb53d2a2
Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
16 | * along with this program. If not, see <http://www.gnu.org/licenses/>. |
f1b8cb53d2a2
Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
17 | */ |
f1b8cb53d2a2
Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
18 | |
f1b8cb53d2a2
Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
19 | #include <errno.h> |
f1b8cb53d2a2
Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
20 | #include <QDir> |
359
bcdfc801658b
more restyle/refactor
Santeri Piippo <crimsondusk64@gmail.com>
parents:
321
diff
changeset
|
21 | #include <QTextStream> |
436
4268a5507725
Converted configuration code to use QSettings.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
430
diff
changeset
|
22 | #include <QSettings> |
183
f1b8cb53d2a2
Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
23 | #include "common.h" |
f1b8cb53d2a2
Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
24 | #include "config.h" |
198
f246725199dc
Split some stuff into separate files
Santeri Piippo <crimsondusk64@gmail.com>
parents:
189
diff
changeset
|
25 | #include "misc.h" |
238
3b35f502a6c7
Use a more Windows-like config dir name under Windows; warn when unable to read it
Santeri Piippo <crimsondusk64@gmail.com>
parents:
199
diff
changeset
|
26 | #include "gui.h" |
436
4268a5507725
Converted configuration code to use QSettings.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
430
diff
changeset
|
27 | #include "file.h" |
183
f1b8cb53d2a2
Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
28 | |
461
fbcc91ae1dd2
- added "Go to line" action, renamed the config classes to proper camelcase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
455
diff
changeset
|
29 | Config* g_configPointers[MAX_CONFIG]; |
239
ea09eeba1c2b
Use a C-array for config too for the same reasons as with actions
Santeri Piippo <crimsondusk64@gmail.com>
parents:
238
diff
changeset
|
30 | static ushort g_cfgPointerCursor = 0; |
183
f1b8cb53d2a2
Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
31 | |
f1b8cb53d2a2
Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
32 | // ============================================================================= |
455
c5d14d112034
Code formatting: use same separators everywhere, remove extra spaces from license headers, simplified message manager api a bit
Santeri Piippo <crimsondusk64@gmail.com>
parents:
436
diff
changeset
|
33 | // ----------------------------------------------------------------------------- |
436
4268a5507725
Converted configuration code to use QSettings.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
430
diff
changeset
|
34 | static QSettings* getSettingsObject() { |
4268a5507725
Converted configuration code to use QSettings.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
430
diff
changeset
|
35 | #ifdef PORTABLE |
4268a5507725
Converted configuration code to use QSettings.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
430
diff
changeset
|
36 | # ifdef _WIN32 |
4268a5507725
Converted configuration code to use QSettings.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
430
diff
changeset
|
37 | # define EXTENSION ".ini" |
4268a5507725
Converted configuration code to use QSettings.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
430
diff
changeset
|
38 | # else |
4268a5507725
Converted configuration code to use QSettings.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
430
diff
changeset
|
39 | # define EXTENSION ".cfg" |
4268a5507725
Converted configuration code to use QSettings.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
430
diff
changeset
|
40 | # endif // _WIN32 |
4268a5507725
Converted configuration code to use QSettings.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
430
diff
changeset
|
41 | return new QSettings (str (APPNAME).toLower() + EXTENSION, QSettings::IniFormat); |
4268a5507725
Converted configuration code to use QSettings.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
430
diff
changeset
|
42 | #else |
4268a5507725
Converted configuration code to use QSettings.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
430
diff
changeset
|
43 | return new QSettings; |
4268a5507725
Converted configuration code to use QSettings.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
430
diff
changeset
|
44 | #endif // PORTABLE |
4268a5507725
Converted configuration code to use QSettings.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
430
diff
changeset
|
45 | } |
4268a5507725
Converted configuration code to use QSettings.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
430
diff
changeset
|
46 | |
463
22bdcca9f78d
ensure that all Configs are polymorphic
Santeri Piippo <crimsondusk64@gmail.com>
parents:
462
diff
changeset
|
47 | Config::Config (const char* name, const char* defstring) : |
465
0f67ff766458
removed broken config type check
Santeri Piippo <crimsondusk64@gmail.com>
parents:
464
diff
changeset
|
48 | name (name), m_defstring (defstring) {} |
463
22bdcca9f78d
ensure that all Configs are polymorphic
Santeri Piippo <crimsondusk64@gmail.com>
parents:
462
diff
changeset
|
49 | |
436
4268a5507725
Converted configuration code to use QSettings.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
430
diff
changeset
|
50 | // ============================================================================= |
455
c5d14d112034
Code formatting: use same separators everywhere, remove extra spaces from license headers, simplified message manager api a bit
Santeri Piippo <crimsondusk64@gmail.com>
parents:
436
diff
changeset
|
51 | // ----------------------------------------------------------------------------- |
183
f1b8cb53d2a2
Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
52 | // Load the configuration from file |
461
fbcc91ae1dd2
- added "Go to line" action, renamed the config classes to proper camelcase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
455
diff
changeset
|
53 | bool Config::load() { |
436
4268a5507725
Converted configuration code to use QSettings.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
430
diff
changeset
|
54 | QSettings* settings = getSettingsObject(); |
4268a5507725
Converted configuration code to use QSettings.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
430
diff
changeset
|
55 | print ("config::load: Loading configuration file from %1...\n", settings->fileName()); |
183
f1b8cb53d2a2
Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
56 | |
461
fbcc91ae1dd2
- added "Go to line" action, renamed the config classes to proper camelcase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
455
diff
changeset
|
57 | for (Config* cfg : g_configPointers) { |
421
7d26db0be944
style cleanup - it should be all unified now
Santeri Piippo <crimsondusk64@gmail.com>
parents:
359
diff
changeset
|
58 | if (!cfg) |
239
ea09eeba1c2b
Use a C-array for config too for the same reasons as with actions
Santeri Piippo <crimsondusk64@gmail.com>
parents:
238
diff
changeset
|
59 | break; |
ea09eeba1c2b
Use a C-array for config too for the same reasons as with actions
Santeri Piippo <crimsondusk64@gmail.com>
parents:
238
diff
changeset
|
60 | |
436
4268a5507725
Converted configuration code to use QSettings.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
430
diff
changeset
|
61 | cfg->loadFromConfig (settings); |
4268a5507725
Converted configuration code to use QSettings.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
430
diff
changeset
|
62 | } |
4268a5507725
Converted configuration code to use QSettings.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
430
diff
changeset
|
63 | |
4268a5507725
Converted configuration code to use QSettings.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
430
diff
changeset
|
64 | settings->deleteLater(); |
4268a5507725
Converted configuration code to use QSettings.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
430
diff
changeset
|
65 | return true; |
4268a5507725
Converted configuration code to use QSettings.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
430
diff
changeset
|
66 | } |
4268a5507725
Converted configuration code to use QSettings.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
430
diff
changeset
|
67 | |
4268a5507725
Converted configuration code to use QSettings.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
430
diff
changeset
|
68 | // ============================================================================= |
455
c5d14d112034
Code formatting: use same separators everywhere, remove extra spaces from license headers, simplified message manager api a bit
Santeri Piippo <crimsondusk64@gmail.com>
parents:
436
diff
changeset
|
69 | // ----------------------------------------------------------------------------- |
461
fbcc91ae1dd2
- added "Go to line" action, renamed the config classes to proper camelcase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
455
diff
changeset
|
70 | void IntConfig::loadFromConfig (const QSettings* cfg) { |
436
4268a5507725
Converted configuration code to use QSettings.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
430
diff
changeset
|
71 | QVariant val = cfg->value (name, str::number (defval)); |
4268a5507725
Converted configuration code to use QSettings.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
430
diff
changeset
|
72 | value = val.toInt(); |
4268a5507725
Converted configuration code to use QSettings.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
430
diff
changeset
|
73 | } |
4268a5507725
Converted configuration code to use QSettings.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
430
diff
changeset
|
74 | |
455
c5d14d112034
Code formatting: use same separators everywhere, remove extra spaces from license headers, simplified message manager api a bit
Santeri Piippo <crimsondusk64@gmail.com>
parents:
436
diff
changeset
|
75 | // ============================================================================= |
c5d14d112034
Code formatting: use same separators everywhere, remove extra spaces from license headers, simplified message manager api a bit
Santeri Piippo <crimsondusk64@gmail.com>
parents:
436
diff
changeset
|
76 | // ----------------------------------------------------------------------------- |
461
fbcc91ae1dd2
- added "Go to line" action, renamed the config classes to proper camelcase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
455
diff
changeset
|
77 | void FloatConfig::loadFromConfig (const QSettings* cfg) { |
436
4268a5507725
Converted configuration code to use QSettings.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
430
diff
changeset
|
78 | QVariant val = cfg->value (name, str::number (defval)); |
4268a5507725
Converted configuration code to use QSettings.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
430
diff
changeset
|
79 | value = val.toFloat(); |
4268a5507725
Converted configuration code to use QSettings.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
430
diff
changeset
|
80 | } |
4268a5507725
Converted configuration code to use QSettings.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
430
diff
changeset
|
81 | |
455
c5d14d112034
Code formatting: use same separators everywhere, remove extra spaces from license headers, simplified message manager api a bit
Santeri Piippo <crimsondusk64@gmail.com>
parents:
436
diff
changeset
|
82 | // ============================================================================= |
c5d14d112034
Code formatting: use same separators everywhere, remove extra spaces from license headers, simplified message manager api a bit
Santeri Piippo <crimsondusk64@gmail.com>
parents:
436
diff
changeset
|
83 | // ----------------------------------------------------------------------------- |
461
fbcc91ae1dd2
- added "Go to line" action, renamed the config classes to proper camelcase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
455
diff
changeset
|
84 | void StringConfig::loadFromConfig (const QSettings* cfg) { |
436
4268a5507725
Converted configuration code to use QSettings.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
430
diff
changeset
|
85 | QVariant val = cfg->value (name, defval); |
4268a5507725
Converted configuration code to use QSettings.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
430
diff
changeset
|
86 | value = val.toString(); |
4268a5507725
Converted configuration code to use QSettings.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
430
diff
changeset
|
87 | } |
4268a5507725
Converted configuration code to use QSettings.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
430
diff
changeset
|
88 | |
455
c5d14d112034
Code formatting: use same separators everywhere, remove extra spaces from license headers, simplified message manager api a bit
Santeri Piippo <crimsondusk64@gmail.com>
parents:
436
diff
changeset
|
89 | // ============================================================================= |
c5d14d112034
Code formatting: use same separators everywhere, remove extra spaces from license headers, simplified message manager api a bit
Santeri Piippo <crimsondusk64@gmail.com>
parents:
436
diff
changeset
|
90 | // ----------------------------------------------------------------------------- |
461
fbcc91ae1dd2
- added "Go to line" action, renamed the config classes to proper camelcase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
455
diff
changeset
|
91 | void BoolConfig::loadFromConfig (const QSettings* cfg) { |
436
4268a5507725
Converted configuration code to use QSettings.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
430
diff
changeset
|
92 | QVariant val = cfg->value (name, str::number (defval)); |
4268a5507725
Converted configuration code to use QSettings.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
430
diff
changeset
|
93 | value = val.toBool(); |
4268a5507725
Converted configuration code to use QSettings.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
430
diff
changeset
|
94 | } |
4268a5507725
Converted configuration code to use QSettings.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
430
diff
changeset
|
95 | |
455
c5d14d112034
Code formatting: use same separators everywhere, remove extra spaces from license headers, simplified message manager api a bit
Santeri Piippo <crimsondusk64@gmail.com>
parents:
436
diff
changeset
|
96 | // ============================================================================= |
c5d14d112034
Code formatting: use same separators everywhere, remove extra spaces from license headers, simplified message manager api a bit
Santeri Piippo <crimsondusk64@gmail.com>
parents:
436
diff
changeset
|
97 | // ----------------------------------------------------------------------------- |
461
fbcc91ae1dd2
- added "Go to line" action, renamed the config classes to proper camelcase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
455
diff
changeset
|
98 | void KeySequenceConfig::loadFromConfig (const QSettings* cfg) { |
436
4268a5507725
Converted configuration code to use QSettings.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
430
diff
changeset
|
99 | QVariant val = cfg->value (name, defval.toString()); |
461
fbcc91ae1dd2
- added "Go to line" action, renamed the config classes to proper camelcase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
455
diff
changeset
|
100 | value = QKeySequence (val.toString()); |
436
4268a5507725
Converted configuration code to use QSettings.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
430
diff
changeset
|
101 | } |
4268a5507725
Converted configuration code to use QSettings.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
430
diff
changeset
|
102 | |
4268a5507725
Converted configuration code to use QSettings.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
430
diff
changeset
|
103 | // ============================================================================= |
455
c5d14d112034
Code formatting: use same separators everywhere, remove extra spaces from license headers, simplified message manager api a bit
Santeri Piippo <crimsondusk64@gmail.com>
parents:
436
diff
changeset
|
104 | // ----------------------------------------------------------------------------- |
436
4268a5507725
Converted configuration code to use QSettings.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
430
diff
changeset
|
105 | // TODO: make virtual |
461
fbcc91ae1dd2
- added "Go to line" action, renamed the config classes to proper camelcase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
455
diff
changeset
|
106 | str Config::toString() const { |
436
4268a5507725
Converted configuration code to use QSettings.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
430
diff
changeset
|
107 | switch (getType()) { |
461
fbcc91ae1dd2
- added "Go to line" action, renamed the config classes to proper camelcase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
455
diff
changeset
|
108 | case Int: |
fbcc91ae1dd2
- added "Go to line" action, renamed the config classes to proper camelcase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
455
diff
changeset
|
109 | return fmt ("%1", static_cast<const IntConfig*> (this)->value); |
436
4268a5507725
Converted configuration code to use QSettings.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
430
diff
changeset
|
110 | break; |
4268a5507725
Converted configuration code to use QSettings.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
430
diff
changeset
|
111 | |
461
fbcc91ae1dd2
- added "Go to line" action, renamed the config classes to proper camelcase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
455
diff
changeset
|
112 | case String: |
fbcc91ae1dd2
- added "Go to line" action, renamed the config classes to proper camelcase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
455
diff
changeset
|
113 | return static_cast<const StringConfig*> (this)->value; |
436
4268a5507725
Converted configuration code to use QSettings.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
430
diff
changeset
|
114 | break; |
4268a5507725
Converted configuration code to use QSettings.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
430
diff
changeset
|
115 | |
461
fbcc91ae1dd2
- added "Go to line" action, renamed the config classes to proper camelcase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
455
diff
changeset
|
116 | case Float: |
fbcc91ae1dd2
- added "Go to line" action, renamed the config classes to proper camelcase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
455
diff
changeset
|
117 | return fmt ("%1", static_cast<const FloatConfig*> (this)->value); |
436
4268a5507725
Converted configuration code to use QSettings.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
430
diff
changeset
|
118 | break; |
4268a5507725
Converted configuration code to use QSettings.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
430
diff
changeset
|
119 | |
461
fbcc91ae1dd2
- added "Go to line" action, renamed the config classes to proper camelcase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
455
diff
changeset
|
120 | case Bool: |
fbcc91ae1dd2
- added "Go to line" action, renamed the config classes to proper camelcase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
455
diff
changeset
|
121 | return (static_cast<const BoolConfig*> (this)->value) ? "true" : "false"; |
436
4268a5507725
Converted configuration code to use QSettings.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
430
diff
changeset
|
122 | break; |
4268a5507725
Converted configuration code to use QSettings.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
430
diff
changeset
|
123 | |
461
fbcc91ae1dd2
- added "Go to line" action, renamed the config classes to proper camelcase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
455
diff
changeset
|
124 | case KeySequence: |
fbcc91ae1dd2
- added "Go to line" action, renamed the config classes to proper camelcase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
455
diff
changeset
|
125 | return static_cast<const KeySequenceConfig*> (this)->value.toString(); |
436
4268a5507725
Converted configuration code to use QSettings.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
430
diff
changeset
|
126 | break; |
4268a5507725
Converted configuration code to use QSettings.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
430
diff
changeset
|
127 | |
4268a5507725
Converted configuration code to use QSettings.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
430
diff
changeset
|
128 | default: |
4268a5507725
Converted configuration code to use QSettings.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
430
diff
changeset
|
129 | break; |
4268a5507725
Converted configuration code to use QSettings.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
430
diff
changeset
|
130 | } |
4268a5507725
Converted configuration code to use QSettings.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
430
diff
changeset
|
131 | |
4268a5507725
Converted configuration code to use QSettings.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
430
diff
changeset
|
132 | return ""; |
4268a5507725
Converted configuration code to use QSettings.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
430
diff
changeset
|
133 | } |
4268a5507725
Converted configuration code to use QSettings.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
430
diff
changeset
|
134 | |
4268a5507725
Converted configuration code to use QSettings.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
430
diff
changeset
|
135 | // ============================================================================= |
455
c5d14d112034
Code formatting: use same separators everywhere, remove extra spaces from license headers, simplified message manager api a bit
Santeri Piippo <crimsondusk64@gmail.com>
parents:
436
diff
changeset
|
136 | // ----------------------------------------------------------------------------- |
436
4268a5507725
Converted configuration code to use QSettings.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
430
diff
changeset
|
137 | // Save the configuration to disk |
461
fbcc91ae1dd2
- added "Go to line" action, renamed the config classes to proper camelcase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
455
diff
changeset
|
138 | bool Config::save() { |
436
4268a5507725
Converted configuration code to use QSettings.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
430
diff
changeset
|
139 | QSettings* settings = getSettingsObject(); |
4268a5507725
Converted configuration code to use QSettings.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
430
diff
changeset
|
140 | print ("Saving configuration to %1...\n", settings->fileName()); |
4268a5507725
Converted configuration code to use QSettings.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
430
diff
changeset
|
141 | |
461
fbcc91ae1dd2
- added "Go to line" action, renamed the config classes to proper camelcase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
455
diff
changeset
|
142 | for (Config* cfg : g_configPointers) { |
436
4268a5507725
Converted configuration code to use QSettings.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
430
diff
changeset
|
143 | if (!cfg) |
183
f1b8cb53d2a2
Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
144 | break; |
189
ac2d3e8dd110
Rewrote the string class with a simpler version. The old one was more than probably leaking water like a boat with an elephant on board...
Santeri Piippo <crimsondusk64@gmail.com>
parents:
183
diff
changeset
|
145 | |
436
4268a5507725
Converted configuration code to use QSettings.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
430
diff
changeset
|
146 | settings->setValue (cfg->name, cfg->toString()); |
183
f1b8cb53d2a2
Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
147 | } |
f1b8cb53d2a2
Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
148 | |
436
4268a5507725
Converted configuration code to use QSettings.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
430
diff
changeset
|
149 | settings->sync(); |
4268a5507725
Converted configuration code to use QSettings.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
430
diff
changeset
|
150 | settings->deleteLater(); |
183
f1b8cb53d2a2
Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
151 | return true; |
f1b8cb53d2a2
Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
152 | } |
f1b8cb53d2a2
Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
153 | |
f1b8cb53d2a2
Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
154 | // ============================================================================= |
455
c5d14d112034
Code formatting: use same separators everywhere, remove extra spaces from license headers, simplified message manager api a bit
Santeri Piippo <crimsondusk64@gmail.com>
parents:
436
diff
changeset
|
155 | // ----------------------------------------------------------------------------- |
461
fbcc91ae1dd2
- added "Go to line" action, renamed the config classes to proper camelcase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
455
diff
changeset
|
156 | void Config::reset() { |
fbcc91ae1dd2
- added "Go to line" action, renamed the config classes to proper camelcase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
455
diff
changeset
|
157 | for (Config* cfg : g_configPointers) { |
421
7d26db0be944
style cleanup - it should be all unified now
Santeri Piippo <crimsondusk64@gmail.com>
parents:
359
diff
changeset
|
158 | if (!cfg) |
239
ea09eeba1c2b
Use a C-array for config too for the same reasons as with actions
Santeri Piippo <crimsondusk64@gmail.com>
parents:
238
diff
changeset
|
159 | break; |
ea09eeba1c2b
Use a C-array for config too for the same reasons as with actions
Santeri Piippo <crimsondusk64@gmail.com>
parents:
238
diff
changeset
|
160 | |
359
bcdfc801658b
more restyle/refactor
Santeri Piippo <crimsondusk64@gmail.com>
parents:
321
diff
changeset
|
161 | cfg->resetValue(); |
239
ea09eeba1c2b
Use a C-array for config too for the same reasons as with actions
Santeri Piippo <crimsondusk64@gmail.com>
parents:
238
diff
changeset
|
162 | } |
183
f1b8cb53d2a2
Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
163 | } |
f1b8cb53d2a2
Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
164 | |
f1b8cb53d2a2
Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
165 | // ============================================================================= |
455
c5d14d112034
Code formatting: use same separators everywhere, remove extra spaces from license headers, simplified message manager api a bit
Santeri Piippo <crimsondusk64@gmail.com>
parents:
436
diff
changeset
|
166 | // ----------------------------------------------------------------------------- |
461
fbcc91ae1dd2
- added "Go to line" action, renamed the config classes to proper camelcase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
455
diff
changeset
|
167 | str Config::filepath (str file) { |
fbcc91ae1dd2
- added "Go to line" action, renamed the config classes to proper camelcase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
455
diff
changeset
|
168 | return Config::dirpath() + DIRSLASH + file; |
183
f1b8cb53d2a2
Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
169 | } |
f1b8cb53d2a2
Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
170 | |
f1b8cb53d2a2
Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
171 | // ============================================================================= |
455
c5d14d112034
Code formatting: use same separators everywhere, remove extra spaces from license headers, simplified message manager api a bit
Santeri Piippo <crimsondusk64@gmail.com>
parents:
436
diff
changeset
|
172 | // ----------------------------------------------------------------------------- |
461
fbcc91ae1dd2
- added "Go to line" action, renamed the config classes to proper camelcase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
455
diff
changeset
|
173 | str Config::dirpath() { |
436
4268a5507725
Converted configuration code to use QSettings.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
430
diff
changeset
|
174 | QSettings* cfg = getSettingsObject(); |
4268a5507725
Converted configuration code to use QSettings.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
430
diff
changeset
|
175 | return dirname (cfg->fileName()); |
239
ea09eeba1c2b
Use a C-array for config too for the same reasons as with actions
Santeri Piippo <crimsondusk64@gmail.com>
parents:
238
diff
changeset
|
176 | } |
ea09eeba1c2b
Use a C-array for config too for the same reasons as with actions
Santeri Piippo <crimsondusk64@gmail.com>
parents:
238
diff
changeset
|
177 | |
436
4268a5507725
Converted configuration code to use QSettings.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
430
diff
changeset
|
178 | // ============================================================================= |
455
c5d14d112034
Code formatting: use same separators everywhere, remove extra spaces from license headers, simplified message manager api a bit
Santeri Piippo <crimsondusk64@gmail.com>
parents:
436
diff
changeset
|
179 | // ----------------------------------------------------------------------------- |
461
fbcc91ae1dd2
- added "Go to line" action, renamed the config classes to proper camelcase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
455
diff
changeset
|
180 | str Config::defaultString() const { |
436
4268a5507725
Converted configuration code to use QSettings.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
430
diff
changeset
|
181 | str defstring = m_defstring; |
4268a5507725
Converted configuration code to use QSettings.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
430
diff
changeset
|
182 | |
4268a5507725
Converted configuration code to use QSettings.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
430
diff
changeset
|
183 | // String types inevitably get extra quotes in their default string due to |
4268a5507725
Converted configuration code to use QSettings.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
430
diff
changeset
|
184 | // preprocessing stuff. We can only remove them now... |
461
fbcc91ae1dd2
- added "Go to line" action, renamed the config classes to proper camelcase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
455
diff
changeset
|
185 | if (getType() == String) { |
436
4268a5507725
Converted configuration code to use QSettings.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
430
diff
changeset
|
186 | defstring.remove (0, 1); |
4268a5507725
Converted configuration code to use QSettings.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
430
diff
changeset
|
187 | defstring.chop (1); |
4268a5507725
Converted configuration code to use QSettings.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
430
diff
changeset
|
188 | } |
4268a5507725
Converted configuration code to use QSettings.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
430
diff
changeset
|
189 | |
4268a5507725
Converted configuration code to use QSettings.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
430
diff
changeset
|
190 | return defstring; |
4268a5507725
Converted configuration code to use QSettings.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
430
diff
changeset
|
191 | } |
4268a5507725
Converted configuration code to use QSettings.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
430
diff
changeset
|
192 | |
4268a5507725
Converted configuration code to use QSettings.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
430
diff
changeset
|
193 | // ============================================================================= |
455
c5d14d112034
Code formatting: use same separators everywhere, remove extra spaces from license headers, simplified message manager api a bit
Santeri Piippo <crimsondusk64@gmail.com>
parents:
436
diff
changeset
|
194 | // ----------------------------------------------------------------------------- |
462 | 195 | void Config::addToArray (Config* ptr) { |
421
7d26db0be944
style cleanup - it should be all unified now
Santeri Piippo <crimsondusk64@gmail.com>
parents:
359
diff
changeset
|
196 | if (g_cfgPointerCursor == 0) |
7d26db0be944
style cleanup - it should be all unified now
Santeri Piippo <crimsondusk64@gmail.com>
parents:
359
diff
changeset
|
197 | memset (g_configPointers, 0, sizeof g_configPointers); |
239
ea09eeba1c2b
Use a C-array for config too for the same reasons as with actions
Santeri Piippo <crimsondusk64@gmail.com>
parents:
238
diff
changeset
|
198 | |
421
7d26db0be944
style cleanup - it should be all unified now
Santeri Piippo <crimsondusk64@gmail.com>
parents:
359
diff
changeset
|
199 | assert (g_cfgPointerCursor < MAX_CONFIG); |
239
ea09eeba1c2b
Use a C-array for config too for the same reasons as with actions
Santeri Piippo <crimsondusk64@gmail.com>
parents:
238
diff
changeset
|
200 | g_configPointers[g_cfgPointerCursor++] = ptr; |
421
7d26db0be944
style cleanup - it should be all unified now
Santeri Piippo <crimsondusk64@gmail.com>
parents:
359
diff
changeset
|
201 | } |