From cb99c35e854e841c41873e1d8d11f9f6e5f6f769 Mon Sep 17 00:00:00 2001 From: Carl Schwan Date: Mon, 2 Nov 2020 15:59:31 +0000 Subject: [PATCH] Add a login page that appears if no account was configured --- imports/Spectral/Dialog/LoginDialog.qml | 81 ------------------------- qml/LoadingPage.qml | 10 +++ qml/LoginPage.qml | 63 +++++++++++++++++++ qml/main.qml | 48 ++++++++++----- res.qrc | 3 +- src/main.cpp | 6 +- 6 files changed, 111 insertions(+), 100 deletions(-) delete mode 100644 imports/Spectral/Dialog/LoginDialog.qml create mode 100644 qml/LoadingPage.qml create mode 100644 qml/LoginPage.qml diff --git a/imports/Spectral/Dialog/LoginDialog.qml b/imports/Spectral/Dialog/LoginDialog.qml deleted file mode 100644 index cdafed19c..000000000 --- a/imports/Spectral/Dialog/LoginDialog.qml +++ /dev/null @@ -1,81 +0,0 @@ -import QtQuick 2.12 -import QtQuick.Controls 2.12 -import QtQuick.Layouts 1.12 - -import Spectral.Component 2.0 - -Dialog { - anchors.centerIn: parent - width: 360 - - id: root - - title: "Login" - - standardButtons: Dialog.Ok | Dialog.Cancel - - onAccepted: doLogin() - - contentItem: ColumnLayout { - AutoTextField { - Layout.fillWidth: true - - id: serverField - - placeholderText: "Server Address" - text: "https://matrix.org" - } - - AutoTextField { - Layout.fillWidth: true - - id: usernameField - - placeholderText: "Username" - - onAccepted: passwordField.forceActiveFocus() - } - - AutoTextField { - Layout.fillWidth: true - - id: passwordField - - placeholderText: "Password" - echoMode: TextInput.Password - - onAccepted: accessTokenField.forceActiveFocus() - } - - AutoTextField { - Layout.fillWidth: true - - id: accessTokenField - - placeholderText: "Access Token (Optional)" - - onAccepted: deviceNameField.forceActiveFocus() - } - - AutoTextField { - Layout.fillWidth: true - - id: deviceNameField - - placeholderText: "Device Name (Optional)" - - onAccepted: root.accept() - } - } - - function doLogin() { - if (accessTokenField.text !== "") { - console.log("Login using access token.") - spectralController.loginWithAccessToken(serverField.text, usernameField.text, accessTokenField.text, deviceNameField.text) - } else { - spectralController.loginWithCredentials(serverField.text, usernameField.text, passwordField.text, deviceNameField.text) - } - } - - onClosed: destroy() -} diff --git a/qml/LoadingPage.qml b/qml/LoadingPage.qml new file mode 100644 index 000000000..4c99a22ee --- /dev/null +++ b/qml/LoadingPage.qml @@ -0,0 +1,10 @@ +import org.kde.kirigami 2.12 as Kirigami +import QtQuick.Controls 2.12 as QQC2 + +Kirigami.Page { + title: i18n("Loading") + + QQC2.BusyIndicator { + anchors.centerIn: parent + } +} diff --git a/qml/LoginPage.qml b/qml/LoginPage.qml new file mode 100644 index 000000000..842747a93 --- /dev/null +++ b/qml/LoginPage.qml @@ -0,0 +1,63 @@ +/** + * SPDX-FileCopyrightText: 2019 Black Hat + * SPDX-FileCopyrightText: 2020 Carl Schwan + * + * SPDX-LicenseIdentifier: GPL-3.0-or-later + */ +import QtQuick 2.12 +import QtQuick.Controls 2.12 as QQC2 +import QtQuick.Layouts 1.12 + +import Spectral.Component 2.0 + +import org.kde.kirigami 2.12 as Kirigami + +Kirigami.ScrollablePage { + id: root + + title: i18n("Login") + + required property var spectralController + + Kirigami.FormLayout { + id: formLayout + QQC2.TextField { + id: serverField + Kirigami.FormData.label: i18n("Server Address") + text: "https://matrix.org" + onAccepted: usernameField.forceActiveFocus() + } + QQC2.TextField { + id: usernameField + Kirigami.FormData.label: i18n("Username") + onAccepted: passwordField.forceActiveFocus() + } + Kirigami.PasswordField { + id: passwordField + Kirigami.FormData.label: i18n("Password") + onAccepted: accessTokenField.forceActiveFocus() + } + QQC2.TextField { + id: accessTokenField + Kirigami.FormData.label: i18n("Access Token (Optional)") + onAccepted: deviceNameField.forceActiveFocus() + } + QQC2.TextField { + id: deviceNameField + Kirigami.FormData.label: i18n("Device Name (Optional)") + onAccepted: doLogin() + } + QQC2.Button { + text: i18n("Login") + onClicked: doLogin() + } + } + + function doLogin() { + if (accessTokenField.text.length > 0) { + spectralController.loginWithAccessToken(serverField.text, usernameField.text, accessTokenField.text, deviceNameField.text) + } else { + spectralController.loginWithCredentials(serverField.text, usernameField.text, passwordField.text, deviceNameField.text) + } + } +} diff --git a/qml/main.qml b/qml/main.qml index b72d191cf..73004f4ba 100644 --- a/qml/main.qml +++ b/qml/main.qml @@ -6,6 +6,7 @@ import org.kde.kirigami 2.12 as Kirigami import Spectral 0.1 import Spectral.Component 2.0 +import Spectral.Dialog 2.0 import Spectral.Panel 2.0 Kirigami.ApplicationWindow { @@ -15,28 +16,28 @@ Kirigami.ApplicationWindow { contextDrawer: RoomDrawer { id: contextDrawer enabled: roomList.enteredRoom !== null - visible: enabled room: root.currentRoom } - pageStack.initialPage: RoomListPanel { - id: roomList - roomListModel: spectralRoomListModel + pageStack.initialPage: LoadingPage {} - Component.onCompleted: { - applicationWindow().pageStack.push(roomPanelComponent, {"currentRoom": roomList.enteredRoom }) - } + Component { + id: roomListComponent + RoomListPanel { + id: roomList + roomListModel: spectralRoomListModel - onEnterRoom: { - applicationWindow().pageStack.push(roomPanelComponent, {"currentRoom": room}) - root.currentRoom = room + onEnterRoom: { + applicationWindow().pageStack.push(roomPanelComponent, {"currentRoom": room}); + root.currentRoom = room; - } - onLeaveRoom: { - var stack = applicationWindow().pageStack; - roomList.enteredRoom = null + } + onLeaveRoom: { + var stack = applicationWindow().pageStack; + roomList.enteredRoom = null; - stack.removePage(stack.lastItem) + stack.removePage(stack.lastItem); + } } } @@ -46,6 +47,23 @@ Kirigami.ApplicationWindow { quitOnLastWindowClosed: true onErrorOccured: showPassiveNotification(error + ": " + detail) + + onInitiated: { + if (spectralController.accountCount === 0) { + pageStack.replace("qrc:/qml/LoginPage.qml", { + 'spectralController': spectralController + }); + } else { + pageStack.replace(roomListComponent); + } + } + + onConnectionAdded: { + if (spectralController.accountCount === 1) { + console.log("roomListComponent") + pageStack.replace(roomListComponent); + } + } } Binding { diff --git a/res.qrc b/res.qrc index 3ca297a06..f05e9f989 100644 --- a/res.qrc +++ b/res.qrc @@ -1,6 +1,8 @@ qml/main.qml + qml/LoginPage.qml + qml/LoadingPage.qml imports/Spectral/Component/Emoji/EmojiPicker.qml imports/Spectral/Component/Emoji/qmldir imports/Spectral/Component/Timeline/MessageDelegate.qml @@ -38,7 +40,6 @@ imports/Spectral/Dialog/RoomSettingsDialog.qml imports/Spectral/Dialog/UserDetailDialog.qml imports/Spectral/Dialog/MessageSourceDialog.qml - imports/Spectral/Dialog/LoginDialog.qml imports/Spectral/Dialog/CreateRoomDialog.qml imports/Spectral/Dialog/JoinRoomDialog.qml imports/Spectral/Dialog/InviteUserDialog.qml diff --git a/src/main.cpp b/src/main.cpp index 266a4de20..91e50a3da 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -38,9 +38,9 @@ int main(int argc, char *argv[]) QApplication app(argc, argv); - app.setOrganizationName("ENCOM"); - app.setOrganizationDomain("encom.eu.org"); - app.setApplicationName("Spectral"); + app.setOrganizationName("KDE"); + app.setOrganizationDomain("kde.org"); + app.setApplicationName("NeoChat"); app.setWindowIcon(QIcon(":/assets/img/icon.png")); qmlRegisterType("Spectral", 0, 1, "Controller");