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", {room: root.room, connection: root.connection}, {title: i18n("Developer Tools")}) 0086 } 0087 } 0088 0089 Delegates.RoundedItemDelegate { 0090 id: searchButton 0091 visible: !root.room.isSpace 0092 icon.name: "search" 0093 text: i18n("Search in this room") 0094 0095 Layout.fillWidth: true 0096 0097 onClicked: { 0098 pageStack.pushDialogLayer("qrc:/org/kde/neochat/qml/SearchPage.qml", { 0099 currentRoom: root.room, 0100 connection: root.connection 0101 }, { 0102 title: i18nc("@action:title", "Search") 0103 }) 0104 } 0105 } 0106 0107 Delegates.RoundedItemDelegate { 0108 id: favouriteButton 0109 visible: !root.room.isSpace 0110 icon.name: root.room && root.room.isFavourite ? "rating" : "rating-unrated" 0111 text: root.room && root.room.isFavourite ? i18n("Remove room from favorites") : i18n("Make room favorite") 0112 0113 onClicked: root.room.isFavourite ? root.room.removeTag("m.favourite") : root.room.addTag("m.favourite", 1.0) 0114 0115 Layout.fillWidth: true 0116 } 0117 0118 Delegates.RoundedItemDelegate { 0119 id: locationsButton 0120 visible: !root.room.isSpace 0121 icon.name: "map-flat" 0122 text: i18n("Show locations for this room") 0123 0124 onClicked: pageStack.pushDialogLayer("qrc:/org/kde/neochat/qml/LocationsPage.qml", { 0125 room: root.room 0126 }, { 0127 title: i18nc("Locations on a map", "Locations") 0128 }) 0129 0130 Layout.fillWidth: true 0131 } 0132 0133 Kirigami.ListSectionHeader { 0134 label: i18n("Members") 0135 activeFocusOnTab: false 0136 spacing: 0 0137 visible: !root.room.isDirectChat() 0138 0139 Layout.fillWidth: true 0140 0141 QQC2.ToolButton { 0142 visible: root.room.canSendState("invite") 0143 icon.name: "list-add-user" 0144 0145 onClicked: { 0146 applicationWindow().pageStack.pushDialogLayer("qrc:/org/kde/neochat/qml/InviteUserPage.qml", {room: root.room}, {title: i18nc("@title", "Invite a User")}) 0147 } 0148 0149 QQC2.ToolTip.text: i18n("Invite user to room") 0150 QQC2.ToolTip.visible: hovered 0151 QQC2.ToolTip.delay: Kirigami.Units.toolTipDelay 0152 } 0153 0154 QQC2.Label { 0155 Layout.alignment: Qt.AlignRight 0156 text: root.room ? i18np("%1 member", "%1 members", root.room.joinedCount) : i18n("No member count") 0157 } 0158 } 0159 0160 Kirigami.SearchField { 0161 id: userListSearchField 0162 0163 visible: !root.room.isDirectChat() 0164 onVisibleChanged: if (visible) forceActiveFocus() 0165 Layout.fillWidth: true 0166 Layout.leftMargin: Kirigami.Units.largeSpacing 0167 Layout.rightMargin: Kirigami.Units.largeSpacing 0168 Layout.bottomMargin: Kirigami.Units.smallSpacing 0169 0170 focusSequence: "Ctrl+Shift+F" 0171 0172 onAccepted: sortedMessageEventModel.filterString = text; 0173 } 0174 } 0175 0176 KSortFilterProxyModel { 0177 id: sortedMessageEventModel 0178 0179 sourceModel: UserListModel { 0180 room: root.room 0181 } 0182 0183 sortRoleName: "powerLevel" 0184 sortOrder: Qt.DescendingOrder 0185 filterRoleName: "name" 0186 filterCaseSensitivity: Qt.CaseInsensitive 0187 } 0188 0189 model: root.room.isDirectChat() ? 0 : sortedMessageEventModel 0190 0191 clip: true 0192 activeFocusOnTab: true 0193 0194 delegate: Delegates.RoundedItemDelegate { 0195 id: userDelegate 0196 0197 required property string name 0198 required property string userId 0199 required property string avatar 0200 required property int powerLevel 0201 required property string powerLevelString 0202 0203 implicitHeight: Kirigami.Units.gridUnit * 2 0204 0205 text: name 0206 0207 onClicked: { 0208 userDelegate.highlighted = true; 0209 RoomManager.resolveResource(userDelegate.userId, "mention") 0210 } 0211 0212 contentItem: RowLayout { 0213 KirigamiComponents.Avatar { 0214 implicitWidth: height 0215 sourceSize { 0216 height: Kirigami.Units.gridUnit + Kirigami.Units.smallSpacing * 2.5 0217 width: Kirigami.Units.gridUnit + Kirigami.Units.smallSpacing * 2.5 0218 } 0219 source: userDelegate.avatar 0220 name: userDelegate.userId 0221 0222 Layout.fillHeight: true 0223 } 0224 0225 QQC2.Label { 0226 text: userDelegate.name 0227 textFormat: Text.PlainText 0228 elide: Text.ElideRight 0229 0230 Layout.fillWidth: true 0231 } 0232 0233 QQC2.Label { 0234 visible: userDelegate.powerLevel > 0 0235 0236 text: userDelegate.powerLevelString 0237 color: Kirigami.Theme.disabledTextColor 0238 textFormat: Text.PlainText 0239 } 0240 } 0241 } 0242 } 0243 0244 Component { 0245 id: groupChatDrawerHeader 0246 GroupChatDrawerHeader { 0247 room: root.room 0248 } 0249 } 0250 0251 Component { 0252 id: directChatDrawerHeader 0253 DirectChatDrawerHeader { 0254 room: root.room 0255 } 0256 } 0257 0258 onRoomChanged: { 0259 if (root.headerItem) { 0260 root.headerItem.userListSearchField.text = ""; 0261 } 0262 userList.currentIndex = -1 0263 } 0264 }