Warning, /network/neochat/src/qml/RoomInformation.qml is written in an unsupported language. File is not indexed.

0001 // SPDX-FileCopyrightText: 2023 James Graham <james.h.graham@protonmail.com>
0002 // SPDX-License-Identifier: GPL-2.0-only OR GPL-3.0-only OR LicenseRef-KDE-Accepted-GPL
0003 
0004 import QtQuick
0005 import QtQuick.Controls as QQC2
0006 import QtQuick.Layouts
0007 
0008 import org.kde.kirigami as Kirigami
0009 import org.kde.kirigamiaddons.delegates as Delegates
0010 import org.kde.kirigamiaddons.labs.components as KirigamiComponents
0011 import org.kde.kitemmodels
0012 
0013 import org.kde.neochat
0014 import org.kde.neochat.config
0015 
0016 /**
0017  * @brief Component for visualising the room information.
0018  *
0019  * The component has a header section which changes between group rooms and direct
0020  * chats with information like the avatar and topic. Followed by the allowed actions
0021  * and finally a user list.
0022  *
0023  * @note This component is only the contents, it will need to be placed in either
0024  *       a drawer (desktop) or page (mobile) to be used.
0025  *
0026  * @sa RoomDrawer, RoomDrawerPage
0027  */
0028 QQC2.ScrollView {
0029     id: root
0030 
0031     /**
0032      * @brief The current room that user is viewing.
0033      */
0034     required property NeoChatRoom room
0035 
0036     required property NeoChatConnection connection
0037 
0038     /**
0039      * @brief The title that should be displayed for this component if available.
0040      */
0041     readonly property string title: root.room.isSpace ? i18nc("@action:title", "Space Members") : i18nc("@action:title", "Room information")
0042 
0043     // HACK: Hide unnecessary horizontal scrollbar (https://bugreports.qt.io/browse/QTBUG-83890)
0044     QQC2.ScrollBar.horizontal.policy: QQC2.ScrollBar.AlwaysOff
0045 
0046     ListView {
0047         id: userList
0048         header: ColumnLayout {
0049             id: columnLayout
0050 
0051             property alias userListSearchField: userListSearchField
0052 
0053             spacing: 0
0054             width: ListView.view ? ListView.view.width - ListView.view.leftMargin - ListView.view.rightMargin : 0
0055 
0056             Loader {
0057                 active: true
0058                 Layout.fillWidth: true
0059                 Layout.topMargin: Kirigami.Units.smallSpacing
0060                 visible: !root.room.isSpace
0061                 sourceComponent: root.room.isDirectChat() ? directChatDrawerHeader : groupChatDrawerHeader
0062                 onItemChanged: if (item) {
0063                     userList.positionViewAtBeginning();
0064                 }
0065             }
0066 
0067             Kirigami.ListSectionHeader {
0068                 visible: !root.room.isSpace
0069                 label: i18n("Options")
0070                 activeFocusOnTab: false
0071 
0072                 Layout.fillWidth: true
0073             }
0074 
0075             Delegates.RoundedItemDelegate {
0076                 id: devtoolsButton
0077 
0078                 icon.name: "tools"
0079                 text: i18n("Open developer tools")
0080                 visible: Config.developerTools && !root.room.isSpace
0081 
0082                 Layout.fillWidth: true
0083 
0084                 onClicked: {
0085                     applicationWindow().pageStack.pushDialogLayer("qrc:/org/kde/neochat/qml/DevtoolsPage.qml", {
0086                         room: root.room,
0087                         connection: root.connection
0088                     }, {
0089                         title: i18n("Developer Tools")
0090                     });
0091                 }
0092             }
0093 
0094             Delegates.RoundedItemDelegate {
0095                 id: searchButton
0096                 visible: !root.room.isSpace
0097                 icon.name: "search"
0098                 text: i18n("Search in this room")
0099 
0100                 Layout.fillWidth: true
0101 
0102                 onClicked: {
0103                     pageStack.pushDialogLayer("qrc:/org/kde/neochat/qml/RoomSearchPage.qml", {
0104                         room: root.room
0105                     }, {
0106                         title: i18nc("@action:title", "Search")
0107                     });
0108                 }
0109             }
0110 
0111             Delegates.RoundedItemDelegate {
0112                 id: favouriteButton
0113                 visible: !root.room.isSpace
0114                 icon.name: root.room && root.room.isFavourite ? "rating" : "rating-unrated"
0115                 text: root.room && root.room.isFavourite ? i18n("Remove room from favorites") : i18n("Make room favorite")
0116 
0117                 onClicked: root.room.isFavourite ? root.room.removeTag("m.favourite") : root.room.addTag("m.favourite", 1.0)
0118 
0119                 Layout.fillWidth: true
0120             }
0121 
0122             Delegates.RoundedItemDelegate {
0123                 id: locationsButton
0124                 visible: !root.room.isSpace
0125                 icon.name: "map-flat"
0126                 text: i18n("Show locations for this room")
0127 
0128                 onClicked: pageStack.pushDialogLayer("qrc:/org/kde/neochat/qml/LocationsPage.qml", {
0129                     room: root.room
0130                 }, {
0131                     title: i18nc("Locations on a map", "Locations")
0132                 })
0133 
0134                 Layout.fillWidth: true
0135             }
0136 
0137             Kirigami.ListSectionHeader {
0138                 label: i18n("Members")
0139                 activeFocusOnTab: false
0140                 spacing: 0
0141                 visible: !root.room.isDirectChat()
0142 
0143                 Layout.fillWidth: true
0144 
0145                 QQC2.ToolButton {
0146                     visible: root.room.canSendState("invite")
0147                     icon.name: "list-add-user"
0148 
0149                     onClicked: {
0150                         applicationWindow().pageStack.pushDialogLayer("qrc:/org/kde/neochat/qml/InviteUserPage.qml", {
0151                             room: root.room
0152                         }, {
0153                             title: i18nc("@title", "Invite a User")
0154                         });
0155                     }
0156 
0157                     QQC2.ToolTip.text: i18n("Invite user to room")
0158                     QQC2.ToolTip.visible: hovered
0159                     QQC2.ToolTip.delay: Kirigami.Units.toolTipDelay
0160                 }
0161 
0162                 QQC2.Label {
0163                     Layout.alignment: Qt.AlignRight
0164                     text: root.room ? i18np("%1 member", "%1 members", root.room.joinedCount) : i18n("No member count")
0165                 }
0166             }
0167 
0168             Kirigami.SearchField {
0169                 id: userListSearchField
0170 
0171                 visible: !root.room.isDirectChat()
0172                 onVisibleChanged: if (visible) {
0173                     forceActiveFocus();
0174                 }
0175                 Layout.fillWidth: true
0176                 Layout.leftMargin: Kirigami.Units.largeSpacing
0177                 Layout.rightMargin: Kirigami.Units.largeSpacing
0178                 Layout.bottomMargin: Kirigami.Units.smallSpacing
0179 
0180                 focusSequence: "Ctrl+Shift+F"
0181 
0182                 onAccepted: sortedMessageEventModel.filterString = text
0183             }
0184         }
0185 
0186         KSortFilterProxyModel {
0187             id: sortedMessageEventModel
0188 
0189             sourceModel: UserListModel {
0190                 room: root.room
0191             }
0192 
0193             sortRoleName: "powerLevel"
0194             sortOrder: Qt.DescendingOrder
0195             filterRoleName: "name"
0196             filterCaseSensitivity: Qt.CaseInsensitive
0197         }
0198 
0199         model: root.room.isDirectChat() ? 0 : sortedMessageEventModel
0200 
0201         clip: true
0202         activeFocusOnTab: true
0203 
0204         delegate: Delegates.RoundedItemDelegate {
0205             id: userDelegate
0206 
0207             required property string name
0208             required property string userId
0209             required property string avatar
0210             required property int powerLevel
0211             required property string powerLevelString
0212 
0213             implicitHeight: Kirigami.Units.gridUnit * 2
0214 
0215             text: name
0216 
0217             onClicked: {
0218                 userDelegate.highlighted = true;
0219                 RoomManager.resolveResource(userDelegate.userId, "mention");
0220             }
0221 
0222             contentItem: RowLayout {
0223                 KirigamiComponents.Avatar {
0224                     implicitWidth: height
0225                     sourceSize {
0226                         height: Kirigami.Units.gridUnit + Kirigami.Units.smallSpacing * 2.5
0227                         width: Kirigami.Units.gridUnit + Kirigami.Units.smallSpacing * 2.5
0228                     }
0229                     source: userDelegate.avatar
0230                     name: userDelegate.userId
0231 
0232                     Layout.fillHeight: true
0233                 }
0234 
0235                 QQC2.Label {
0236                     text: userDelegate.name
0237                     textFormat: Text.PlainText
0238                     elide: Text.ElideRight
0239 
0240                     Layout.fillWidth: true
0241                 }
0242 
0243                 QQC2.Label {
0244                     visible: userDelegate.powerLevel > 0
0245 
0246                     text: userDelegate.powerLevelString
0247                     color: Kirigami.Theme.disabledTextColor
0248                     textFormat: Text.PlainText
0249                 }
0250             }
0251         }
0252     }
0253 
0254     Component {
0255         id: groupChatDrawerHeader
0256         GroupChatDrawerHeader {
0257             room: root.room
0258         }
0259     }
0260 
0261     Component {
0262         id: directChatDrawerHeader
0263         DirectChatDrawerHeader {
0264             room: root.room
0265         }
0266     }
0267 
0268     onRoomChanged: {
0269         if (root.headerItem) {
0270             root.headerItem.userListSearchField.text = "";
0271         }
0272         userList.currentIndex = -1;
0273     }
0274 }