Settings (dialog): add username/password options for proxy server
authorgregor herrmann <gregor@toastfreeware.priv.at>
Fri, 6 Oct 2017 19:34:23 +0000 (21:34 +0200)
committergregor herrmann <gregor@toastfreeware.priv.at>
Fri, 6 Oct 2017 19:34:23 +0000 (21:34 +0200)
Cf. #59

src/app/appsettings.cpp
src/app/appsettings.h
src/gui/mainwindow.cpp
src/gui/settingsdialog.cpp
src/gui/settingsdialog.ui

index f220969..f92c17e 100644 (file)
@@ -22,6 +22,8 @@
 const QString PROXY_ADDRESS_SETTING ("proxyAddress"); 
 const QString PROXY_PORT_SETTING ("proxyPort"); 
 const QString PROXY_TYPE_SETTING ("proxyType");
+const QString PROXY_USERNAME_SETTING ("proxyUsername");
+const QString PROXY_PASSWORD_SETTING ("proxyPassword");
 const QString PROXY_ISDIRECT_SETTING ("proxyIsDirectConnection");
 
 QSettings AppSettings::mSettings("Toastfreeware", "ConfClerk");
@@ -44,6 +46,16 @@ QNetworkProxy::ProxyType AppSettings::proxyType()
     return QNetworkProxy::ProxyType(proxyType);
 }
 
+QString AppSettings::proxyUsername()
+{
+    return mSettings.value(PROXY_USERNAME_SETTING).toString();
+}
+
+QString AppSettings::proxyPassword()
+{
+    return mSettings.value(PROXY_PASSWORD_SETTING).toString();
+}
+
 bool AppSettings::isDirectConnection()
 {
     return mSettings.value(PROXY_ISDIRECT_SETTING).toBool();
@@ -64,6 +76,16 @@ void AppSettings::setProxyType(QNetworkProxy::ProxyType aProxyType)
     mSettings.setValue(PROXY_TYPE_SETTING, aProxyType);
 }
 
+void AppSettings::setProxyUsername(const QString &aUsername)
+{
+    mSettings.setValue(PROXY_USERNAME_SETTING, aUsername);
+}
+
+void AppSettings::setProxyPassword(const QString &aPassword)
+{
+    mSettings.setValue(PROXY_PASSWORD_SETTING, aPassword);
+}
+
 void AppSettings::setDirectConnection(bool aDirectConnection)
 {
     mSettings.setValue(PROXY_ISDIRECT_SETTING, aDirectConnection);
index 1b5a16b..f116f18 100644 (file)
@@ -37,11 +37,15 @@ class AppSettings
         static QString proxyAddress();
         static quint16 proxyPort();
         static QNetworkProxy::ProxyType proxyType();
+        static QString proxyUsername();
+        static QString proxyPassword();
         static bool isDirectConnection();
 
         static void setProxyAddress(const QString &aAddress);
         static void setProxyPort(const quint16 aPort);
         static void setProxyType(QNetworkProxy::ProxyType aProxyType);
+        static void setProxyUsername(const QString &aUsername);
+        static void setProxyPassword(const QString &aPassword);
         static void setDirectConnection(bool aDirectConnection);
         static int preEventAlarmSec() {return 60*15;} ///< seconds that alarm should ring before an event starts
 };
index dbbcb2f..9181343 100644 (file)
@@ -49,9 +49,6 @@
 #include "tabcontainer.h"
 #include "appsettings.h"
 
-const QString PROXY_USERNAME;
-const QString PROXY_PASSWD;
-
 MainWindow::MainWindow(QWidget* parent): QMainWindow(parent) {
     setupUi(this);
 
@@ -85,8 +82,8 @@ MainWindow::MainWindow(QWidget* parent): QMainWindow(parent) {
             AppSettings::isDirectConnection() ? QNetworkProxy::NoProxy : (QNetworkProxy::ProxyType)AppSettings::proxyType(),
             AppSettings::proxyAddress(),
             AppSettings::proxyPort(),
-            PROXY_USERNAME,
-            PROXY_PASSWD);
+            AppSettings::proxyUsername(),
+            AppSettings::proxyPassword());
     QNetworkProxy::setApplicationProxy(proxy);
 
     // event details have changed
@@ -366,8 +363,8 @@ void MainWindow::on_settingsAction_triggered()
                 AppSettings::isDirectConnection() ? QNetworkProxy::NoProxy : (QNetworkProxy::ProxyType)AppSettings::proxyType(),
                 AppSettings::proxyAddress(),
                 AppSettings::proxyPort(),
-                PROXY_USERNAME,
-                PROXY_PASSWD);
+                AppSettings::proxyUsername(),
+                AppSettings::proxyPassword());
         QNetworkProxy::setApplicationProxy(proxy);
     }
 }
index f00ce94..0262d91 100644 (file)
@@ -38,6 +38,8 @@ void SettingsDialog::loadDialogData()
     const QNetworkProxy::ProxyType proxyType = AppSettings::proxyType();
     proxyTypeHTTP->setChecked(proxyType != QNetworkProxy::Socks5Proxy); // we enable QNetworkProxy::HttpProxy by default unless we have QNetworkProxy::Socks5Proxy
     proxyTypeSOCKS5->setChecked(proxyType == QNetworkProxy::Socks5Proxy);
+    username->setText(AppSettings::proxyUsername());
+    password->setText(AppSettings::proxyPassword());
     directConnection->setChecked(AppSettings::isDirectConnection());
     proxyWidget->setDisabled(directConnection->isChecked());
 }
@@ -49,6 +51,8 @@ void SettingsDialog::saveDialogData()
     AppSettings::setProxyAddress(address->text());
     AppSettings::setProxyPort(port->value());
     AppSettings::setProxyType(proxyTypeHTTP->isChecked() ? QNetworkProxy::HttpProxy : proxyTypeSOCKS5->isChecked() ? QNetworkProxy::Socks5Proxy : QNetworkProxy::DefaultProxy);
+    AppSettings::setProxyUsername(username->text());
+    AppSettings::setProxyPassword(password->text());
     AppSettings::setDirectConnection(directConnection->isChecked());
 }
 
index 579ffd6..7fa6da6 100644 (file)
            </item>
           </layout>
          </item>
+          <item>
+           <layout class="QHBoxLayout" name="horizontalLayout_3">
+            <item>
+             <widget class="QLabel" name="label_4">
+              <property name="text">
+               <string>Optional: Username:</string>
+              </property>
+             </widget>
+            </item>
+            <item>
+             <widget class="QLineEdit" name="username">
+             </widget>
+            </item>
+            <item>
+             <widget class="QLabel" name="label_5">
+              <property name="text">
+               <string>Password:</string>
+              </property>
+             </widget>
+            </item>
+            <item>
+             <widget class="QLineEdit" name="password">
+              <property name="echoMode">
+               <enum>QLineEdit::Password</enum>
+              </property>
+             </widget>
+            </item>
+           </layout>
+          </item>
         </layout>
        </widget>
       </item>