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({"text": i18n("Room"), "isSpace": false}); 0054 roomTypeModel.append({"text": i18n("Space"), "isSpace": true}); 0055 roomTypeCombo.currentIndex = 0 0056 roomTypeCombo.isInitialising = false 0057 } 0058 onCurrentValueChanged: { 0059 if (!isInitialising) { 0060 root.isSpace = currentValue 0061 } 0062 } 0063 } 0064 FormCard.FormTextFieldDelegate { 0065 id: roomNameField 0066 label: i18n("Name:") 0067 onAccepted: if (roomNameField.text.length > 0) roomTopicField.forceActiveFocus(); 0068 } 0069 0070 FormCard.FormTextFieldDelegate { 0071 id: roomTopicField 0072 label: i18n("Topic:") 0073 onAccepted: ok.clicked() 0074 } 0075 FormCard.FormCheckDelegate { 0076 id: newOfficialCheck 0077 visible: root.parentId.length > 0 0078 text: i18nc("@option:check As in make the space from which this dialog was created an official parent.", "Make this parent official") 0079 checked: true 0080 } 0081 FormCard.FormButtonDelegate { 0082 id: ok 0083 text: i18nc("@action:button", "Ok") 0084 enabled: roomNameField.text.length > 0 0085 onClicked: { 0086 if (root.isSpace) { 0087 root.connection.createSpace(roomNameField.text, roomTopicField.text, root.parentId, newOfficialCheck.checked); 0088 } else { 0089 root.connection.createRoom(roomNameField.text, roomTopicField.text, root.parentId, newOfficialCheck.checked); 0090 } 0091 root.newChild(roomNameField.text) 0092 root.closeDialog() 0093 } 0094 } 0095 } 0096 FormCard.FormHeader { 0097 visible: root.showChildType 0098 title: i18n("Select Existing Room") 0099 } 0100 FormCard.FormCard { 0101 visible: root.showChildType 0102 FormCard.FormButtonDelegate { 0103 visible: !chosenRoomDelegate.visible 0104 text: i18nc("@action:button", "Pick room") 0105 onClicked: { 0106 let dialog = pageStack.pushDialogLayer("qrc:/org/kde/neochat/qml/JoinRoomPage.qml", {connection: root.connection}, {title: i18nc("@title", "Explore Rooms")}) 0107 dialog.roomSelected.connect((roomId, displayName, avatarUrl, alias, topic, memberCount, isJoined) => { 0108 chosenRoomDelegate.roomId = roomId; 0109 chosenRoomDelegate.displayName = displayName; 0110 chosenRoomDelegate.avatarUrl = avatarUrl; 0111 chosenRoomDelegate.alias = alias; 0112 chosenRoomDelegate.topic = topic; 0113 chosenRoomDelegate.memberCount = memberCount; 0114 chosenRoomDelegate.isJoined = isJoined; 0115 chosenRoomDelegate.visible = true; 0116 }) 0117 } 0118 } 0119 FormCard.AbstractFormDelegate { 0120 id: chosenRoomDelegate 0121 property string roomId 0122 property string displayName 0123 property url avatarUrl 0124 property string alias 0125 property string topic 0126 property int memberCount 0127 property bool isJoined 0128 0129 visible: false 0130 0131 contentItem: RowLayout { 0132 Components.Avatar { 0133 Layout.preferredWidth: Kirigami.Units.gridUnit * 2 0134 Layout.preferredHeight: Kirigami.Units.gridUnit * 2 0135 0136 source: chosenRoomDelegate.avatarUrl 0137 name: chosenRoomDelegate.displayName 0138 } 0139 ColumnLayout { 0140 Layout.fillWidth: true 0141 RowLayout { 0142 Layout.fillWidth: true 0143 Kirigami.Heading { 0144 Layout.fillWidth: true 0145 level: 4 0146 text: chosenRoomDelegate.displayName 0147 font.bold: true 0148 textFormat: Text.PlainText 0149 elide: Text.ElideRight 0150 wrapMode: Text.NoWrap 0151 } 0152 QQC2.Label { 0153 visible: chosenRoomDelegate.isJoined 0154 text: i18n("Joined") 0155 color: Kirigami.Theme.linkColor 0156 } 0157 } 0158 QQC2.Label { 0159 Layout.fillWidth: true 0160 visible: text 0161 text: chosenRoomDelegate.topic ? chosenRoomDelegate.topic.replace(/(\r\n\t|\n|\r\t)/gm," ") : "" 0162 textFormat: Text.PlainText 0163 elide: Text.ElideRight 0164 wrapMode: Text.NoWrap 0165 } 0166 RowLayout { 0167 Layout.fillWidth: true 0168 Kirigami.Icon { 0169 source: "user" 0170 color: Kirigami.Theme.disabledTextColor 0171 implicitHeight: Kirigami.Units.iconSizes.small 0172 implicitWidth: Kirigami.Units.iconSizes.small 0173 } 0174 QQC2.Label { 0175 text: chosenRoomDelegate.memberCount + " " + (chosenRoomDelegate.alias ?? chosenRoomDelegate.roomId) 0176 color: Kirigami.Theme.disabledTextColor 0177 elide: Text.ElideRight 0178 Layout.fillWidth: true 0179 } 0180 } 0181 } 0182 } 0183 0184 onClicked: { 0185 let dialog = pageStack.pushDialogLayer("qrc:/org/kde/neochat/qml/JoinRoomPage.qml", {connection: root.connection}, {title: i18nc("@title", "Explore Rooms")}) 0186 dialog.roomSelected.connect((roomId, displayName, avatarUrl, alias, topic, memberCount, isJoined) => { 0187 chosenRoomDelegate.roomId = roomId; 0188 chosenRoomDelegate.displayName = displayName; 0189 chosenRoomDelegate.avatarUrl = avatarUrl; 0190 chosenRoomDelegate.alias = alias; 0191 chosenRoomDelegate.topic = topic; 0192 chosenRoomDelegate.memberCount = memberCount; 0193 chosenRoomDelegate.isJoined = isJoined; 0194 chosenRoomDelegate.visible = true; 0195 }) 0196 } 0197 } 0198 FormCard.FormCheckDelegate { 0199 id: existingOfficialCheck 0200 visible: root.parentId.length > 0 0201 text: i18nc("@option:check As in make the space from which this dialog was created an official parent.", "Make this parent official") 0202 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") 0203 checked: enabled 0204 0205 enabled: { 0206 if (chosenRoomDelegate.visible) { 0207 let room = root.connection.room(chosenRoomDelegate.roomId); 0208 if (room) { 0209 if (room.canSendState("m.space.parent")) { 0210 return true; 0211 } 0212 } 0213 } 0214 return false; 0215 } 0216 } 0217 FormCard.FormCheckDelegate { 0218 id: makeCanonicalCheck 0219 text: i18nc("@option:check The canonical parent is the default one if a room has multiple parent spaces.", "Make this space the canonical parent") 0220 checked: enabled 0221 0222 enabled: existingOfficialCheck.enabled 0223 } 0224 FormCard.FormButtonDelegate { 0225 text: i18nc("@action:button", "Ok") 0226 enabled: chosenRoomDelegate.visible 0227 onClicked: { 0228 root.addChild(chosenRoomDelegate.roomId, existingOfficialCheck.checked, makeCanonicalCheck.checked); 0229 root.closeDialog(); 0230 } 0231 } 0232 } 0233 }