From 8554898e45addd253bf87084f4dbb4f94c50cbd1 Mon Sep 17 00:00:00 2001 From: Tobias Fella Date: Tue, 30 Apr 2024 22:21:55 +0200 Subject: [PATCH] Move consent sheet to separate file --- src/CMakeLists.txt | 1 + src/qml/ConsentDialog.qml | 39 +++++++++++++++++++++++++++++++++++++++ src/qml/Main.qml | 36 +++--------------------------------- 3 files changed, 43 insertions(+), 33 deletions(-) create mode 100644 src/qml/ConsentDialog.qml diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index b16b027d4..8bd3cad99 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -270,6 +270,7 @@ qt_add_qml_module(neochat URI org.kde.neochat NO_PLUGIN qml/ConfirmLeaveDialog.qml qml/CodeMaximizeComponent.qml qml/EditStateDialog.qml + qml/ConsentDialog.qml ) add_subdirectory(settings) diff --git a/src/qml/ConsentDialog.qml b/src/qml/ConsentDialog.qml new file mode 100644 index 000000000..da8675e9d --- /dev/null +++ b/src/qml/ConsentDialog.qml @@ -0,0 +1,39 @@ +// SPDX-FileCopyrightText: 2024 Tobias Fella +// SPDX-License-Identifier: LGPL-2.0-or-later + +import QtQuick +import QtQuick.Controls as QQC2 + +import org.kde.kirigami as Kirigami + +import org.kde.neochat + +Kirigami.Dialog { + id: root + + required property string url + + width: Math.min(Kirigami.Units.gridUnit * 24, QQC2.ApplicationWindow.window.width) + height: Kirigami.Units.gridUnit * 8 + leftPadding: Kirigami.Units.largeSpacing + rightPadding: Kirigami.Units.largeSpacing + + title: i18nc("@title:dialog", "User Consent") + + contentItem: QQC2.Label { + text: i18nc("@info", "Your homeserver requires you to agree to its terms and conditions before being able to use it. Please click the button below to read them.") + wrapMode: Text.WordWrap + horizontalAlignment: Qt.AlignHCenter + verticalAlignment: Qt.AlignVCenter + } + customFooterActions: [ + Kirigami.Action { + text: i18nc("@action:button", "Open") + icon.name: "internet-services" + onTriggered: { + UrlHelper.openUrl(root.url); + root.close(); + } + } + ] +} diff --git a/src/qml/Main.qml b/src/qml/Main.qml index 3db949ee2..3fb183534 100644 --- a/src/qml/Main.qml +++ b/src/qml/Main.qml @@ -304,39 +304,9 @@ Kirigami.ApplicationWindow { }); } function onUserConsentRequired(url) { - let consent = consentDialogComponent.createObject(this); - consent.url = url; - consent.open(); - } - } - - Component { - id: consentDialogComponent - Kirigami.Dialog { - id: consentDialog - - property string url: "" - - width: Math.min(Kirigami.Units.gridUnit * 24, root.width) - height: Kirigami.Units.gridUnit * 8 - leftPadding: Kirigami.Units.largeSpacing - rightPadding: Kirigami.Units.largeSpacing - - title: i18nc("@title:dialog", "User Consent") - - contentItem: QQC2.Label { - text: i18n("Your homeserver requires you to agree to its terms and conditions before being able to use it. Please click the button below to read them.") - wrapMode: Text.WordWrap - horizontalAlignment: Qt.AlignHCenter - verticalAlignment: Qt.AlignVCenter - } - customFooterActions: [ - Kirigami.Action { - text: i18n("Open") - icon.name: "internet-services" - onTriggered: UrlHelper.openUrl(consentDialog.url) - } - ] + Qt.createComponent("org.kde.neochat", "ConsentDialog").createObject(this, { + url: url + }).open(); } }