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