From: David Date: Mon, 17 Feb 2014 01:55:18 +0000 (+0000) Subject: Configuration values are passed between the interface and main code. X-Git-Url: https://www.flypig.org.uk/git/?p=openvpnui.git;a=commitdiff_plain;h=2e0816fb79e6c696ada4fe098ba006fca2741a1f Configuration values are passed between the interface and main code. --- diff --git a/qml/pages/ConfigurePage.qml b/qml/pages/ConfigurePage.qml index f02f335..0db890a 100644 --- a/qml/pages/ConfigurePage.qml +++ b/qml/pages/ConfigurePage.qml @@ -41,6 +41,10 @@ Dialog { canAccept: true acceptDestinationAction: PageStackAction.Pop + Connections { + target:VpnControl + } + SilicaFlickable { // ComboBox requires a flickable ancestor width: parent.width @@ -64,6 +68,7 @@ Dialog { TextField { id: configureAddress width: parent.width + text: VpnControl.server label: "Server address" placeholderText: "Server address" focus: true @@ -73,6 +78,7 @@ Dialog { TextField { id: configurePort width: parent.width + text: VpnControl.port; inputMethodHints: Qt.ImhFormattedNumbersOnly label: "Port number" placeholderText: "Port number" @@ -82,22 +88,26 @@ Dialog { TextSwitch { id: configureCompression text: "Use Compression" + checked: VpnControl.compressed + automaticCheck: true } TextSwitch { id: configureTLS text: "Use TLS authentication" + checked: VpnControl.useTLS onCheckedChanged: { configureTLSdirection.enabled = checked configureTLSinfo.visible = checked } + automaticCheck: true } // set currentIndex to change the selected value ComboBox { id: configureTLSdirection width: parent.width label: "TLS direction" - currentIndex: 1 + currentIndex: VpnControl.tlsDirection; enabled: false menu: ContextMenu { @@ -143,6 +153,12 @@ Dialog { } onAccepted: { + VpnControl.setServer(configureAddress.text) + VpnControl.setPort(configurePort.text) + VpnControl.setCompressed(configureCompression.checked) + VpnControl.setUseTLS(configureTLS.checked) + VpnControl.setTlsDirection(configureTLSdirection.currentIndex) + VpnControl.updateConfiguration() } } diff --git a/src/vpncontrol.cpp b/src/vpncontrol.cpp index 8b0c79a..a519dce 100644 --- a/src/vpncontrol.cpp +++ b/src/vpncontrol.cpp @@ -4,7 +4,12 @@ VPNControl::VPNControl(QObject *parent) : QObject(parent), vpnProcess(NULL), - vpnStatus(VPNSTATUS_INVALID) + vpnStatus(VPNSTATUS_INVALID), + server(""), + port(1174), + compressed(true), + useTLS(true), + tlsDirection(1) { } @@ -21,6 +26,66 @@ void VPNControl::setStatus(VPNSTATUS newStatus) printf ("Emitting status %d\n", newStatus); } } +int VPNControl::getTlsDirection() const +{ + return tlsDirection; +} + +void VPNControl::setTlsDirection(int value) +{ + printf ("TLS direction set to %d\n", value); + tlsDirection = value; + emit tlsDirectionChanged (value); +} + +bool VPNControl::getUseTLS() const +{ + return useTLS; +} + +void VPNControl::setUseTLS(bool value) +{ + printf ("Use TLS set to %d\n", value); + useTLS = value; + emit useTLSChanged(useTLS); +} + +bool VPNControl::getCompressed() const +{ + return compressed; +} + +void VPNControl::setCompressed(bool value) +{ + printf ("Use compression set to %d\n", value); + compressed = value; + emit compressedChanged(compressed); +} + +unsigned int VPNControl::getPort() const +{ + return port; +} + +void VPNControl::setPort(unsigned int value) +{ + printf ("Port set to %d\n", value); + port = value; + emit portChanged(port); +} + +QString VPNControl::getServer() const +{ + return server; +} + +void VPNControl::setServer(const QString &value) +{ + printf ("Server set to %s\n", value.toUtf8().constData()); + server = value; + emit serverChanged(server); +} + void VPNControl::vpnConnect() { if (vpnProcess != NULL) { @@ -95,3 +160,8 @@ void VPNControl::readError(QProcess::ProcessError error) // Disconnect vpnDisconnect(); } + +void VPNControl::updateConfiguration() +{ + printf ("Update configuration\n"); +} diff --git a/src/vpncontrol.h b/src/vpncontrol.h index d73f344..e994b83 100644 --- a/src/vpncontrol.h +++ b/src/vpncontrol.h @@ -19,17 +19,39 @@ enum VPNSTATUS { class VPNControl : public QObject { Q_OBJECT + + Q_PROPERTY (QString server READ getServer WRITE setServer NOTIFY serverChanged) + Q_PROPERTY (unsigned int port READ getPort WRITE setPort NOTIFY portChanged) + Q_PROPERTY (bool compressed READ getCompressed WRITE setCompressed NOTIFY compressedChanged) + Q_PROPERTY (bool useTLS READ getUseTLS WRITE setUseTLS NOTIFY useTLSChanged) + Q_PROPERTY (int tlsDirection READ getTlsDirection WRITE setTlsDirection NOTIFY tlsDirectionChanged) + private: QProcess * vpnProcess; VPNSTATUS vpnStatus; void setStatus (VPNSTATUS newStatus); + QString server; + unsigned int port; + bool compressed; + bool useTLS; + int tlsDirection; public: explicit VPNControl(QObject *parent = 0); void initialise(); + QString getServer() const; + unsigned int getPort() const; + bool getCompressed() const; + bool getUseTLS() const; + int getTlsDirection() const; signals: void statusChanged(int status); + void serverChanged(QString server); + void portChanged(unsigned int port); + void compressedChanged(bool compressed); + void useTLSChanged(bool useTLS); + void tlsDirectionChanged (int direction); public slots: void vpnConnect (); @@ -38,6 +60,12 @@ public slots: void started (); void finished (int code); void readError (QProcess::ProcessError error); + void updateConfiguration (); + void setServer(const QString &value); + void setPort(unsigned int value); + void setCompressed(bool value); + void setUseTLS(bool value); + void setTlsDirection(int value); }; #endif // VPNCONTROL_H