magpie/qml/ServerPick.qml

78 lines
2.0 KiB
QML
Raw Normal View History

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.Components as Components
2023-12-16 01:44:25 +00:00
2023-11-24 23:48:01 +00:00
Page {
property string address
signal back()
title: qsTr("Chosing a server")
Column {
anchors.centerIn: parent
spacing: 10
Label {
anchors.horizontalCenter: parent.horizontalCenter
id: label
text: qsTr("Type server address in the field below")
}
TextField {
width: parent.width
anchors.horizontalCenter: parent.horizontalCenter
id: input
placeholderText: "https://example.org"
text: address
onAccepted: modal.check()
validator: RegularExpressionValidator {
regularExpression: /^(?:http|https)?:\/\/(?:\w*\.)*(?:\w)+(?:\:\d+)?(?:(?:\/\w+)\/?)*$/
}
}
Row {
anchors.horizontalCenter: parent.horizontalCenter
spacing: 10
Button {
text: qsTr("Cancel")
onClicked: back()
}
Button {
text: qsTr("Confirm")
enabled: input.acceptableInput
onClicked: modal.check()
}
}
Components.Modal {
2023-11-24 23:48:01 +00:00
id: modal
function check () {
2023-12-17 00:06:04 +00:00
if (modal.inProgress)
2023-12-03 14:39:48 +00:00
return;
2023-11-24 23:48:01 +00:00
modal.inProgress = true;
modal.status = qsTr("Checking") + " " + address + "...";
2023-11-24 23:48:01 +00:00
modal.open()
API.test(input.text, function (err, success) {
if (!modal.inProgress)
return;
modal.inProgress = false;
if (err)
modal.status = err;
2023-11-24 23:48:01 +00:00
else
modal.status = qsTr("Success");
2023-11-24 23:48:01 +00:00
2023-12-17 00:06:04 +00:00
if (!!success)
2023-11-24 23:48:01 +00:00
modal.close()
});
}
}
}
}