// SPDX-FileCopyrightText: 2023 Yury Gubich // SPDX-License-Identifier: GPL-3.0-or-later import QtQuick import QtQuick.Controls import QtQuick.Layouts import magpie import magpie.Forms as Forms import magpie.Components as Components Page { id: page QtObject { id: priv property bool loggingIn: false } signal pickServer(address: string) // title: qsTr("Welcome") Column { id: column anchors.centerIn: parent spacing: 5 Label { anchors.horizontalCenter: parent.horizontalCenter text: qsTr("Welcome to Magpie!") font { pixelSize: 22 bold: true } } Row { anchors.horizontalCenter: parent.horizontalCenter spacing: 5 Label { horizontalAlignment: Label.AlignRight text: qsTr("Current server:") } Label { horizontalAlignment: Label.AlignLeft text: Magpie.state === Magpie.NoServer ? qsTr("choose") : Magpie.address font { italic: true underline: true } MouseArea { anchors.fill: parent onClicked: pickServer(Magpie.address) } } } Components.Modal { inProgress: Magpie.state === Magpie.Authenticating visible: !priv.loggingIn && Magpie.state === Magpie.Authenticating closable: Magpie.state === Magpie.NotAuthenticated status: "Logging into " + Magpie.address + "..." } Item { visible: priv.loggingIn || Magpie.state === Magpie.NotAuthenticated || Magpie.state === Magpie.Authenticating width: page.width height: stack.currentItem ? stack.currentItem.implicitHeight: 0 StackView { property string pendingLogin: "" property string pendingPassword: "" id: stack initialItem: loginForm anchors.fill: parent anchors.topMargin: 20 Component { id: loginForm Forms.Login { onRegister: stack.replace(registerForm) onLoggingIn: function (value) { priv.loggingIn = value; } Component.onCompleted: { if (stack.pendingLogin && stack.pendingPassword) this.login(stack.pendingLogin, stack.pendingPassword) stack.pendingLogin = ""; stack.pendingPassword = ""; } Component.onDestruction: priv.loggingIn = false } } Component { id: registerForm Forms.Register { onLogin: stack.replace(loginForm, StackView.PopTransition) onSuccess: function(login, password) { stack.pendingLogin = login; stack.pendingPassword = password; stack.replace(loginForm, StackView.PopTransition); } } } } } } }