Fri, 12 Apr 2013 02:54:25 +0300
Added basic object moving with MLCAD-like controls.
30
31ff9aabd506
Licensed LDForge GPL3, added some more icons
Santeri Piippo <crimsondusk64@gmail.com>
parents:
29
diff
changeset
|
1 | /* |
31ff9aabd506
Licensed LDForge GPL3, added some more icons
Santeri Piippo <crimsondusk64@gmail.com>
parents:
29
diff
changeset
|
2 | * LDForge: LDraw parts authoring CAD |
31ff9aabd506
Licensed LDForge GPL3, added some more icons
Santeri Piippo <crimsondusk64@gmail.com>
parents:
29
diff
changeset
|
3 | * Copyright (C) 2013 Santeri `arezey` Piippo |
31ff9aabd506
Licensed LDForge GPL3, added some more icons
Santeri Piippo <crimsondusk64@gmail.com>
parents:
29
diff
changeset
|
4 | * |
31ff9aabd506
Licensed LDForge GPL3, added some more icons
Santeri Piippo <crimsondusk64@gmail.com>
parents:
29
diff
changeset
|
5 | * This program is free software: you can redistribute it and/or modify |
31ff9aabd506
Licensed LDForge GPL3, added some more icons
Santeri Piippo <crimsondusk64@gmail.com>
parents:
29
diff
changeset
|
6 | * it under the terms of the GNU General Public License as published by |
31ff9aabd506
Licensed LDForge GPL3, added some more icons
Santeri Piippo <crimsondusk64@gmail.com>
parents:
29
diff
changeset
|
7 | * the Free Software Foundation, either version 3 of the License, or |
31ff9aabd506
Licensed LDForge GPL3, added some more icons
Santeri Piippo <crimsondusk64@gmail.com>
parents:
29
diff
changeset
|
8 | * (at your option) any later version. |
31ff9aabd506
Licensed LDForge GPL3, added some more icons
Santeri Piippo <crimsondusk64@gmail.com>
parents:
29
diff
changeset
|
9 | * |
31ff9aabd506
Licensed LDForge GPL3, added some more icons
Santeri Piippo <crimsondusk64@gmail.com>
parents:
29
diff
changeset
|
10 | * This program is distributed in the hope that it will be useful, |
31ff9aabd506
Licensed LDForge GPL3, added some more icons
Santeri Piippo <crimsondusk64@gmail.com>
parents:
29
diff
changeset
|
11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
31ff9aabd506
Licensed LDForge GPL3, added some more icons
Santeri Piippo <crimsondusk64@gmail.com>
parents:
29
diff
changeset
|
12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
31ff9aabd506
Licensed LDForge GPL3, added some more icons
Santeri Piippo <crimsondusk64@gmail.com>
parents:
29
diff
changeset
|
13 | * GNU General Public License for more details. |
31ff9aabd506
Licensed LDForge GPL3, added some more icons
Santeri Piippo <crimsondusk64@gmail.com>
parents:
29
diff
changeset
|
14 | * |
31ff9aabd506
Licensed LDForge GPL3, added some more icons
Santeri Piippo <crimsondusk64@gmail.com>
parents:
29
diff
changeset
|
15 | * You should have received a copy of the GNU General Public License |
31ff9aabd506
Licensed LDForge GPL3, added some more icons
Santeri Piippo <crimsondusk64@gmail.com>
parents:
29
diff
changeset
|
16 | * along with this program. If not, see <http://www.gnu.org/licenses/>. |
31ff9aabd506
Licensed LDForge GPL3, added some more icons
Santeri Piippo <crimsondusk64@gmail.com>
parents:
29
diff
changeset
|
17 | */ |
31ff9aabd506
Licensed LDForge GPL3, added some more icons
Santeri Piippo <crimsondusk64@gmail.com>
parents:
29
diff
changeset
|
18 | |
0 | 19 | #include <stdio.h> |
69
6790dea720a8
Simplified configuration code. Use a std::vector object to contain config pointers and have config objects register themselves upon creation instead of relying on a cfgdefs.h. Removed sections, all configurations are just simply written one after another now.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
68
diff
changeset
|
20 | #include <stdlib.h> |
0 | 21 | #include <errno.h> |
22 | #include <time.h> | |
23 | #include "str.h" | |
24 | #include "config.h" | |
25 | #include <QDir> | |
26 | ||
69
6790dea720a8
Simplified configuration code. Use a std::vector object to contain config pointers and have config objects register themselves upon creation instead of relying on a cfgdefs.h. Removed sections, all configurations are just simply written one after another now.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
68
diff
changeset
|
27 | std::vector<config*> g_pConfigPointers; |
0 | 28 | |
29 | // ============================================================================= | |
30 | const char* g_WeekdayNames[7] = { | |
31 | "Sunday", | |
32 | "Monday", | |
33 | "Tuesday", | |
34 | "Wednesday", | |
35 | "Thursday", | |
36 | "Friday", | |
37 | "Saturday", | |
38 | }; | |
39 | ||
40 | // ============================================================================= | |
41 | static const char* g_MonthNames[12] = { | |
42 | "Januray", | |
43 | "February", | |
44 | "March", | |
45 | "April", | |
46 | "May", | |
47 | "June", | |
48 | "July", | |
49 | "August", | |
50 | "September", | |
51 | "October", | |
52 | "November" | |
53 | "December", | |
54 | }; | |
55 | ||
56 | static const char* g_ConfigTypeNames[] = { | |
57 | "None", | |
58 | "Integer", | |
59 | "String", | |
60 | "Float", | |
61 | "Boolean", | |
78
c190fe218506
Keyboard shortcuts can now be configured.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
69
diff
changeset
|
62 | "Key sequence", |
0 | 63 | }; |
64 | ||
65 | // ============================================================================= | |
66 | // Load the configuration from file | |
67 | bool config::load () { | |
99
920d51fec412
Recent files are now remembered and displayed in a submenu
Santeri Piippo <crimsondusk64@gmail.com>
parents:
78
diff
changeset
|
68 | printf ("config::load: loading configuration file.\n"); |
920d51fec412
Recent files are now remembered and displayed in a submenu
Santeri Piippo <crimsondusk64@gmail.com>
parents:
78
diff
changeset
|
69 | |
68
c637b172d565
Further fixes to bad color handling. Allow main color be represented with arbitrary transparency.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
30
diff
changeset
|
70 | // Locale must be disabled for atof |
c637b172d565
Further fixes to bad color handling. Allow main color be represented with arbitrary transparency.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
30
diff
changeset
|
71 | setlocale (LC_NUMERIC, "C"); |
c637b172d565
Further fixes to bad color handling. Allow main color be represented with arbitrary transparency.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
30
diff
changeset
|
72 | |
0 | 73 | FILE* fp = fopen (filepath().chars(), "r"); |
74 | char linedata[MAX_INI_LINE]; | |
75 | char* line; | |
76 | size_t ln = 0; | |
77 | ||
78 | if (!fp) | |
79 | return false; // can't open for reading | |
80 | ||
81 | // Read the values. | |
82 | while (fgets (linedata, MAX_INI_LINE, fp)) { | |
83 | ln++; | |
84 | line = linedata; | |
85 | ||
86 | while (*line != 0 && (*line <= 32 || *line >= 127)) | |
87 | line++; // Skip junk | |
88 | ||
89 | if (*line == '\0' || line[0] == '#') | |
90 | continue; // Empty line or comment. | |
91 | ||
92 | // Find the equals sign. | |
93 | char* equals = strchr (line, '='); | |
94 | if (!equals) { | |
95 | fprintf (stderr, "couldn't find `=` sign in entry `%s`\n", line); | |
96 | continue; | |
97 | } | |
98 | ||
99 | str entry = str (line).substr (0, equals - line); | |
100 | ||
101 | // Find the config entry for this. | |
69
6790dea720a8
Simplified configuration code. Use a std::vector object to contain config pointers and have config objects register themselves upon creation instead of relying on a cfgdefs.h. Removed sections, all configurations are just simply written one after another now.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
68
diff
changeset
|
102 | config* cfg = nullptr; |
6790dea720a8
Simplified configuration code. Use a std::vector object to contain config pointers and have config objects register themselves upon creation instead of relying on a cfgdefs.h. Removed sections, all configurations are just simply written one after another now.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
68
diff
changeset
|
103 | for (config* i : g_pConfigPointers) |
6790dea720a8
Simplified configuration code. Use a std::vector object to contain config pointers and have config objects register themselves upon creation instead of relying on a cfgdefs.h. Removed sections, all configurations are just simply written one after another now.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
68
diff
changeset
|
104 | if (entry == i->name) |
6790dea720a8
Simplified configuration code. Use a std::vector object to contain config pointers and have config objects register themselves upon creation instead of relying on a cfgdefs.h. Removed sections, all configurations are just simply written one after another now.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
68
diff
changeset
|
105 | cfg = i; |
0 | 106 | |
107 | if (!cfg) { | |
69
6790dea720a8
Simplified configuration code. Use a std::vector object to contain config pointers and have config objects register themselves upon creation instead of relying on a cfgdefs.h. Removed sections, all configurations are just simply written one after another now.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
68
diff
changeset
|
108 | fprintf (stderr, "unknown config `%s`\n", entry.chars()); |
0 | 109 | continue; |
110 | } | |
111 | ||
112 | str valstring = str (line).substr (equals - line + 1, -1); | |
113 | ||
114 | // Trim the crap off the end | |
115 | while (~valstring) { | |
116 | char c = valstring[~valstring - 1]; | |
117 | if (c <= 32 || c >= 127) | |
118 | valstring -= 1; | |
119 | else | |
120 | break; | |
121 | } | |
122 | ||
123 | switch (const_cast<config*> (cfg)->getType()) { | |
124 | case CONFIG_int: | |
125 | static_cast<intconfig*> (cfg)->value = atoi (valstring.chars()); | |
126 | break; | |
78
c190fe218506
Keyboard shortcuts can now be configured.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
69
diff
changeset
|
127 | |
0 | 128 | case CONFIG_str: |
129 | static_cast<strconfig*> (cfg)->value = valstring; | |
130 | break; | |
78
c190fe218506
Keyboard shortcuts can now be configured.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
69
diff
changeset
|
131 | |
0 | 132 | case CONFIG_float: |
133 | static_cast<floatconfig*> (cfg)->value = atof (valstring.chars()); | |
134 | break; | |
78
c190fe218506
Keyboard shortcuts can now be configured.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
69
diff
changeset
|
135 | |
0 | 136 | case CONFIG_bool: |
137 | { | |
138 | bool& val = static_cast<boolconfig*> (cfg)->value; | |
139 | ||
140 | if (+valstring == "TRUE" || valstring == "1") | |
141 | val = true; | |
142 | else if (+valstring == "FALSE" || valstring == "0") | |
143 | val = false; | |
144 | break; | |
145 | } | |
78
c190fe218506
Keyboard shortcuts can now be configured.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
69
diff
changeset
|
146 | |
c190fe218506
Keyboard shortcuts can now be configured.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
69
diff
changeset
|
147 | case CONFIG_keyseq: |
c190fe218506
Keyboard shortcuts can now be configured.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
69
diff
changeset
|
148 | static_cast<keyseqconfig*> (cfg)->value = keyseq::fromString (valstring.chars ()); |
c190fe218506
Keyboard shortcuts can now be configured.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
69
diff
changeset
|
149 | break; |
c190fe218506
Keyboard shortcuts can now be configured.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
69
diff
changeset
|
150 | |
0 | 151 | default: |
152 | break; | |
153 | } | |
154 | } | |
155 | ||
156 | fclose (fp); | |
157 | return true; | |
158 | } | |
159 | ||
160 | // ============================================================================= | |
161 | // Write a given formatted string to the given file stream | |
162 | static size_t writef (FILE* fp, const char* fmt, ...) { | |
163 | va_list va; | |
164 | ||
165 | va_start (va, fmt); | |
166 | char* buf = vdynformat (fmt, va, 256); | |
167 | va_end (va); | |
168 | ||
169 | size_t len = fwrite (buf, 1, strlen (buf), fp); | |
170 | delete[] buf; | |
171 | ||
172 | return len; | |
173 | } | |
174 | ||
175 | // ============================================================================= | |
176 | // Save the configuration to disk | |
177 | bool config::save () { | |
68
c637b172d565
Further fixes to bad color handling. Allow main color be represented with arbitrary transparency.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
30
diff
changeset
|
178 | // The function will write floats, disable the locale now so that they |
c637b172d565
Further fixes to bad color handling. Allow main color be represented with arbitrary transparency.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
30
diff
changeset
|
179 | // are written properly. |
c637b172d565
Further fixes to bad color handling. Allow main color be represented with arbitrary transparency.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
30
diff
changeset
|
180 | setlocale (LC_NUMERIC, "C"); |
c637b172d565
Further fixes to bad color handling. Allow main color be represented with arbitrary transparency.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
30
diff
changeset
|
181 | |
69
6790dea720a8
Simplified configuration code. Use a std::vector object to contain config pointers and have config objects register themselves upon creation instead of relying on a cfgdefs.h. Removed sections, all configurations are just simply written one after another now.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
68
diff
changeset
|
182 | // If the directory doesn't exist, create it now. |
6790dea720a8
Simplified configuration code. Use a std::vector object to contain config pointers and have config objects register themselves upon creation instead of relying on a cfgdefs.h. Removed sections, all configurations are just simply written one after another now.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
68
diff
changeset
|
183 | if (!QDir (dirpath().chars()).exists ()) { |
6790dea720a8
Simplified configuration code. Use a std::vector object to contain config pointers and have config objects register themselves upon creation instead of relying on a cfgdefs.h. Removed sections, all configurations are just simply written one after another now.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
68
diff
changeset
|
184 | fprintf (stderr, "Creating config path %s...\n", dirpath().chars()); |
6790dea720a8
Simplified configuration code. Use a std::vector object to contain config pointers and have config objects register themselves upon creation instead of relying on a cfgdefs.h. Removed sections, all configurations are just simply written one after another now.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
68
diff
changeset
|
185 | if (!QDir ().mkpath (dirpath().chars())) { |
6790dea720a8
Simplified configuration code. Use a std::vector object to contain config pointers and have config objects register themselves upon creation instead of relying on a cfgdefs.h. Removed sections, all configurations are just simply written one after another now.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
68
diff
changeset
|
186 | fprintf (stderr, "Failed to create the directory. Configuration cannot be saved!\n"); |
6790dea720a8
Simplified configuration code. Use a std::vector object to contain config pointers and have config objects register themselves upon creation instead of relying on a cfgdefs.h. Removed sections, all configurations are just simply written one after another now.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
68
diff
changeset
|
187 | return false; // Couldn't create directory |
0 | 188 | } |
69
6790dea720a8
Simplified configuration code. Use a std::vector object to contain config pointers and have config objects register themselves upon creation instead of relying on a cfgdefs.h. Removed sections, all configurations are just simply written one after another now.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
68
diff
changeset
|
189 | } |
0 | 190 | |
191 | FILE* fp = fopen (filepath().chars(), "w"); | |
192 | printf ("writing cfg to %s\n", filepath().chars()); | |
193 | ||
194 | if (!fp) { | |
195 | printf ("Couldn't open %s for writing\n", filepath().chars()); | |
196 | return false; | |
197 | } | |
198 | ||
199 | const time_t curtime = time (NULL); | |
200 | const struct tm* timeinfo = localtime (&curtime); | |
201 | const char* daysuffix = | |
202 | (timeinfo->tm_mday % 10 == 1) ? "st" : | |
203 | (timeinfo->tm_mday % 10 == 2) ? "nd" : | |
204 | (timeinfo->tm_mday % 10 == 3) ? "rd" : "th"; | |
205 | ||
206 | writef (fp, "# Configuration file for " APPNAME "\n"); | |
207 | writef (fp, "# Written on %s, %s %d%s %d %.2d:%.2d:%.2d\n", | |
208 | g_WeekdayNames[timeinfo->tm_wday], g_MonthNames[timeinfo->tm_mon], | |
209 | timeinfo->tm_mday, daysuffix, timeinfo->tm_year + 1900, | |
210 | timeinfo->tm_hour, timeinfo->tm_min, timeinfo->tm_sec); | |
211 | ||
69
6790dea720a8
Simplified configuration code. Use a std::vector object to contain config pointers and have config objects register themselves upon creation instead of relying on a cfgdefs.h. Removed sections, all configurations are just simply written one after another now.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
68
diff
changeset
|
212 | for (config* cfg : g_pConfigPointers) { |
6790dea720a8
Simplified configuration code. Use a std::vector object to contain config pointers and have config objects register themselves upon creation instead of relying on a cfgdefs.h. Removed sections, all configurations are just simply written one after another now.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
68
diff
changeset
|
213 | str valstring; |
6790dea720a8
Simplified configuration code. Use a std::vector object to contain config pointers and have config objects register themselves upon creation instead of relying on a cfgdefs.h. Removed sections, all configurations are just simply written one after another now.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
68
diff
changeset
|
214 | switch (cfg->getType()) { |
6790dea720a8
Simplified configuration code. Use a std::vector object to contain config pointers and have config objects register themselves upon creation instead of relying on a cfgdefs.h. Removed sections, all configurations are just simply written one after another now.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
68
diff
changeset
|
215 | case CONFIG_int: |
6790dea720a8
Simplified configuration code. Use a std::vector object to contain config pointers and have config objects register themselves upon creation instead of relying on a cfgdefs.h. Removed sections, all configurations are just simply written one after another now.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
68
diff
changeset
|
216 | valstring.format ("%d", static_cast<intconfig*> (cfg)->value); |
6790dea720a8
Simplified configuration code. Use a std::vector object to contain config pointers and have config objects register themselves upon creation instead of relying on a cfgdefs.h. Removed sections, all configurations are just simply written one after another now.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
68
diff
changeset
|
217 | break; |
6790dea720a8
Simplified configuration code. Use a std::vector object to contain config pointers and have config objects register themselves upon creation instead of relying on a cfgdefs.h. Removed sections, all configurations are just simply written one after another now.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
68
diff
changeset
|
218 | case CONFIG_str: |
6790dea720a8
Simplified configuration code. Use a std::vector object to contain config pointers and have config objects register themselves upon creation instead of relying on a cfgdefs.h. Removed sections, all configurations are just simply written one after another now.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
68
diff
changeset
|
219 | valstring = static_cast<strconfig*> (cfg)->value; |
6790dea720a8
Simplified configuration code. Use a std::vector object to contain config pointers and have config objects register themselves upon creation instead of relying on a cfgdefs.h. Removed sections, all configurations are just simply written one after another now.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
68
diff
changeset
|
220 | break; |
6790dea720a8
Simplified configuration code. Use a std::vector object to contain config pointers and have config objects register themselves upon creation instead of relying on a cfgdefs.h. Removed sections, all configurations are just simply written one after another now.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
68
diff
changeset
|
221 | case CONFIG_float: |
6790dea720a8
Simplified configuration code. Use a std::vector object to contain config pointers and have config objects register themselves upon creation instead of relying on a cfgdefs.h. Removed sections, all configurations are just simply written one after another now.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
68
diff
changeset
|
222 | valstring.format ("%f", static_cast<floatconfig*> (cfg)->value); |
0 | 223 | |
69
6790dea720a8
Simplified configuration code. Use a std::vector object to contain config pointers and have config objects register themselves upon creation instead of relying on a cfgdefs.h. Removed sections, all configurations are just simply written one after another now.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
68
diff
changeset
|
224 | // Trim any trailing zeros |
6790dea720a8
Simplified configuration code. Use a std::vector object to contain config pointers and have config objects register themselves upon creation instead of relying on a cfgdefs.h. Removed sections, all configurations are just simply written one after another now.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
68
diff
changeset
|
225 | if (valstring.first (".") != -1) { |
6790dea720a8
Simplified configuration code. Use a std::vector object to contain config pointers and have config objects register themselves upon creation instead of relying on a cfgdefs.h. Removed sections, all configurations are just simply written one after another now.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
68
diff
changeset
|
226 | while (valstring[~valstring - 1] == '0') |
6790dea720a8
Simplified configuration code. Use a std::vector object to contain config pointers and have config objects register themselves upon creation instead of relying on a cfgdefs.h. Removed sections, all configurations are just simply written one after another now.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
68
diff
changeset
|
227 | valstring -= 1; |
0 | 228 | |
69
6790dea720a8
Simplified configuration code. Use a std::vector object to contain config pointers and have config objects register themselves upon creation instead of relying on a cfgdefs.h. Removed sections, all configurations are just simply written one after another now.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
68
diff
changeset
|
229 | // But don't trim the only one out... |
6790dea720a8
Simplified configuration code. Use a std::vector object to contain config pointers and have config objects register themselves upon creation instead of relying on a cfgdefs.h. Removed sections, all configurations are just simply written one after another now.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
68
diff
changeset
|
230 | if (valstring[~valstring - 1] == '.') |
6790dea720a8
Simplified configuration code. Use a std::vector object to contain config pointers and have config objects register themselves upon creation instead of relying on a cfgdefs.h. Removed sections, all configurations are just simply written one after another now.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
68
diff
changeset
|
231 | valstring += '0'; |
0 | 232 | } |
233 | ||
69
6790dea720a8
Simplified configuration code. Use a std::vector object to contain config pointers and have config objects register themselves upon creation instead of relying on a cfgdefs.h. Removed sections, all configurations are just simply written one after another now.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
68
diff
changeset
|
234 | break; |
6790dea720a8
Simplified configuration code. Use a std::vector object to contain config pointers and have config objects register themselves upon creation instead of relying on a cfgdefs.h. Removed sections, all configurations are just simply written one after another now.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
68
diff
changeset
|
235 | case CONFIG_bool: |
6790dea720a8
Simplified configuration code. Use a std::vector object to contain config pointers and have config objects register themselves upon creation instead of relying on a cfgdefs.h. Removed sections, all configurations are just simply written one after another now.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
68
diff
changeset
|
236 | valstring = (static_cast<boolconfig*> (cfg)->value) ? "true" : "false"; |
6790dea720a8
Simplified configuration code. Use a std::vector object to contain config pointers and have config objects register themselves upon creation instead of relying on a cfgdefs.h. Removed sections, all configurations are just simply written one after another now.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
68
diff
changeset
|
237 | break; |
78
c190fe218506
Keyboard shortcuts can now be configured.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
69
diff
changeset
|
238 | case CONFIG_keyseq: |
c190fe218506
Keyboard shortcuts can now be configured.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
69
diff
changeset
|
239 | valstring = static_cast<keyseqconfig*> (cfg)->value.toString (); |
c190fe218506
Keyboard shortcuts can now be configured.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
69
diff
changeset
|
240 | break; |
69
6790dea720a8
Simplified configuration code. Use a std::vector object to contain config pointers and have config objects register themselves upon creation instead of relying on a cfgdefs.h. Removed sections, all configurations are just simply written one after another now.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
68
diff
changeset
|
241 | default: |
6790dea720a8
Simplified configuration code. Use a std::vector object to contain config pointers and have config objects register themselves upon creation instead of relying on a cfgdefs.h. Removed sections, all configurations are just simply written one after another now.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
68
diff
changeset
|
242 | break; |
0 | 243 | } |
69
6790dea720a8
Simplified configuration code. Use a std::vector object to contain config pointers and have config objects register themselves upon creation instead of relying on a cfgdefs.h. Removed sections, all configurations are just simply written one after another now.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
68
diff
changeset
|
244 | |
78
c190fe218506
Keyboard shortcuts can now be configured.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
69
diff
changeset
|
245 | const char* sDefault = (cfg->getType() != CONFIG_keyseq) ? cfg->defaultstring : |
c190fe218506
Keyboard shortcuts can now be configured.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
69
diff
changeset
|
246 | static_cast<keyseqconfig*> (cfg)->defval.toString ().toUtf8 ().constData (); |
c190fe218506
Keyboard shortcuts can now be configured.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
69
diff
changeset
|
247 | |
69
6790dea720a8
Simplified configuration code. Use a std::vector object to contain config pointers and have config objects register themselves upon creation instead of relying on a cfgdefs.h. Removed sections, all configurations are just simply written one after another now.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
68
diff
changeset
|
248 | // Write the entry now. |
78
c190fe218506
Keyboard shortcuts can now be configured.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
69
diff
changeset
|
249 | writef (fp, "\n# [%s] default: %s\n", g_ConfigTypeNames[cfg->getType()], sDefault); |
69
6790dea720a8
Simplified configuration code. Use a std::vector object to contain config pointers and have config objects register themselves upon creation instead of relying on a cfgdefs.h. Removed sections, all configurations are just simply written one after another now.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
68
diff
changeset
|
250 | writef (fp, "%s=%s\n", cfg->name, valstring.chars()); |
0 | 251 | } |
252 | ||
253 | fclose (fp); | |
254 | return true; | |
255 | } | |
256 | ||
257 | // ============================================================================= | |
258 | void config::reset () { | |
259 | for (size_t i = 0; i < NUM_CONFIG; i++) | |
69
6790dea720a8
Simplified configuration code. Use a std::vector object to contain config pointers and have config objects register themselves upon creation instead of relying on a cfgdefs.h. Removed sections, all configurations are just simply written one after another now.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
68
diff
changeset
|
260 | g_pConfigPointers[i]->resetValue (); |
0 | 261 | } |
262 | ||
263 | // ============================================================================= | |
264 | str config::filepath () { | |
265 | str path; | |
69
6790dea720a8
Simplified configuration code. Use a std::vector object to contain config pointers and have config objects register themselves upon creation instead of relying on a cfgdefs.h. Removed sections, all configurations are just simply written one after another now.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
68
diff
changeset
|
266 | path.format ("%s" CONFIGFILE, dirpath().chars()); |
0 | 267 | return path; |
268 | } | |
269 | ||
270 | // ============================================================================= | |
271 | str config::dirpath () { | |
69
6790dea720a8
Simplified configuration code. Use a std::vector object to contain config pointers and have config objects register themselves upon creation instead of relying on a cfgdefs.h. Removed sections, all configurations are just simply written one after another now.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
68
diff
changeset
|
272 | str path = (QDir::homePath ().toStdString().c_str()); |
0 | 273 | path += "/." APPNAME "/"; |
274 | ||
275 | return path; | |
276 | } |