magpie/qml/Welcome.qml

115 lines
3.4 KiB
QML
Raw Permalink 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
2024-01-20 21:17:21 +00:00
import magpie
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
2024-01-20 21:17:21 +00:00
text: Magpie.state === Magpie.NoServer ? qsTr("choose") : Magpie.address
2023-11-24 23:48:01 +00:00
font {
italic: true
underline: true
}
MouseArea {
anchors.fill: parent
2024-01-20 21:17:21 +00:00
onClicked: pickServer(Magpie.address)
2023-12-16 01:44:25 +00:00
}
}
}
Components.Modal {
2024-01-20 21:17:21 +00:00
inProgress: Magpie.state === Magpie.Authenticating
visible: !priv.loggingIn && Magpie.state === Magpie.Authenticating
closable: Magpie.state === Magpie.NotAuthenticated
status: "Logging into " + Magpie.address + "..."
}
2023-12-17 20:10:27 +00:00
Item {
2024-01-20 21:17:21 +00:00
visible: priv.loggingIn || Magpie.state === Magpie.NotAuthenticated || Magpie.state === Magpie.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
}
}
}
}