AppSettings returns the proxy type as QNetworkProxy instead of int now.
authorPhilipp Spitzer <philipp@spitzer.priv.at>
Thu, 5 Oct 2017 20:50:44 +0000 (22:50 +0200)
committerPhilipp Spitzer <philipp@spitzer.priv.at>
Thu, 5 Oct 2017 20:50:44 +0000 (22:50 +0200)
src/app/appsettings.cpp
src/app/appsettings.h
src/gui/settingsdialog.cpp

index 477c1b0..f220969 100644 (file)
@@ -36,10 +36,12 @@ quint16 AppSettings::proxyPort()
     return mSettings.value(PROXY_PORT_SETTING).toUInt();
 }
 
-//QNetworkProxy::ProxyType
-int AppSettings::proxyType()
+QNetworkProxy::ProxyType AppSettings::proxyType()
 {
-    return mSettings.value(PROXY_TYPE_SETTING).toInt();
+    bool ok;
+    int proxyType = mSettings.value(PROXY_TYPE_SETTING).toInt(&ok);
+    if (!ok || proxyType < 0 || proxyType > 5) return QNetworkProxy::DefaultProxy;
+    return QNetworkProxy::ProxyType(proxyType);
 }
 
 bool AppSettings::isDirectConnection()
@@ -57,10 +59,9 @@ void AppSettings::setProxyPort(const quint16 aPort)
     mSettings.setValue(PROXY_PORT_SETTING, aPort);
 }
 
-// QNetworkProxy::ProxyType
-void AppSettings::setProxyType(const int aType)
+void AppSettings::setProxyType(QNetworkProxy::ProxyType aProxyType)
 {
-    mSettings.setValue(PROXY_TYPE_SETTING, aType);
+    mSettings.setValue(PROXY_TYPE_SETTING, aProxyType);
 }
 
 void AppSettings::setDirectConnection(bool aDirectConnection)
index 7f26441..1b5a16b 100644 (file)
@@ -36,12 +36,12 @@ class AppSettings
 
         static QString proxyAddress();
         static quint16 proxyPort();
-        static int proxyType(); // QNetworkProxy::ProxyType
+        static QNetworkProxy::ProxyType proxyType();
         static bool isDirectConnection();
 
         static void setProxyAddress(const QString &aAddress);
         static void setProxyPort(const quint16 aPort);
-        static void setProxyType(const int aProxyType); // QNetworkProxy::ProxyType
+        static void setProxyType(QNetworkProxy::ProxyType aProxyType);
         static void setDirectConnection(bool aDirectConnection);
         static int preEventAlarmSec() {return 60*15;} ///< seconds that alarm should ring before an event starts
 };
index 3e29c78..91f5fdc 100644 (file)
@@ -35,9 +35,9 @@ void SettingsDialog::loadDialogData()
     // deserialize dialog data
     address->setText(AppSettings::proxyAddress());
     port->setValue(AppSettings::proxyPort());
-    const int proxyType = AppSettings::proxyType(); // QNetworkProxy::ProxyType
-    proxyTypeHTTP->setChecked(proxyType != 1); // HTTP=3, but we enable it by default, i.e. unless SOCKS5=1
-    proxyTypeSOCKS5->setChecked(proxyType == 1);
+    const QNetworkProxy::ProxyType proxyType = AppSettings::proxyType();
+    proxyTypeHTTP->setChecked(proxyType != QNetworkProxy::Socks5Proxy); // we enable it by default unless SOCKS5=1
+    proxyTypeSOCKS5->setChecked(proxyType == QNetworkProxy::Socks5Proxy);
     directConnection->setChecked(AppSettings::isDirectConnection());
     proxyWidget->setDisabled(directConnection->isChecked());
 }
@@ -48,7 +48,7 @@ void SettingsDialog::saveDialogData()
     // serialize dialog data
     AppSettings::setProxyAddress(address->text());
     AppSettings::setProxyPort(port->value());
-    AppSettings::setProxyType(proxyTypeHTTP->isChecked() ? 3 : proxyTypeSOCKS5->isChecked() ? 1 : 0);
+    AppSettings::setProxyType(proxyTypeHTTP->isChecked() ? QNetworkProxy::HttpProxy : proxyTypeSOCKS5->isChecked() ? QNetworkProxy::Socks5Proxy : QNetworkProxy::DefaultProxy);
     AppSettings::setDirectConnection(directConnection->isChecked());
 }