summary refs log tree commit diff
path: root/resources
diff options
context:
space:
mode:
authorDeepBlueV7.X <nicolas.werner@hotmail.de>2023-07-06 18:53:03 +0000
committerGitHub <noreply@github.com>2023-07-06 18:53:03 +0000
commit8112922c5f167f68a12c7989bd2aef75d2eb18b5 (patch)
tree3d61ed11aa2229e5d67a69886c7950ee7088a180 /resources
parentAdd an early out cache for event expiration (diff)
parentRemove duplicate UIA error display (diff)
downloadnheko-8112922c5f167f68a12c7989bd2aef75d2eb18b5.tar.xz
Merge pull request #1501 from Nheko-Reborn/qmlRecaptcha
QML the reCAPTCHA dialog
Diffstat (limited to 'resources')
-rw-r--r--resources/qml/Root.qml22
-rw-r--r--resources/qml/dialogs/ReCaptchaDialog.qml63
2 files changed, 76 insertions, 9 deletions
diff --git a/resources/qml/Root.qml b/resources/qml/Root.qml
index e26b386a..fb0c6036 100644
--- a/resources/qml/Root.qml
+++ b/resources/qml/Root.qml
@@ -348,11 +348,6 @@ Pane {
         }
     }
     Platform.MessageDialog {
-        id: uiaErrorDialog
-
-        buttons: Platform.MessageDialog.Ok
-    }
-    Platform.MessageDialog {
         id: uiaConfirmationLinkDialog
 
         buttons: Platform.MessageDialog.Ok
@@ -360,6 +355,7 @@ Pane {
 
         onAccepted: UIA.continue3pidReceived()
     }
+
     Connections {
         function onConfirm3pidToken() {
             uiaConfirmationLinkDialog.open();
@@ -367,10 +363,6 @@ Pane {
         function onEmail() {
             uiaEmailPrompt.show();
         }
-        function onError(msg) {
-            uiaErrorDialog.text = msg;
-            uiaErrorDialog.open();
-        }
         function onPassword() {
             console.log("UIA: password needed");
             uiaPassPrompt.show();
@@ -381,6 +373,18 @@ Pane {
         function onPrompt3pidToken() {
             uiaTokenPrompt.show();
         }
+        function onReCaptcha(recaptcha) {
+            var component = Qt.createComponent("qrc:/resources/qml/dialogs/ReCaptchaDialog.qml");
+            if (component.status == Component.Ready) {
+                var dialog = component.createObject(timelineRoot, {
+                        "recaptcha": recaptcha
+                    });
+                dialog.show();
+                destroyOnClose(dialog);
+            } else {
+                console.error("Failed to create component: " + component.errorString());
+            }
+        }
 
         target: UIA
     }
diff --git a/resources/qml/dialogs/ReCaptchaDialog.qml b/resources/qml/dialogs/ReCaptchaDialog.qml
new file mode 100644
index 00000000..0da62cbc
--- /dev/null
+++ b/resources/qml/dialogs/ReCaptchaDialog.qml
@@ -0,0 +1,63 @@
+// SPDX-FileCopyrightText: Nheko Contributors
+//
+// SPDX-License-Identifier: GPL-3.0-or-later
+
+import QtQuick
+import QtQuick.Controls
+import im.nheko
+
+ApplicationWindow {
+    id: recaptchaRoot
+
+    required property ReCaptcha recaptcha
+
+    function accept() {
+        recaptcha.confirm();
+        recaptchaRoot.close();
+    }
+
+    function reject() {
+        recaptcha.cancel();
+        recaptchaRoot.close();
+    }
+
+    color: palette.window
+    title: recaptcha.context
+    flags: Qt.Tool | Qt.WindowStaysOnTopHint | Qt.WindowCloseButtonHint | Qt.WindowTitleHint
+    height: msg.implicitHeight + footer.implicitHeight
+    width: Math.max(msg.implicitWidth, footer.implicitWidth)
+
+    Shortcut {
+        sequence: StandardKey.Cancel
+        onActivated: recaptchaRoot.reject()
+    }
+
+    Label {
+        id: msg
+
+        anchors.fill: parent
+        padding: 8
+        text: qsTr("Solve the reCAPTCHA and press the confirm button")
+    }
+
+    footer: DialogButtonBox {
+        onAccepted: recaptchaRoot.accept()
+        onRejected: recaptchaRoot.reject()
+
+        Button {
+            text: qsTr("Open reCAPTCHA")
+            onClicked: recaptcha.openReCaptcha()
+        }
+
+        Button {
+            text: qsTr("Cancel")
+            DialogButtonBox.buttonRole: DialogButtonBox.RejectRole
+        }
+
+        Button {
+            text: qsTr("Confirm")
+            DialogButtonBox.buttonRole: DialogButtonBox.AcceptRole
+        }
+    }
+
+}