Settings stored persistently using QSettings.
authorDavid <david@flypig.co.uk>
Sun, 9 Mar 2014 23:31:41 +0000 (23:31 +0000)
committerDavid <david@flypig.co.uk>
Sun, 9 Mar 2014 23:31:41 +0000 (23:31 +0000)
qml/pages/ConfigurePage.qml
qml/pages/ConnectPage.qml
src/OpenVPNUI.cpp
src/vpncontrol.cpp
src/vpncontrol.h

index ecb75da..1692d1e 100644 (file)
@@ -34,7 +34,6 @@
 
 import QtQuick 2.0
 import Sailfish.Silica 1.0
 
 import QtQuick 2.0
 import Sailfish.Silica 1.0
-import QtQuick.Dialogs 1.0
 
 Dialog {
     id: configurePage
 
 Dialog {
     id: configurePage
index fcc2222..23bd65b 100644 (file)
@@ -35,7 +35,6 @@
 import QtQuick 2.0
 import Sailfish.Silica 1.0
 
 import QtQuick 2.0
 import Sailfish.Silica 1.0
 
-
 Page {
     id: connectPage
 
 Page {
     id: connectPage
 
index c998750..40e28ef 100644 (file)
@@ -56,6 +56,13 @@ int main(int argc, char *argv[])
     // To display the view, call "show()" (will show fullscreen on device).
 
     QScopedPointer<QGuiApplication> app(SailfishApp::application(argc, argv));
     // To display the view, call "show()" (will show fullscreen on device).
 
     QScopedPointer<QGuiApplication> app(SailfishApp::application(argc, argv));
+
+    // These values are used by QSettings to access the config file in
+    // /home/nemo/.local/share/flypig/OpenVPNUI.conf
+    QCoreApplication::setOrganizationName("flypig");
+    QCoreApplication::setOrganizationDomain("www.flypig.co.uk");
+    QCoreApplication::setApplicationName("OpenVPNUI");
+
     QScopedPointer<QQuickView> view(SailfishApp::createView());
 
     view->setSource(SailfishApp::pathTo("qml/OpenVPNUI.qml"));
     QScopedPointer<QQuickView> view(SailfishApp::createView());
 
     view->setSource(SailfishApp::pathTo("qml/OpenVPNUI.qml"));
index 1935194..7bd002f 100644 (file)
@@ -1,16 +1,26 @@
 #include "vpncontrol.h"
 #include "stdio.h"
 #include "vpncontrol.h"
 #include "stdio.h"
+#include <QSettings>
+
 
 VPNControl::VPNControl(QObject *parent) :
     QObject(parent),
     vpnProcess(NULL),
     vpnStatus(VPNSTATUS_INVALID),
     server(""),
 
 VPNControl::VPNControl(QObject *parent) :
     QObject(parent),
     vpnProcess(NULL),
     vpnStatus(VPNSTATUS_INVALID),
     server(""),
-    port(1174),
+    port(1194),
     compressed(true),
     useTLS(true),
     tlsDirection(1)
 {
     compressed(true),
     useTLS(true),
     tlsDirection(1)
 {
+    // Read in the settings
+    QSettings settings;
+
+    server = settings.value("server", "127.0.0.1").toString();
+    port = settings.value("port", 1194).toInt();
+    compressed = settings.value("compressed", true).toBool();
+    useTLS = settings.value("useTLS", true).toBool();
+    tlsDirection = settings.value("tlsDirection", 1).toInt();
 }
 
 void VPNControl::initialise()
 }
 
 void VPNControl::initialise()
@@ -33,9 +43,12 @@ int VPNControl::getTlsDirection() const
 
 void VPNControl::setTlsDirection(int value)
 {
 
 void VPNControl::setTlsDirection(int value)
 {
-    printf ("TLS direction set to %d\n", value);
-    tlsDirection = value;
-    emit tlsDirectionChanged (value);
+    if (value != tlsDirection) {
+        printf ("TLS direction set to %d\n", value);
+        tlsDirection = value;
+        settingsSetValue("tlsDirection", value);
+        emit tlsDirectionChanged (value);
+    }
 }
 
 bool VPNControl::getUseTLS() const
 }
 
 bool VPNControl::getUseTLS() const
@@ -45,9 +58,12 @@ bool VPNControl::getUseTLS() const
 
 void VPNControl::setUseTLS(bool value)
 {
 
 void VPNControl::setUseTLS(bool value)
 {
-    printf ("Use TLS set to %d\n", value);
-    useTLS = value;
-    emit useTLSChanged(useTLS);
+    if (value != useTLS) {
+        printf ("Use TLS set to %d\n", value);
+        useTLS = value;
+        settingsSetValue("useTLS", value);
+        emit useTLSChanged(useTLS);
+    }
 }
 
 bool VPNControl::getCompressed() const
 }
 
 bool VPNControl::getCompressed() const
@@ -57,9 +73,12 @@ bool VPNControl::getCompressed() const
 
 void VPNControl::setCompressed(bool value)
 {
 
 void VPNControl::setCompressed(bool value)
 {
-    printf ("Use compression set to %d\n", value);
-    compressed = value;
-    emit compressedChanged(compressed);
+    if (value != compressed) {
+        printf ("Use compression set to %d\n", value);
+        compressed = value;
+        settingsSetValue("compressed", value);
+        emit compressedChanged(compressed);
+    }
 }
 
 unsigned int VPNControl::getPort() const
 }
 
 unsigned int VPNControl::getPort() const
@@ -69,9 +88,12 @@ unsigned int VPNControl::getPort() const
 
 void VPNControl::setPort(unsigned int value)
 {
 
 void VPNControl::setPort(unsigned int value)
 {
-    printf ("Port set to %d\n", value);
-    port = value;
-    emit portChanged(port);
+    if (value != port) {
+        printf ("Port set to %d\n", value);
+        port = value;
+        settingsSetValue("port", value);
+        emit portChanged(port);
+    }
 }
 
 QString VPNControl::getServer() const
 }
 
 QString VPNControl::getServer() const
@@ -81,9 +103,24 @@ QString VPNControl::getServer() const
 
 void VPNControl::setServer(const QString &value)
 {
 
 void VPNControl::setServer(const QString &value)
 {
-    printf ("Server set to %s\n", value.toUtf8().constData());
-    server = value;
-    emit serverChanged(server);
+    if (value != server) {
+        printf ("Server set to %s\n", value.toUtf8().constData());
+        server = value;
+        settingsSetValue("server", value);
+        emit serverChanged(server);
+    }
+}
+
+void VPNControl::settingsSetValue (QString key, QString value) {
+    QSettings settings;
+
+    settings.setValue(key, value);
+}
+
+void VPNControl::settingsSetValue (QString key, int value) {
+    QSettings settings;
+
+    settings.setValue(key, value);
 }
 
 void VPNControl::vpnConnect() {
 }
 
 void VPNControl::vpnConnect() {
index 909f3b2..542ec95 100644 (file)
@@ -30,17 +30,22 @@ private:
     QProcess * vpnProcess;
     VPNSTATUS vpnStatus;
     QStringList arguments;
     QProcess * vpnProcess;
     VPNSTATUS vpnStatus;
     QStringList arguments;
+
+    // Configuration options
     QString server;
     unsigned int port;
     bool compressed;
     bool useTLS;
     int tlsDirection;
     QString server;
     unsigned int port;
     bool compressed;
     bool useTLS;
     int tlsDirection;
+
     void collectArguments ();
     void setStatus (VPNSTATUS newStatus);
     void addArgument (QString key, QString value);
     void addArgument (QString key);
     void addOption (QString key, bool add);
     void addValue (QString key);
     void collectArguments ();
     void setStatus (VPNSTATUS newStatus);
     void addArgument (QString key, QString value);
     void addArgument (QString key);
     void addOption (QString key, bool add);
     void addValue (QString key);
+    void settingsSetValue (QString key, QString value);
+    void settingsSetValue (QString key, int value);
 
 public:
     explicit VPNControl(QObject *parent = 0);
 
 public:
     explicit VPNControl(QObject *parent = 0);