Add Default and RememberAccount? pages

This commit is contained in:
miruka 2019-04-27 21:07:20 -04:00
parent 0db5a3233d
commit 8a714fb7a0
8 changed files with 103 additions and 23 deletions

View File

@ -90,29 +90,32 @@ class Client(QObject):
return getattr(self, method)(*args or [], **kwargs or {}) return getattr(self, method)(*args or [], **kwargs or {})
@pyqtSlot(str) @pyqtSlot(str, result="QVariant")
@pyqtSlot(str, str) @pyqtSlot(str, str, result="QVariant")
@futurize() @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) response = self.net.talk(self.nio.login, password, device_name)
self.nio_sync.receive_response(response) self.nio_sync.receive_response(response)
return self
@pyqtSlot(str, str, str) @pyqtSlot(str, str, str, result="QVariant")
@futurize() @futurize()
def resumeSession(self, user_id: str, token: str, device_id: str def resumeSession(self, user_id: str, token: str, device_id: str
) -> None: ) -> "Client":
response = nr.LoginResponse(user_id, device_id, token) response = nr.LoginResponse(user_id, device_id, token)
self.nio.receive_response(response) self.nio.receive_response(response)
self.nio_sync.receive_response(response) self.nio_sync.receive_response(response)
return self
@pyqtSlot() @pyqtSlot(result="QVariant")
@futurize() @futurize()
def logout(self) -> None: def logout(self) -> "Client":
self._stop_sync.set() self._stop_sync.set()
self.net.http_disconnect() self.net.http_disconnect()
self.net_sync.http_disconnect() self.net_sync.http_disconnect()
return self
@futurize(pyqt=False) @futurize(pyqt=False)

View File

@ -128,8 +128,8 @@ class ClientManager(QObject):
return json.loads(file.read().strip()) or {} return json.loads(file.read().strip()) or {}
@pyqtSlot(Client) @pyqtSlot("QVariant")
def configAdd(self, client: Client) -> None: def remember(self, client: Client) -> None:
self._write_config({ self._write_config({
**self.configAccounts(), **self.configAccounts(),
**{client.userId: { **{client.userId: {
@ -141,7 +141,7 @@ class ClientManager(QObject):
@pyqtSlot(str) @pyqtSlot(str)
def configDelete(self, user_id: str) -> None: def forget(self, user_id: str) -> None:
self._write_config({ self._write_config({
uid: info uid: info
for uid, info in self.configAccounts().items() if uid != user_id for uid, info in self.configAccounts().items() if uid != user_id

View File

@ -7,7 +7,7 @@ import "sidePane" as SidePane
import "chat" as Chat import "chat" as Chat
Base.HImage { Base.HImage {
id: loginPage id: mainUI
fillMode: Image.PreserveAspectCrop fillMode: Image.PreserveAspectCrop
source: "../images/login_background.jpg" source: "../images/login_background.jpg"
anchors.fill: parent anchors.fill: parent
@ -25,8 +25,8 @@ Base.HImage {
} }
StackView { StackView {
function showPage(path, properties) { function showPage(name, properties) {
pageStack.replace(path, properties || {}) pageStack.replace("pages/" + name + ".qml", properties || {})
} }
function showRoom(userId, roomId) { function showRoom(userId, roomId) {
@ -36,7 +36,9 @@ Base.HImage {
} }
id: pageStack id: pageStack
initialItem: accountsLoggedIn ? undefined : "pages/SignIn.qml" Component.onCompleted: showPage(
accountsLoggedIn ? "Default" : "SignIn"
)
onCurrentItemChanged: if (currentItem) { onCurrentItemChanged: if (currentItem) {
currentItem.forceActiveFocus() currentItem.forceActiveFocus()

View File

@ -33,8 +33,12 @@ HScalingBox {
} }
} }
Item { Layout.fillHeight: true }
ColumnLayout { id: interfaceBody } ColumnLayout { id: interfaceBody }
Item { Layout.fillHeight: true }
HRowLayout { HRowLayout {
Repeater { Repeater {
id: interfaceButtonsRepeater id: interfaceButtonsRepeater

View File

@ -1,8 +1,6 @@
import QtQuick 2.7 import QtQuick 2.7
Rectangle { Rectangle {
property var container: parent
property real widthForHeight: 0.75 property real widthForHeight: 0.75
property int baseHeight: 300 property int baseHeight: 300
property int startScalingUpAboveHeight: 1080 property int startScalingUpAboveHeight: 1080
@ -11,7 +9,7 @@ Rectangle {
readonly property int margins: baseHeight * 0.03 readonly property int margins: baseHeight * 0.03
color: Qt.hsla(1, 1, 1, 0.3) color: Qt.hsla(1, 1, 1, 0.3)
height: Math.min(container.height, baseHeight) height: Math.min(parent.height, baseHeight)
width: Math.min(container.width, baseWidth) width: Math.min(parent.width, baseWidth)
scale: Math.max(1, container.height / startScalingUpAboveHeight) scale: Math.max(1, parent.height / startScalingUpAboveHeight)
} }

View File

@ -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)
}
}
}

View File

@ -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 }
}
}

View File

@ -25,11 +25,16 @@ Item {
"register": function(button) {}, "register": function(button) {},
"login": function(button) { "login": function(button) {
button.loadingUntilFutureDone( var future = Backend.clientManager.new(
Backend.clientManager.new(
"matrix.org", identifierField.text, passwordField.text "matrix.org", identifierField.text, passwordField.text
) )
button.loadingUntilFutureDone(future)
future.onGotResult.connect(function(client) {
pageStack.showPage(
"RememberAccount",
{"loginWith": loginWith, "client": client}
) )
})
}, },
"forgot": function(button) {} "forgot": function(button) {}
@ -60,6 +65,7 @@ Item {
loginWith === "phone" ? "Phone" : loginWith === "phone" ? "Phone" :
"Username" "Username"
) )
text: "test_mary"
onAccepted: signInBox.clickEnterButtonTarget() onAccepted: signInBox.clickEnterButtonTarget()
Layout.fillWidth: true Layout.fillWidth: true
@ -67,6 +73,7 @@ Item {
} }
Base.HTextField { Base.HTextField {
text: "1234"
id: passwordField id: passwordField
placeholderText: qsTr("Password") placeholderText: qsTr("Password")
echoMode: TextField.Password echoMode: TextField.Password