From ff0990bb7c870b12ff5de2391fae6cc4fce202ff Mon Sep 17 00:00:00 2001 From: James Graham Date: Mon, 11 Sep 2023 17:16:12 +0000 Subject: [PATCH] Emit Room Selected from JoinRoomPage Change the `JoinRoomPage` so that it emits a `roomSelected` signal with the selected delegate's info instead of calling the functions to join or enter the room itself. This is so that the `JoinRoomPage` can be used for other purposes like selecting an existing child to add to a space. --- src/qml/Menu/GlobalMenu.qml | 11 ++++++++- src/qml/Page/ExplorerDelegate.qml | 27 +++++++++++++++++----- src/qml/Page/JoinRoomPage.qml | 20 +++++++++++++++- src/qml/Page/RoomList/ExploreComponent.qml | 9 +++++++- src/qml/Page/RoomList/Page.qml | 19 +++++++++++---- 5 files changed, 73 insertions(+), 13 deletions(-) diff --git a/src/qml/Menu/GlobalMenu.qml b/src/qml/Menu/GlobalMenu.qml index f0fe6a5da..e46cf8a8b 100644 --- a/src/qml/Menu/GlobalMenu.qml +++ b/src/qml/Menu/GlobalMenu.qml @@ -54,7 +54,16 @@ Labs.MenuBar { } Labs.MenuItem { text: i18nc("menu", "Browse Chats…") - onTriggered: pushReplaceLayer("qrc:/JoinRoomPage.qml", {connection: Controller.activeConnection}) + onTriggered: { + let dialog = pageStack.pushDialogLayer("qrc:/JoinRoomPage.qml", {connection: Controller.activeConnection}, {title: i18nc("@title", "Explore Rooms")}) + dialog.roomSelected.connect((roomId, displayName, avatarUrl, alias, topic, memberCount, isJoined) => { + if (isJoined) { + RoomManager.enterRoom(Controller.activeConnection.room(roomId)) + } else { + Controller.joinRoom(roomId) + } + }) + } } } EditMenu { diff --git a/src/qml/Page/ExplorerDelegate.qml b/src/qml/Page/ExplorerDelegate.qml index 7c1f4717e..34a31b179 100644 --- a/src/qml/Page/ExplorerDelegate.qml +++ b/src/qml/Page/ExplorerDelegate.qml @@ -14,7 +14,6 @@ import org.kde.neochat 1.0 Delegates.RoundedItemDelegate { id: root - required property NeoChatConnection connection required property string roomId required property string displayName required property url avatarUrl @@ -24,16 +23,32 @@ Delegates.RoundedItemDelegate { required property bool isJoined property bool justJoined: false - signal roomSelected() + /** + * @brief Signal emitted when a room delegate is selected. + * + * The signal contains all the delegate's model info so that it can be acted + * upon as required, e.g. joining or entering the room or adding the room as + * the child of a space. + */ + signal roomSelected(string roomId, + string displayName, + url avatarUrl, + string alias, + string topic, + int memberCount, + bool isJoined) onClicked: { if (!isJoined) { - Controller.joinRoom(root.roomId) justJoined = true; - } else { - RoomManager.enterRoom(root.connection.room(root.roomId)) } - root.roomSelected() + root.roomSelected(root.roomId, + root.displayName, + root.avatarUrl, + root.alias, + root.topic, + root.memberCount, + root.isJoined) } contentItem: RowLayout { diff --git a/src/qml/Page/JoinRoomPage.qml b/src/qml/Page/JoinRoomPage.qml index c5ee4ec25..f8b3086dd 100644 --- a/src/qml/Page/JoinRoomPage.qml +++ b/src/qml/Page/JoinRoomPage.qml @@ -20,6 +20,21 @@ Kirigami.ScrollablePage { property alias keyword: identifierField.text property string server + /** + * @brief Signal emitted when a room is selected. + * + * The signal contains all the room's info so that it can be acted + * upon as required, e.g. joinng or entering the room or adding the room as + * the child of a space. + */ + signal roomSelected(string roomId, + string displayName, + url avatarUrl, + string alias, + string topic, + int memberCount, + bool isJoined) + title: i18n("Explore Rooms") Component.onCompleted: identifierField.forceActiveFocus() @@ -211,7 +226,10 @@ Kirigami.ScrollablePage { } delegate: ExplorerDelegate { connection: root.connection - onRoomSelected: root.closeDialog() + onRoomSelected: (roomId, displayName, avatarUrl, alias, topic, memberCount, isJoined) => { + root.roomSelected(roomId, displayName, avatarUrl, alias, topic, memberCount, isJoined); + root.closeDialog(); + } } footer: RowLayout { diff --git a/src/qml/Page/RoomList/ExploreComponent.qml b/src/qml/Page/RoomList/ExploreComponent.qml index 3e7fb3144..abf7593e0 100644 --- a/src/qml/Page/RoomList/ExploreComponent.qml +++ b/src/qml/Page/RoomList/ExploreComponent.qml @@ -19,7 +19,14 @@ RowLayout { text: i18n("Explore rooms") icon.name: "compass" onTriggered: { - pageStack.pushDialogLayer("qrc:/JoinRoomPage.qml", {connection: Controller.activeConnection}, {title: i18nc("@title", "Explore Rooms")}) + let dialog = pageStack.pushDialogLayer("qrc:/JoinRoomPage.qml", {connection: Controller.activeConnection}, {title: i18nc("@title", "Explore Rooms")}) + dialog.roomSelected.connect((roomId, displayName, avatarUrl, alias, topic, memberCount, isJoined) => { + if (isJoined) { + RoomManager.enterRoom(Controller.activeConnection.room(roomId)) + } else { + Controller.joinRoom(roomId) + } + }) } } property Kirigami.Action chatAction: Kirigami.Action { diff --git a/src/qml/Page/RoomList/Page.qml b/src/qml/Page/RoomList/Page.qml index 57c92bedf..627277006 100644 --- a/src/qml/Page/RoomList/Page.qml +++ b/src/qml/Page/RoomList/Page.qml @@ -153,10 +153,21 @@ Kirigami.Page { helpfulAction: Kirigami.Action { icon.name: sortFilterRoomListModel.filterText.length > 0 ? "search" : "list-add" text: sortFilterRoomListModel.filterText.length > 0 ? i18n("Search in room directory") : i18n("Explore rooms") - onTriggered: pageStack.layers.push("qrc:/JoinRoomPage.qml", { - connection: Controller.activeConnection, - keyword: sortFilterRoomListModel.filterText - }) + onTriggered: { + let dialog = pageStack.layers.push("qrc:/JoinRoomPage.qml", { + connection: Controller.activeConnection, + keyword: sortFilterRoomListModel.filterText + }, { + title: i18nc("@title", "Explore Rooms") + }) + dialog.roomSelected.connect((roomId, displayName, avatarUrl, alias, topic, memberCount, isJoined) => { + if (isJoined) { + RoomManager.enterRoom(Controller.activeConnection.room(roomId)) + } else { + Controller.joinRoom(roomId) + } + }) + } } }