So that it doesn't conflict with the "Settings" menu setting storage. Running script would clear those settings while storing its data This adds some backward compatible code to move the scripts settings to the new location.
Showing the changes to libraries/script-engine/src/ScriptEngines.cpp (1 of 1 file). Show all
Unified · Split
| @@ -256,7 +256,7 @@ QVariantList ScriptEngines::getRunning() { · 255 unmodified lines | ||
| 256 | 256 | } |
| 257 | 257 | |
| 258 | 258 | |
| 259 | −static const QString SETTINGS_KEY = "Settings"; | |
| 259 | +static const QString SETTINGS_KEY = "RunningScripts"; | |
| 260 | 260 | |
| 261 | 261 | void ScriptEngines::loadDefaultScripts() { |
| 262 | 262 | QUrl defaultScriptsLoc = defaultScriptsLocation(); |
| @@ -281,6 +281,43 @@ void ScriptEngines::loadScripts() { · 18 unmodified lines | ||
| 281 | 281 | |
| 282 | 282 | // loads all saved scripts |
| 283 | 283 | Settings settings; |
| 284 | + | |
| 285 | + | |
| 286 | + // START of backward compatibility code | |
| 287 | + // This following if statement is only meant to update the settings file still using the old setting key. | |
| 288 | + // If you read that comment and it has been more than a couple months since it was merged, | |
| 289 | + // then by all means, feel free to remove it. | |
| 290 | + if (!settings.childGroups().contains(SETTINGS_KEY)) { | |
| 291 | + qWarning() << "Detected old script settings config, loading from previous location"; | |
| 292 | + const QString oldKey = "Settings"; | |
| 293 | + | |
| 294 | + // Load old scripts array from settings | |
| 295 | + int size = settings.beginReadArray(oldKey); | |
| 296 | + for (int i = 0; i < size; ++i) { | |
| 297 | + settings.setArrayIndex(i); | |
| 298 | + QString string = settings.value("script").toString(); | |
| 299 | + if (!string.isEmpty()) { | |
| 300 | + loadScript(string); | |
| 301 | + } | |
| 302 | + } | |
| 303 | + settings.endArray(); | |
| 304 | + | |
| 305 | + // Cleanup old scripts array from settings | |
| 306 | + settings.beginWriteArray(oldKey); | |
| 307 | + for (int i = 0; i < size; ++i) { | |
| 308 | + settings.setArrayIndex(i); | |
| 309 | + settings.remove(""); | |
| 310 | + } | |
| 311 | + settings.endArray(); | |
| 312 | + settings.beginGroup(oldKey); | |
| 313 | + settings.remove("size"); | |
| 314 | + settings.endGroup(); | |
| 315 | + | |
| 316 | + return; | |
| 317 | + } | |
| 318 | + // END of backward compatibility code | |
| 319 | + | |
| 320 | + | |
| 284 | 321 | int size = settings.beginReadArray(SETTINGS_KEY); |
| 285 | 322 | for (int i = 0; i < size; ++i) { |
| 286 | 323 | settings.setArrayIndex(i); |