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

0001 // SPDX-FileCopyrightText: 2020-2023 Tobias Fella <tobias.fella@kde.org>
0002 // SPDX-FileCopyrightText: 2021-2022 Bart De Vries <bart@mogwai.be>
0003 // SPDX-License-Identifier: GPL-2.0-only OR GPL-3.0-only OR LicenseRef-KDE-Accepted-GPL
0004 
0005 import QtQuick
0006 import QtQuick.Controls as QQC2
0007 import QtQuick.Layouts
0008 
0009 import org.kde.kirigami as Kirigami
0010 
0011 import org.kde.neochat
0012 
0013 QQC2.Control {
0014     id: root
0015 
0016     readonly property real pinnedWidth: Kirigami.Units.gridUnit * 6
0017     required property NeoChatConnection connection
0018 
0019     leftPadding: 0
0020     rightPadding: 0
0021     topPadding: 0
0022     bottomPadding: 0
0023 
0024     property string selectedSpaceId: RoomManager.lastSpaceId
0025     Connections {
0026         target: RoomManager
0027         function onConnectionChanged() {
0028             // We need to rebind as any previous change will have been overwritten.
0029             selectedSpaceId = RoomManager.lastSpaceId
0030         }
0031     }
0032 
0033     property bool showDirectChats: false
0034 
0035     signal selectionChanged
0036     signal spacesUpdated
0037 
0038     contentItem: Loader {
0039         id: sidebarColumn
0040         z: 0
0041 
0042         sourceComponent: ColumnLayout {
0043             spacing: 0
0044 
0045             QQC2.ScrollView {
0046                 id: scrollView
0047                 Layout.fillWidth: true
0048                 Layout.fillHeight: true
0049 
0050                 QQC2.ScrollBar.vertical.policy: QQC2.ScrollBar.AlwaysOff
0051                 QQC2.ScrollBar.horizontal.policy: QQC2.ScrollBar.AlwaysOff
0052                 contentWidth: -1 // disable horizontal scroll
0053 
0054                 background: Rectangle {
0055                     color: Kirigami.Theme.backgroundColor
0056                     Kirigami.Theme.colorSet: Kirigami.Theme.View
0057                 }
0058 
0059                 ColumnLayout {
0060                     id: column
0061                     width: scrollView.width
0062                     spacing: 0
0063 
0064                     AvatarTabButton {
0065                         id: notificationsButton
0066 
0067                         Layout.fillWidth: true
0068                         Layout.preferredHeight: width - Kirigami.Units.smallSpacing
0069                         Layout.maximumHeight: width - Kirigami.Units.smallSpacing
0070                         Layout.topMargin: Kirigami.Units.smallSpacing / 2
0071                         Layout.bottomMargin: Kirigami.Units.smallSpacing / 2
0072                         text: i18n("View notifications")
0073                         contentItem: Kirigami.Icon {
0074                             source: "notifications"
0075                         }
0076 
0077                         onClicked: pageStack.pushDialogLayer("qrc:/org/kde/neochat/qml/NotificationsView.qml", {
0078                             connection: root.connection
0079                         }, {
0080                             title: i18nc("@title", "Notifications")
0081                         })
0082                     }
0083 
0084                     Kirigami.Separator {
0085                         Layout.fillWidth: true
0086                         Layout.leftMargin: Kirigami.Units.smallSpacing
0087                         Layout.rightMargin: Kirigami.Units.smallSpacing
0088                     }
0089 
0090                     AvatarTabButton {
0091                         id: allRoomButton
0092 
0093                         Layout.fillWidth: true
0094                         Layout.preferredHeight: width - Kirigami.Units.smallSpacing
0095                         Layout.maximumHeight: width - Kirigami.Units.smallSpacing
0096                         Layout.topMargin: Kirigami.Units.smallSpacing / 2
0097 
0098                         text: i18n("Home")
0099                         contentItem: Kirigami.Icon {
0100                             source: "user-home-symbolic"
0101                         }
0102 
0103                         checked: root.selectedSpaceId === "" && root.showDirectChats === false
0104                         onClicked: {
0105                             root.showDirectChats = false;
0106                             root.selectedSpaceId = "";
0107                             root.selectionChanged();
0108                         }
0109                     }
0110                     AvatarTabButton {
0111                         id: directChatButton
0112 
0113                         Layout.fillWidth: true
0114                         Layout.preferredHeight: width - Kirigami.Units.smallSpacing
0115                         Layout.maximumHeight: width - Kirigami.Units.smallSpacing
0116                         Layout.topMargin: Kirigami.Units.smallSpacing / 2
0117 
0118                         text: i18nc("@button View all one-on-one chats with your friends.", "Friends")
0119                         contentItem: Kirigami.Icon {
0120                             source: "system-users"
0121                         }
0122 
0123                         checked: root.showDirectChats === true
0124                         onClicked: {
0125                             root.showDirectChats = true;
0126                             root.selectedSpaceId = "";
0127                             root.selectionChanged();
0128                         }
0129 
0130                         QQC2.Label {
0131                             id: notificationCountLabel
0132                             anchors.top: parent.top
0133                             anchors.right: parent.right
0134                             anchors.rightMargin: Kirigami.Units.smallSpacing / 2
0135                             z: 1
0136                             width: Math.max(notificationCountTextMetrics.advanceWidth + Kirigami.Units.smallSpacing * 2, height)
0137                             height: Kirigami.Units.iconSizes.smallMedium
0138 
0139                             text: root.connection.directChatNotifications > 0 ? root.connection.directChatNotifications : ""
0140                             visible: root.connection.directChatNotifications > 0 || root.connection.directChatInvites
0141                             color: Kirigami.Theme.textColor
0142                             horizontalAlignment: Text.AlignHCenter
0143                             background: Rectangle {
0144                                 visible: true
0145                                 Kirigami.Theme.colorSet: Kirigami.Theme.Button
0146                                 color: Kirigami.Theme.positiveTextColor
0147                                 radius: height / 2
0148                             }
0149 
0150                             TextMetrics {
0151                                 id: notificationCountTextMetrics
0152                                 text: notificationCountLabel.text
0153                             }
0154                         }
0155                     }
0156 
0157                     Repeater {
0158                         model: SortFilterSpaceListModel {
0159                             sourceModel: RoomListModel {
0160                                 connection: root.connection
0161                             }
0162                             onLayoutChanged: root.spacesUpdated()
0163                         }
0164                         onCountChanged: {
0165                             if (!root.connection.room(root.selectedSpaceId)) {
0166                                 root.selectedSpaceId = "";
0167                             }
0168                         }
0169 
0170                         delegate: AvatarTabButton {
0171                             id: spaceDelegate
0172 
0173                             required property string displayName
0174                             required property string avatar
0175                             required property string roomId
0176                             required property var currentRoom
0177 
0178                             Layout.fillWidth: true
0179                             Layout.preferredHeight: width - Kirigami.Units.smallSpacing
0180                             Layout.maximumHeight: width - Kirigami.Units.smallSpacing
0181 
0182                             text: displayName
0183                             source: avatar ? ("image://mxc/" + avatar) : ""
0184 
0185                             onSelected: {
0186                                 root.showDirectChats = false;
0187                                 if (!SpaceHierarchyCache.isSpaceChild(roomId, RoomManager.currentRoom.id) || root.selectedSpaceId == roomId) {
0188                                     RoomManager.resolveResource(currentRoom.id);
0189                                 }
0190                                 root.selectedSpaceId = roomId;
0191                                 root.selectionChanged();
0192                             }
0193                             checked: root.selectedSpaceId === roomId
0194                             onContextMenuRequested: root.createContextMenu(currentRoom)
0195                         }
0196                     }
0197 
0198                     Kirigami.Separator {
0199                         Layout.fillWidth: true
0200                         Layout.topMargin: Kirigami.Units.smallSpacing / 2
0201                         Layout.bottomMargin: Kirigami.Units.smallSpacing / 2
0202                         Layout.leftMargin: Kirigami.Units.smallSpacing
0203                         Layout.rightMargin: Kirigami.Units.smallSpacing
0204                     }
0205 
0206                     AvatarTabButton {
0207                         Layout.fillWidth: true
0208                         Layout.preferredHeight: width - Kirigami.Units.smallSpacing
0209                         Layout.maximumHeight: width - Kirigami.Units.smallSpacing
0210 
0211                         text: i18n("Create a space")
0212                         contentItem: Kirigami.Icon {
0213                             source: "list-add"
0214                         }
0215                         onClicked: pageStack.pushDialogLayer("qrc:/org/kde/neochat/qml/CreateRoomDialog.qml", {
0216                             connection: root.connection,
0217                             isSpace: true,
0218                             title: i18nc("@title", "Create a Space")
0219                         }, {
0220                             title: i18nc("@title", "Create a Space")
0221                         })
0222                     }
0223                 }
0224             }
0225         }
0226     }
0227 
0228     function createContextMenu(room) {
0229         let context = spaceListContextMenu.createObject(root, {
0230             room: room,
0231             connection: root.connection
0232         });
0233         context.open();
0234     }
0235     Component {
0236         id: spaceListContextMenu
0237         SpaceListContextMenu {}
0238     }
0239 }