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/JoinRoomPage.qml", {connection: root.room.connection, showOnlySpaces: true}, {title: i18nc("@title", "Choose Parent Space")}) 0053 dialog.roomSelected.connect((roomId, displayName, avatarUrl, alias, topic, memberCount, isJoined) => { 0054 chosenRoomDelegate.roomId = roomId; 0055 chosenRoomDelegate.displayName = displayName; 0056 chosenRoomDelegate.avatarUrl = avatarUrl; 0057 chosenRoomDelegate.alias = alias; 0058 chosenRoomDelegate.topic = topic; 0059 chosenRoomDelegate.memberCount = memberCount; 0060 chosenRoomDelegate.isJoined = isJoined; 0061 chosenRoomDelegate.visible = true; 0062 }) 0063 } 0064 } 0065 FormCard.AbstractFormDelegate { 0066 id: chosenRoomDelegate 0067 property string roomId 0068 property string displayName 0069 property url avatarUrl 0070 property string alias 0071 property string topic 0072 property int memberCount 0073 property bool isJoined 0074 0075 visible: false 0076 0077 contentItem: RowLayout { 0078 Components.Avatar { 0079 Layout.preferredWidth: Kirigami.Units.gridUnit * 2 0080 Layout.preferredHeight: Kirigami.Units.gridUnit * 2 0081 0082 source: chosenRoomDelegate.avatarUrl 0083 name: chosenRoomDelegate.displayName 0084 } 0085 ColumnLayout { 0086 Layout.fillWidth: true 0087 RowLayout { 0088 Layout.fillWidth: true 0089 Kirigami.Heading { 0090 Layout.fillWidth: true 0091 level: 4 0092 text: chosenRoomDelegate.displayName 0093 font.bold: true 0094 textFormat: Text.PlainText 0095 elide: Text.ElideRight 0096 wrapMode: Text.NoWrap 0097 } 0098 QQC2.Label { 0099 visible: chosenRoomDelegate.isJoined 0100 text: i18n("Joined") 0101 color: Kirigami.Theme.linkColor 0102 } 0103 } 0104 QQC2.Label { 0105 Layout.fillWidth: true 0106 visible: text 0107 text: chosenRoomDelegate.topic ? chosenRoomDelegate.topic.replace(/(\r\n\t|\n|\r\t)/gm," ") : "" 0108 textFormat: Text.PlainText 0109 elide: Text.ElideRight 0110 wrapMode: Text.NoWrap 0111 } 0112 RowLayout { 0113 Layout.fillWidth: true 0114 Kirigami.Icon { 0115 source: "user" 0116 color: Kirigami.Theme.disabledTextColor 0117 implicitHeight: Kirigami.Units.iconSizes.small 0118 implicitWidth: Kirigami.Units.iconSizes.small 0119 } 0120 QQC2.Label { 0121 text: chosenRoomDelegate.memberCount + " " + (chosenRoomDelegate.alias ?? chosenRoomDelegate.roomId) 0122 color: Kirigami.Theme.disabledTextColor 0123 elide: Text.ElideRight 0124 Layout.fillWidth: true 0125 } 0126 } 0127 } 0128 } 0129 0130 onClicked: { 0131 let dialog = pageStack.pushDialogLayer("qrc:/org/kde/neochat/qml/JoinRoomPage.qml", {connection: root.room.connection, showOnlySpaces: true}, {title: i18nc("@title", "Explore Rooms")}) 0132 dialog.roomSelected.connect((roomId, displayName, avatarUrl, alias, topic, memberCount, isJoined) => { 0133 chosenRoomDelegate.roomId = roomId; 0134 chosenRoomDelegate.displayName = displayName; 0135 chosenRoomDelegate.avatarUrl = avatarUrl; 0136 chosenRoomDelegate.alias = alias; 0137 chosenRoomDelegate.topic = topic; 0138 chosenRoomDelegate.memberCount = memberCount; 0139 chosenRoomDelegate.isJoined = isJoined; 0140 chosenRoomDelegate.visible = true; 0141 }) 0142 } 0143 } 0144 FormCard.FormCheckDelegate { 0145 id: existingOfficialCheck 0146 property NeoChatRoom space: root.room.connection.room(chosenRoomDelegate.roomId) 0147 text: i18n("Set this room as a child of the space %1", space?.displayName ?? "") 0148 checked: enabled 0149 0150 enabled: chosenRoomDelegate.visible && space && space.canSendState("m.space.child") 0151 } 0152 FormCard.FormTextDelegate { 0153 visible: chosenRoomDelegate.visible && !root.room.canModifyParent(chosenRoomDelegate.roomId) 0154 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") 0155 textItem.color: Kirigami.Theme.negativeTextColor 0156 } 0157 FormCard.FormCheckDelegate { 0158 id: makeCanonicalCheck 0159 text: i18n("Make this space the canonical parent") 0160 checked: enabled 0161 0162 enabled: chosenRoomDelegate.visible 0163 } 0164 } 0165 }