From 253b12e140905d3a38bcd09d55b9c5dbf0601d66 Mon Sep 17 00:00:00 2001
From: "kali kaneko (leap communications)" <kali@leap.se>
Date: Wed, 17 Jun 2020 13:17:16 +0200
Subject: [PATCH] [feat] working about dialog

---
 build.sh                                |  2 +-
 gui/gui.qrc                             |  2 +
 gui/qml/AboutDialog.qml                 | 26 +++++++++++++
 gui/qml/DonateDialog.qml                |  6 +--
 gui/qml/LoginConfirmation.qml           | 11 ++++++
 gui/qml/LoginDialog.qml                 | 28 ++++++++++++++
 gui/qml/main.qml                        | 51 +++++++++++++------------
 pkg/backend/bitmask.go                  |  2 +
 pkg/backend/status.go                   |  1 +
 pkg/config/version/gen.go               |  3 --
 pkg/config/version/genver/gen.go        |  3 ++
 pkg/config/version/{ => genver}/main.go |  2 +-
 12 files changed, 105 insertions(+), 32 deletions(-)
 create mode 100644 gui/qml/AboutDialog.qml
 create mode 100644 gui/qml/LoginConfirmation.qml
 create mode 100644 gui/qml/LoginDialog.qml
 delete mode 100644 pkg/config/version/gen.go
 create mode 100644 pkg/config/version/genver/gen.go
 rename pkg/config/version/{ => genver}/main.go (95%)

