magpie/qml/Welcome.qml

115 lines
3.4 KiB
QML

// SPDX-FileCopyrightText: 2023 Yury Gubich <blue@macaw.me>
// SPDX-License-Identifier: GPL-3.0-or-later
import QtQuick
import QtQuick.Controls
import QtQuick.Layouts
import magpie.API
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: API.state === API.NoServer ? qsTr("choose") : API.address
font {
italic: true
underline: true
}
MouseArea {
anchors.fill: parent
onClicked: pickServer(API.address)
}
}
}
Components.Modal {
inProgress: API.state === API.Authenticating
visible: !priv.loggingIn && API.state === API.Authenticating
closable: API.state === API.NotAuthenticated
status: "Logging into " + API.address + "..."
}
Item {
visible: priv.loggingIn || API.state === API.NotAuthenticated || API.state === API.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);
}
}
}
}
}
}
}