Sat, 20 Apr 2013 04:26:36 +0300
some GUI tweaks
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 |
104 | 3 | * Copyright (C) 2013 Santeri Piippo |
30
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> | |
104 | 23 | #include <QDir> |
24 | #include "common.h" | |
0 | 25 | #include "str.h" |
26 | #include "config.h" | |
27 | ||
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
|
28 | std::vector<config*> g_pConfigPointers; |
0 | 29 | |
30 | // ============================================================================= | |
31 | const char* g_WeekdayNames[7] = { | |
32 | "Sunday", | |
33 | "Monday", | |
34 | "Tuesday", | |
35 | "Wednesday", | |
36 | "Thursday", | |
37 | "Friday", | |
38 | "Saturday", | |
39 | }; | |
40 | ||
41 | // ============================================================================= | |
42 | static const char* g_MonthNames[12] = { | |
43 | "Januray", | |
44 | "February", | |
45 | "March", | |
46 | "April", | |
47 | "May", | |
48 | "June", | |
49 | "July", | |
50 | "August", | |
51 | "September", | |
52 | "October", | |
53 | "November" | |
54 | "December", | |
55 | }; | |
56 | ||
57 | static const char* g_ConfigTypeNames[] = { | |
58 | "None", | |
59 | "Integer", | |
60 | "String", | |
61 | "Float", | |
62 | "Boolean", | |
78
c190fe218506
Keyboard shortcuts can now be configured.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
69
diff
changeset
|
63 | "Key sequence", |
0 | 64 | }; |
65 | ||
66 | // ============================================================================= | |
67 | // Load the configuration from file | |
68 | bool config::load () { | |
99
920d51fec412
Recent files are now remembered and displayed in a submenu
Santeri Piippo <crimsondusk64@gmail.com>
parents:
78
diff
changeset
|
69 | 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
|
70 | |
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
|
71 | // 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
|
72 | 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
|
73 | |
0 | 74 | FILE* fp = fopen (filepath().chars(), "r"); |
75 | char linedata[MAX_INI_LINE]; | |
76 | char* line; | |
77 | size_t ln = 0; | |
78 | ||
79 | if (!fp) | |
80 | return false; // can't open for reading | |
81 | ||
82 | // Read the values. | |
83 | while (fgets (linedata, MAX_INI_LINE, fp)) { | |
84 | ln++; | |
85 | line = linedata; | |
86 | ||
87 | while (*line != 0 && (*line <= 32 || *line >= 127)) | |
88 | line++; // Skip junk | |
89 | ||
90 | if (*line == '\0' || line[0] == '#') | |
91 | continue; // Empty line or comment. | |
92 | ||
93 | // Find the equals sign. | |
94 | char* equals = strchr (line, '='); | |
95 | if (!equals) { | |
96 | fprintf (stderr, "couldn't find `=` sign in entry `%s`\n", line); | |
97 | continue; | |
98 | } | |
99 | ||
100 | str entry = str (line).substr (0, equals - line); | |
101 | ||
102 | // Find the config entry for this. | |
104 | 103 | config* cfg = null; |
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
|
104 | 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
|
105 | 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
|
106 | cfg = i; |
0 | 107 | |
108 | 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
|
109 | fprintf (stderr, "unknown config `%s`\n", entry.chars()); |
0 | 110 | continue; |
111 | } | |
112 | ||
113 | str valstring = str (line).substr (equals - line + 1, -1); | |
114 | ||
115 | // Trim the crap off the end | |
116 | while (~valstring) { | |
117 | char c = valstring[~valstring - 1]; | |
118 | if (c <= 32 || c >= 127) | |
119 | valstring -= 1; | |
120 | else | |
121 | break; | |
122 | } | |
123 | ||
124 | switch (const_cast<config*> (cfg)->getType()) { | |
125 | case CONFIG_int: | |
126 | static_cast<intconfig*> (cfg)->value = atoi (valstring.chars()); | |
127 | break; | |
78
c190fe218506
Keyboard shortcuts can now be configured.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
69
diff
changeset
|
128 | |
0 | 129 | case CONFIG_str: |
130 | static_cast<strconfig*> (cfg)->value = valstring; | |
131 | break; | |
78
c190fe218506
Keyboard shortcuts can now be configured.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
69
diff
changeset
|
132 | |
0 | 133 | case CONFIG_float: |
134 | static_cast<floatconfig*> (cfg)->value = atof (valstring.chars()); | |
135 | break; | |
78
c190fe218506
Keyboard shortcuts can now be configured.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
69
diff
changeset
|
136 | |
0 | 137 | case CONFIG_bool: |
138 | { | |
139 | bool& val = static_cast<boolconfig*> (cfg)->value; | |
140 | ||
141 | if (+valstring == "TRUE" || valstring == "1") | |
142 | val = true; | |
143 | else if (+valstring == "FALSE" || valstring == "0") | |
144 | val = false; | |
145 | break; | |
146 | } | |
78
c190fe218506
Keyboard shortcuts can now be configured.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
69
diff
changeset
|
147 | |
c190fe218506
Keyboard shortcuts can now be configured.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
69
diff
changeset
|
148 | case CONFIG_keyseq: |
c190fe218506
Keyboard shortcuts can now be configured.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
69
diff
changeset
|
149 | 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
|
150 | break; |
c190fe218506
Keyboard shortcuts can now be configured.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
69
diff
changeset
|
151 | |
0 | 152 | default: |
153 | break; | |
154 | } | |
155 | } | |
156 | ||
157 | fclose (fp); | |
158 | return true; | |
159 | } | |
160 | ||
161 | // ============================================================================= | |
162 | // Write a given formatted string to the given file stream | |
163 | static size_t writef (FILE* fp, const char* fmt, ...) { | |
164 | va_list va; | |
165 | ||
166 | va_start (va, fmt); | |
167 | char* buf = vdynformat (fmt, va, 256); | |
168 | va_end (va); | |
169 | ||
170 | size_t len = fwrite (buf, 1, strlen (buf), fp); | |
171 | delete[] buf; | |
172 | ||
173 | return len; | |
174 | } | |
175 | ||
176 | // ============================================================================= | |
177 | // Save the configuration to disk | |
178 | 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
|
179 | // 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
|
180 | // 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
|
181 | 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
|
182 | |
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
|
183 | // 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
|
184 | 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
|
185 | 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
|
186 | 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
|
187 | 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
|
188 | return false; // Couldn't create directory |
0 | 189 | } |
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
|
190 | } |
0 | 191 | |
192 | FILE* fp = fopen (filepath().chars(), "w"); | |
193 | printf ("writing cfg to %s\n", filepath().chars()); | |
194 | ||
195 | if (!fp) { | |
196 | printf ("Couldn't open %s for writing\n", filepath().chars()); | |
197 | return false; | |
198 | } | |
199 | ||
200 | const time_t curtime = time (NULL); | |
201 | const struct tm* timeinfo = localtime (&curtime); | |
202 | const char* daysuffix = | |
203 | (timeinfo->tm_mday % 10 == 1) ? "st" : | |
204 | (timeinfo->tm_mday % 10 == 2) ? "nd" : | |
205 | (timeinfo->tm_mday % 10 == 3) ? "rd" : "th"; | |
206 | ||
207 | writef (fp, "# Configuration file for " APPNAME "\n"); | |
208 | writef (fp, "# Written on %s, %s %d%s %d %.2d:%.2d:%.2d\n", | |
209 | g_WeekdayNames[timeinfo->tm_wday], g_MonthNames[timeinfo->tm_mon], | |
210 | timeinfo->tm_mday, daysuffix, timeinfo->tm_year + 1900, | |
211 | timeinfo->tm_hour, timeinfo->tm_min, timeinfo->tm_sec); | |
212 | ||
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
|
213 | 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
|
214 | 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
|
215 | 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
|
216 | 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
|
217 | 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
|
218 | 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
|
219 | 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
|
220 | 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
|
221 | 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
|
222 | 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
|
223 | valstring.format ("%f", static_cast<floatconfig*> (cfg)->value); |
0 | 224 | |
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
|
225 | // 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
|
226 | 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
|
227 | 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
|
228 | valstring -= 1; |
0 | 229 | |
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
|
230 | // 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
|
231 | 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
|
232 | valstring += '0'; |
0 | 233 | } |
234 | ||
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
|
235 | 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
|
236 | 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
|
237 | 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
|
238 | break; |
78
c190fe218506
Keyboard shortcuts can now be configured.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
69
diff
changeset
|
239 | case CONFIG_keyseq: |
c190fe218506
Keyboard shortcuts can now be configured.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
69
diff
changeset
|
240 | valstring = static_cast<keyseqconfig*> (cfg)->value.toString (); |
c190fe218506
Keyboard shortcuts can now be configured.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
69
diff
changeset
|
241 | 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
|
242 | 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
|
243 | break; |
0 | 244 | } |
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
|
245 | |
78
c190fe218506
Keyboard shortcuts can now be configured.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
69
diff
changeset
|
246 | 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
|
247 | static_cast<keyseqconfig*> (cfg)->defval.toString ().toUtf8 ().constData (); |
c190fe218506
Keyboard shortcuts can now be configured.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
69
diff
changeset
|
248 | |
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
|
249 | // Write the entry now. |
78
c190fe218506
Keyboard shortcuts can now be configured.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
69
diff
changeset
|
250 | 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
|
251 | writef (fp, "%s=%s\n", cfg->name, valstring.chars()); |
0 | 252 | } |
253 | ||
254 | fclose (fp); | |
255 | return true; | |
256 | } | |
257 | ||
258 | // ============================================================================= | |
259 | void config::reset () { | |
260 | 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
|
261 | g_pConfigPointers[i]->resetValue (); |
0 | 262 | } |
263 | ||
264 | // ============================================================================= | |
265 | str config::filepath () { | |
266 | 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
|
267 | path.format ("%s" CONFIGFILE, dirpath().chars()); |
0 | 268 | return path; |
269 | } | |
270 | ||
271 | // ============================================================================= | |
272 | 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
|
273 | str path = (QDir::homePath ().toStdString().c_str()); |
0 | 274 | path += "/." APPNAME "/"; |
275 | ||
276 | return path; | |
277 | } |