From 052fa14434d3ca4b7d08c2c2fccf3791e20afbaa Mon Sep 17 00:00:00 2001 From: David Date: Mon, 17 Mar 2014 00:31:10 +0000 Subject: [PATCH] Linked key and ca file configuration to vpn execution. Added option to clear field in file select menu. Improved search capability including automatic search on open and fixed search file menu. --- qml/components/ValueButtonAlignRight.qml | 4 +- qml/filebrowse/pages/DirectoryPage.qml | 24 +++-- qml/filebrowse/pages/FilePage.qml | 2 +- qml/filebrowse/pages/SearchPage.qml | 54 +++++++----- qml/pages/ConfigurePage.qml | 19 ++-- qml/pages/ConnectPage.qml | 1 + src/vpncontrol.cpp | 108 +++++++++++++++++++---- src/vpncontrol.h | 32 ++++++- 8 files changed, 181 insertions(+), 63 deletions(-) diff --git a/qml/components/ValueButtonAlignRight.qml b/qml/components/ValueButtonAlignRight.qml index 899e16f..12fcb9d 100644 --- a/qml/components/ValueButtonAlignRight.qml +++ b/qml/components/ValueButtonAlignRight.qml @@ -39,7 +39,6 @@ BackgroundItem { id: root property alias label: titleText.text - property alias value: valueText.text property alias labelColor: titleText.color property alias valueColor: valueText.color @@ -47,6 +46,8 @@ BackgroundItem { property real labelMargin: Theme.paddingLarge property int _duration: 200 + property string value + property string placeholderText width: parent ? parent.width : 0 height: contentItem.height @@ -75,6 +76,7 @@ BackgroundItem { width: Math.min(implicitWidth, parent.width) truncationMode: TruncationMode.Fade horizontalAlignment: ((implicitWidth <= (parent.width - titleText.width)) ? Text.AlignLeft : Text.AlignRight) + text: (value != "" ? value : placeholderText) } } } diff --git a/qml/filebrowse/pages/DirectoryPage.qml b/qml/filebrowse/pages/DirectoryPage.qml index eb55286..6641846 100644 --- a/qml/filebrowse/pages/DirectoryPage.qml +++ b/qml/filebrowse/pages/DirectoryPage.qml @@ -6,7 +6,7 @@ import "../components" Page { id: page - allowedOrientations: Orientation.All + //allowedOrientations: Orientation.All property string dir: "/" property string initialDir: "" property bool initial: false // this is set to true if the page is initial page @@ -36,14 +36,17 @@ Page { Functions.cancel() break; case 2: - pageStack.push(Qt.resolvedUrl("SearchPage.qml"), { dir: page.dir }); + Functions.fileSelect("") break; case 3: + pageStack.push(Qt.resolvedUrl("SearchPage.qml"), { dir: page.dir }); + break; + case 4: fileModel.showAll = true menuShowAll.visible = false menuShowFiltered.visible = true break; - case 4: + case 5: fileModel.showAll = false menuShowFiltered.visible = false menuShowAll.visible = true @@ -57,20 +60,24 @@ Page { onClicked: _selectedMenu = 1 } MenuItem { - text: qsTr("Search") + text: qsTr("Clear") onClicked: _selectedMenu = 2 } + MenuItem { + text: qsTr("Search") + onClicked: _selectedMenu = 3 + } MenuItem { id: menuShowAll visible: !fileModel.showAll text: qsTr("Show all files") - onClicked: _selectedMenu = 3 + onClicked: _selectedMenu = 4 } MenuItem { id: menuShowFiltered visible: fileModel.showAll text: qsTr("Show only ") + engine.extensionFilter + qsTr(" files") - onClicked: _selectedMenu = 4 + onClicked: _selectedMenu = 5 } } @@ -140,8 +147,8 @@ Page { { dir: fileModel.appendPath(listLabel.text) }); } else { - Functions.cancel() Functions.fileSelect(fileModel.appendPath(listLabel.text)) + //Functions.cancel() //pageStack.push(Qt.resolvedUrl("FilePage.qml"), // { file: fileModel.appendPath(listLabel.text) }); } @@ -164,8 +171,7 @@ Page { visible: true text: qsTr("Properties") onClicked: { - pageStack.push(Qt.resolvedUrl("FilePage.qml"), - { file: fileModel.fileNameAt(index) }); + pageStack.push(Qt.resolvedUrl("FilePage.qml"), { file: fileModel.fileNameAt(index) }); } } } diff --git a/qml/filebrowse/pages/FilePage.qml b/qml/filebrowse/pages/FilePage.qml index 1519d41..225324a 100644 --- a/qml/filebrowse/pages/FilePage.qml +++ b/qml/filebrowse/pages/FilePage.qml @@ -7,7 +7,7 @@ import "../components" Page { id: page - allowedOrientations: Orientation.All + //allowedOrientations: Orientation.All property string file: "/" FileInfo { diff --git a/qml/filebrowse/pages/SearchPage.qml b/qml/filebrowse/pages/SearchPage.qml index e11d8e8..67c5d62 100644 --- a/qml/filebrowse/pages/SearchPage.qml +++ b/qml/filebrowse/pages/SearchPage.qml @@ -6,11 +6,18 @@ import "../components" Page { id: page - allowedOrientations: Orientation.All + //allowedOrientations: Orientation.All showNavigationIndicator: false // hide back indicator because it would be on top of search field property string dir: "/" property string currentDirectory: "" + onStatusChanged: { + if (status === PageStatus.Active) { + listModel.update("." + engine.extensionFilter); + //foundText.visible = true; + } + } + // this and its bg worker thread will be destroyed when page in popped from stack SearchEngine { id: searchEngine @@ -49,12 +56,12 @@ Page { VerticalScrollDecorator { flickable: fileList } - PullDownMenu { - MenuItem { - text: qsTr("Settings") - onClicked: pageStack.push(Qt.resolvedUrl("SettingsPage.qml")) - } - } +// PullDownMenu { +// MenuItem { +// text: qsTr("Settings") +// onClicked: pageStack.push(Qt.resolvedUrl("SettingsPage.qml")) +// } +// } header: Item { width: parent.width @@ -117,7 +124,7 @@ Page { } Label { id: foundText - visible: false + visible: true anchors.left: parent.left anchors.leftMargin: searchField.textLeftMargin anchors.top: searchField.bottom @@ -183,8 +190,9 @@ Page { pageStack.push(Qt.resolvedUrl("DirectoryPage.qml"), { dir: model.fullname }); else - pageStack.push(Qt.resolvedUrl("FilePage.qml"), - { file: model.fullname }); + Functions.fileSelect(model.fullname) +// pageStack.push(Qt.resolvedUrl("FilePage.qml"), +// { file: model.fullname }); } // delete file after remorse time @@ -205,17 +213,23 @@ Page { onClicked: Functions.goToFolder(model.absoluteDir) } MenuItem { - text: qsTr("Cut") - onClicked: engine.cutFiles([ model.fullname ]); - } - MenuItem { - text: qsTr("Copy") - onClicked: engine.copyFiles([ model.fullname ]); - } - MenuItem { - text: qsTr("Delete") - onClicked: deleteFile(model.fullname); + text: qsTr("Properties") + onClicked: { + pageStack.push(Qt.resolvedUrl("FilePage.qml"), { file: model.fullname }); + } } +// MenuItem { +// text: qsTr("Cut") +// onClicked: engine.cutFiles([ model.fullname ]); +// } +// MenuItem { +// text: qsTr("Copy") +// onClicked: engine.copyFiles([ model.fullname ]); +// } +// MenuItem { +// text: qsTr("Delete") +// onClicked: deleteFile(model.fullname); +// } } } } diff --git a/qml/pages/ConfigurePage.qml b/qml/pages/ConfigurePage.qml index 1615c97..d00f37f 100644 --- a/qml/pages/ConfigurePage.qml +++ b/qml/pages/ConfigurePage.qml @@ -140,7 +140,8 @@ Dialog { ValueButtonAlignRight { id: caCertFilename label: "CA cert" - value: "Select" + value: VpnControl.caCertFile + placeholderText: "Select" width: parent.width onClicked: { _fileDialogue = 1 @@ -150,7 +151,7 @@ Dialog { ValueButtonAlignRight { id: clientCertFilename - value: "Select" + value: ((VpnControl.clientCertFile === "") ? "Select" : VpnControl.clientCertFile) label: "Client cert" width: parent.width onClicked: { @@ -161,7 +162,7 @@ Dialog { ValueButtonAlignRight { id: clientKeyFilename - value: "Select" + value: ((VpnControl.clientKeyFile === "") ? "Select" : VpnControl.clientKeyFile) label: "Client key" width: parent.width onClicked: { @@ -172,7 +173,7 @@ Dialog { ValueButtonAlignRight { id: tlsKeyFilename - value: "Select" + value: ((VpnControl.tlsKeyFile === "") ? "Select" : VpnControl.tlsKeyFile) label: "TLS key" width: parent.width enabled: configureTLS.checked @@ -191,11 +192,9 @@ Dialog { VpnControl.setUseTLS(configureTLS.checked) VpnControl.setTlsDirection(configureTLSdirection.currentIndex) VpnControl.updateConfiguration() + VpnControl.setCaCertFile(caCertFilename.value) + VpnControl.setClientCertFile(clientCertFilename.value) + VpnControl.setClientKeyFile(clientKeyFilename.value) + VpnControl.setTlsKeyFile(tlsKeyFilename.value) } - } - - - - - diff --git a/qml/pages/ConnectPage.qml b/qml/pages/ConnectPage.qml index 6d32705..3d6c296 100644 --- a/qml/pages/ConnectPage.qml +++ b/qml/pages/ConnectPage.qml @@ -172,6 +172,7 @@ Page { visible: true text: VpnControl.logText maximumLineCount: Math.floor(18 / 0.6) + verticalAlignment: Text.AlignBottom x: Theme.paddingSmall y: Theme.paddingSmall } diff --git a/src/vpncontrol.cpp b/src/vpncontrol.cpp index 057cb36..3588f7b 100644 --- a/src/vpncontrol.cpp +++ b/src/vpncontrol.cpp @@ -21,6 +21,11 @@ VPNControl::VPNControl(QObject *parent) : 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); } @@ -106,6 +111,62 @@ void VPNControl::setServer(const QString &value) } } +QString VPNControl::getCaCertFile () const +{ + return caCertFile; +} + +void VPNControl::setCaCertFile(const QString &value) +{ + if (value != caCertFile) { + caCertFile = value; + settingsSetValue("caCertFile", value); + emit caCertFileChanged(caCertFile); + } +} + +void VPNControl::setClientCertFile(const QString &value) +{ + if (value != clientCertFile) { + clientCertFile = value; + settingsSetValue("clientCertFile", value); + emit clientCertFileChanged(clientCertFile); + } +} + +void VPNControl::setClientKeyFile(const QString &value) +{ + if (value != clientKeyFile) { + clientKeyFile = value; + settingsSetValue("clientKeyFile", value); + emit clientKeyFileChanged(clientKeyFile); + } +} + +void VPNControl::setTlsKeyFile(const QString &value) +{ + if (value != tlsKeyFile) { + tlsKeyFile = value; + settingsSetValue("tlsKeyFile", value); + emit tlsKeyFileChanged(tlsKeyFile); + } +} + +QString VPNControl::getClientCertFile () const +{ + return clientCertFile; +} + +QString VPNControl::getClientKeyFile () const +{ + return clientKeyFile; +} + +QString VPNControl::getTlsKeyFile () const +{ + return tlsKeyFile; +} + QString VPNControl::getLogText() const { return logText; @@ -114,7 +175,7 @@ QString VPNControl::getLogText() const void VPNControl::setLogText(const QString &value) { logText = value; - emit logTextChanged(value); + emit logTextChanged(logText); } void VPNControl::settingsSetValue (QString key, QString value) { @@ -153,17 +214,17 @@ void VPNControl::vpnConnect() { void VPNControl::collectArguments () { arguments.clear(); - addArgument("config", "/home/nemo/Documents/Configure/OpenVPN/config.ovpn"); - addArgument("remote", server); - addArgument("port", QString::number(port)); + addArgumentNonempty("config", "/home/nemo/Documents/Configure/OpenVPN/config.ovpn"); + addArgumentNonempty("remote", server); + addArgumentNonempty("port", QString::number(port)); addOption("comp-lzo", compressed); - if (useTLS) { - addArgument("tls-auth", "/home/nemo/Documents/Configure/OpenVPN/ta.key"); + if ((useTLS) && (!tlsKeyFile.isEmpty())) { + addArgument("tls-auth", tlsKeyFile); addValue(QString::number(tlsDirection)); } - addArgument("ca", "/home/nemo/Documents/Configure/OpenVPN/ca.crt"); - addArgument("cert", "/home/nemo/Documents/Configure/OpenVPN/Jolla.crt"); - addArgument("key", "/home/nemo/Documents/Configure/OpenVPN/Jolla.key"); + addArgumentNonempty("ca", caCertFile); + addArgumentNonempty("cert", clientCertFile); + addArgumentNonempty("key", clientKeyFile); } void VPNControl::addArgument (QString key, QString value) { @@ -171,7 +232,17 @@ void VPNControl::addArgument (QString key, QString value) { argument = "--" + key; arguments.append(argument); - if (value != "") { + if (!value.isEmpty()) { + arguments.append(value); + } +} + +void VPNControl::addArgumentNonempty (QString key, QString value) { + QString argument; + + if (!value.isEmpty()) { + argument = "--" + key; + arguments.append(argument); arguments.append(value); } } @@ -255,16 +326,17 @@ void VPNControl::logAppend(const QString &text) int removeLines = currentLines + newLines - 18; // Remove excess lines - while (removeLines > 0) { - int nextLine = logText.lastIndexOf('\n'); - if (nextLine > 0) { - logText = logText.left(nextLine); - } - removeLines--; - } +// while (removeLines > 0) { +// int nextLine = logText.indexOf('\n'); +// if (nextLine > 0) { +// logText = logText.right(nextLine); +// } +// removeLines--; +// } // Add new lines - logText.prepend(text); + logText.append(text); emit logTextChanged(logText); } } + diff --git a/src/vpncontrol.h b/src/vpncontrol.h index 33dbc38..12ff248 100644 --- a/src/vpncontrol.h +++ b/src/vpncontrol.h @@ -25,6 +25,10 @@ class VPNControl : public QObject 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) + Q_PROPERTY (QString caCertFile READ getCaCertFile WRITE setCaCertFile NOTIFY caCertFileChanged) + 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) @@ -32,6 +36,7 @@ private: QProcess * vpnProcess; VPNSTATUS vpnStatus; QStringList arguments; + QString logText; // Configuration options QString server; @@ -39,12 +44,16 @@ private: bool compressed; bool useTLS; int tlsDirection; - QString logText; + QString caCertFile; + QString clientCertFile; + QString clientKeyFile; + QString tlsKeyFile; void collectArguments (); void setStatus (VPNSTATUS newStatus); void addArgument (QString key, QString value); void addArgument (QString key); + void addArgumentNonempty (QString key, QString value); void addOption (QString key, bool add); void addValue (QString key); void settingsSetValue (QString key, QString value); @@ -58,16 +67,26 @@ public: bool getCompressed() const; bool getUseTLS() const; int getTlsDirection() const; + QString getCaCertFile () const; + QString getClientCertFile () const; + QString getClientKeyFile () const; + QString getTlsKeyFile () const; + QString getLogText() const; signals: void statusChanged(int status); - void serverChanged(QString server); + void serverChanged(QString &server); void portChanged(unsigned int port); void compressedChanged(bool compressed); void useTLSChanged(bool useTLS); - void tlsDirectionChanged (int direction); - void logTextChanged (QString logText); + void tlsDirectionChanged(int direction); + void caCertFileChanged(QString &caCertFile); + void clientCertFileChanged(QString &clientCertFile); + void clientKeyFileChanged(QString &clientKeyFile); + void tlsKeyFileChanged(QString &tlsKeyFile); + + void logTextChanged (QString &logText); public slots: void vpnConnect (); @@ -82,6 +101,11 @@ public slots: void setCompressed(bool value); void setUseTLS(bool value); void setTlsDirection(int value); + void setCaCertFile(const QString &value); + 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); }; -- 2.25.1