From 8a714fb7a091bad4b8a770e08f00f2bc1346e743 Mon Sep 17 00:00:00 2001 From: miruka Date: Sat, 27 Apr 2019 21:07:20 -0400 Subject: [PATCH] Add Default and RememberAccount? pages --- harmonyqml/backend/client.py | 17 ++++--- harmonyqml/backend/client_manager.py | 6 +-- harmonyqml/components/UI.qml | 10 +++-- harmonyqml/components/base/HInterfaceBox.qml | 4 ++ harmonyqml/components/base/HScalingBox.qml | 8 ++-- harmonyqml/components/pages/Default.qml | 22 ++++++++++ .../components/pages/RememberAccount.qml | 44 +++++++++++++++++++ harmonyqml/components/pages/SignIn.qml | 15 +++++-- 8 files changed, 103 insertions(+), 23 deletions(-) create mode 100644 harmonyqml/components/pages/Default.qml create mode 100644 harmonyqml/components/pages/RememberAccount.qml diff --git a/harmonyqml/backend/client.py b/harmonyqml/backend/client.py index 5c772edb..fdfca83d 100644 --- a/harmonyqml/backend/client.py +++ b/harmonyqml/backend/client.py @@ -90,29 +90,32 @@ class Client(QObject): return getattr(self, method)(*args or [], **kwargs or {}) - @pyqtSlot(str) - @pyqtSlot(str, str) + @pyqtSlot(str, result="QVariant") + @pyqtSlot(str, str, result="QVariant") @futurize() - def login(self, password: str, device_name: str = "") -> None: + def login(self, password: str, device_name: str = "") -> "Client": response = self.net.talk(self.nio.login, password, device_name) self.nio_sync.receive_response(response) + return self - @pyqtSlot(str, str, str) + @pyqtSlot(str, str, str, result="QVariant") @futurize() def resumeSession(self, user_id: str, token: str, device_id: str - ) -> None: + ) -> "Client": response = nr.LoginResponse(user_id, device_id, token) self.nio.receive_response(response) self.nio_sync.receive_response(response) + return self - @pyqtSlot() + @pyqtSlot(result="QVariant") @futurize() - def logout(self) -> None: + def logout(self) -> "Client": self._stop_sync.set() self.net.http_disconnect() self.net_sync.http_disconnect() + return self @futurize(pyqt=False) diff --git a/harmonyqml/backend/client_manager.py b/harmonyqml/backend/client_manager.py index 9975e8c9..c423c07c 100644 --- a/harmonyqml/backend/client_manager.py +++ b/harmonyqml/backend/client_manager.py @@ -128,8 +128,8 @@ class ClientManager(QObject): return json.loads(file.read().strip()) or {} - @pyqtSlot(Client) - def configAdd(self, client: Client) -> None: + @pyqtSlot("QVariant") + def remember(self, client: Client) -> None: self._write_config({ **self.configAccounts(), **{client.userId: { @@ -141,7 +141,7 @@ class ClientManager(QObject): @pyqtSlot(str) - def configDelete(self, user_id: str) -> None: + def forget(self, user_id: str) -> None: self._write_config({ uid: info for uid, info in self.configAccounts().items() if uid != user_id diff --git a/harmonyqml/components/UI.qml b/harmonyqml/components/UI.qml index e66035e2..99366b09 100644 --- a/harmonyqml/components/UI.qml +++ b/harmonyqml/components/UI.qml @@ -7,7 +7,7 @@ import "sidePane" as SidePane import "chat" as Chat Base.HImage { - id: loginPage + id: mainUI fillMode: Image.PreserveAspectCrop source: "../images/login_background.jpg" anchors.fill: parent @@ -25,8 +25,8 @@ Base.HImage { } StackView { - function showPage(path, properties) { - pageStack.replace(path, properties || {}) + function showPage(name, properties) { + pageStack.replace("pages/" + name + ".qml", properties || {}) } function showRoom(userId, roomId) { @@ -36,7 +36,9 @@ Base.HImage { } id: pageStack - initialItem: accountsLoggedIn ? undefined : "pages/SignIn.qml" + Component.onCompleted: showPage( + accountsLoggedIn ? "Default" : "SignIn" + ) onCurrentItemChanged: if (currentItem) { currentItem.forceActiveFocus() diff --git a/harmonyqml/components/base/HInterfaceBox.qml b/harmonyqml/components/base/HInterfaceBox.qml index a331cf6f..3601210e 100644 --- a/harmonyqml/components/base/HInterfaceBox.qml +++ b/harmonyqml/components/base/HInterfaceBox.qml @@ -33,8 +33,12 @@ HScalingBox { } } + Item { Layout.fillHeight: true } + ColumnLayout { id: interfaceBody } + Item { Layout.fillHeight: true } + HRowLayout { Repeater { id: interfaceButtonsRepeater diff --git a/harmonyqml/components/base/HScalingBox.qml b/harmonyqml/components/base/HScalingBox.qml index 9575c8cc..1dc83b13 100644 --- a/harmonyqml/components/base/HScalingBox.qml +++ b/harmonyqml/components/base/HScalingBox.qml @@ -1,8 +1,6 @@ import QtQuick 2.7 Rectangle { - property var container: parent - property real widthForHeight: 0.75 property int baseHeight: 300 property int startScalingUpAboveHeight: 1080 @@ -11,7 +9,7 @@ Rectangle { readonly property int margins: baseHeight * 0.03 color: Qt.hsla(1, 1, 1, 0.3) - height: Math.min(container.height, baseHeight) - width: Math.min(container.width, baseWidth) - scale: Math.max(1, container.height / startScalingUpAboveHeight) + height: Math.min(parent.height, baseHeight) + width: Math.min(parent.width, baseWidth) + scale: Math.max(1, parent.height / startScalingUpAboveHeight) } diff --git a/harmonyqml/components/pages/Default.qml b/harmonyqml/components/pages/Default.qml new file mode 100644 index 00000000..2a311546 --- /dev/null +++ b/harmonyqml/components/pages/Default.qml @@ -0,0 +1,22 @@ +import QtQuick 2.7 +import QtQuick.Controls 2.2 +import QtQuick.Layouts 1.4 +import "../base" as Base + +Base.HRowLayout { + Base.HLabel { + text: "Select or add a room to start." + wrapMode: Text.Wrap + padding: 3 + leftPadding: 10 + rightPadding: 10 + + Layout.margins: 10 + Layout.alignment: Qt.AlignCenter + Layout.maximumWidth: parent.width - Layout.margins * 2 + + background: Rectangle { + color: Qt.hsla(1, 1, 1, 0.3) + } + } +} diff --git a/harmonyqml/components/pages/RememberAccount.qml b/harmonyqml/components/pages/RememberAccount.qml new file mode 100644 index 00000000..47710e5a --- /dev/null +++ b/harmonyqml/components/pages/RememberAccount.qml @@ -0,0 +1,44 @@ +import QtQuick 2.7 +import QtQuick.Controls 2.2 +import QtQuick.Layouts 1.4 +import "../base" as Base + +Item { + property string loginWith: "username" + property var client: null + + Base.HInterfaceBox { + id: rememberBox + title: "Sign in" + anchors.centerIn: parent + + enterButtonTarget: "yes" + + buttonModel: [ + { name: "yes", text: qsTr("Yes") }, + { name: "no", text: qsTr("No") }, + ] + + buttonCallbacks: { + "yes": function(button) { + Backend.clientManager.remember(client) + pageStack.showPage("Default") + }, + "no": function(button) { pageStack.showPage("Default") }, + } + + Base.HLabel { + text: qsTr( + "Do you want to remember this account?\n\n" + + "If yes, the " + loginWith + " and an access token will be " + + "stored to automatically sign in on this device." + ) + wrapMode: Text.Wrap + + Layout.margins: rememberBox.margins + Layout.maximumWidth: rememberBox.width - Layout.margins * 2 + } + + Item { Layout.fillHeight: true } + } +} diff --git a/harmonyqml/components/pages/SignIn.qml b/harmonyqml/components/pages/SignIn.qml index 631157e0..4204c805 100644 --- a/harmonyqml/components/pages/SignIn.qml +++ b/harmonyqml/components/pages/SignIn.qml @@ -25,11 +25,16 @@ Item { "register": function(button) {}, "login": function(button) { - button.loadingUntilFutureDone( - Backend.clientManager.new( - "matrix.org", identifierField.text, passwordField.text - ) + var future = Backend.clientManager.new( + "matrix.org", identifierField.text, passwordField.text ) + button.loadingUntilFutureDone(future) + future.onGotResult.connect(function(client) { + pageStack.showPage( + "RememberAccount", + {"loginWith": loginWith, "client": client} + ) + }) }, "forgot": function(button) {} @@ -60,6 +65,7 @@ Item { loginWith === "phone" ? "Phone" : "Username" ) + text: "test_mary" onAccepted: signInBox.clickEnterButtonTarget() Layout.fillWidth: true @@ -67,6 +73,7 @@ Item { } Base.HTextField { + text: "1234" id: passwordField placeholderText: qsTr("Password") echoMode: TextField.Password