magpie/qml/Welcome.qml

115 lines
3.4 KiB
QML
Raw Normal View History

// SPDX-FileCopyrightText: 2023 Yury Gubich <blue@macaw.me>
// SPDX-License-Identifier: GPL-3.0-or-later
2023-11-24 23:48:01 +00:00
import QtQuick
import QtQuick.Controls
import QtQuick.Layouts
2023-12-17 00:06:04 +00:00
import magpie.API
import magpie.Forms as Forms
import magpie.Components as Components
2023-11-24 23:48:01 +00:00
2023-12-16 01:44:25 +00:00
Page {
2023-12-17 20:10:27 +00:00
id: page
QtObject {
id: priv
property bool loggingIn: false
}
2023-11-24 23:48:01 +00:00
signal pickServer(address: string)
2023-12-25 20:07:51 +00:00
// title: qsTr("Welcome")
2023-11-24 23:48:01 +00:00
Column {
2023-12-17 20:10:27 +00:00
id: column
2023-11-24 23:48:01 +00:00
anchors.centerIn: parent
2023-12-17 20:10:27 +00:00
spacing: 5
2023-11-24 23:48:01 +00:00
Label {
anchors.horizontalCenter: parent.horizontalCenter
2023-12-03 21:34:16 +00:00
text: qsTr("Welcome to Magpie!")
2023-11-24 23:48:01 +00:00
font {
pixelSize: 22
bold: true
}
}
Row {
anchors.horizontalCenter: parent.horizontalCenter
spacing: 5
Label {
horizontalAlignment: Label.AlignRight
text: qsTr("Current server:")
}
Label {
horizontalAlignment: Label.AlignLeft
2023-12-16 01:44:25 +00:00
text: API.state === API.NoServer ? qsTr("choose") : API.address
2023-11-24 23:48:01 +00:00
font {
italic: true
underline: true
}
MouseArea {
anchors.fill: parent
2023-12-16 01:44:25 +00:00
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 + "..."
}
2023-12-17 20:10:27 +00:00
Item {
visible: priv.loggingIn || API.state === API.NotAuthenticated || API.state === API.Authenticating
2023-12-16 01:44:25 +00:00
2023-12-17 20:10:27 +00:00
width: page.width
height: stack.currentItem ? stack.currentItem.implicitHeight: 0
2023-12-16 01:44:25 +00:00
2023-12-17 20:10:27 +00:00
StackView {
property string pendingLogin: ""
property string pendingPassword: ""
2023-12-17 20:10:27 +00:00
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
2023-12-17 20:10:27 +00:00
}
}
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);
}
2023-12-17 20:10:27 +00:00
}
}
2023-11-24 23:48:01 +00:00
}
}
}
}