Warning, /network/neochat/src/qml/SelectParentDialog.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.formcard as FormCard
0010 import org.kde.kirigamiaddons.labs.components as Components
0011 
0012 import org.kde.neochat
0013 
0014 /**
0015  * @brief A dialog to select a parent space to add to a given room.
0016  */
0017 Kirigami.Dialog {
0018     id: root
0019 
0020     /**
0021      * @brief The current room that a parent is being selected for.
0022      */
0023     required property NeoChatRoom room
0024 
0025     title: i18nc("@title", "Select new official parent")
0026 
0027     width: Math.min(applicationWindow().width, Kirigami.Units.gridUnit * 24)
0028     leftPadding: 0
0029     rightPadding: 0
0030     topPadding: 0
0031     bottomPadding: 0
0032 
0033     standardButtons: Kirigami.Dialog.Cancel
0034     customFooterActions: [
0035         Kirigami.Action {
0036             enabled: chosenRoomDelegate.visible && root.room.canModifyParent(chosenRoomDelegate.roomId)
0037             text: i18n("OK")
0038             icon.name: "dialog-ok"
0039             onTriggered: {
0040                 root.room.addParent(chosenRoomDelegate.roomId, makeCanonicalCheck.checked, existingOfficialCheck.checked);
0041                 root.close();
0042             }
0043         }
0044     ]
0045 
0046     contentItem: ColumnLayout {
0047         spacing: 0
0048         FormCard.FormButtonDelegate {
0049             visible: !chosenRoomDelegate.visible
0050             text: i18nc("@action:button", "Pick room")
0051             onClicked: {
0052                 let dialog = pageStack.pushDialogLayer("qrc:/org/kde/neochat/qml/ExploreRoomsPage.qml", {
0053                     connection: root.room.connection,
0054                     showOnlySpaces: true
0055                 }, {
0056                     title: i18nc("@title", "Choose Parent Space")
0057                 });
0058                 dialog.roomSelected.connect((roomId, displayName, avatarUrl, alias, topic, memberCount, isJoined) => {
0059                     chosenRoomDelegate.roomId = roomId;
0060                     chosenRoomDelegate.displayName = displayName;
0061                     chosenRoomDelegate.avatarUrl = avatarUrl;
0062                     chosenRoomDelegate.alias = alias;
0063                     chosenRoomDelegate.topic = topic;
0064                     chosenRoomDelegate.memberCount = memberCount;
0065                     chosenRoomDelegate.isJoined = isJoined;
0066                     chosenRoomDelegate.visible = true;
0067                 });
0068             }
0069         }
0070         FormCard.AbstractFormDelegate {
0071             id: chosenRoomDelegate
0072             property string roomId
0073             property string displayName
0074             property url avatarUrl
0075             property string alias
0076             property string topic
0077             property int memberCount
0078             property bool isJoined
0079 
0080             visible: false
0081 
0082             contentItem: RowLayout {
0083                 Components.Avatar {
0084                     Layout.preferredWidth: Kirigami.Units.gridUnit * 2
0085                     Layout.preferredHeight: Kirigami.Units.gridUnit * 2
0086 
0087                     source: chosenRoomDelegate.avatarUrl
0088                     name: chosenRoomDelegate.displayName
0089                 }
0090                 ColumnLayout {
0091                     Layout.fillWidth: true
0092                     RowLayout {
0093                         Layout.fillWidth: true
0094                         Kirigami.Heading {
0095                             Layout.fillWidth: true
0096                             level: 4
0097                             text: chosenRoomDelegate.displayName
0098                             font.bold: true
0099                             textFormat: Text.PlainText
0100                             elide: Text.ElideRight
0101                             wrapMode: Text.NoWrap
0102                         }
0103                         QQC2.Label {
0104                             visible: chosenRoomDelegate.isJoined
0105                             text: i18n("Joined")
0106                             color: Kirigami.Theme.linkColor
0107                         }
0108                     }
0109                     QQC2.Label {
0110                         Layout.fillWidth: true
0111                         visible: text
0112                         text: chosenRoomDelegate.topic ? chosenRoomDelegate.topic.replace(/(\r\n\t|\n|\r\t)/gm, " ") : ""
0113                         textFormat: Text.PlainText
0114                         elide: Text.ElideRight
0115                         wrapMode: Text.NoWrap
0116                     }
0117                     RowLayout {
0118                         Layout.fillWidth: true
0119                         Kirigami.Icon {
0120                             source: "user"
0121                             color: Kirigami.Theme.disabledTextColor
0122                             implicitHeight: Kirigami.Units.iconSizes.small
0123                             implicitWidth: Kirigami.Units.iconSizes.small
0124                         }
0125                         QQC2.Label {
0126                             text: chosenRoomDelegate.memberCount + " " + (chosenRoomDelegate.alias ?? chosenRoomDelegate.roomId)
0127                             color: Kirigami.Theme.disabledTextColor
0128                             elide: Text.ElideRight
0129                             Layout.fillWidth: true
0130                         }
0131                     }
0132                 }
0133             }
0134 
0135             onClicked: {
0136                 let dialog = pageStack.pushDialogLayer("qrc:/org/kde/neochat/qml/ExploreRoomsPage.qml", {
0137                     connection: root.room.connection,
0138                     showOnlySpaces: true
0139                 }, {
0140                     title: i18nc("@title", "Explore Rooms")
0141                 });
0142                 dialog.roomSelected.connect((roomId, displayName, avatarUrl, alias, topic, memberCount, isJoined) => {
0143                     chosenRoomDelegate.roomId = roomId;
0144                     chosenRoomDelegate.displayName = displayName;
0145                     chosenRoomDelegate.avatarUrl = avatarUrl;
0146                     chosenRoomDelegate.alias = alias;
0147                     chosenRoomDelegate.topic = topic;
0148                     chosenRoomDelegate.memberCount = memberCount;
0149                     chosenRoomDelegate.isJoined = isJoined;
0150                     chosenRoomDelegate.visible = true;
0151                 });
0152             }
0153         }
0154         FormCard.FormCheckDelegate {
0155             id: existingOfficialCheck
0156             property NeoChatRoom space: root.room.connection.room(chosenRoomDelegate.roomId)
0157             text: i18n("Set this room as a child of the space %1", space?.displayName ?? "")
0158             checked: enabled
0159 
0160             enabled: chosenRoomDelegate.visible && space && space.canSendState("m.space.child")
0161         }
0162         FormCard.FormTextDelegate {
0163             visible: chosenRoomDelegate.visible && !root.room.canModifyParent(chosenRoomDelegate.roomId)
0164             text: existingOfficialCheck.space ? (existingOfficialCheck.space.isSpace ? i18n("You do not have a high enough privilege level in the parent to set this state") : i18n("The selected room is not a space")) : i18n("You do not have the privileges to complete this action")
0165             textItem.color: Kirigami.Theme.negativeTextColor
0166         }
0167         FormCard.FormCheckDelegate {
0168             id: makeCanonicalCheck
0169             text: i18n("Make this space the canonical parent")
0170             checked: enabled
0171 
0172             enabled: chosenRoomDelegate.visible
0173         }
0174     }
0175 }