From e0ce5d9544807c5c31c2a6d06c0a11765dc19416 Mon Sep 17 00:00:00 2001 From: Tobias Fella Date: Wed, 21 Feb 2024 21:22:07 +0100 Subject: [PATCH] Show AccountData in Devtools --- src/CMakeLists.txt | 1 + src/neochatconnection.cpp | 6 ++++++ src/neochatconnection.h | 5 +++++ src/qml/AccountData.qml | 35 +++++++++++++++++++++++++++++++++++ src/qml/DevtoolsPage.qml | 6 ++++++ 5 files changed, 53 insertions(+) create mode 100644 src/qml/AccountData.qml diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 0e8a225e9..7434b83cc 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -326,6 +326,7 @@ qt_add_qml_module(neochat URI org.kde.neochat NO_PLUGIN qml/ShareDialog.qml qml/FeatureFlagPage.qml qml/IgnoredUsersDialog.qml + qml/AccountData.qml RESOURCES qml/confetti.png qml/glowdot.png diff --git a/src/neochatconnection.cpp b/src/neochatconnection.cpp index 6207f532d..d9dddc396 100644 --- a/src/neochatconnection.cpp +++ b/src/neochatconnection.cpp @@ -4,6 +4,7 @@ #include "neochatconnection.h" #include +#include #include "controller.h" #include "jobs/neochatchangepasswordjob.h" @@ -434,4 +435,9 @@ void NeoChatConnection::setIsOnline(bool isOnline) Q_EMIT isOnlineChanged(); } +QString NeoChatConnection::accountDataJsonString(const QString &type) const +{ + return QString::fromUtf8(QJsonDocument(accountDataJson(type)).toJson()); +} + #include "moc_neochatconnection.cpp" diff --git a/src/neochatconnection.h b/src/neochatconnection.h index 945e7730d..d42eacd7e 100644 --- a/src/neochatconnection.h +++ b/src/neochatconnection.h @@ -113,6 +113,11 @@ public: */ Q_INVOKABLE void openOrCreateDirectChat(Quotient::User *user); + /** + * @brief Get the account data with \param type as a formatted JSON string. + */ + Q_INVOKABLE QString accountDataJsonString(const QString &type) const; + qsizetype directChatNotifications() const; qsizetype homeNotifications() const; bool directChatInvites() const; diff --git a/src/qml/AccountData.qml b/src/qml/AccountData.qml new file mode 100644 index 000000000..c3e65b90a --- /dev/null +++ b/src/qml/AccountData.qml @@ -0,0 +1,35 @@ +// SPDX-FileCopyrightText: 2024 Tobias Fella +// SPDX-License-Identifier: LGPL-2.0-or-later + +import QtQuick +import QtQuick.Controls as QQC2 +import QtQuick.Layouts + +import org.kde.kirigami as Kirigami +import org.kde.kirigamiaddons.formcard as FormCard + +import org.kde.neochat + +ColumnLayout { + id: root + + required property NeoChatConnection connection + + FormCard.FormHeader { + title: i18nc("@title:group", "Account Data") + } + FormCard.FormCard { + Repeater { + model: root.connection.accountDataEventTypes + delegate: FormCard.FormButtonDelegate { + text: modelData + onClicked: applicationWindow().pageStack.pushDialogLayer("qrc:/org/kde/neochat/qml/MessageSourceSheet.qml", { + sourceText: root.connection.accountDataJsonString(modelData) + }, { + title: i18nc("@title:window", "Event Source"), + width: Kirigami.Units.gridUnit * 25 + }) + } + } + } +} diff --git a/src/qml/DevtoolsPage.qml b/src/qml/DevtoolsPage.qml index a5d49c1c7..d1e54292a 100644 --- a/src/qml/DevtoolsPage.qml +++ b/src/qml/DevtoolsPage.qml @@ -29,6 +29,9 @@ FormCard.FormCardPage { QQC2.TabButton { text: qsTr("Server Info") } + QQC2.TabButton { + text: i18nc("@title:tab", "Account Data") + } QQC2.TabButton { text: i18nc("@title:tab", "Feature Flags") } @@ -46,6 +49,9 @@ FormCard.FormCardPage { ServerData { connection: root.connection } + AccountData { + connection: root.connection + } FeatureFlagPage {} } }