From 72c85af4070c2cd8e7bc6f985402e3996bb198bb Mon Sep 17 00:00:00 2001 From: Tobias Fella Date: Thu, 8 Jun 2023 20:05:53 +0000 Subject: [PATCH] Implement creating spaces --- src/controller.cpp | 21 +++++++++++ src/controller.h | 5 +++ src/qml/Dialog/CreateSpaceDialog.qml | 44 ++++++++++++++++++++++ src/qml/Page/RoomList/ExploreComponent.qml | 20 +++++++++- src/qml/main.qml | 5 +++ src/res.qrc | 1 + 6 files changed, 94 insertions(+), 2 deletions(-) create mode 100644 src/qml/Dialog/CreateSpaceDialog.qml diff --git a/src/controller.cpp b/src/controller.cpp index f7e8cac0d..d4ebcfdcd 100644 --- a/src/controller.cpp +++ b/src/controller.cpp @@ -533,6 +533,27 @@ void Controller::createRoom(const QString &name, const QString &topic) connectSingleShot(this, &Controller::roomAdded, &RoomManager::instance(), &RoomManager::enterRoom, Qt::QueuedConnection); } +void Controller::createSpace(const QString &name, const QString &topic) +{ + auto createRoomJob = m_connection->createRoom(Connection::UnpublishRoom, + {}, + name, + topic, + QStringList(), + {}, + {}, + false, + {}, + {}, + QJsonObject{ + {"type"_ls, "m.space"_ls}, + }); + connect(createRoomJob, &CreateRoomJob::failure, this, [this, createRoomJob] { + Q_EMIT errorOccured(i18n("Space creation failed: %1", createRoomJob->errorString())); + }); + connectSingleShot(this, &Controller::roomAdded, &RoomManager::instance(), &RoomManager::enterRoom, Qt::QueuedConnection); +} + bool Controller::isOnline() const { return m_isOnline; diff --git a/src/controller.h b/src/controller.h index f29fe2c80..efdb46ed7 100644 --- a/src/controller.h +++ b/src/controller.h @@ -159,6 +159,11 @@ public: */ Q_INVOKABLE void createRoom(const QString &name, const QString &topic); + /** + * @brief Create new space. + */ + Q_INVOKABLE void createSpace(const QString &name, const QString &topic); + /** * @brief Join a room. */ diff --git a/src/qml/Dialog/CreateSpaceDialog.qml b/src/qml/Dialog/CreateSpaceDialog.qml new file mode 100644 index 000000000..38b63e5d8 --- /dev/null +++ b/src/qml/Dialog/CreateSpaceDialog.qml @@ -0,0 +1,44 @@ +// SPDX-FileCopyrightText: 2023 Tobias Fella +// SPDX-License-Identifier: GPL-2.0-or-later + +import QtQuick 2.15 +import QtQuick.Controls 2.15 as QQC2 +import QtQuick.Layouts 1.15 +import org.kde.kirigami 2.20 as Kirigami + +import org.kde.neochat 1.0 +import org.kde.kirigamiaddons.labs.mobileform 0.1 as MobileForm + +Kirigami.OverlaySheet { + id: root + + title: i18n("Create a Space") + + Kirigami.Theme.colorSet: Kirigami.Theme.Window + + MobileForm.FormCard { + contentItem: ColumnLayout { + spacing: 0 + MobileForm.FormCardHeader { + title: i18nc("@title", "Create a Space") + } + MobileForm.FormTextFieldDelegate { + id: nameDelegate + label: i18n("Space name") + } + MobileForm.FormTextFieldDelegate { + id: topicDelegate + label: i18n("Space topic (optional)") + } + MobileForm.FormButtonDelegate { + text: i18n("Create space") + onClicked: { + Controller.createSpace(nameDelegate.text, topicDelegate.text) + root.close() + root.destroy() + } + enabled: nameDelegate.text.length > 0 + } + } + } +} diff --git a/src/qml/Page/RoomList/ExploreComponent.qml b/src/qml/Page/RoomList/ExploreComponent.qml index 40a661847..b04b9d56e 100644 --- a/src/qml/Page/RoomList/ExploreComponent.qml +++ b/src/qml/Page/RoomList/ExploreComponent.qml @@ -24,18 +24,26 @@ QQC2.ToolBar { } property Kirigami.Action chatAction: Kirigami.Action { text: i18n("Start a Chat") - icon.name: "irc-join-channel" + icon.name: "list-add-user" onTriggered: applicationWindow().pushReplaceLayer("qrc:/StartChatPage.qml", {connection: Controller.activeConnection}) } property Kirigami.Action roomAction: Kirigami.Action { text: i18n("Create a Room") - icon.name: "irc-join-channel" + icon.name: "system-users" onTriggered: { let dialog = createRoomDialog.createObject(root.overlay); dialog.open(); } shortcut: StandardKey.New } + property Kirigami.Action spaceAction: Kirigami.Action { + text: i18n("Create a Space") + icon.name: "list-add" + onTriggered: { + let dialog = createSpaceDialog.createObject(root.overlay); + dialog.open() + } + } padding: 0 @@ -86,6 +94,9 @@ QQC2.ToolBar { QQC2.MenuItem { action: roomAction } + QQC2.MenuItem { + action: spaceAction + } } } Component { @@ -123,6 +134,11 @@ QQC2.ToolBar { action: roomAction onClicked: menuRoot.close() } + Kirigami.BasicListItem { + implicitHeight: Kirigami.Units.gridUnit * 3 + action: roomAction + onClicked: menuRoot.close() + } } } } diff --git a/src/qml/main.qml b/src/qml/main.qml index 583a2f8c8..c7e88cbde 100644 --- a/src/qml/main.qml +++ b/src/qml/main.qml @@ -323,6 +323,11 @@ Kirigami.ApplicationWindow { CreateRoomDialog {} } + Component { + id: createSpaceDialog + CreateSpaceDialog {} + } + Component { id: roomWindow RoomWindow {} diff --git a/src/res.qrc b/src/res.qrc index 72e6484df..95d291adb 100644 --- a/src/res.qrc +++ b/src/res.qrc @@ -76,6 +76,7 @@ qml/Panel/GroupChatDrawerHeader.qml qml/Dialog/UserDetailDialog.qml qml/Dialog/CreateRoomDialog.qml + qml/Dialog/CreateSpaceDialog.qml qml/Dialog/EmojiDialog.qml qml/Dialog/OpenFileDialog.qml qml/Dialog/KeyVerification/KeyVerificationDialog.qml