diff --git a/build.sh b/build.sh
index 4ce1e777..c7085a69 100755
--- a/build.sh
+++ b/build.sh
@@ -28,7 +28,7 @@ function init {
 
 function buildGoLib {
     echo "[+] Using go in" $GO "[`go version`]"
-    $GO generate ./pkg/config/version/gen.go
+    $GO generate ./pkg/config/version/genver/gen.go
     if [ "$XBUILD" == "no" ]
     then
         echo "[+] Building Go library with standard Go compiler"
diff --git a/gui/gui.qrc b/gui/gui.qrc
index b0cd72c9..28fcf7f4 100644
--- a/gui/gui.qrc
+++ b/gui/gui.qrc
@@ -1,7 +1,9 @@
 <RCC>
     <qresource prefix="/">
         <file>qml/main.qml</file>
+        <file>qml/AboutDialog.qml</file>
         <file>qml/DonateDialog.qml</file>
+        <file>qml/LoginDialog.qml</file>
          
         <file>assets/icon/png/black/vpn_off.png</file>
         <file>assets/icon/png/black/vpn_on.png</file>
diff --git a/gui/qml/AboutDialog.qml b/gui/qml/AboutDialog.qml
new file mode 100644
index 00000000..98cacdc5
--- /dev/null
+++ b/gui/qml/AboutDialog.qml
@@ -0,0 +1,26 @@
+import QtQuick 2.0
+import QtQuick.Dialogs 1.2
+
+MessageDialog {
+    title: qsTr("About")
+    text: getText()
+    informativeText: getVersion() 
+
+    function getText() {
+        var _name = ctx ? ctx.appName : "vpn"
+        var _provider = ctx ? ctx.provider : "unknown"
+        var _donateURL= ctx ? ctx.donateURL : "..."
+        var _tosURL = ctx ? ctx.tosURL : "..."
+        var _txt = qsTr(
+            "<p>%1 is an easy, fast, and secure VPN service from %2. %1 does not require a user account, keep logs, or track you in any way.</p> <p>This service is paid for entirely by donations from users like you. <a href=\"%3\">Please donate</a>.</p> <p>By using this application, you agree to the <a href=\"%4\">Terms of Service</a>. This service is provided as-is, without any warranty, and is intended for people who work to make the world a better place.</p>").arg(_name).arg(_provider).arg(_donateURL).arg(_tosURL)
+        return _txt
+    }
+
+    function getVersion() {
+        var _name = ctx ? ctx.appName : "vpn"
+        var _ver  = ctx ? ctx.version : "unknown"
+        var _txt  = "%1 version: %2".arg(_name).arg(_ver)
+        return _txt
+    }
+}
+
diff --git a/gui/qml/DonateDialog.qml b/gui/qml/DonateDialog.qml
index eb761a4a..fd27a6bf 100644
--- a/gui/qml/DonateDialog.qml
+++ b/gui/qml/DonateDialog.qml
@@ -3,15 +3,15 @@ import QtQuick.Dialogs 1.2
 
 MessageDialog {
     standardButtons: StandardButton.No | StandardButton.Yes
-    title: "Donate"
+    title: qsTr("Donate")
     icon: StandardIcon.Warning
     text: getText()
 
     function getText() {
         var _name = ctx ? ctx.appName : "vpn"
-        var donateTxt = qsTr(
+        var _txt = qsTr(
             "The %1 service is expensive to run. Because we don't want to store personal information about you, there are no accounts or billing for this service. But if you want the service to continue, donate at least $5 each month.\n\nDo you want to donate now?").arg(_name)
-        return donateTxt
+        return _txt
     }
 
     onAccepted: {
diff --git a/gui/qml/LoginConfirmation.qml b/gui/qml/LoginConfirmation.qml
new file mode 100644
index 00000000..476cdadb
--- /dev/null
+++ b/gui/qml/LoginConfirmation.qml
@@ -0,0 +1,11 @@
+import QtQuick 2.0
+import QtQuick.Dialogs 1.2
+import QtQuick.Controls 1.4
+
+Dialog {
+    standardButtons: StandardButton.Ok
+    title: "Login Success"
+    text: "You are now logged in, connecting now"
+
+    visible: ctxSystray.loginConfirmationDialog == true
+}
diff --git a/gui/qml/LoginDialog.qml b/gui/qml/LoginDialog.qml
new file mode 100644
index 00000000..fbe5ce12
--- /dev/null
+++ b/gui/qml/LoginDialog.qml
@@ -0,0 +1,28 @@
+import QtQuick 2.0
+import QtQuick.Dialogs 1.2
+import QtQuick.Controls 1.4
+
+Dialog {
+    standardButtons: StandardButton.Ok
+    title: "Login"
+    Column {
+        anchors.fill: parent
+        Text {
+            text: "Log in with your library credentials"
+        }
+        TextField {
+            id: username
+            placeholderText: "patron id"
+        }
+        TextField {
+            id: password
+            placeholderText: "password"
+            echoMode: TextInput.PasswordEchoOnEdit
+        }
+    }
+
+    visible: false
+    //visible: ctx.showLogin == true
+    //onAccepted: backend.login(username.text, password.text)
+    onRejected: backend.quit()  // TODO: it doesn't close
+}
diff --git a/gui/qml/main.qml b/gui/qml/main.qml
index b9b844a6..8d756c6c 100644
--- a/gui/qml/main.qml
+++ b/gui/qml/main.qml
@@ -175,7 +175,7 @@ ApplicationWindow {
 
             MenuItem {
                 text: qsTr("About...")
-                //onTriggered: { about.visible = true }
+                onTriggered: { about.visible = true }
             }
 
             MenuSeparator {}
@@ -188,48 +188,51 @@ ApplicationWindow {
     }
 
     DonateDialog {
-        visible: false
         id: donate
+        visible: false
     }
-}
 
+    AboutDialog {
+        id: about
+        visible: false
+    }
 
-    /*
     LoginDialog {
         id: login
+        visible: false
     }
-    MessageDialog {
-        id: about
-        buttons: MessageDialog.Ok
-        title: "About"
-        text: "<p>%1 is an easy, fast, and secure VPN service from %2. %1 does not require a user account, keep logs, or track you in any way.</p>
-<p>This service is paid for entirely by donations from users like you. <a href=\"%3\">Please donate</a>.</p>
-<p>By using this application, you agree to the <a href=\"%4\">Terms of Service</a>. This service is provided as-is, without any warranty, and is intended for people who work to make the world a better place.</p>".arg(ctxSystray.applicationName).arg(ctxSystray.provider).arg(ctxSystray.donateURL).arg(ctxSystray.tosURL)
-        informativeText: "%1 version: %2".arg(ctxSystray.applicationName).arg(ctxSystray.version)
-    }
+
     MessageDialog {
         id: errorStartingVPN
         buttons: MessageDialog.Ok
         modality: Qt.NonModal
-        title: "Error starting VPN"
-        text: "Can't connect to %1".arg(ctxSystray.applicationName)
-        detailedText: ctxSystray.errorStartingMsg
-        visible: ctxSystray.errorStartingMsg != ""
+        title: qsTr("Error starting VPN")
+        text: ""
+        detailedText: ""
+        visible: false
+        //text: ctx ? qsTr("Can't connect to %1").arg(ctx.appName) : ""
+        //detailedText: ctx ? ctx.errorStartingMsg : ""
+        //visible: ctx.errorStartingMsg != ""
     }
+
     MessageDialog {
         id: authAgent
         buttons: MessageDialog.Ok
         modality: Qt.NonModal
-        title: "Missing authentication agent"
-        text: "Could not find a polkit authentication agent. Please run one and try again."
-        visible: ctxSystray.authAgent == true
+        title: qsTr("Missing authentication agent")
+        text: qsTr("Could not find a polkit authentication agent. Please run one and try again.")
+        visible: false
+        //visible: ctx.missingAuthAgent == "true"
     }
+
     MessageDialog {
         id: initFailure
         buttons: MessageDialog.Ok
         modality: Qt.NonModal
-        title: "Initialization Error"
-        text: ctxSystray.errorInitMsg
-        visible: ctxSystray.errorInitMsg != ""
+        title: qsTr("Initialization Error")
+        text: ""
+        visible: false
+        //text: ctx ? ctx.errorInitMsg : ""
+        //visible: ctx.errorInitMsg != ""
     }
-    */
+}
diff --git a/pkg/backend/bitmask.go b/pkg/backend/bitmask.go
index feff1152..2b588596 100644
--- a/pkg/backend/bitmask.go
+++ b/pkg/backend/bitmask.go
@@ -6,6 +6,7 @@ import (
 
 	"0xacab.org/leap/bitmask-vpn/pkg/bitmask"
 	"0xacab.org/leap/bitmask-vpn/pkg/config"
+	"0xacab.org/leap/bitmask-vpn/pkg/config/version"
 )
 
 func initializeBitmask() {
@@ -58,6 +59,7 @@ func initializeContext(provider, appName string) {
 		DonateURL:       config.DonateURL,
 		AskForDonations: wantDonations(),
 		DonateDialog:    false,
+		Version:         version.VERSION,
 		Status:          st,
 	}
 	go trigger(OnStatusChanged)
diff --git a/pkg/backend/status.go b/pkg/backend/status.go
index 6b13dd30..84b27b7c 100644
--- a/pkg/backend/status.go
+++ b/pkg/backend/status.go
@@ -34,6 +34,7 @@ type connectionCtx struct {
 	AskForDonations bool   `json:"askForDonations"`
 	DonateDialog    bool   `json:"donateDialog"`
 	DonateURL       string `json:"donateURL"`
+	Version         string `json:"version"`
 	Status          status `json:"status"`
 	bm              bitmask.Bitmask
 	cfg             *config.Config
diff --git a/pkg/config/version/gen.go b/pkg/config/version/gen.go
deleted file mode 100644
index 334ed50a..00000000
--- a/pkg/config/version/gen.go
+++ /dev/null
@@ -1,3 +0,0 @@
-package main
-
-//go:generate go run . -output version.go
diff --git a/pkg/config/version/genver/gen.go b/pkg/config/version/genver/gen.go
new file mode 100644
index 00000000..e4538240
--- /dev/null
+++ b/pkg/config/version/genver/gen.go
@@ -0,0 +1,3 @@
+package main
+
+//go:generate go run . -output ../version.go
diff --git a/pkg/config/version/main.go b/pkg/config/version/genver/main.go
similarity index 95%
rename from pkg/config/version/main.go
rename to pkg/config/version/genver/main.go
index a86b6196..e0d80b01 100644
--- a/pkg/config/version/main.go
+++ b/pkg/config/version/genver/main.go
@@ -13,7 +13,7 @@ import (
 )
 
 var (
-	flPackageName  = flag.String("package", "main", "name for the generated golang package")
+	flPackageName  = flag.String("package", "version", "name for the generated golang package")
 	flVariableName = flag.String("variable", "VERSION", "variable name in the generated golang package")
 	flOutputFile   = flag.String("output", "", "output filename (default stdout)")
 )
-- 
GitLab