Warning, /network/neochat/src/qml/WelcomePage.qml is written in an unsupported language. File is not indexed.

0001 // SPDX-FileCopyrightText: 2020 Tobias Fella <tobias.fella@kde.org>
0002 // SPDX-License-Identifier: GPL-2.0-or-later
0003 
0004 import QtQuick
0005 import QtQuick.Controls as QQC2
0006 import QtQuick.Layouts
0007 
0008 import org.kde.kirigami as Kirigami
0009 import org.kde.kirigamiaddons.formcard as FormCard
0010 
0011 import org.kde.neochat
0012 import org.kde.neochat.accounts
0013 
0014 FormCard.FormCardPage {
0015     id: root
0016 
0017     property bool showExisting: false
0018     property bool _showExisting: showExisting && module.source == root.initialStep
0019     property alias currentStep: module.item
0020     property string initialStep: "qrc:/org/kde/neochat/qml/LoginRegister.qml"
0021 
0022     signal connectionChosen
0023 
0024     title: i18n("Welcome")
0025 
0026     header: QQC2.Control {
0027         contentItem: Kirigami.InlineMessage {
0028             id: headerMessage
0029             type: Kirigami.MessageType.Error
0030             showCloseButton: true
0031             visible: false
0032         }
0033     }
0034 
0035     Kirigami.Icon {
0036         source: "org.kde.neochat"
0037         Layout.alignment: Qt.AlignHCenter
0038         implicitWidth: Math.round(Kirigami.Units.iconSizes.huge * 1.5)
0039         implicitHeight: Math.round(Kirigami.Units.iconSizes.huge * 1.5)
0040     }
0041 
0042     Kirigami.Heading {
0043         id: welcomeMessage
0044 
0045         text: i18n("Welcome to NeoChat")
0046 
0047         Layout.alignment: Qt.AlignHCenter
0048         Layout.topMargin: Kirigami.Units.largeSpacing
0049     }
0050 
0051     FormCard.FormHeader {
0052         id: existingAccountsHeader
0053         title: i18nc("@title", "Continue with an existing account")
0054         visible: (loadedAccounts.count > 0 || loadingAccounts.count > 0) && root._showExisting
0055     }
0056 
0057     FormCard.FormCard {
0058         visible: existingAccountsHeader.visible
0059         Repeater {
0060             id: loadedAccounts
0061             model: AccountRegistry
0062             delegate: FormCard.FormButtonDelegate {
0063                 text: model.userId
0064                 onClicked: {
0065                     Controller.activeConnection = model.connection;
0066                     root.connectionChosen();
0067                 }
0068             }
0069         }
0070         Repeater {
0071             id: loadingAccounts
0072             model: Controller.accountsLoading
0073             delegate: FormCard.FormButtonDelegate {
0074                 text: i18nc("As in 'this account is still loading'", "%1 (loading)", modelData)
0075                 enabled: false
0076             }
0077         }
0078     }
0079 
0080     FormCard.FormHeader {
0081         title: i18nc("@title", "Log in or Create a New Account")
0082     }
0083 
0084     FormCard.FormCard {
0085         Loader {
0086             id: module
0087             Layout.fillWidth: true
0088             source: root.initialStep
0089 
0090             Connections {
0091                 id: stepConnections
0092                 target: currentStep
0093 
0094                 function onProcessed(nextUrl: string): void {
0095                     module.source = nextUrl;
0096                     headerMessage.text = "";
0097                     headerMessage.visible = false;
0098                     if (!module.item.noControls) {
0099                         module.item.forceActiveFocus();
0100                     } else {
0101                         continueButton.forceActiveFocus();
0102                     }
0103                 }
0104 
0105                 function onShowMessage(message: string): void {
0106                     headerMessage.text = message;
0107                     headerMessage.visible = true;
0108                     headerMessage.type = Kirigami.MessageType.Information;
0109                 }
0110 
0111                 function onClearError(): void {
0112                     headerMessage.text = "";
0113                     headerMessage.visible = false;
0114                 }
0115 
0116                 function onCloseDialog(): void {
0117                     root.closeDialog();
0118                 }
0119             }
0120 
0121             Connections {
0122                 target: Registration
0123                 function onNextStepChanged() {
0124                     if (Registration.nextStep === "m.login.recaptcha") {
0125                         stepConnections.onProcessed("qrc:/org/kde/neochat/qml/Captcha.qml");
0126                     }
0127                     if (Registration.nextStep === "m.login.terms") {
0128                         stepConnections.onProcessed("qrc:/org/kde/neochat/qml/Terms.qml");
0129                     }
0130                     if (Registration.nextStep === "m.login.email.identity") {
0131                         stepConnections.onProcessed("qrc:/org/kde/neochat/qml/Email.qml");
0132                     }
0133                     if (Registration.nextStep === "loading") {
0134                         stepConnections.onProcessed("qrc:/org/kde/neochat/qml/Loading.qml");
0135                     }
0136                 }
0137             }
0138             Connections {
0139                 target: LoginHelper
0140                 function onErrorOccured(message) {
0141                     headerMessage.text = message;
0142                     headerMessage.visible = message.length > 0;
0143                     headerMessage.type = Kirigami.MessageType.Error;
0144                 }
0145             }
0146         }
0147 
0148         FormCard.FormDelegateSeparator {
0149             below: continueButton
0150         }
0151 
0152         FormCard.FormButtonDelegate {
0153             id: continueButton
0154             text: root.currentStep.nextAction && root.currentStep.nextAction.text ? root.currentStep.nextAction.text : i18nc("@action:button", "Continue")
0155             visible: root.currentStep.nextAction
0156             onClicked: root.currentStep.nextAction.trigger()
0157             icon.name: "arrow-right"
0158             enabled: root.currentStep.nextAction ? root.currentStep.nextAction.enabled : false
0159         }
0160 
0161         FormCard.FormButtonDelegate {
0162             text: i18nc("@action:button", "Go back")
0163             visible: root.currentStep.previousAction
0164             onClicked: root.currentStep.previousAction.trigger()
0165             icon.name: "arrow-left"
0166             enabled: root.currentStep.previousAction ? root.currentStep.previousAction.enabled : false
0167         }
0168     }
0169 
0170     Component.onCompleted: {
0171         LoginHelper.init();
0172         module.item.forceActiveFocus();
0173         Registration.username = "";
0174         Registration.password = "";
0175         Registration.email = "";
0176     }
0177 }