2023-12-27 20:59:22 +00:00
|
|
|
// 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
|
2023-12-21 18:03:44 +00:00
|
|
|
import magpie.Forms as Forms
|
2023-12-26 23:31:55 +00:00
|
|
|
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
|
2023-12-26 23:31:55 +00:00
|
|
|
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)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-12-26 23:31:55 +00:00
|
|
|
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 {
|
2023-12-26 23:31:55 +00:00
|
|
|
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 {
|
2023-12-21 18:03:44 +00:00
|
|
|
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)
|
2023-12-26 23:31:55 +00:00
|
|
|
onLoggingIn: function (value) {
|
|
|
|
priv.loggingIn = value;
|
|
|
|
}
|
2023-12-21 18:03:44 +00:00
|
|
|
Component.onCompleted: {
|
|
|
|
if (stack.pendingLogin && stack.pendingPassword)
|
|
|
|
this.login(stack.pendingLogin, stack.pendingPassword)
|
|
|
|
|
|
|
|
stack.pendingLogin = "";
|
|
|
|
stack.pendingPassword = "";
|
|
|
|
}
|
2023-12-26 23:31:55 +00:00
|
|
|
Component.onDestruction: priv.loggingIn = false
|
2023-12-17 20:10:27 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
Component {
|
|
|
|
id: registerForm
|
|
|
|
Forms.Register {
|
|
|
|
onLogin: stack.replace(loginForm, StackView.PopTransition)
|
2023-12-21 18:03:44 +00:00
|
|
|
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
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|