some more thoughts about state management
This commit is contained in:
parent
437e76067f
commit
b38ed2107b
13 changed files with 125 additions and 13 deletions
12
qml/Application/CMakeLists.txt
Normal file
12
qml/Application/CMakeLists.txt
Normal file
|
@ -0,0 +1,12 @@
|
|||
qt_add_qml_module(magpieApplication
|
||||
URI magpie.Application
|
||||
VERSION 1.0
|
||||
STATIC
|
||||
RESOURCE_PREFIX /
|
||||
OUTPUT_DIRECTORY ../magpie/Application
|
||||
NO_PLUGIN
|
||||
QML_FILES
|
||||
Root.qml
|
||||
)
|
||||
|
||||
target_link_libraries(magpie PRIVATE magpieApplication)
|
13
qml/Application/Root.qml
Normal file
13
qml/Application/Root.qml
Normal file
|
@ -0,0 +1,13 @@
|
|||
import QtQuick
|
||||
import QtQuick.Controls
|
||||
|
||||
Page {
|
||||
Label {
|
||||
anchors.centerIn: parent
|
||||
text: "Here we go!"
|
||||
font {
|
||||
pixelSize: 24
|
||||
bold: true
|
||||
}
|
||||
}
|
||||
}
|
|
@ -18,3 +18,4 @@ target_link_libraries(magpie PRIVATE magpieQml)
|
|||
|
||||
add_subdirectory(Forms)
|
||||
add_subdirectory(Components)
|
||||
add_subdirectory(Application)
|
||||
|
|
|
@ -2,6 +2,7 @@ import QtQuick
|
|||
import QtQuick.Controls
|
||||
|
||||
Popup {
|
||||
property bool closable: true
|
||||
property bool inProgress: false
|
||||
property string status: ""
|
||||
|
||||
|
@ -11,7 +12,7 @@ Popup {
|
|||
focus: true
|
||||
width: column.width + 60
|
||||
height: column.height + 60
|
||||
closePolicy: Popup.CloseOnEscape
|
||||
closePolicy: closable ? Popup.CloseOnEscape : Popup.NoAutoClose
|
||||
onClosed: inProgress = false
|
||||
|
||||
Column {
|
||||
|
@ -32,11 +33,11 @@ Popup {
|
|||
Button {
|
||||
text: qsTr("Close")
|
||||
anchors.horizontalCenter: parent.horizontalCenter
|
||||
visible: !inProgress
|
||||
visible: closable && !inProgress
|
||||
onClicked: modal.close()
|
||||
focus: true
|
||||
Keys.onReturnPressed: {
|
||||
if (!inProgress)
|
||||
if (closable && !inProgress)
|
||||
modal.close()
|
||||
}
|
||||
}
|
||||
|
|
|
@ -6,11 +6,13 @@ import magpie.Components as Components
|
|||
|
||||
Column {
|
||||
signal register()
|
||||
signal loggingIn(value: bool)
|
||||
|
||||
function login(login, password) {
|
||||
if (modal.inProgress)
|
||||
return;
|
||||
|
||||
loggingIn(true);
|
||||
loginField.text = login;
|
||||
passwordField.text = password;
|
||||
|
||||
|
@ -28,6 +30,7 @@ Column {
|
|||
else
|
||||
modal.status = qsTr("Success");
|
||||
|
||||
loggingIn(false);
|
||||
if (!!result)
|
||||
modal.close();
|
||||
});
|
||||
|
|
|
@ -4,9 +4,15 @@ 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")
|
||||
|
@ -48,8 +54,15 @@ Page {
|
|||
}
|
||||
}
|
||||
|
||||
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: API.state === API.NotAuthenticated
|
||||
visible: priv.loggingIn || API.state === API.NotAuthenticated || API.state === API.Authenticating
|
||||
|
||||
width: page.width
|
||||
height: stack.currentItem ? stack.currentItem.implicitHeight: 0
|
||||
|
@ -67,6 +80,9 @@ Page {
|
|||
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)
|
||||
|
@ -74,6 +90,7 @@ Page {
|
|||
stack.pendingLogin = "";
|
||||
stack.pendingPassword = "";
|
||||
}
|
||||
Component.onDestruction: priv.loggingIn = false
|
||||
}
|
||||
}
|
||||
|
||||
|
|
12
qml/main.qml
12
qml/main.qml
|
@ -5,6 +5,7 @@ import QtQuick.Layouts
|
|||
import QtCore
|
||||
|
||||
import magpie.API
|
||||
import magpie.Application as Application
|
||||
|
||||
ApplicationWindow {
|
||||
property int counter: 0
|
||||
|
@ -41,6 +42,13 @@ ApplicationWindow {
|
|||
StackView.onDeactivating: pickingServer = false;
|
||||
}
|
||||
}
|
||||
|
||||
Component {
|
||||
id: app
|
||||
Application.Root {
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Connections {
|
||||
|
@ -49,5 +57,9 @@ ApplicationWindow {
|
|||
if (pickingServer && url.toString().length > 0)
|
||||
stack.pop()
|
||||
}
|
||||
function onStateChanged (state) {
|
||||
if (state === API.Authenticated)
|
||||
stack.push(app)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue