From 4ebcc36fb3bd789d98fdf5ca6213ac99248d66e3 Mon Sep 17 00:00:00 2001 From: Tobias Fella Date: Mon, 29 Jan 2024 23:12:51 +0100 Subject: [PATCH] Add a way for distros to recommend joining a space Implements #137 --- src/CMakeLists.txt | 1 + src/qml/RecommendedSpaceDialog.qml | 69 ++++++++++++++++++++++++++++++ src/qml/SpaceDrawer.qml | 37 ++++++++++++++++ src/spacehierarchycache.cpp | 37 ++++++++++++++++ src/spacehierarchycache.h | 14 ++++++ 5 files changed, 158 insertions(+) create mode 100644 src/qml/RecommendedSpaceDialog.qml diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 2979bf4ac..f7b8115af 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -314,6 +314,7 @@ qt_add_qml_module(neochat URI org.kde.neochat NO_PLUGIN qml/PollComponent.qml qml/LinkPreviewComponent.qml qml/LoadComponent.qml + qml/RecommendedSpaceDialog.qml RESOURCES qml/confetti.png qml/glowdot.png diff --git a/src/qml/RecommendedSpaceDialog.qml b/src/qml/RecommendedSpaceDialog.qml new file mode 100644 index 000000000..b4419d2e4 --- /dev/null +++ b/src/qml/RecommendedSpaceDialog.qml @@ -0,0 +1,69 @@ +// SPDX-FileCopyrightText: 2024 Tobias Fella +// SPDX-License-Identifier: GPL-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.kirigamiaddons.components + +import org.kde.neochat + +Kirigami.Dialog { + id: root + + property var connection + + + parent: applicationWindow().overlay + + leftPadding: 0 + rightPadding: 0 + topPadding: 0 + bottomPadding: 0 + + title: i18nc("@title Join ", "Join %1", SpaceHierarchyCache.recommendedSpaceDisplayName) + + width: Math.min(applicationWindow().width, Kirigami.Units.gridUnit * 24) + + contentItem: ColumnLayout { + FormCard.AbstractFormDelegate { + background: null + contentItem: RowLayout { + spacing: Kirigami.Units.largeSpacing * 4 + Avatar { + source: root.connection.makeMediaUrl(SpaceHierarchyCache.recommendedSpaceAvatar) + } + ColumnLayout { + Layout.fillWidth: true + Kirigami.Heading { + Layout.fillWidth: true + text: SpaceHierarchyCache.recommendedSpaceDisplayName + } + QQC2.Label { + Layout.fillWidth: true + text: SpaceHierarchyCache.recommendedSpaceDescription + } + } + } + + } + FormCard.FormDelegateSeparator {} + FormCard.FormButtonDelegate { + text: i18nc("@action:button", "Join") + onClicked: { + SpaceHierarchyCache.recommendedSpaceHidden = true + RoomManager.resolveResource(SpaceHierarchyCache.recommendedSpaceId, "join") + root.close() + } + } + FormCard.FormButtonDelegate { + text: i18nc("@action:button", "Ignore") + onClicked: { + SpaceHierarchyCache.recommendedSpaceHidden = true + root.close() + } + } + } +} diff --git a/src/qml/SpaceDrawer.qml b/src/qml/SpaceDrawer.qml index d8cb8099a..1ac912b06 100644 --- a/src/qml/SpaceDrawer.qml +++ b/src/qml/SpaceDrawer.qml @@ -254,6 +254,43 @@ QQC2.Control { } } + AvatarTabButton { + id: recommendedSpaceButton + Layout.fillWidth: true + Layout.preferredHeight: width - Kirigami.Units.smallSpacing + Layout.maximumHeight: width - Kirigami.Units.smallSpacing + + visible: SpaceHierarchyCache.recommendedSpaceId.length > 0 && !root.connection.room(SpaceHierarchyCache.recommendedSpaceId) && !SpaceHierarchyCache.recommendedSpaceHidden + + text: i18nc("Join ", "Join %1", SpaceHierarchyCache.recommendedSpaceDisplayName) + source: root.connection.makeMediaUrl(SpaceHierarchyCache.recommendedSpaceAvatar) + onClicked: { + recommendedSpaceDialogComponent.createObject(QQC2.ApplicationWindow.overlay, { + connection: root.connection + }).open() + } + Component { + id: recommendedSpaceDialogComponent + RecommendedSpaceDialog {} + } + Rectangle { + color: Kirigami.Theme.backgroundColor + width: Kirigami.Units.gridUnit * 1.5 + height: width + anchors.bottom: parent.bottom + anchors.bottomMargin: Kirigami.Units.smallSpacing + anchors.rightMargin: Kirigami.Units.smallSpacing * 2 + anchors.right: parent.right + radius: width / 2 + z: parent.z + 1 + Kirigami.Icon { + anchors.fill: parent + z: parent + 1 + source: "list-add" + } + } + } + Kirigami.Separator { Layout.fillWidth: true Layout.topMargin: Kirigami.Units.smallSpacing / 2 diff --git a/src/spacehierarchycache.cpp b/src/spacehierarchycache.cpp index bcd49795b..129a04d09 100644 --- a/src/spacehierarchycache.cpp +++ b/src/spacehierarchycache.cpp @@ -6,6 +6,9 @@ #include #include +#include +#include + #include "neochatroom.h" #include "roomlistmodel.h" @@ -163,4 +166,38 @@ void SpaceHierarchyCache::setConnection(NeoChatConnection *connection) connect(connection, &Connection::aboutToDeleteRoom, this, &SpaceHierarchyCache::removeSpaceFromHierarchy); } +QString SpaceHierarchyCache::recommendedSpaceId() const +{ + return KConfigGroup(KSharedConfig::openConfig(), QStringLiteral("RecommendedSpace")).readEntry(QStringLiteral("Id"), {}); +} + +QString SpaceHierarchyCache::recommendedSpaceAvatar() const +{ + return KConfigGroup(KSharedConfig::openConfig(), QStringLiteral("RecommendedSpace")).readEntry(QStringLiteral("Avatar"), {}); +} + +QString SpaceHierarchyCache::recommendedSpaceDisplayName() const +{ + return KConfigGroup(KSharedConfig::openConfig(), QStringLiteral("RecommendedSpace")).readEntry(QStringLiteral("DisplayName"), {}); +} + +QString SpaceHierarchyCache::recommendedSpaceDescription() const +{ + return KConfigGroup(KSharedConfig::openConfig(), QStringLiteral("RecommendedSpace")).readEntry(QStringLiteral("Description"), {}); +} + +bool SpaceHierarchyCache::recommendedSpaceHidden() const +{ + KConfigGroup group(KSharedConfig::openStateConfig(), QStringLiteral("RecommendedSpace")); + return group.readEntry(QStringLiteral("hidden"), false); +} + +void SpaceHierarchyCache::setRecommendedSpaceHidden(bool hidden) +{ + KConfigGroup group(KSharedConfig::openStateConfig(), QStringLiteral("RecommendedSpace")); + group.writeEntry(QStringLiteral("hidden"), hidden); + group.sync(); + Q_EMIT recommendedSpaceHiddenChanged(); +} + #include "moc_spacehierarchycache.cpp" diff --git a/src/spacehierarchycache.h b/src/spacehierarchycache.h index 32e9d9c0d..78ee31553 100644 --- a/src/spacehierarchycache.h +++ b/src/spacehierarchycache.h @@ -31,6 +31,11 @@ class SpaceHierarchyCache : public QObject QML_SINGLETON Q_PROPERTY(NeoChatConnection *connection READ connection WRITE setConnection NOTIFY connectionChanged) + Q_PROPERTY(QString recommendedSpaceId READ recommendedSpaceId CONSTANT) + Q_PROPERTY(QString recommendedSpaceAvatar READ recommendedSpaceAvatar CONSTANT) + Q_PROPERTY(QString recommendedSpaceDisplayName READ recommendedSpaceDisplayName CONSTANT) + Q_PROPERTY(QString recommendedSpaceDescription READ recommendedSpaceDescription CONSTANT) + Q_PROPERTY(bool recommendedSpaceHidden READ recommendedSpaceHidden WRITE setRecommendedSpaceHidden NOTIFY recommendedSpaceHiddenChanged) public: static SpaceHierarchyCache &instance() @@ -76,10 +81,19 @@ public: NeoChatConnection *connection() const; void setConnection(NeoChatConnection *connection); + QString recommendedSpaceId() const; + QString recommendedSpaceAvatar() const; + QString recommendedSpaceDisplayName() const; + QString recommendedSpaceDescription() const; + + bool recommendedSpaceHidden() const; + void setRecommendedSpaceHidden(bool hidden); + Q_SIGNALS: void spaceHierarchyChanged(); void connectionChanged(); void spaceNotifcationCountChanged(const QStringList &spaces); + void recommendedSpaceHiddenChanged(); private Q_SLOTS: void addSpaceToHierarchy(Quotient::Room *room);