From e7040a518abcfa7336acdcb00382207803e601c9 Mon Sep 17 00:00:00 2001 From: James Graham Date: Sat, 17 May 2025 14:27:38 +0100 Subject: [PATCH] Create a new module for the room info drawer QML. Create a new module for the room info drawer QML. This also requires moving some QML to LibNeoChat common with other modules. Finally all QML in roominfo is modifed to not depend on app. --- src/CMakeLists.txt | 1 + src/app/CMakeLists.txt | 16 ++------- src/app/qml/FullScreenMap.qml | 2 ++ src/app/qml/Main.qml | 19 +++++++++-- src/libneochat/CMakeLists.txt | 5 +++ .../models/userfiltermodel.cpp | 0 .../models/userfiltermodel.h | 0 .../qml/GroupChatDrawerHeader.qml | 0 .../qml/LocationMapItem.qml | 0 src/{app => libneochat}/qml/SearchPage.qml | 0 src/roominfo/CMakeLists.txt | 17 ++++++++++ .../DirectChatDrawerHeader.qml | 6 ++-- src/{app/qml => roominfo}/LocationsPage.qml | 5 +-- src/{app/qml => roominfo}/RoomDrawer.qml | 33 +++++++++++-------- src/{app/qml => roominfo}/RoomDrawerPage.qml | 17 +++++++--- src/{app/qml => roominfo}/RoomInformation.qml | 12 ++++--- src/{app/qml => roominfo}/RoomMedia.qml | 22 ++++++------- .../RoomPinnedMessagesPage.qml | 2 +- src/{app/qml => roominfo}/RoomSearchPage.qml | 2 +- 19 files changed, 104 insertions(+), 55 deletions(-) rename src/{app => libneochat}/models/userfiltermodel.cpp (100%) rename src/{app => libneochat}/models/userfiltermodel.h (100%) rename src/{app => libneochat}/qml/GroupChatDrawerHeader.qml (100%) rename src/{app => libneochat}/qml/LocationMapItem.qml (100%) rename src/{app => libneochat}/qml/SearchPage.qml (100%) create mode 100644 src/roominfo/CMakeLists.txt rename src/{app/qml => roominfo}/DirectChatDrawerHeader.qml (93%) rename src/{app/qml => roominfo}/LocationsPage.qml (96%) rename src/{app/qml => roominfo}/RoomDrawer.qml (82%) rename src/{app/qml => roominfo}/RoomDrawerPage.qml (83%) rename src/{app/qml => roominfo}/RoomInformation.qml (96%) rename src/{app/qml => roominfo}/RoomMedia.qml (73%) rename src/{app/qml => roominfo}/RoomPinnedMessagesPage.qml (97%) rename src/{app/qml => roominfo}/RoomSearchPage.qml (96%) diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index b278acc9e..458e8f585 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -8,6 +8,7 @@ endif() add_subdirectory(libneochat) add_subdirectory(login) add_subdirectory(rooms) +add_subdirectory(roominfo) add_subdirectory(timeline) add_subdirectory(spaces) add_subdirectory(chatbar) diff --git a/src/app/CMakeLists.txt b/src/app/CMakeLists.txt index 3b8e0458f..1ec05c2c3 100644 --- a/src/app/CMakeLists.txt +++ b/src/app/CMakeLists.txt @@ -8,8 +8,6 @@ add_library(neochat STATIC controller.h roommanager.cpp roommanager.h - models/userfiltermodel.cpp - models/userfiltermodel.h models/userdirectorylistmodel.cpp models/userdirectorylistmodel.h notificationsmanager.cpp @@ -79,26 +77,15 @@ ecm_add_qml_module(neochat URI org.kde.neochat GENERATE_PLUGIN_SOURCE qml/EmojiSas.qml qml/VerificationCanceled.qml qml/MessageSourceSheet.qml - qml/RoomSearchPage.qml - qml/RoomPinnedMessagesPage.qml qml/LocationChooser.qml qml/InvitationView.qml qml/AvatarTabButton.qml qml/OsmLocationPlugin.qml qml/FullScreenMap.qml - qml/LocationsPage.qml - qml/LocationMapItem.qml - qml/RoomDrawer.qml - qml/RoomDrawerPage.qml - qml/DirectChatDrawerHeader.qml - qml/GroupChatDrawerHeader.qml - qml/RoomInformation.qml - qml/RoomMedia.qml qml/ChooseRoomDialog.qml qml/RemoveChildDialog.qml qml/QrCodeMaximizeComponent.qml qml/NotificationsView.qml - qml/SearchPage.qml qml/ServerComboBox.qml qml/UserSearchPage.qml qml/ManualUserDialog.qml @@ -124,6 +111,7 @@ ecm_add_qml_module(neochat URI org.kde.neochat GENERATE_PLUGIN_SOURCE IMPORTS org.kde.neochat.libneochat org.kde.neochat.rooms + org.kde.neochat.roominfo org.kde.neochat.timeline org.kde.neochat.spaces org.kde.neochat.settings @@ -189,7 +177,7 @@ else() endif() target_include_directories(neochat PRIVATE ${CMAKE_BINARY_DIR} ${CMAKE_CURRENT_SOURCE_DIR}/models) -target_link_libraries(neochat PRIVATE Loginplugin Roomsplugin Timelineplugin Spacesplugin Chatbarplugin Settingsplugin Devtoolsplugin) +target_link_libraries(neochat PRIVATE Loginplugin Roomsplugin RoomInfoplugin Timelineplugin Spacesplugin Chatbarplugin Settingsplugin Devtoolsplugin) target_link_libraries(neochat PUBLIC LibNeoChat Timeline diff --git a/src/app/qml/FullScreenMap.qml b/src/app/qml/FullScreenMap.qml index 9bb4e2c4b..0d2d9d566 100644 --- a/src/app/qml/FullScreenMap.qml +++ b/src/app/qml/FullScreenMap.qml @@ -8,6 +8,8 @@ import QtPositioning import org.kde.kirigami as Kirigami +import org.kde.neochat.libneochat + ApplicationWindow { id: root diff --git a/src/app/qml/Main.qml b/src/app/qml/Main.qml index e2e1b4bec..5bb879d02 100644 --- a/src/app/qml/Main.qml +++ b/src/app/qml/Main.qml @@ -149,9 +149,13 @@ Kirigami.ApplicationWindow { } function openRoomDrawer() { - pageStack.push(Qt.createComponent('org.kde.neochat', 'RoomDrawerPage'), { - connection: root.connection + const page = pageStack.push(Qt.createComponent('org.kde.neochat', 'RoomDrawerPage'), { + connection: root.connection, + room: RoomManager.currentRoom, + userListModel: RoomManager.userListModel, + mediaMessageFilterModel: RoomManager.mediaMessageFilterModel }); + page.resolveResource.connect((idOrUri, action) => RoomManager.resolveResource(idOrUri, action)) } contextDrawer: RoomDrawer { @@ -161,7 +165,18 @@ Kirigami.ApplicationWindow { // It is used to ensure that user choice is remembered when changing pages and expanding and contracting the window width property bool drawerUserState: NeoChatConfig.autoRoomInfoDrawer + room: RoomManager.currentRoom connection: root.connection + userListModel: RoomManager.userListModel + mediaMessageFilterModel: RoomManager.mediaMessageFilterModel + + onResolveResource: (idOrUri, action) => RoomManager.resolveResource(idOrUri, action) + + roomDrawerWidth: NeoChatConfig.roomDrawerWidth + onRoomDrawerWidthChanged: { + NeoChatConfig.roomDrawerWidth = actualWidth; + NeoChatConfig.save(); + } handleClosedIcon.source: "documentinfo-symbolic" handleClosedToolTip: i18nc("@action:button", "Show Room Information") diff --git a/src/libneochat/CMakeLists.txt b/src/libneochat/CMakeLists.txt index 0eee2f6c7..faac80c4f 100644 --- a/src/libneochat/CMakeLists.txt +++ b/src/libneochat/CMakeLists.txt @@ -41,12 +41,17 @@ target_sources(LibNeoChat PRIVATE models/locationsmodel.cpp models/roomlistmodel.cpp models/stickermodel.cpp + models/userfiltermodel.cpp models/userlistmodel.cpp ) ecm_add_qml_module(LibNeoChat GENERATE_PLUGIN_SOURCE URI org.kde.neochat.libneochat OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/src/org/kde/neochat/libneochat + QML_FILES + qml/GroupChatDrawerHeader.qml + qml/LocationMapItem.qml + qml/SearchPage.qml ) ecm_qt_declare_logging_category(LibNeoChat diff --git a/src/app/models/userfiltermodel.cpp b/src/libneochat/models/userfiltermodel.cpp similarity index 100% rename from src/app/models/userfiltermodel.cpp rename to src/libneochat/models/userfiltermodel.cpp diff --git a/src/app/models/userfiltermodel.h b/src/libneochat/models/userfiltermodel.h similarity index 100% rename from src/app/models/userfiltermodel.h rename to src/libneochat/models/userfiltermodel.h diff --git a/src/app/qml/GroupChatDrawerHeader.qml b/src/libneochat/qml/GroupChatDrawerHeader.qml similarity index 100% rename from src/app/qml/GroupChatDrawerHeader.qml rename to src/libneochat/qml/GroupChatDrawerHeader.qml diff --git a/src/app/qml/LocationMapItem.qml b/src/libneochat/qml/LocationMapItem.qml similarity index 100% rename from src/app/qml/LocationMapItem.qml rename to src/libneochat/qml/LocationMapItem.qml diff --git a/src/app/qml/SearchPage.qml b/src/libneochat/qml/SearchPage.qml similarity index 100% rename from src/app/qml/SearchPage.qml rename to src/libneochat/qml/SearchPage.qml diff --git a/src/roominfo/CMakeLists.txt b/src/roominfo/CMakeLists.txt new file mode 100644 index 000000000..1bba1d72f --- /dev/null +++ b/src/roominfo/CMakeLists.txt @@ -0,0 +1,17 @@ +# SPDX-FileCopyrightText: 2025 James Graham +# SPDX-License-Identifier: BSD-2-Clause + +qt_add_library(RoomInfo STATIC) +ecm_add_qml_module(RoomInfo GENERATE_PLUGIN_SOURCE + URI org.kde.neochat.roominfo + OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/src/org/kde/neochat/roominfo + QML_FILES + RoomDrawer.qml + RoomDrawerPage.qml + RoomInformation.qml + RoomMedia.qml + DirectChatDrawerHeader.qml + LocationsPage.qml + RoomPinnedMessagesPage.qml + RoomSearchPage.qml +) diff --git a/src/app/qml/DirectChatDrawerHeader.qml b/src/roominfo/DirectChatDrawerHeader.qml similarity index 93% rename from src/app/qml/DirectChatDrawerHeader.qml rename to src/roominfo/DirectChatDrawerHeader.qml index 9c433d130..296efe260 100644 --- a/src/app/qml/DirectChatDrawerHeader.qml +++ b/src/roominfo/DirectChatDrawerHeader.qml @@ -8,7 +8,7 @@ import QtQuick.Layouts import org.kde.kirigami as Kirigami import org.kde.kirigamiaddons.labs.components as KirigamiComponents -import org.kde.neochat +import org.kde.neochat.libneochat ColumnLayout { id: root @@ -18,6 +18,8 @@ ColumnLayout { */ required property NeoChatRoom room + signal resolveResource(string idOrUri, string action) + Layout.fillWidth: true Layout.alignment: Qt.AlignVCenter spacing: 0 @@ -33,7 +35,7 @@ ColumnLayout { Layout.alignment: Qt.AlignHCenter onClicked: { - RoomManager.resolveResource(root.room.directChatRemoteMember.uri) + root.resolveResource(root.room.directChatRemoteMember.uri, "") } contentItem: KirigamiComponents.Avatar { diff --git a/src/app/qml/LocationsPage.qml b/src/roominfo/LocationsPage.qml similarity index 96% rename from src/app/qml/LocationsPage.qml rename to src/roominfo/LocationsPage.qml index 7eb1f70dc..149aeaf56 100644 --- a/src/app/qml/LocationsPage.qml +++ b/src/roominfo/LocationsPage.qml @@ -6,12 +6,13 @@ import QtLocation import QtPositioning import org.kde.kirigami as Kirigami -import org.kde.neochat + +import org.kde.neochat.libneochat Kirigami.Page { id: root - required property var room + required property NeoChatRoom room title: i18nc("Locations on a map", "Locations") diff --git a/src/app/qml/RoomDrawer.qml b/src/roominfo/RoomDrawer.qml similarity index 82% rename from src/app/qml/RoomDrawer.qml rename to src/roominfo/RoomDrawer.qml index f2125aae6..a3fda6095 100644 --- a/src/app/qml/RoomDrawer.qml +++ b/src/roominfo/RoomDrawer.qml @@ -9,14 +9,19 @@ import QtQuick.Layouts import org.kde.kirigami as Kirigami import org.kde.kitemmodels -import org.kde.neochat -import org.kde.neochat.settings +import org.kde.neochat.libneochat +import org.kde.neochat.timeline as Timeline +import org.kde.neochat.settings as Settings Kirigami.OverlayDrawer { id: root - readonly property NeoChatRoom room: RoomManager.currentRoom + required property NeoChatRoom room required property NeoChatConnection connection + required property UserListModel userListModel + required property Timeline.MediaMessageFilterModel mediaMessageFilterModel + + signal resolveResource(string idOrUri, string action) width: actualWidth interactive: modal @@ -24,11 +29,12 @@ Kirigami.OverlayDrawer { readonly property int minWidth: Kirigami.Units.gridUnit * 15 readonly property int maxWidth: Kirigami.Units.gridUnit * 25 readonly property int defaultWidth: Kirigami.Units.gridUnit * 20 + property int roomDrawerWidth property int actualWidth: { - if (NeoChatConfig.roomDrawerWidth === -1) { + if (root.roomDrawerWidth === -1) { return Kirigami.Units.gridUnit * 20; } else { - return NeoChatConfig.roomDrawerWidth; + return root.roomDrawerWidth; } } @@ -46,8 +52,7 @@ Kirigami.OverlayDrawer { visible: true onPressed: _lastX = mapToGlobal(mouseX, mouseY).x onReleased: { - NeoChatConfig.roomDrawerWidth = root.actualWidth; - NeoChatConfig.save(); + root.roomDrawerWidth = root.actualWidth; } property real _lastX: -1 @@ -56,9 +61,9 @@ Kirigami.OverlayDrawer { return; } if (Qt.application.layoutDirection === Qt.RightToLeft) { - root.actualWidth = Math.min(root.maxWidth, Math.max(root.minWidth, NeoChatConfig.roomDrawerWidth - _lastX + mapToGlobal(mouseX, mouseY).x)); + root.actualWidth = Math.min(root.maxWidth, Math.max(root.minWidth, root.roomDrawerWidth - _lastX + mapToGlobal(mouseX, mouseY).x)); } else { - root.actualWidth = Math.min(root.maxWidth, Math.max(root.minWidth, NeoChatConfig.roomDrawerWidth + _lastX - mapToGlobal(mouseX, mouseY).x)); + root.actualWidth = Math.min(root.maxWidth, Math.max(root.minWidth, root.roomDrawerWidth + _lastX - mapToGlobal(mouseX, mouseY).x)); } } } @@ -121,7 +126,7 @@ Kirigami.OverlayDrawer { QQC2.ToolTip.visible: hovered onClicked: { - RoomSettingsView.openRoomSettings(root.room, RoomSettingsView.Room); + Settings.RoomSettingsView.openRoomSettings(root.room, Settings.RoomSettingsView.Room); } } } @@ -138,15 +143,17 @@ Kirigami.OverlayDrawer { id: roomInformation RoomInformation { room: root.room - connection: root.connection + userListModel: root.userListModel + + onResolveResource: (idOrUri, action) => root.resolveResource(idOrUri, action) } } Component { id: roomMedia RoomMedia { - currentRoom: root.room - connection: root.connection + room: root.room + mediaMessageFilterModel: root.mediaMessageFilterModel } } diff --git a/src/app/qml/RoomDrawerPage.qml b/src/roominfo/RoomDrawerPage.qml similarity index 83% rename from src/app/qml/RoomDrawerPage.qml rename to src/roominfo/RoomDrawerPage.qml index 2cb267979..fff50b785 100644 --- a/src/app/qml/RoomDrawerPage.qml +++ b/src/roominfo/RoomDrawerPage.qml @@ -7,7 +7,8 @@ import QtQuick.Layouts import org.kde.kirigami as Kirigami import org.kde.kitemmodels -import org.kde.neochat +import org.kde.neochat.libneochat +import org.kde.neochat.timeline as Timeline /** * @brief Page for holding a room drawer component. @@ -24,8 +25,12 @@ Kirigami.Page { /** * @brief The current room that user is viewing. */ - readonly property NeoChatRoom room: RoomManager.currentRoom + required property NeoChatRoom room required property NeoChatConnection connection + required property UserListModel userListModel + required property Timeline.MediaMessageFilterModel mediaMessageFilterModel + + signal resolveResource(string idOrUri, string action) title: drawerItemLoader.item ? drawerItemLoader.item.title : "" @@ -61,15 +66,17 @@ Kirigami.Page { id: roomInformation RoomInformation { room: root.room - connection: root.connection + userListModel: root.userListModel + + onResolveResource: (idOrUri, action) => root.resolveResource(idOrUri, action) } } Component { id: roomMedia RoomMedia { - currentRoom: root.room - connection: root.connection + room: root.room + mediaMessageFilterModel: root.mediaMessageFilterModel } } diff --git a/src/app/qml/RoomInformation.qml b/src/roominfo/RoomInformation.qml similarity index 96% rename from src/app/qml/RoomInformation.qml rename to src/roominfo/RoomInformation.qml index 52ffa9301..cfccf0edf 100644 --- a/src/app/qml/RoomInformation.qml +++ b/src/roominfo/RoomInformation.qml @@ -12,7 +12,7 @@ import org.kde.kirigamiaddons.delegates as Delegates import org.kde.kirigamiaddons.labs.components as KirigamiComponents import org.kde.kitemmodels -import org.kde.neochat +import org.kde.neochat.libneochat /** * @brief Component for visualising the room information. @@ -34,13 +34,15 @@ QQC2.ScrollView { */ required property NeoChatRoom room - required property NeoChatConnection connection + required property UserListModel userListModel /** * @brief The title that should be displayed for this component if available. */ readonly property string title: root.room.isSpace ? i18nc("@action:title", "Space Members") : i18nc("@action:title", "Room Information") + signal resolveResource(string idOrUri, string action) + // HACK: Hide unnecessary horizontal scrollbar (https://bugreports.qt.io/browse/QTBUG-83890) QQC2.ScrollBar.horizontal.policy: QQC2.ScrollBar.AlwaysOff @@ -216,7 +218,7 @@ QQC2.ScrollView { UserFilterModel { id: userFilterModel - sourceModel: RoomManager.userListModel + sourceModel: root.userListModel allowEmpty: true } @@ -249,7 +251,7 @@ QQC2.ScrollView { KeyNavigation.backtab: index === 0 ? userList.headerItem.userListSearchField : null onClicked: { - RoomManager.resolveResource(userDelegate.userId, "mention"); + root.resolveResource(userDelegate.userId, "mention"); } contentItem: RowLayout { @@ -286,6 +288,8 @@ QQC2.ScrollView { id: directChatDrawerHeader DirectChatDrawerHeader { room: root.room + + onResolveResource: (idOrUri, action) => root.resolveResource(idOrUri, action) } } diff --git a/src/app/qml/RoomMedia.qml b/src/roominfo/RoomMedia.qml similarity index 73% rename from src/app/qml/RoomMedia.qml rename to src/roominfo/RoomMedia.qml index f12ea6742..967d281c5 100644 --- a/src/app/qml/RoomMedia.qml +++ b/src/roominfo/RoomMedia.qml @@ -6,8 +6,8 @@ import QtQuick.Controls as QQC2 import QtQuick.Layouts import Qt.labs.qmlmodels -import org.kde.neochat -import org.kde.neochat.timeline +import org.kde.neochat.libneochat +import org.kde.neochat.timeline as Timeline /** * @brief Component for visualising the loaded media items in the room. @@ -31,9 +31,9 @@ QQC2.ScrollView { /** * @brief The current room that user is viewing. */ - required property NeoChatRoom currentRoom + required property NeoChatRoom room - required property NeoChatConnection connection + required property Timeline.MediaMessageFilterModel mediaMessageFilterModel // HACK: Hide unnecessary horizontal scrollbar (https://bugreports.qt.io/browse/QTBUG-83890) QQC2.ScrollBar.horizontal.policy: QQC2.ScrollBar.AlwaysOff @@ -42,26 +42,26 @@ QQC2.ScrollView { clip: true verticalLayoutDirection: ListView.BottomToTop - model: RoomManager.mediaMessageFilterModel + model: root.mediaMessageFilterModel delegate: DelegateChooser { role: "type" DelegateChoice { - roleValue: MediaMessageFilterModel.Image - delegate: MessageDelegate { + roleValue: Timeline.MediaMessageFilterModel.Image + delegate: Timeline.MessageDelegate { alwaysFillWidth: true cardBackground: false - room: root.currentRoom + room: root.room } } DelegateChoice { - roleValue: MediaMessageFilterModel.Video - delegate: MessageDelegate { + roleValue: Timeline.MediaMessageFilterModel.Video + delegate: Timeline.MessageDelegate { alwaysFillWidth: true cardBackground: false - room: root.currentRoom + room: root.room } } } diff --git a/src/app/qml/RoomPinnedMessagesPage.qml b/src/roominfo/RoomPinnedMessagesPage.qml similarity index 97% rename from src/app/qml/RoomPinnedMessagesPage.qml rename to src/roominfo/RoomPinnedMessagesPage.qml index feeee66d3..b4c6c01d6 100644 --- a/src/app/qml/RoomPinnedMessagesPage.qml +++ b/src/roominfo/RoomPinnedMessagesPage.qml @@ -6,7 +6,7 @@ import QtQuick.Layouts import org.kde.kirigami as Kirigami -import org.kde.neochat +import org.kde.neochat.libneochat import org.kde.neochat.timeline /** diff --git a/src/app/qml/RoomSearchPage.qml b/src/roominfo/RoomSearchPage.qml similarity index 96% rename from src/app/qml/RoomSearchPage.qml rename to src/roominfo/RoomSearchPage.qml index 24abc3b08..384baaa9d 100644 --- a/src/app/qml/RoomSearchPage.qml +++ b/src/roominfo/RoomSearchPage.qml @@ -3,7 +3,7 @@ import QtQuick -import org.kde.neochat +import org.kde.neochat.libneochat import org.kde.neochat.timeline /**