Thu, 11 Apr 2013 01:35:30 +0300
Fleshed out the history dialog further
|
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 () { | |
|
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
|
68 | // 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
|
69 | 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
|
70 | |
| 0 | 71 | FILE* fp = fopen (filepath().chars(), "r"); |
| 72 | char linedata[MAX_INI_LINE]; | |
| 73 | char* line; | |
| 74 | size_t ln = 0; | |
| 75 | ||
| 76 | if (!fp) | |
| 77 | return false; // can't open for reading | |
| 78 | ||
| 79 | // Read the values. | |
| 80 | while (fgets (linedata, MAX_INI_LINE, fp)) { | |
| 81 | ln++; | |
| 82 | line = linedata; | |
| 83 | ||
| 84 | while (*line != 0 && (*line <= 32 || *line >= 127)) | |
| 85 | line++; // Skip junk | |
| 86 | ||
| 87 | if (*line == '\0' || line[0] == '#') | |
| 88 | continue; // Empty line or comment. | |
| 89 | ||
| 90 | // Find the equals sign. | |
| 91 | char* equals = strchr (line, '='); | |
| 92 | if (!equals) { | |
| 93 | fprintf (stderr, "couldn't find `=` sign in entry `%s`\n", line); | |
| 94 | continue; | |
| 95 | } | |
| 96 | ||
| 97 | str entry = str (line).substr (0, equals - line); | |
| 98 | ||
| 99 | // 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
|
100 | 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
|
101 | 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
|
102 | 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
|
103 | cfg = i; |
| 0 | 104 | |
| 105 | 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
|
106 | fprintf (stderr, "unknown config `%s`\n", entry.chars()); |
| 0 | 107 | continue; |
| 108 | } | |
| 109 | ||
| 110 | str valstring = str (line).substr (equals - line + 1, -1); | |
| 111 | ||
| 112 | // Trim the crap off the end | |
| 113 | while (~valstring) { | |
| 114 | char c = valstring[~valstring - 1]; | |
| 115 | if (c <= 32 || c >= 127) | |
| 116 | valstring -= 1; | |
| 117 | else | |
| 118 | break; | |
| 119 | } | |
| 120 | ||
| 121 | switch (const_cast<config*> (cfg)->getType()) { | |
| 122 | case CONFIG_int: | |
| 123 | static_cast<intconfig*> (cfg)->value = atoi (valstring.chars()); | |
| 124 | break; | |
|
78
c190fe218506
Keyboard shortcuts can now be configured.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
69
diff
changeset
|
125 | |
| 0 | 126 | case CONFIG_str: |
| 127 | static_cast<strconfig*> (cfg)->value = valstring; | |
| 128 | break; | |
|
78
c190fe218506
Keyboard shortcuts can now be configured.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
69
diff
changeset
|
129 | |
| 0 | 130 | case CONFIG_float: |
| 131 | static_cast<floatconfig*> (cfg)->value = atof (valstring.chars()); | |
| 132 | break; | |
|
78
c190fe218506
Keyboard shortcuts can now be configured.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
69
diff
changeset
|
133 | |
| 0 | 134 | case CONFIG_bool: |
| 135 | { | |
| 136 | bool& val = static_cast<boolconfig*> (cfg)->value; | |
| 137 | ||
| 138 | if (+valstring == "TRUE" || valstring == "1") | |
| 139 | val = true; | |
| 140 | else if (+valstring == "FALSE" || valstring == "0") | |
| 141 | val = false; | |
| 142 | break; | |
| 143 | } | |
|
78
c190fe218506
Keyboard shortcuts can now be configured.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
69
diff
changeset
|
144 | |
|
c190fe218506
Keyboard shortcuts can now be configured.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
69
diff
changeset
|
145 | case CONFIG_keyseq: |
|
c190fe218506
Keyboard shortcuts can now be configured.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
69
diff
changeset
|
146 | 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
|
147 | break; |
|
c190fe218506
Keyboard shortcuts can now be configured.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
69
diff
changeset
|
148 | |
| 0 | 149 | default: |
| 150 | break; | |
| 151 | } | |
| 152 | } | |
| 153 | ||
| 154 | fclose (fp); | |
| 155 | return true; | |
| 156 | } | |
| 157 | ||
| 158 | // ============================================================================= | |
| 159 | // Write a given formatted string to the given file stream | |
| 160 | static size_t writef (FILE* fp, const char* fmt, ...) { | |
| 161 | va_list va; | |
| 162 | ||
| 163 | va_start (va, fmt); | |
| 164 | char* buf = vdynformat (fmt, va, 256); | |
| 165 | va_end (va); | |
| 166 | ||
| 167 | size_t len = fwrite (buf, 1, strlen (buf), fp); | |
| 168 | delete[] buf; | |
| 169 | ||
| 170 | return len; | |
| 171 | } | |
| 172 | ||
| 173 | // ============================================================================= | |
| 174 | // Save the configuration to disk | |
| 175 | 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
|
176 | // 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
|
177 | // 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
|
178 | 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
|
179 | |
|
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
|
180 | // 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
|
181 | 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
|
182 | 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
|
183 | 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
|
184 | 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
|
185 | return false; // Couldn't create directory |
| 0 | 186 | } |
|
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
|
187 | } |
| 0 | 188 | |
| 189 | FILE* fp = fopen (filepath().chars(), "w"); | |
| 190 | printf ("writing cfg to %s\n", filepath().chars()); | |
| 191 | ||
| 192 | if (!fp) { | |
| 193 | printf ("Couldn't open %s for writing\n", filepath().chars()); | |
| 194 | return false; | |
| 195 | } | |
| 196 | ||
| 197 | const time_t curtime = time (NULL); | |
| 198 | const struct tm* timeinfo = localtime (&curtime); | |
| 199 | const char* daysuffix = | |
| 200 | (timeinfo->tm_mday % 10 == 1) ? "st" : | |
| 201 | (timeinfo->tm_mday % 10 == 2) ? "nd" : | |
| 202 | (timeinfo->tm_mday % 10 == 3) ? "rd" : "th"; | |
| 203 | ||
| 204 | writef (fp, "# Configuration file for " APPNAME "\n"); | |
| 205 | writef (fp, "# Written on %s, %s %d%s %d %.2d:%.2d:%.2d\n", | |
| 206 | g_WeekdayNames[timeinfo->tm_wday], g_MonthNames[timeinfo->tm_mon], | |
| 207 | timeinfo->tm_mday, daysuffix, timeinfo->tm_year + 1900, | |
| 208 | timeinfo->tm_hour, timeinfo->tm_min, timeinfo->tm_sec); | |
| 209 | ||
|
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
|
210 | 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
|
211 | 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
|
212 | 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
|
213 | 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
|
214 | 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
|
215 | 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
|
216 | 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
|
217 | 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
|
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_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
|
220 | valstring.format ("%f", static_cast<floatconfig*> (cfg)->value); |
| 0 | 221 | |
|
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
|
222 | // 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
|
223 | 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
|
224 | 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
|
225 | valstring -= 1; |
| 0 | 226 | |
|
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
|
227 | // 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
|
228 | 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
|
229 | valstring += '0'; |
| 0 | 230 | } |
| 231 | ||
|
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
|
232 | 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
|
233 | 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
|
234 | 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
|
235 | break; |
|
78
c190fe218506
Keyboard shortcuts can now be configured.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
69
diff
changeset
|
236 | case CONFIG_keyseq: |
|
c190fe218506
Keyboard shortcuts can now be configured.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
69
diff
changeset
|
237 | valstring = static_cast<keyseqconfig*> (cfg)->value.toString (); |
|
c190fe218506
Keyboard shortcuts can now be configured.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
69
diff
changeset
|
238 | 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
|
239 | 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
|
240 | break; |
| 0 | 241 | } |
|
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 | |
|
78
c190fe218506
Keyboard shortcuts can now be configured.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
69
diff
changeset
|
243 | 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
|
244 | static_cast<keyseqconfig*> (cfg)->defval.toString ().toUtf8 ().constData (); |
|
c190fe218506
Keyboard shortcuts can now be configured.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
69
diff
changeset
|
245 | |
|
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
|
246 | // Write the entry now. |
|
78
c190fe218506
Keyboard shortcuts can now be configured.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
69
diff
changeset
|
247 | 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
|
248 | writef (fp, "%s=%s\n", cfg->name, valstring.chars()); |
| 0 | 249 | } |
| 250 | ||
| 251 | fclose (fp); | |
| 252 | return true; | |
| 253 | } | |
| 254 | ||
| 255 | // ============================================================================= | |
| 256 | void config::reset () { | |
| 257 | 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
|
258 | g_pConfigPointers[i]->resetValue (); |
| 0 | 259 | } |
| 260 | ||
| 261 | // ============================================================================= | |
| 262 | str config::filepath () { | |
| 263 | 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
|
264 | path.format ("%s" CONFIGFILE, dirpath().chars()); |
| 0 | 265 | return path; |
| 266 | } | |
| 267 | ||
| 268 | // ============================================================================= | |
| 269 | 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
|
270 | str path = (QDir::homePath ().toStdString().c_str()); |
| 0 | 271 | path += "/." APPNAME "/"; |
| 272 | ||
| 273 | return path; | |
| 274 | } |