Warning, /network/neochat/src/qml/SpaceHomePage.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 
0010 import org.kde.neochat
0011 
0012 Kirigami.Page {
0013     id: root
0014 
0015     readonly property NeoChatRoom currentRoom: RoomManager.currentRoom
0016 
0017     padding: 0
0018 
0019     ColumnLayout {
0020         id: columnLayout
0021         anchors.fill: parent
0022         spacing: 0
0023 
0024         Item {
0025             id: headerItem
0026             Layout.fillWidth: true
0027             Layout.topMargin: Kirigami.Units.smallSpacing
0028             implicitHeight: headerColumn.implicitHeight
0029 
0030             ColumnLayout {
0031                 id: headerColumn
0032                 anchors.centerIn: headerItem
0033                 width: sizeHelper.currentWidth
0034                 spacing: Kirigami.Units.largeSpacing
0035 
0036                 GroupChatDrawerHeader {
0037                     id: header
0038                     Layout.fillWidth: true
0039                     room: root.currentRoom
0040                 }
0041                 RowLayout {
0042                     Layout.fillWidth: true
0043                     Layout.leftMargin: Kirigami.Units.largeSpacing
0044                     Layout.rightMargin: Kirigami.Units.largeSpacing
0045                     QQC2.Button {
0046                         visible: root.currentRoom.canSendState("invite")
0047                         text: i18nc("@button", "Invite user to space")
0048                         icon.name: "list-add-user"
0049                         onClicked: applicationWindow().pageStack.pushDialogLayer("qrc:/org/kde/neochat/qml/InviteUserPage.qml", {
0050                             room: root.currentRoom
0051                         }, {
0052                             title: i18nc("@title", "Invite a User")
0053                         })
0054                     }
0055                     QQC2.Button {
0056                         visible: root.currentRoom.canSendState("m.space.child")
0057                         text: i18nc("@button", "Add new child")
0058                         icon.name: "list-add"
0059                         onClicked: _private.createRoom(root.currentRoom.id)
0060                     }
0061                     QQC2.Button {
0062                         text: i18nc("@button", "Leave the space")
0063                         icon.name: "go-previous"
0064                         onClicked: RoomManager.leaveRoom(root.currentRoom)
0065                     }
0066                     Item {
0067                         Layout.fillWidth: true
0068                     }
0069                     QQC2.Button {
0070                         text: i18nc("@button", "Space settings")
0071                         icon.name: "settings-configure"
0072                         display: QQC2.AbstractButton.IconOnly
0073                         onClicked: applicationWindow().pageStack.pushDialogLayer('qrc:/org/kde/neochat/qml/Categories.qml', {
0074                             room: root.currentRoom,
0075                             connection: root.currentRoom.connection
0076                         }, {
0077                             title: i18n("Room Settings")
0078                         })
0079 
0080                         QQC2.ToolTip.text: text
0081                         QQC2.ToolTip.delay: Kirigami.Units.toolTipDelay
0082                         QQC2.ToolTip.visible: hovered
0083                     }
0084                 }
0085                 Kirigami.SearchField {
0086                     Layout.fillWidth: true
0087                     Layout.leftMargin: Kirigami.Units.largeSpacing
0088                     Layout.rightMargin: Kirigami.Units.largeSpacing
0089                     Layout.bottomMargin: Kirigami.Units.largeSpacing
0090                     onTextChanged: spaceChildSortFilterModel.filterText = text
0091                 }
0092             }
0093             DelegateSizeHelper {
0094                 id: sizeHelper
0095                 startBreakpoint: Kirigami.Units.gridUnit * 46
0096                 endBreakpoint: Kirigami.Units.gridUnit * 66
0097                 startPercentWidth: 100
0098                 endPercentWidth: 85
0099                 maxWidth: Kirigami.Units.gridUnit * 60
0100 
0101                 parentWidth: columnLayout.width
0102             }
0103         }
0104         Kirigami.Separator {
0105             Layout.fillWidth: true
0106         }
0107         QQC2.ScrollView {
0108             id: hierarchyScrollView
0109             Layout.fillWidth: true
0110             Layout.fillHeight: true
0111             visible: !spaceChildrenModel.loading
0112 
0113             TreeView {
0114                 id: spaceTree
0115                 columnWidthProvider: function (column) {
0116                     return spaceTree.width;
0117                 }
0118 
0119                 clip: true
0120 
0121                 model: SpaceChildSortFilterModel {
0122                     id: spaceChildSortFilterModel
0123                     sourceModel: SpaceChildrenModel {
0124                         id: spaceChildrenModel
0125                         space: root.currentRoom
0126                     }
0127                 }
0128 
0129                 delegate: SpaceHierarchyDelegate {
0130                     onCreateRoom: _private.createRoom(roomId)
0131                 }
0132             }
0133 
0134             background: Rectangle {
0135                 color: Kirigami.Theme.backgroundColor
0136                 Kirigami.Theme.colorSet: Kirigami.Theme.View
0137             }
0138         }
0139         Item {
0140             Layout.fillWidth: true
0141             Layout.fillHeight: true
0142             visible: spaceChildrenModel.loading
0143 
0144             Loader {
0145                 active: spaceChildrenModel.loading
0146                 anchors.centerIn: parent
0147                 sourceComponent: Kirigami.LoadingPlaceholder {}
0148             }
0149         }
0150     }
0151 
0152     background: Rectangle {
0153         color: Kirigami.Theme.backgroundColor
0154         Kirigami.Theme.inherit: false
0155         Kirigami.Theme.colorSet: Kirigami.Theme.View
0156     }
0157 
0158     QtObject {
0159         id: _private
0160         function createRoom(parentId) {
0161             let dialog = applicationWindow().pageStack.pushDialogLayer("qrc:/org/kde/neochat/qml/CreateRoomDialog.qml", {
0162                 title: i18nc("@title", "Create a Child"),
0163                 connection: root.currentRoom.connection,
0164                 parentId: parentId,
0165                 showChildType: true,
0166                 showCreateChoice: true
0167             }, {
0168                 title: i18nc("@title", "Create a Child")
0169             });
0170             dialog.addChild.connect((childId, setChildParent, canonical) => {
0171                 // We have to get a room object from the connection as we may not
0172                 // be adding to the top level parent.
0173                 let parent = root.currentRoom.connection.room(parentId);
0174                 if (parent) {
0175                     parent.addChild(childId, setChildParent, canonical);
0176                 }
0177             });
0178             dialog.newChild.connect(childName => {
0179                 spaceChildrenModel.addPendingChild(childName);
0180             });
0181         }
0182     }
0183 }