proxy: Actually fix settings migration logic
authorManuel Nickschas <sputnick@quassel-irc.org>
Thu, 1 Mar 2018 21:03:53 +0000 (22:03 +0100)
committerManuel Nickschas <sputnick@quassel-irc.org>
Thu, 1 Mar 2018 21:09:12 +0000 (22:09 +0100)
Not sure what the previous code was supposed to accomplish, but
proxy settings are stored in [CoreAccounts] and thus migration needs
to happen for each configured account. Also, the UseProxy flag was
removed and thus must be translated to ProxyType::NoProxy.

Closes GH-181.

src/qtui/qtuiapplication.cpp

index 05ffeed..927248f 100644 (file)
@@ -281,12 +281,17 @@ bool QtUiApplication::applySettingsMigration(QtUiSettings settings, const uint n
     // migrateSettings()!  Otherwise, your upgrade logic won't ever be called.
     case 7:
     {
-        // New default changes: ProxyType=3 (no proxy) now means QNetworkProxy::HttpProxy
-        // So we have to change it to ProxyType=2 (QNetworkProxy::NoProxy)
-        const QString proxyType = "ProxyType";
-        if (settings.valueExists(proxyType) && settings.value(proxyType)=="3") {
-            settings.setValue(proxyType, 2);
+        // New default changes: UseProxy is no longer used in CoreAccountSettings
+        CoreAccountSettings s;
+        for (auto &&accountId : s.knownAccounts()) {
+            auto map = s.retrieveAccountData(accountId);
+            if (!map.value("UseProxy", false).toBool()) {
+                map["ProxyType"] = static_cast<int>(QNetworkProxy::ProxyType::NoProxy);
+            }
+            map.remove("UseProxy");
+            s.storeAccountData(accountId, map);
         }
+
         // Migration complete!
         return true;
     }