Fix AddServerSheet

(cherry picked from commit 7e4361bb5e)
This commit is contained in:
Tobias Fella
2024-04-26 19:11:03 +02:00
parent ca85b99fe9
commit ad97af20b7

View File

@@ -1,3 +1,4 @@
// SPDX-FileCopyrightText: 2024 James Graham <james.h.graham@protonmail.com> // SPDX-FileCopyrightText: 2024 James Graham <james.h.graham@protonmail.com>
// SPDX-License-Identifier: GPL-2.0-only OR GPL-3.0-only OR LicenseRef-KDE-Accepted-GPL // SPDX-License-Identifier: GPL-2.0-only OR GPL-3.0-only OR LicenseRef-KDE-Accepted-GPL
@@ -7,6 +8,7 @@ import QtQuick.Layouts
import org.kde.kirigami as Kirigami import org.kde.kirigami as Kirigami
import org.kde.kirigamiaddons.delegates as Delegates import org.kde.kirigamiaddons.delegates as Delegates
import org.kde.kirigamiaddons.formcard as FormCard
import org.kde.neochat import org.kde.neochat
@@ -49,6 +51,7 @@ QQC2.ComboBox {
bottomInset: index === ListView.view.count - 1 ? Kirigami.Units.smallSpacing : Math.round(Kirigami.Units.smallSpacing / 2) bottomInset: index === ListView.view.count - 1 ? Kirigami.Units.smallSpacing : Math.round(Kirigami.Units.smallSpacing / 2)
onClicked: if (isAddServerDelegate) { onClicked: if (isAddServerDelegate) {
addServerSheet.parent = QQC2.Overlay.overlay
addServerSheet.open(); addServerSheet.open();
} }
@@ -75,6 +78,7 @@ QQC2.ComboBox {
root.popup.close(); root.popup.close();
} }
if (serverItem.isAddServerDelegate) { if (serverItem.isAddServerDelegate) {
addServerSheet.parent = QQC2.Overlay.overlay
addServerSheet.open(); addServerSheet.open();
serverItem.clicked(); serverItem.clicked();
} else { } else {
@@ -91,10 +95,10 @@ QQC2.ComboBox {
} }
} }
Kirigami.OverlaySheet { Kirigami.Dialog {
id: addServerSheet id: addServerSheet
parent: applicationWindow().overlay width: Math.min(Kirigami.Units.gridUnit * 24, QQC2.ApplicationWindow.window.width)
title: i18nc("@title:window", "Add server") title: i18nc("@title:window", "Add server")
@@ -109,19 +113,16 @@ QQC2.ComboBox {
root.currentIndex = root.indexOfValue(root.server); root.currentIndex = root.indexOfValue(root.server);
} }
contentItem: Kirigami.FormLayout { contentItem: ColumnLayout {
QQC2.Label { FormCard.FormTextDelegate {
Layout.minimumWidth: Kirigami.Units.gridUnit * 20
text: serverUrlField.length > 0 ? (serverUrlField.acceptableInput ? (serverUrlField.isValidServer ? i18n("Valid server entered") : i18n("This server cannot be resolved or has already been added")) : i18n("The entered text is not a valid url")) : i18n("Enter server url e.g. kde.org") text: serverUrlField.length > 0 ? (serverUrlField.acceptableInput ? (serverUrlField.isValidServer ? i18n("Valid server entered") : i18n("This server cannot be resolved or has already been added")) : i18n("The entered text is not a valid url")) : i18n("Enter server url e.g. kde.org")
color: serverUrlField.length > 0 ? (serverUrlField.acceptableInput ? (serverUrlField.isValidServer ? Kirigami.Theme.positiveTextColor : Kirigami.Theme.negativeTextColor) : Kirigami.Theme.negativeTextColor) : Kirigami.Theme.textColor
} }
QQC2.TextField { FormCard.FormTextFieldDelegate {
id: serverUrlField id: serverUrlField
property bool isValidServer: false property bool isValidServer: false
Kirigami.FormData.label: i18n("Server URL") label: i18n("Server URL")
onTextChanged: { onTextChanged: {
if (acceptableInput) { if (acceptableInput) {
serverListModel.checkServer(text); serverListModel.checkServer(text);
@@ -141,19 +142,17 @@ QQC2.ComboBox {
} }
} }
} }
}
QQC2.Button { customFooterActions: Kirigami.Action {
id: okButton text: i18nc("@action:button", "Ok")
enabled: serverUrlField.acceptableInput && serverUrlField.isValidServer
text: i18nc("@action:button", "Ok") onTriggered: {
enabled: serverUrlField.acceptableInput && serverUrlField.isValidServer serverListModel.addServer(serverUrlField.text);
onClicked: { root.currentIndex = root.indexOfValue(serverUrlField.text);
serverListModel.addServer(serverUrlField.text); root.server = root.currentValue;
root.currentIndex = root.indexOfValue(serverUrlField.text); serverUrlField.text = "";
root.server = root.currentValue; addServerSheet.close();
serverUrlField.text = "";
addServerSheet.close();
}
} }
} }
} }