From e217f990bcdc687b8c0cdf8f84929aaf5aa8f935 Mon Sep 17 00:00:00 2001
From: "kali kaneko (leap communications)" <kali@leap.se>
Date: Tue, 8 Sep 2020 16:51:32 +0200
Subject: [PATCH] [feat] improve phrasing for login dialog, split into its own
 file

---
 gui/gui.qrc                  |  1 +
 gui/providers/providers.json |  2 +-
 gui/qml/FailDialog.qml       | 23 +++++++++++++++++++++
 gui/qml/LoginDialog.qml      | 19 +++++++++++++++++-
 gui/qml/main.qml             | 39 ++++++++++++++++++------------------
 5 files changed, 63 insertions(+), 21 deletions(-)
 create mode 100644 gui/qml/FailDialog.qml

diff --git a/gui/gui.qrc b/gui/gui.qrc
index 112a1ce6..36252dd6 100644
--- a/gui/gui.qrc
+++ b/gui/gui.qrc
@@ -6,6 +6,7 @@
         <file>qml/DonateDialog.qml</file>
         <file>qml/LoginDialog.qml</file>
         <file>qml/LoginOKDialog.qml</file>
+        <file>qml/FailDialog.qml</file>
 
         <file>assets/icon/png/black/vpn_off.png</file>
         <file>assets/icon/png/black/vpn_on.png</file>
diff --git a/gui/providers/providers.json b/gui/providers/providers.json
index e0c52b87..8cbfbc0f 100644
--- a/gui/providers/providers.json
+++ b/gui/providers/providers.json
@@ -18,4 +18,4 @@
             "timeStamp": "2020-09-08 03:42:39"
         }
     ]
-}
\ No newline at end of file
+}
diff --git a/gui/qml/FailDialog.qml b/gui/qml/FailDialog.qml
new file mode 100644
index 00000000..3da421bf
--- /dev/null
+++ b/gui/qml/FailDialog.qml
@@ -0,0 +1,23 @@
+import QtQuick 2.0
+import QtQuick.Dialogs 1.2
+
+MessageDialog {
+    title: qsTr("Initialization Error")
+    modality: Qt.NonModal
+    text: ""
+    onAccepted: retryOrQuit()
+    onRejected: retryOrQuit()
+
+    Component.onCompleted: {
+        buttons: MessageDialog.Ok
+    }
+
+    function retryOrQuit() {
+        if (ctx.loginDialog == 'true') {
+            login.visible = true
+        } else {
+            backend.quit()
+        }
+    }
+}
+
diff --git a/gui/qml/LoginDialog.qml b/gui/qml/LoginDialog.qml
index 897081b7..44a1d793 100644
--- a/gui/qml/LoginDialog.qml
+++ b/gui/qml/LoginDialog.qml
@@ -5,10 +5,15 @@ import QtQuick.Controls 1.4
 Dialog {
     standardButtons: StandardButton.Ok
     title: qsTr("Login")
+
     Column {
         anchors.fill: parent
         Text {
-            text: qsTr("Log in with your library credentials")
+            text: getLoginText()
+            font.bold: true
+        }
+        Text {
+            text: getDetailedText()
         }
         TextField {
             id: username
@@ -25,4 +30,16 @@ Dialog {
     visible: false
     onAccepted: backend.login(username.text, password.text)
     onRejected: backend.quit()
+
+    function getLoginText() {
+        if (allowEmptyPass) {
+            return qsTr("Enter your Patron ID")
+        } else {
+            return qsTr("Log in with your library credentials")
+        }
+    }
+
+    function getDetailedText() {
+        return qsTr("You can check your Patron ID number in the back of your library card")
+    }
 }
diff --git a/gui/qml/main.qml b/gui/qml/main.qml
index f0303452..4d0e648c 100644
--- a/gui/qml/main.qml
+++ b/gui/qml/main.qml
@@ -37,16 +37,30 @@ ApplicationWindow {
                } else if ( ctx.errors == "nopolkit" ) {
                    showInitFailure(qsTr("Could not find polkit agent."))
                } else {
-                   //: %1 -> application name
-                   //: %2 -> error string
-                   showInitFailure(qsTr("Got an error starting %1: %2").arg(ctx.appName).arg(ctx.errors))
-                   console.debug(ctx.errors)
+                   showInitFailure()
                }
             }
         }
     }
 
     function showInitFailure(msg) {
+      console.debug("ERRORS:", ctx.errors)
+      if (msg == undefined) {
+          if (ctx.errors == 'bad_auth') {
+              if (allowEmptyPass) {
+                  // For now, this is a libraryVPN, so we can be explicit about what credentials are here.
+                  // Another option to consider is to customize the error strings while vendoring.
+                  msg = qsTr("Please check your Patron ID")
+              } else {
+                  msg = qsTr("Could not log in with those credentials, please retry")
+              }
+              initFailure.title = qsTr("Login Error")
+          } else {
+              //: %1 -> application name
+              //: %2 -> error string
+              msg = qsTr("Got an error starting %1: %2").arg(ctx.appName).arg(ctx.errors)
+          }
+      }
       initFailure.text = msg
       initFailure.visible  = true
     }
@@ -249,6 +263,7 @@ ApplicationWindow {
         id: about
         visible: false
     }
+   
 
     LoginDialog {
         id: login
@@ -279,22 +294,8 @@ ApplicationWindow {
         visible: false
     }
 
-    MessageDialog {
+    FailDialog {
         id: initFailure
-        buttons: MessageDialog.Ok
-        modality: Qt.NonModal
-        title: qsTr("Initialization Error")
-        text: ""
         visible: false
-    	onAccepted: retryOrQuit()
-        onRejected: retryOrQuit()
-        
-        function retryOrQuit() {
-            if (ctx.loginDialog == 'true') {
-                login.visible = true
-            } else {
-                backend.quit()
-            }
-        }
     }
 }
-- 
GitLab