Warning, /network/neochat/src/qml/General.qml is written in an unsupported language. File is not indexed.

0001 // SPDX-FileCopyrightText: 2019-2020 Black Hat <bhat@encom.eu.org>
0002 // SPDX-FileCopyrightText: 2021 Carl Schwan <carl@carlschwan.eu>
0003 // SPDX-License-Identifier: GPL-3.0-only
0004 
0005 import QtQuick
0006 import QtQuick.Controls as QQC2
0007 import QtQuick.Layouts
0008 import QtQuick.Window
0009 
0010 import org.kde.kirigami as Kirigami
0011 import org.kde.kirigamiaddons.formcard as FormCard
0012 import org.kde.kirigamiaddons.labs.components as KirigamiComponents
0013 
0014 import org.kde.neochat
0015 
0016 FormCard.FormCardPage {
0017     id: root
0018 
0019     property NeoChatRoom room
0020     required property NeoChatConnection connection
0021 
0022     title: i18n("General")
0023 
0024     FormCard.FormHeader {
0025         title: i18n("Room Information")
0026     }
0027     FormCard.FormCard {
0028         FormCard.AbstractFormDelegate {
0029             background: null
0030             contentItem: RowLayout {
0031                 Item {
0032                     Layout.fillWidth: true
0033                 }
0034                 KirigamiComponents.Avatar {
0035                     id: avatar
0036                     Layout.alignment: Qt.AlignRight
0037                     name: room.name
0038                     source: room.avatarMediaId ? ("image://mxc/" + room.avatarMediaId) : ""
0039                     implicitWidth: Kirigami.Units.iconSizes.enormous
0040                     implicitHeight: Kirigami.Units.iconSizes.enormous
0041                 }
0042                 QQC2.Button {
0043                     Layout.alignment: Qt.AlignLeft
0044                     enabled: room.canSendState("m.room.avatar")
0045                     visible: enabled
0046                     icon.name: "cloud-upload"
0047                     text: i18n("Update avatar")
0048                     display: QQC2.AbstractButton.IconOnly
0049 
0050                     onClicked: {
0051                         const fileDialog = openFileDialog.createObject(QQC2.ApplicationWindow.overlay)
0052 
0053                         fileDialog.chosen.connect(function(path) {
0054                             if (!path) return
0055 
0056                             room.changeAvatar(path)
0057                         })
0058 
0059                         fileDialog.open()
0060                     }
0061 
0062                     QQC2.ToolTip.text: text
0063                     QQC2.ToolTip.visible: hovered
0064                 }
0065                 Item {
0066                     Layout.fillWidth: true
0067                 }
0068             }
0069         }
0070         FormCard.FormTextFieldDelegate {
0071             id: roomNameField
0072             label: i18n("Room name:")
0073             text: room.name
0074             readOnly: !room.canSendState("m.room.name")
0075         }
0076         FormCard.AbstractFormDelegate {
0077             id: roomTopicField
0078             background: Item {}
0079             contentItem: ColumnLayout {
0080                 QQC2.Label {
0081                     id: roomTopicLabel
0082                     text: i18n("Room topic:")
0083                     Layout.fillWidth: true
0084                 }
0085                 QQC2.TextArea {
0086                     id: roomTopicTextArea
0087                     Accessible.description: roomTopicLabel.text
0088                     Layout.fillWidth: true
0089                     wrapMode: TextEdit.Wrap
0090                     text: room.topic
0091                     readOnly: !room.canSendState("m.room.topic")
0092                     onTextChanged: roomTopicField.text = text
0093                 }
0094             }
0095         }
0096         FormCard.AbstractFormDelegate {
0097             visible: !roomNameField.readOnly || !roomTopicTextArea.readOnly
0098             background: Item {}
0099             contentItem: RowLayout {
0100                 Item {
0101                     Layout.fillWidth: true
0102                 }
0103                 QQC2.Button {
0104                     Layout.bottomMargin: Kirigami.Units.smallSpacing
0105                     Layout.topMargin: Kirigami.Units.smallSpacing
0106                     enabled: room.name !== roomNameField.text || room.topic !== roomTopicField.text
0107                     text: i18n("Save")
0108                     onClicked: {
0109                         if (room.name != roomNameField.text) {
0110                             room.setName(roomNameField.text)
0111                         }
0112 
0113                         if (room.topic != roomTopicField.text) {
0114                             room.setTopic(roomTopicField.text)
0115                         }
0116                     }
0117                 }
0118             }
0119         }
0120         FormCard.FormTextDelegate {
0121             id: roomIdDelegate
0122             text: i18n("Room ID")
0123             description: room.id
0124 
0125             contentItem.children: QQC2.Button {
0126                 visible: roomIdDelegate.hovered
0127                 text: i18n("Copy room ID to clipboard")
0128                 icon.name: "edit-copy"
0129                 display: QQC2.AbstractButton.IconOnly
0130 
0131                 onClicked: {
0132                     Clipboard.saveText(room.id)
0133                 }
0134 
0135                 QQC2.ToolTip.text: text
0136                 QQC2.ToolTip.delay: Kirigami.Units.toolTipDelay
0137                 QQC2.ToolTip.visible: hovered
0138             }
0139         }
0140         FormCard.FormTextDelegate {
0141             text: i18n("Room version")
0142             description: room.version
0143 
0144             contentItem.children: QQC2.Button {
0145                 visible: room.canSwitchVersions()
0146                 enabled: room.version < room.maxRoomVersion
0147                 text: i18n("Upgrade Room")
0148                 icon.name: "arrow-up-double"
0149 
0150                 onClicked: {
0151                     if (room.canSwitchVersions()) {
0152                         roomUpgradeSheet.currentRoomVersion = room.version
0153                         roomUpgradeSheet.open()
0154                     }
0155                 }
0156 
0157                 QQC2.ToolTip {
0158                     text: text
0159                     delay: Kirigami.Units.toolTipDelay
0160                 }
0161             }
0162         }
0163     }
0164 
0165     FormCard.FormHeader {
0166         title: i18n("Aliases")
0167     }
0168     FormCard.FormCard {
0169         FormCard.FormTextDelegate {
0170             visible: room.aliases.length <= 0
0171             text: i18n("No canonical alias set")
0172         }
0173         Repeater {
0174             id: altAliasRepeater
0175             model: room.aliases.slice().reverse()
0176 
0177             delegate: FormCard.FormTextDelegate {
0178                 text: modelData
0179                 description: room.canonicalAlias.length > 0 && modelData === room.canonicalAlias ? "Canonical alias" : ""
0180                 contentItem.children: [
0181                     QQC2.ToolButton {
0182                         id: setCanonicalAliasButton
0183                         visible: modelData !== room.canonicalAlias && room.canSendState("m.room.canonical_alias")
0184                         text: i18n("Make this alias the room's canonical alias")
0185                         icon.name: "checkmark"
0186                         display: QQC2.AbstractButton.IconOnly
0187 
0188                         onClicked: {
0189                             room.setCanonicalAlias(modelData)
0190                         }
0191                         QQC2.ToolTip {
0192                             text: setCanonicalAliasButton.text
0193                             delay: Kirigami.Units.toolTipDelay
0194                         }
0195                     },
0196                     QQC2.ToolButton {
0197                         id: deleteButton
0198                         visible: room.canSendState("m.room.canonical_alias")
0199                         text: i18n("Delete alias")
0200                         icon.name: "edit-delete-remove"
0201                         display: QQC2.AbstractButton.IconOnly
0202 
0203                         onClicked: {
0204                             room.unmapAlias(modelData)
0205                         }
0206                         QQC2.ToolTip {
0207                             text: deleteButton.text
0208                             delay: Kirigami.Units.toolTipDelay
0209                         }
0210                     }
0211                 ]
0212 
0213             }
0214         }
0215         FormCard.AbstractFormDelegate {
0216             visible: room.canSendState("m.room.canonical_alias")
0217 
0218             contentItem : RowLayout {
0219                 Kirigami.ActionTextField {
0220                     id: aliasAddField
0221 
0222                     Layout.fillWidth: true
0223 
0224                     placeholderText: i18n("#new_alias:server.org")
0225 
0226                     rightActions: Kirigami.Action {
0227                         icon.name: "edit-clear"
0228                         visible: aliasAddField.text.length > 0
0229                         onTriggered: {
0230                             aliasAddField.text = ""
0231                         }
0232                     }
0233 
0234                     onAccepted: {
0235                         room.mapAlias(aliasAddField.text)
0236                     }
0237                 }
0238                 QQC2.Button {
0239                     id: addButton
0240 
0241                     text: i18n("Add new alias")
0242                     Accessible.name: text
0243                     icon.name: "list-add"
0244                     display: QQC2.AbstractButton.IconOnly
0245                     enabled: aliasAddField.text.length > 0
0246 
0247                     onClicked: {
0248                         room.mapAlias(aliasAddField.text)
0249                     }
0250 
0251                     QQC2.ToolTip {
0252                         text: addButton.text
0253                         delay: Kirigami.Units.toolTipDelay
0254                     }
0255                 }
0256             }
0257         }
0258     }
0259 
0260     FormCard.FormHeader {
0261         title: i18n("URL Previews")
0262     }
0263     FormCard.FormCard {
0264         FormCard.FormCheckDelegate {
0265             text: i18n("Enable URL previews by default for room members")
0266             checked: room.defaultUrlPreviewState
0267             visible: room.canSendState("org.matrix.room.preview_urls")
0268             onToggled: {
0269                 room.defaultUrlPreviewState = checked
0270             }
0271         }
0272         FormCard.FormCheckDelegate {
0273             text: i18n("Enable URL previews")
0274             // Most users won't see the above setting so tell them the default.
0275             description: room.defaultUrlPreviewState ? i18n("URL previews are enabled by default in this room") : i18n("URL previews are disabled by default in this room")
0276             checked: room.urlPreviewEnabled
0277             onToggled: {
0278                 room.urlPreviewEnabled = checked
0279             }
0280         }
0281     }
0282     FormCard.FormHeader {
0283         title: i18n("Official Parent Spaces")
0284     }
0285     FormCard.FormCard {
0286         Repeater {
0287             id: officalParentRepeater
0288             model: root.room.parentIds
0289 
0290             delegate: FormCard.FormTextDelegate {
0291                 id: officalParentDelegate
0292                 required property string modelData
0293                 property NeoChatRoom space: root.connection.room(modelData)
0294                 text: {
0295                     if (space) {
0296                         return space.displayName;
0297                     } else {
0298                         return modelData;
0299                     }
0300                 }
0301                 description: {
0302                     if (space) {
0303                         if (space.canonicalAlias.length > 0) {
0304                             return space.canonicalAlias;
0305                         } else {
0306                             return modelData;
0307                         }
0308                     } else {
0309                         return "";
0310                     }
0311                 }
0312 
0313                 contentItem.children: RowLayout {
0314                     QQC2.Label {
0315                         visible: root.room.canonicalParent === officalParentDelegate.modelData
0316                         text: i18n("Canonical")
0317                     }
0318                     QQC2.ToolButton {
0319                         visible: root.room.canSendState("m.space.parent") && root.room.canonicalParent !== officalParentDelegate.modelData
0320                         display: QQC2.AbstractButton.IconOnly
0321                         action: Kirigami.Action {
0322                             id: canonicalParentAction
0323                             text: i18n("Make canonical parent")
0324                             icon.name: "checkmark"
0325                             onTriggered: root.room.canonicalParent = officalParentDelegate.modelData
0326                         }
0327                         QQC2.ToolTip {
0328                             text: canonicalParentAction.text
0329                             delay: Kirigami.Units.toolTipDelay
0330                         }
0331                     }
0332                     QQC2.ToolButton {
0333                         visible: officalParentDelegate?.space.canSendState("m.space.child") && root.room.canSendState("m.space.parent")
0334                         display: QQC2.AbstractButton.IconOnly
0335                         action: Kirigami.Action {
0336                             id: removeParentAction
0337                             text: i18n("Remove parent")
0338                             icon.name: "edit-delete-remove"
0339                             onTriggered: root.room.removeParent(officalParentDelegate.modelData)
0340                         }
0341                         QQC2.ToolTip {
0342                             text: removeParentAction.text
0343                             delay: Kirigami.Units.toolTipDelay
0344                         }
0345                     }
0346                 }
0347             }
0348         }
0349         FormCard.FormTextDelegate {
0350             visible: officalParentRepeater.count <= 0
0351             text: i18n("This room has no official parent spaces.")
0352         }
0353         FormCard.FormButtonDelegate {
0354             visible: root.room.canSendState("m.space.parent")
0355             text: i18nc("@action:button", "Add new official parent")
0356             onClicked: selectParentDialog.createObject(applicationWindow().overlay).open();
0357 
0358             Component {
0359                 id: selectParentDialog
0360                 SelectParentDialog {
0361                     room: root.room
0362                 }
0363             }
0364         }
0365     }
0366 
0367     Kirigami.InlineMessage {
0368         Layout.maximumWidth: Kirigami.Units.gridUnit * 30
0369         Layout.alignment: Qt.AlignHCenter
0370         text: i18n("This room continues another conversation.")
0371         type: Kirigami.MessageType.Information
0372         visible: room.predecessorId && room.connection.room(room.predecessorId)
0373         actions: Kirigami.Action {
0374             text: i18n("See older messages…")
0375             onTriggered: {
0376                 RoomManager.enterRoom(root.connection.room(room.predecessorId));
0377                 root.close();
0378             }
0379         }
0380     }
0381     Kirigami.InlineMessage {
0382         Layout.maximumWidth: Kirigami.Units.gridUnit * 30
0383         Layout.alignment: Qt.AlignHCenter
0384         text: i18n("This room has been replaced.")
0385         type: Kirigami.MessageType.Information
0386         visible: room.successorId && room.connection.room(room.successorId)
0387         actions: Kirigami.Action {
0388             text: i18n("See new room…")
0389             onTriggered: {
0390                 RoomManager.enterRoom(root.connection.room(room.successorId));
0391                 root.close();
0392             }
0393         }
0394     }
0395 
0396     property Component openFileDialog: Component {
0397         id: openFileDialog
0398 
0399         OpenFileDialog {
0400             parentWindow: root.Window.window
0401         }
0402     }
0403 
0404     property Kirigami.OverlaySheet roomUpgradeSheet: Kirigami.OverlaySheet {
0405         id: roomUpgradeSheet
0406 
0407         property var currentRoomVersion
0408 
0409         title: i18n("Upgrade the Room")
0410         Kirigami.FormLayout {
0411             QQC2.SpinBox {
0412                 id: spinBox
0413                 Kirigami.FormData.label: i18n("Select new version")
0414                 from: room.version
0415                 to: room.maxRoomVersion
0416                 value: room.version
0417             }
0418             QQC2.Button {
0419                 text: i18n("Confirm")
0420                 onClicked: {
0421                     room.switchVersion(spinBox.value)
0422                     roomUpgradeSheet.close()
0423                 }
0424             }
0425         }
0426     }
0427 }
0428