From 7a870818f95f0dd0ced94643aac1bbae6f68b2fd Mon Sep 17 00:00:00 2001 From: David Date: Tue, 18 Mar 2014 01:08:55 +0000 Subject: [PATCH] Added configurable path to extra configuration file. --- OpenVPNUI.pro.user | 2 +- qml/pages/ConfigurePage.qml | 25 ++++++++++++++++++++++--- qml/pages/ConnectPage.qml | 1 + rpm/OpenVPNUI.spec | 20 ++++++++++---------- rpm/OpenVPNUI.yaml | 20 ++++++++++---------- src/vpncontrol.cpp | 27 +++++++++++++++++++++------ src/vpncontrol.h | 33 ++++++++++++++++++++++++--------- 7 files changed, 89 insertions(+), 39 deletions(-) diff --git a/OpenVPNUI.pro.user b/OpenVPNUI.pro.user index b84568c..3f36955 100644 --- a/OpenVPNUI.pro.user +++ b/OpenVPNUI.pro.user @@ -1,6 +1,6 @@ - + ProjectExplorer.Project.ActiveTarget diff --git a/qml/pages/ConfigurePage.qml b/qml/pages/ConfigurePage.qml index d00f37f..7d21761 100644 --- a/qml/pages/ConfigurePage.qml +++ b/qml/pages/ConfigurePage.qml @@ -64,6 +64,9 @@ Dialog { case 4: tlsKeyFilename.value = engine.selectedFilename break; + case 5: + configFilename.value = engine.selectedFilename + break; } _fileDialogue = 0; } @@ -151,8 +154,9 @@ Dialog { ValueButtonAlignRight { id: clientCertFilename - value: ((VpnControl.clientCertFile === "") ? "Select" : VpnControl.clientCertFile) label: "Client cert" + value: VpnControl.clientCertFile + placeholderText: "Select" width: parent.width onClicked: { _fileDialogue = 2; @@ -162,8 +166,9 @@ Dialog { ValueButtonAlignRight { id: clientKeyFilename - value: ((VpnControl.clientKeyFile === "") ? "Select" : VpnControl.clientKeyFile) label: "Client key" + value: VpnControl.clientKeyFile + placeholderText: "Select" width: parent.width onClicked: { _fileDialogue = 3; @@ -173,8 +178,9 @@ Dialog { ValueButtonAlignRight { id: tlsKeyFilename - value: ((VpnControl.tlsKeyFile === "") ? "Select" : VpnControl.tlsKeyFile) label: "TLS key" + value: VpnControl.tlsKeyFile + placeholderText: "Select" width: parent.width enabled: configureTLS.checked onClicked: { @@ -182,6 +188,18 @@ Dialog { Functions.goToInitial(Functions.folderFromFile(value), "key") } } + + ValueButtonAlignRight { + id: configFilename + label: "Extra options" + value: VpnControl.configFile + placeholderText: "Select" + width: parent.width + onClicked: { + _fileDialogue = 5; + Functions.goToInitial(Functions.folderFromFile(value), "ovpn") + } + } } } @@ -196,5 +214,6 @@ Dialog { VpnControl.setClientCertFile(clientCertFilename.value) VpnControl.setClientKeyFile(clientKeyFilename.value) VpnControl.setTlsKeyFile(tlsKeyFilename.value) + VpnControl.setConfigFile(configFilename.value) } } diff --git a/qml/pages/ConnectPage.qml b/qml/pages/ConnectPage.qml index 3d6c296..665226e 100644 --- a/qml/pages/ConnectPage.qml +++ b/qml/pages/ConnectPage.qml @@ -165,6 +165,7 @@ Page { id: logOutput textFormat: Text.PlainText width: parent.width - 2 * Theme.paddingSmall + height: parent.height - 2 * Theme.paddingSmall wrapMode: Text.WrapAnywhere font.pixelSize: Theme.fontSizeTiny * 0.6 font.family: "Monospace" diff --git a/rpm/OpenVPNUI.spec b/rpm/OpenVPNUI.spec index 93b06cf..5ee1235 100644 --- a/rpm/OpenVPNUI.spec +++ b/rpm/OpenVPNUI.spec @@ -21,10 +21,10 @@ URL: http://example.org/ Source0: %{name}-%{version}.tar.bz2 Source100: OpenVPNUI.yaml Requires: sailfishsilica-qt5 >= 0.10.9 -BuildRequires: pkgconfig(sailfishapp) >= 0.0.10 -BuildRequires: pkgconfig(Qt5Core) -BuildRequires: pkgconfig(Qt5Qml) BuildRequires: pkgconfig(Qt5Quick) +BuildRequires: pkgconfig(Qt5Qml) +BuildRequires: pkgconfig(Qt5Core) +BuildRequires: pkgconfig(sailfishapp) >= 0.0.10 BuildRequires: desktop-file-utils %description @@ -63,13 +63,13 @@ desktop-file-install --delete-original \ %files %defattr(-,root,root,-) -/usr/share/icons/hicolor/86x86/apps -/usr/share/applications -/usr/share/OpenVPNUI -/usr/bin -%{_datadir}/icons/hicolor/86x86/apps/%{name}.png -%{_datadir}/applications/%{name}.desktop -%{_datadir}/%{name}/qml %{_bindir} +%{_datadir}/%{name}/qml +%{_datadir}/applications/%{name}.desktop +%{_datadir}/icons/hicolor/86x86/apps/%{name}.png +/usr/bin +/usr/share/OpenVPNUI +/usr/share/applications +/usr/share/icons/hicolor/86x86/apps # >> files # << files diff --git a/rpm/OpenVPNUI.yaml b/rpm/OpenVPNUI.yaml index 6c5cd7b..daa3264 100644 --- a/rpm/OpenVPNUI.yaml +++ b/rpm/OpenVPNUI.yaml @@ -12,19 +12,19 @@ Description: | Configure: none Builder: qtc5 PkgConfigBR: -- sailfishapp >= 0.0.10 -- Qt5Core -- Qt5Qml - Qt5Quick +- Qt5Qml +- Qt5Core +- sailfishapp >= 0.0.10 Requires: - sailfishsilica-qt5 >= 0.10.9 Files: -- /usr/share/icons/hicolor/86x86/apps -- /usr/share/applications -- /usr/share/OpenVPNUI -- /usr/bin -- '%{_datadir}/icons/hicolor/86x86/apps/%{name}.png' -- '%{_datadir}/applications/%{name}.desktop' -- '%{_datadir}/%{name}/qml' - '%{_bindir}' +- '%{_datadir}/%{name}/qml' +- '%{_datadir}/applications/%{name}.desktop' +- '%{_datadir}/icons/hicolor/86x86/apps/%{name}.png' +- /usr/bin +- /usr/share/OpenVPNUI +- /usr/share/applications +- /usr/share/icons/hicolor/86x86/apps PkgBR: [] diff --git a/src/vpncontrol.cpp b/src/vpncontrol.cpp index 3588f7b..12ca3f1 100644 --- a/src/vpncontrol.cpp +++ b/src/vpncontrol.cpp @@ -15,18 +15,19 @@ VPNControl::VPNControl(QObject *parent) : { // Read in the settings QSettings settings; + settings.setValue("showAll", false); + // Read configuration 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(); caCertFile = settings.value("caCertFile", "").toString(); - clientCertFile = settings.value("clientCertFile", "").toString();; - clientKeyFile = settings.value("clientKeyFile", "").toString();; - tlsKeyFile = settings.value("tlsKeyFile", "").toString();; - - settings.setValue("showAll", false); + clientCertFile = settings.value("clientCertFile", "").toString(); + clientKeyFile = settings.value("clientKeyFile", "").toString(); + tlsKeyFile = settings.value("tlsKeyFile", "").toString(); + configFile = settings.value("configFile", "").toString(); } void VPNControl::initialise() @@ -152,6 +153,15 @@ void VPNControl::setTlsKeyFile(const QString &value) } } +void VPNControl::setConfigFile(const QString &value) +{ + if (value != configFile) { + configFile = value; + settingsSetValue("configFile", value); + emit tlsKeyFileChanged(configFile); + } +} + QString VPNControl::getClientCertFile () const { return clientCertFile; @@ -167,6 +177,11 @@ QString VPNControl::getTlsKeyFile () const return tlsKeyFile; } +QString VPNControl::getConfigFile () const +{ + return configFile; +} + QString VPNControl::getLogText() const { return logText; @@ -214,7 +229,7 @@ void VPNControl::vpnConnect() { void VPNControl::collectArguments () { arguments.clear(); - addArgumentNonempty("config", "/home/nemo/Documents/Configure/OpenVPN/config.ovpn"); + addArgumentNonempty("config", configFile); addArgumentNonempty("remote", server); addArgumentNonempty("port", QString::number(port)); addOption("comp-lzo", compressed); diff --git a/src/vpncontrol.h b/src/vpncontrol.h index 12ff248..d89120f 100644 --- a/src/vpncontrol.h +++ b/src/vpncontrol.h @@ -20,6 +20,10 @@ class VPNControl : public QObject { Q_OBJECT + // General properties + Q_PROPERTY (QString logText READ getLogText WRITE setLogText NOTIFY logTextChanged) + + // Configuration properties 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) @@ -29,10 +33,10 @@ class VPNControl : public QObject Q_PROPERTY (QString clientCertFile READ getClientCertFile WRITE setClientCertFile NOTIFY clientCertFileChanged) Q_PROPERTY (QString clientKeyFile READ getClientKeyFile WRITE setClientKeyFile NOTIFY clientKeyFileChanged) Q_PROPERTY (QString tlsKeyFile READ getTlsKeyFile WRITE setTlsKeyFile NOTIFY tlsKeyFileChanged) - - Q_PROPERTY (QString logText READ getLogText WRITE setLogText NOTIFY logTextChanged) + Q_PROPERTY (QString configFile READ getConfigFile WRITE setConfigFile NOTIFY configFileChanged) private: + // General variables QProcess * vpnProcess; VPNSTATUS vpnStatus; QStringList arguments; @@ -48,7 +52,9 @@ private: QString clientCertFile; QString clientKeyFile; QString tlsKeyFile; + QString configFile; + // Internal methods void collectArguments (); void setStatus (VPNSTATUS newStatus); void addArgument (QString key, QString value); @@ -60,8 +66,12 @@ private: void settingsSetValue (QString key, int value); public: + // General methods explicit VPNControl(QObject *parent = 0); void initialise(); + QString getLogText() const; + + // Configuration retreival methods QString getServer() const; unsigned int getPort() const; bool getCompressed() const; @@ -71,11 +81,14 @@ public: QString getClientCertFile () const; QString getClientKeyFile () const; QString getTlsKeyFile () const; - - QString getLogText() const; + QString getConfigFile () const; signals: + // General signals void statusChanged(int status); + void logTextChanged (QString &logText); + + // Configuration change signals void serverChanged(QString &server); void portChanged(unsigned int port); void compressedChanged(bool compressed); @@ -85,10 +98,10 @@ signals: void clientCertFileChanged(QString &clientCertFile); void clientKeyFileChanged(QString &clientKeyFile); void tlsKeyFileChanged(QString &tlsKeyFile); - - void logTextChanged (QString &logText); + void configFileChanged(QString &configFile); public slots: + // General methods void vpnConnect (); void vpnDisconnect (); void readData (); @@ -96,6 +109,10 @@ public slots: void finished (int code); void readError (QProcess::ProcessError error); void updateConfiguration (); + void setLogText(const QString &value); + void logAppend(const QString &text); + + // Configuration setting void setServer(const QString &value); void setPort(unsigned int value); void setCompressed(bool value); @@ -105,9 +122,7 @@ public slots: void setClientCertFile(const QString &value); void setClientKeyFile(const QString &value); void setTlsKeyFile(const QString &value); - - void setLogText(const QString &value); - void logAppend(const QString &text); + void setConfigFile(const QString &value); }; #endif // VPNCONTROL_H -- 2.25.1