1// SPDX-FileCopyrightText: 2021 Nheko Contributors 2// 3// SPDX-License-Identifier: GPL-3.0-or-later 4 5import ".." 6import "../ui" 7import Qt.labs.platform 1.1 as Platform 8import QtQuick 2.15 9import QtQuick.Controls 2.3 10import QtQuick.Layouts 1.2 11import QtQuick.Window 2.13 12import im.nheko 1.0 13 14ApplicationWindow { 15 id: roomSettingsDialog 16 17 property var roomSettings 18 19 minimumWidth: 450 20 minimumHeight: 680 21 palette: Nheko.colors 22 color: Nheko.colors.window 23 modality: Qt.NonModal 24 flags: Qt.Dialog | Qt.WindowCloseButtonHint | Qt.WindowTitleHint 25 Component.onCompleted: Nheko.reparent(roomSettingsDialog) 26 title: qsTr("Room Settings") 27 28 Shortcut { 29 sequence: StandardKey.Cancel 30 onActivated: roomSettingsDialog.close() 31 } 32 33 ColumnLayout { 34 id: contentLayout1 35 36 anchors.fill: parent 37 anchors.margins: Nheko.paddingMedium 38 spacing: Nheko.paddingMedium 39 40 Avatar { 41 url: roomSettings.roomAvatarUrl.replace("mxc://", "image://MxcImage/") 42 roomid: roomSettings.roomId 43 displayName: roomSettings.roomName 44 height: 130 45 width: 130 46 Layout.alignment: Qt.AlignHCenter 47 onClicked: { 48 if (roomSettings.canChangeAvatar) 49 roomSettings.updateAvatar(); 50 51 } 52 } 53 54 Spinner { 55 Layout.alignment: Qt.AlignHCenter 56 visible: roomSettings.isLoading 57 foreground: Nheko.colors.mid 58 running: roomSettings.isLoading 59 } 60 61 Text { 62 id: errorText 63 64 color: "red" 65 visible: opacity > 0 66 opacity: 0 67 Layout.alignment: Qt.AlignHCenter 68 } 69 70 SequentialAnimation { 71 id: hideErrorAnimation 72 73 running: false 74 75 PauseAnimation { 76 duration: 4000 77 } 78 79 NumberAnimation { 80 target: errorText 81 property: 'opacity' 82 to: 0 83 duration: 1000 84 } 85 86 } 87 88 Connections { 89 target: roomSettings 90 function onDisplayError(errorMessage) { 91 errorText.text = errorMessage; 92 errorText.opacity = 1; 93 hideErrorAnimation.restart(); 94 } 95 } 96 97 ColumnLayout { 98 Layout.alignment: Qt.AlignHCenter 99 100 MatrixText { 101 text: roomSettings.roomName 102 font.pixelSize: fontMetrics.font.pixelSize * 2 103 Layout.alignment: Qt.AlignHCenter 104 } 105 106 MatrixText { 107 text: qsTr("%1 member(s)").arg(roomSettings.memberCount) 108 Layout.alignment: Qt.AlignHCenter 109 110 TapHandler { 111 onTapped: TimelineManager.openRoomMembers(roomSettings.roomId) 112 } 113 114 CursorShape { 115 cursorShape: Qt.PointingHandCursor 116 anchors.fill: parent 117 } 118 119 } 120 121 } 122 123 ImageButton { 124 Layout.alignment: Qt.AlignHCenter 125 image: ":/icons/icons/ui/edit.svg" 126 visible: roomSettings.canChangeNameAndTopic 127 onClicked: roomSettings.openEditModal() 128 } 129 130 ScrollView { 131 Layout.fillHeight: true 132 Layout.alignment: Qt.AlignHCenter 133 Layout.fillWidth: true 134 Layout.leftMargin: Nheko.paddingLarge 135 Layout.rightMargin: Nheko.paddingLarge 136 137 TextArea { 138 text: TimelineManager.escapeEmoji(roomSettings.roomTopic) 139 wrapMode: TextEdit.WordWrap 140 textFormat: TextEdit.RichText 141 readOnly: true 142 background: null 143 selectByMouse: true 144 color: Nheko.colors.text 145 horizontalAlignment: TextEdit.AlignHCenter 146 onLinkActivated: Nheko.openLink(link) 147 148 CursorShape { 149 anchors.fill: parent 150 cursorShape: parent.hoveredLink ? Qt.PointingHandCursor : Qt.ArrowCursor 151 } 152 153 } 154 155 } 156 157 GridLayout { 158 columns: 2 159 rowSpacing: Nheko.paddingMedium 160 161 MatrixText { 162 text: qsTr("SETTINGS") 163 font.bold: true 164 } 165 166 Item { 167 Layout.fillWidth: true 168 } 169 170 MatrixText { 171 text: qsTr("Notifications") 172 Layout.fillWidth: true 173 } 174 175 ComboBox { 176 model: [qsTr("Muted"), qsTr("Mentions only"), qsTr("All messages")] 177 currentIndex: roomSettings.notifications 178 onActivated: { 179 roomSettings.changeNotifications(index); 180 } 181 Layout.fillWidth: true 182 } 183 184 MatrixText { 185 text: qsTr("Room access") 186 Layout.fillWidth: true 187 } 188 189 ComboBox { 190 enabled: roomSettings.canChangeJoinRules 191 model: { 192 let opts = [qsTr("Anyone and guests"), qsTr("Anyone"), qsTr("Invited users")]; 193 if (roomSettings.supportsKnocking) 194 opts.push(qsTr("By knocking")); 195 196 if (roomSettings.supportsRestricted) 197 opts.push(qsTr("Restricted by membership in other rooms")); 198 199 return opts; 200 } 201 currentIndex: roomSettings.accessJoinRules 202 onActivated: { 203 roomSettings.changeAccessRules(index); 204 } 205 Layout.fillWidth: true 206 } 207 208 MatrixText { 209 text: qsTr("Encryption") 210 } 211 212 ToggleButton { 213 id: encryptionToggle 214 215 checked: roomSettings.isEncryptionEnabled 216 onClicked: { 217 if (roomSettings.isEncryptionEnabled) { 218 checked = true; 219 return ; 220 } 221 confirmEncryptionDialog.open(); 222 } 223 Layout.alignment: Qt.AlignRight 224 } 225 226 Platform.MessageDialog { 227 id: confirmEncryptionDialog 228 229 title: qsTr("End-to-End Encryption") 230 text: qsTr("Encryption is currently experimental and things might break unexpectedly. <br> 231 Please take note that it can't be disabled afterwards.") 232 modality: Qt.NonModal 233 onAccepted: { 234 if (roomSettings.isEncryptionEnabled) 235 return ; 236 237 roomSettings.enableEncryption(); 238 } 239 onRejected: { 240 encryptionToggle.checked = false; 241 } 242 buttons: Platform.MessageDialog.Ok | Platform.MessageDialog.Cancel 243 } 244 245 MatrixText { 246 text: qsTr("Sticker & Emote Settings") 247 } 248 249 Button { 250 text: qsTr("Change") 251 ToolTip.text: qsTr("Change what packs are enabled, remove packs or create new ones") 252 onClicked: TimelineManager.openImagePackSettings(roomSettings.roomId) 253 Layout.alignment: Qt.AlignRight 254 } 255 256 Item { 257 // for adding extra space between sections 258 Layout.fillWidth: true 259 } 260 261 Item { 262 // for adding extra space between sections 263 Layout.fillWidth: true 264 } 265 266 MatrixText { 267 text: qsTr("INFO") 268 font.bold: true 269 } 270 271 Item { 272 Layout.fillWidth: true 273 } 274 275 MatrixText { 276 text: qsTr("Internal ID") 277 } 278 279 MatrixText { 280 text: roomSettings.roomId 281 font.pixelSize: Math.floor(fontMetrics.font.pixelSize * 0.8) 282 Layout.alignment: Qt.AlignRight 283 } 284 285 MatrixText { 286 text: qsTr("Room Version") 287 } 288 289 MatrixText { 290 text: roomSettings.roomVersion 291 font.pixelSize: fontMetrics.font.pixelSize 292 Layout.alignment: Qt.AlignRight 293 } 294 295 } 296 297 DialogButtonBox { 298 Layout.fillWidth: true 299 standardButtons: DialogButtonBox.Ok 300 onAccepted: close() 301 } 302 303 } 304 305} 306