Warning, /network/neochat/src/qml/CreateRoomDialog.qml is written in an unsupported language. File is not indexed.
0001 // SPDX-FileCopyrightText: 2023 Tobias Fella <tobias.fella@kde.org> 0002 // SPDX-License-Identifier: GPL-2.0-only OR GPL-3.0-or-later 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 FormCard.FormCardPage { 0015 id: root 0016 0017 property string parentId: "" 0018 0019 property bool isSpace: false 0020 0021 property bool showChildType: false 0022 0023 property bool showCreateChoice: false 0024 0025 required property NeoChatConnection connection 0026 0027 signal addChild(string childId, bool setChildParent, bool canonical) 0028 signal newChild(string childName) 0029 0030 title: isSpace ? i18nc("@title", "Create a Space") : i18nc("@title", "Create a Room") 0031 0032 Component.onCompleted: roomNameField.forceActiveFocus() 0033 0034 FormCard.FormHeader { 0035 title: root.isSpace ? i18n("New Space Information") : i18n("New Room Information") 0036 } 0037 FormCard.FormCard { 0038 FormCard.FormComboBoxDelegate { 0039 id: roomTypeCombo 0040 property bool isInitialising: true 0041 0042 visible: root.showChildType 0043 0044 text: i18n("Select type") 0045 model: ListModel { 0046 id: roomTypeModel 0047 } 0048 textRole: "text" 0049 valueRole: "isSpace" 0050 0051 Component.onCompleted: { 0052 currentIndex = indexOfValue(root.isSpace); 0053 roomTypeModel.append({ 0054 "text": i18n("Room"), 0055 "isSpace": false 0056 }); 0057 roomTypeModel.append({ 0058 "text": i18n("Space"), 0059 "isSpace": true 0060 }); 0061 roomTypeCombo.currentIndex = 0; 0062 roomTypeCombo.isInitialising = false; 0063 } 0064 onCurrentValueChanged: { 0065 if (!isInitialising) { 0066 root.isSpace = currentValue; 0067 } 0068 } 0069 } 0070 FormCard.FormTextFieldDelegate { 0071 id: roomNameField 0072 label: i18n("Name:") 0073 onAccepted: if (roomNameField.text.length > 0) { 0074 roomTopicField.forceActiveFocus(); 0075 } 0076 } 0077 0078 FormCard.FormTextFieldDelegate { 0079 id: roomTopicField 0080 label: i18n("Topic:") 0081 onAccepted: ok.clicked() 0082 } 0083 FormCard.FormCheckDelegate { 0084 id: newOfficialCheck 0085 visible: root.parentId.length > 0 0086 text: i18nc("@option:check As in make the space from which this dialog was created an official parent.", "Make this parent official") 0087 checked: true 0088 } 0089 FormCard.FormButtonDelegate { 0090 id: ok 0091 text: i18nc("@action:button", "Ok") 0092 enabled: roomNameField.text.length > 0 0093 onClicked: { 0094 if (root.isSpace) { 0095 root.connection.createSpace(roomNameField.text, roomTopicField.text, root.parentId, newOfficialCheck.checked); 0096 } else { 0097 root.connection.createRoom(roomNameField.text, roomTopicField.text, root.parentId, newOfficialCheck.checked); 0098 } 0099 root.newChild(roomNameField.text); 0100 root.closeDialog(); 0101 } 0102 } 0103 } 0104 FormCard.FormHeader { 0105 visible: root.showChildType 0106 title: i18n("Select Existing Room") 0107 } 0108 FormCard.FormCard { 0109 visible: root.showChildType 0110 FormCard.FormButtonDelegate { 0111 visible: !chosenRoomDelegate.visible 0112 text: i18nc("@action:button", "Pick room") 0113 onClicked: { 0114 let dialog = pageStack.pushDialogLayer("qrc:/org/kde/neochat/qml/ExploreRoomsPage.qml", { 0115 connection: root.connection 0116 }, { 0117 title: i18nc("@title", "Explore Rooms") 0118 }); 0119 dialog.roomSelected.connect((roomId, displayName, avatarUrl, alias, topic, memberCount, isJoined) => { 0120 chosenRoomDelegate.roomId = roomId; 0121 chosenRoomDelegate.displayName = displayName; 0122 chosenRoomDelegate.avatarUrl = avatarUrl; 0123 chosenRoomDelegate.alias = alias; 0124 chosenRoomDelegate.topic = topic; 0125 chosenRoomDelegate.memberCount = memberCount; 0126 chosenRoomDelegate.isJoined = isJoined; 0127 chosenRoomDelegate.visible = true; 0128 }); 0129 } 0130 } 0131 FormCard.AbstractFormDelegate { 0132 id: chosenRoomDelegate 0133 property string roomId 0134 property string displayName 0135 property url avatarUrl 0136 property string alias 0137 property string topic 0138 property int memberCount 0139 property bool isJoined 0140 0141 visible: false 0142 0143 contentItem: RowLayout { 0144 Components.Avatar { 0145 Layout.preferredWidth: Kirigami.Units.gridUnit * 2 0146 Layout.preferredHeight: Kirigami.Units.gridUnit * 2 0147 0148 source: chosenRoomDelegate.avatarUrl 0149 name: chosenRoomDelegate.displayName 0150 } 0151 ColumnLayout { 0152 Layout.fillWidth: true 0153 RowLayout { 0154 Layout.fillWidth: true 0155 Kirigami.Heading { 0156 Layout.fillWidth: true 0157 level: 4 0158 text: chosenRoomDelegate.displayName 0159 font.bold: true 0160 textFormat: Text.PlainText 0161 elide: Text.ElideRight 0162 wrapMode: Text.NoWrap 0163 } 0164 QQC2.Label { 0165 visible: chosenRoomDelegate.isJoined 0166 text: i18n("Joined") 0167 color: Kirigami.Theme.linkColor 0168 } 0169 } 0170 QQC2.Label { 0171 Layout.fillWidth: true 0172 visible: text 0173 text: chosenRoomDelegate.topic ? chosenRoomDelegate.topic.replace(/(\r\n\t|\n|\r\t)/gm, " ") : "" 0174 textFormat: Text.PlainText 0175 elide: Text.ElideRight 0176 wrapMode: Text.NoWrap 0177 } 0178 RowLayout { 0179 Layout.fillWidth: true 0180 Kirigami.Icon { 0181 source: "user" 0182 color: Kirigami.Theme.disabledTextColor 0183 implicitHeight: Kirigami.Units.iconSizes.small 0184 implicitWidth: Kirigami.Units.iconSizes.small 0185 } 0186 QQC2.Label { 0187 text: chosenRoomDelegate.memberCount + " " + (chosenRoomDelegate.alias ?? chosenRoomDelegate.roomId) 0188 color: Kirigami.Theme.disabledTextColor 0189 elide: Text.ElideRight 0190 Layout.fillWidth: true 0191 } 0192 } 0193 } 0194 } 0195 0196 onClicked: { 0197 let dialog = pageStack.pushDialogLayer("qrc:/org/kde/neochat/qml/ExploreRoomsPage.qml", { 0198 connection: root.connection 0199 }, { 0200 title: i18nc("@title", "Explore Rooms") 0201 }); 0202 dialog.roomSelected.connect((roomId, displayName, avatarUrl, alias, topic, memberCount, isJoined) => { 0203 chosenRoomDelegate.roomId = roomId; 0204 chosenRoomDelegate.displayName = displayName; 0205 chosenRoomDelegate.avatarUrl = avatarUrl; 0206 chosenRoomDelegate.alias = alias; 0207 chosenRoomDelegate.topic = topic; 0208 chosenRoomDelegate.memberCount = memberCount; 0209 chosenRoomDelegate.isJoined = isJoined; 0210 chosenRoomDelegate.visible = true; 0211 }); 0212 } 0213 } 0214 FormCard.FormCheckDelegate { 0215 id: existingOfficialCheck 0216 visible: root.parentId.length > 0 0217 text: i18nc("@option:check As in make the space from which this dialog was created an official parent.", "Make this parent official") 0218 description: enabled ? i18n("You have the required privilege level in the child to set this state") : i18n("You do not have a high enough privilege level in the child to set this state") 0219 checked: enabled 0220 0221 enabled: { 0222 if (chosenRoomDelegate.visible) { 0223 let room = root.connection.room(chosenRoomDelegate.roomId); 0224 if (room) { 0225 if (room.canSendState("m.space.parent")) { 0226 return true; 0227 } 0228 } 0229 } 0230 return false; 0231 } 0232 } 0233 FormCard.FormCheckDelegate { 0234 id: makeCanonicalCheck 0235 text: i18nc("@option:check The canonical parent is the default one if a room has multiple parent spaces.", "Make this space the canonical parent") 0236 checked: enabled 0237 0238 enabled: existingOfficialCheck.enabled 0239 } 0240 FormCard.FormButtonDelegate { 0241 text: i18nc("@action:button", "Ok") 0242 enabled: chosenRoomDelegate.visible 0243 onClicked: { 0244 root.addChild(chosenRoomDelegate.roomId, existingOfficialCheck.checked, makeCanonicalCheck.checked); 0245 root.closeDialog(); 0246 } 0247 } 0248 } 0249 }