Add Default and RememberAccount? pages
This commit is contained in:
parent
0db5a3233d
commit
8a714fb7a0
|
@ -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)
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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()
|
||||
|
|
|
@ -33,8 +33,12 @@ HScalingBox {
|
|||
}
|
||||
}
|
||||
|
||||
Item { Layout.fillHeight: true }
|
||||
|
||||
ColumnLayout { id: interfaceBody }
|
||||
|
||||
Item { Layout.fillHeight: true }
|
||||
|
||||
HRowLayout {
|
||||
Repeater {
|
||||
id: interfaceButtonsRepeater
|
||||
|
|
|
@ -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)
|
||||
}
|
||||
|
|
22
harmonyqml/components/pages/Default.qml
Normal file
22
harmonyqml/components/pages/Default.qml
Normal 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)
|
||||
}
|
||||
}
|
||||
}
|
44
harmonyqml/components/pages/RememberAccount.qml
Normal file
44
harmonyqml/components/pages/RememberAccount.qml
Normal 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 }
|
||||
}
|
||||
}
|
|
@ -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
|
||||
|
|
Loading…
Reference in New Issue
Block a user