magpie/qml/ServerPick.qml

78 lines
2.0 KiB
QML

import QtQuick
import QtQuick.Controls
import QtQuick.Layouts
import magpie.API
import magpie.Components as Components
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 {
id: modal
function check () {
if (modal.inProgress)
return;
modal.inProgress = true;
modal.status = qsTr("Checking") + " " + address + "...";
modal.open()
API.test(input.text, function (err, success) {
if (!modal.inProgress)
return;
modal.inProgress = false;
if (err)
modal.status = err;
else
modal.status = qsTr("Success");
if (!!success)
modal.close()
});
}
}
}
}