Changeset View
Changeset View
Standalone View
Standalone View
src/contents/ui/LoginPage.qml
| /* | /* | ||||
| * This file is part of kazv. | * This file is part of kazv. | ||||
| * SPDX-FileCopyrightText: 2020-2021 Tusooa Zhu <tusooa@kazv.moe> | * SPDX-FileCopyrightText: 2020-2021 Tusooa Zhu <tusooa@kazv.moe> | ||||
| * SPDX-License-Identifier: AGPL-3.0-or-later | * SPDX-License-Identifier: AGPL-3.0-or-later | ||||
| */ | */ | ||||
| import QtQuick 2.2 | import QtQuick 2.2 | ||||
| import QtQuick.Layouts 1.1 | import QtQuick.Layouts 1.1 | ||||
| import QtQuick.Controls 2.15 | import QtQuick.Controls 2.15 | ||||
| import org.kde.kirigami 2.8 as Kirigami | import org.kde.kirigami 2.8 as Kirigami | ||||
| Kirigami.Page { | Kirigami.Page { | ||||
| id: loginPage | id: loginPage | ||||
| title: l10n.get('login-page-title') | title: l10n.get('login-page-title') | ||||
| property var isSwitchingAccount: false | property var isSwitchingAccount: false | ||||
| property bool loading: loadingSession | |||||
| ColumnLayout { | ColumnLayout { | ||||
| width: parent.width | width: parent.width | ||||
| spacing: Kirigami.Units.largeSpacing | spacing: Kirigami.Units.largeSpacing | ||||
| ColumnLayout { | ColumnLayout { | ||||
| id: restoreSessionPart | id: restoreSessionPart | ||||
| width: parent.width | width: parent.width | ||||
| spacing: Kirigami.Units.largeSpacing | spacing: Kirigami.Units.largeSpacing | ||||
| property var sessions: matrixSdk.allSessions().filter(s => s !== sessionNameFor(matrixSdk.userId, matrixSdk.deviceId)) | property var sessions: matrixSdk.allSessions().filter(s => s !== sessionNameFor(matrixSdk.userId, matrixSdk.deviceId)) | ||||
| Label { | Label { | ||||
| text: l10n.get('login-page-existing-sessions-prompt') | text: l10n.get('login-page-existing-sessions-prompt') | ||||
| } | } | ||||
| ComboBox { | ComboBox { | ||||
| id: sessionChooser | id: sessionChooser | ||||
| Layout.fillWidth: true | Layout.fillWidth: true | ||||
| model: restoreSessionPart.sessions | model: restoreSessionPart.sessions | ||||
| currentIndex: -1 | currentIndex: -1 | ||||
| enabled: !loginPage.loading | |||||
| } | } | ||||
| Button { | Button { | ||||
| id: restoreButton | id: restoreButton | ||||
| text: l10n.get('login-page-restore-session-button') | text: l10n.get('login-page-restore-session-button') | ||||
| Layout.fillWidth: true | Layout.fillWidth: true | ||||
| enabled: sessionChooser.currentIndex != -1 | enabled: sessionChooser.currentIndex != -1 && !loginPage.loading | ||||
| onClicked: { | onClicked: { | ||||
| const sess = restoreSessionPart.sessions[sessionChooser.currentIndex]; | const sess = restoreSessionPart.sessions[sessionChooser.currentIndex]; | ||||
| console.log('Selected session ', sess); | console.log('Selected session ', sess); | ||||
| loadSession(sess); | loadSession(sess); | ||||
| } | } | ||||
| } | } | ||||
| Label { | Label { | ||||
| text: l10n.get('login-page-alternative-password-login-prompt') | text: l10n.get('login-page-alternative-password-login-prompt') | ||||
| } | } | ||||
| visible: sessions.length > 0 | visible: sessions.length > 0 | ||||
| } | } | ||||
| Kirigami.FormLayout { | Kirigami.FormLayout { | ||||
| TextField { | TextField { | ||||
| id: userIdField | id: userIdField | ||||
| objectName: 'userIdField' | objectName: 'userIdField' | ||||
| Layout.fillWidth: true | Layout.fillWidth: true | ||||
| placeholderText: l10n.get('login-page-userid-input-placeholder') | placeholderText: l10n.get('login-page-userid-input-placeholder') | ||||
| Kirigami.FormData.label: l10n.get('login-page-userid-prompt') | Kirigami.FormData.label: l10n.get('login-page-userid-prompt') | ||||
| enabled: !loginPage.loading | |||||
| } | } | ||||
| Kirigami.PasswordField { | Kirigami.PasswordField { | ||||
| id: passwordField | id: passwordField | ||||
| objectName: 'passwordField' | objectName: 'passwordField' | ||||
| Layout.fillWidth: true | Layout.fillWidth: true | ||||
| Kirigami.FormData.label: l10n.get('login-page-password-prompt') | Kirigami.FormData.label: l10n.get('login-page-password-prompt') | ||||
| enabled: !loginPage.loading | |||||
| } | } | ||||
| TextField { | TextField { | ||||
| id: serverUrlField | id: serverUrlField | ||||
| objectName: 'serverUrlField' | objectName: 'serverUrlField' | ||||
| Layout.fillWidth: true | Layout.fillWidth: true | ||||
| placeholderText: l10n.get('login-page-server-url-placeholder') | placeholderText: l10n.get('login-page-server-url-placeholder') | ||||
| Kirigami.FormData.label: l10n.get('login-page-server-url-prompt') | Kirigami.FormData.label: l10n.get('login-page-server-url-prompt') | ||||
| enabled: !loginPage.loading | |||||
| } | } | ||||
| RowLayout { | RowLayout { | ||||
| Layout.fillWidth: true | Layout.fillWidth: true | ||||
| property var loginButton: Button { | property var loginButton: Button { | ||||
| id: loginButton | id: loginButton | ||||
| objectName: 'loginButton' | objectName: 'loginButton' | ||||
| text: l10n.get('login-page-login-button') | text: l10n.get('login-page-login-button') | ||||
| Layout.fillWidth: true | Layout.fillWidth: true | ||||
| onClicked: { | onClicked: { | ||||
| console.log('Trying to login...') | console.log('Trying to login...') | ||||
| if (isSwitchingAccount) { | if (isSwitchingAccount) { | ||||
| matrixSdk.startNewSession(); | matrixSdk.startNewSession(); | ||||
| } | } | ||||
| matrixSdk.login(userIdField.text, passwordField.text, serverUrlField.text); | matrixSdk.login(userIdField.text, passwordField.text, serverUrlField.text); | ||||
| console.log('Login job sent') | console.log('Login job sent') | ||||
| } | } | ||||
| enabled: !loginPage.loading | |||||
| } | } | ||||
| property var closeButton: Button { | property var closeButton: Button { | ||||
| id: closeButton | id: closeButton | ||||
| text: l10n.get('login-page-close-button') | text: l10n.get('login-page-close-button') | ||||
| Layout.fillWidth: true | Layout.fillWidth: true | ||||
| onClicked: { | onClicked: { | ||||
| pageStack.removePage(loginPage); | pageStack.removePage(loginPage); | ||||
| } | } | ||||
| enabled: !loginPage.loading | |||||
| } | } | ||||
| data: isSwitchingAccount ? [closeButton, loginButton] : [loginButton] | data: isSwitchingAccount ? [closeButton, loginButton] : [loginButton] | ||||
| } | } | ||||
| } | |||||
| ProgressBar { | |||||
| visible: loginPage.loading | |||||
| indeterminate: true | |||||
| Layout.fillWidth: true | |||||
| } | } | ||||
| } | } | ||||
| } | } | ||||