History

Move runnings scripts setting storage

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.

Atlante45 committed 10 years ago

Commit de36cd11 parent 10c412d1 file · +38 −1Browse files

Showing the changes to libraries/script-engine/src/ScriptEngines.cpp (1 of 1 file). Show all

Unified · Split

libraries/script-engine/src/ScriptEngines.cpp+38−1
@@ -256,7 +256,7 @@ QVariantList ScriptEngines::getRunning() { · 255 unmodified lines
256256 }
257257
258258
259−static const QString SETTINGS_KEY = "Settings";
259+static const QString SETTINGS_KEY = "RunningScripts";
260260
261261 void ScriptEngines::loadDefaultScripts() {
262262 QUrl defaultScriptsLoc = defaultScriptsLocation();
@@ -281,6 +281,43 @@ void ScriptEngines::loadScripts() { · 18 unmodified lines
281281
282282 // loads all saved scripts
283283 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+
284321 int size = settings.beginReadArray(SETTINGS_KEY);
285322 for (int i = 0; i < size; ++i) {
286323 settings.setArrayIndex(i);