magpie/qml/ServerPick.qml

81 lines
2.1 KiB
QML
Raw 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.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()
2023-12-25 20:07:51 +00:00
// title: qsTr("Chosing a server")
2023-11-24 23:48:01 +00:00
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()
});
}
}
}
}