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

0001 // SPDX-FileCopyrightText: 2019 Black Hat <bhat@encom.eu.org>
0002 // SPDX-FileCopyrightText: 2020 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 
0009 import org.kde.kirigami as Kirigami
0010 import org.kde.kirigamiaddons.components as KirigamiComponents
0011 import org.kde.kirigamiaddons.delegates as Delegates
0012 
0013 import org.kde.neochat
0014 
0015 /**
0016  * Context menu when clicking on a room in the room list
0017  */
0018 Loader {
0019     id: root
0020 
0021     property NeoChatRoom room
0022     required property NeoChatConnection connection
0023 
0024     signal closed()
0025 
0026     Component {
0027         id: regularMenu
0028         QQC2.Menu {
0029             QQC2.MenuItem {
0030                 id: newWindow
0031                 text: i18n("Open in New Window")
0032                 icon.name: "window-new"
0033                 onTriggered: RoomManager.openWindow(room);
0034                 visible: !Kirigami.Settings.isMobile
0035             }
0036 
0037             QQC2.MenuSeparator {
0038                 visible: newWindow.visible
0039             }
0040 
0041             QQC2.MenuItem {
0042                 text: room.isFavourite ? i18n("Remove from Favourites") : i18n("Add to Favourites")
0043                 icon.name: room.isFavourite ? "bookmark-remove" : "bookmark-new"
0044                 onTriggered: room.isFavourite ? room.removeTag("m.favourite") : room.addTag("m.favourite", 1.0)
0045             }
0046 
0047             QQC2.MenuItem {
0048                 text: room.isLowPriority ? i18n("Reprioritize") : i18n("Deprioritize")
0049                 icon.name: room.isLowPriority ? "arrow-up" : "arrow-down"
0050                 onTriggered: room.isLowPriority ? room.removeTag("m.lowpriority") : room.addTag("m.lowpriority", 1.0)
0051             }
0052 
0053             QQC2.MenuItem {
0054                 text: i18n("Mark as Read")
0055                 icon.name: "checkmark"
0056                 onTriggered: room.markAllMessagesAsRead()
0057             }
0058 
0059             QQC2.MenuItem {
0060                 text: room.isDirectChat() ? i18nc("@action:inmenu", "Copy user's Matrix ID to Clipboard") : i18nc("@action:inmenu", "Copy Address to Clipboard")
0061                 icon.name: "edit-copy"
0062                 onTriggered: if (room.isDirectChat()) {
0063                     Clipboard.saveText(room.directChatRemoteUser.id)
0064                 } else if (room.canonicalAlias.length === 0) {
0065                     Clipboard.saveText(room.id)
0066                 } else {
0067                     Clipboard.saveText(room.canonicalAlias)
0068                 }
0069             }
0070 
0071             QQC2.Menu {
0072                 title: i18n("Notification State")
0073 
0074                 QQC2.MenuItem {
0075                     text: i18n("Follow Global Setting")
0076                     icon.name: "globe"
0077                     checkable: true
0078                     autoExclusive: true
0079                     checked: room.pushNotificationState === PushNotificationState.Default
0080                     enabled: room.pushNotificationState != PushNotificationState.Unknown
0081                     onTriggered: {
0082                         room.pushNotificationState = PushNotificationState.Default
0083                     }
0084                 }
0085                 QQC2.MenuItem {
0086                     text: i18nc("As in 'notify for all messages'","All")
0087                     icon.name: "notifications"
0088                     checkable: true
0089                     autoExclusive: true
0090                     checked: room.pushNotificationState === PushNotificationState.All
0091                     enabled: room.pushNotificationState != PushNotificationState.Unknown
0092                     onTriggered: {
0093                         room.pushNotificationState = PushNotificationState.All
0094                     }
0095                 }
0096                 QQC2.MenuItem {
0097                     text: i18nc("As in 'notify when the user is mentioned or the message contains a set keyword'","@Mentions and Keywords")
0098                     icon.name: "im-user"
0099                     checkable: true
0100                     autoExclusive: true
0101                     checked: room.pushNotificationState === PushNotificationState.MentionKeyword
0102                     enabled: room.pushNotificationState != PushNotificationState.Unknown
0103                     onTriggered: {
0104                         room.pushNotificationState = PushNotificationState.MentionKeyword
0105                     }
0106                 }
0107                 QQC2.MenuItem {
0108                     text: i18nc("As in 'do not notify for any messages'","Off")
0109                     icon.name: "notifications-disabled"
0110                     checkable: true
0111                     autoExclusive: true
0112                     checked: room.pushNotificationState === PushNotificationState.Mute
0113                     enabled: room.pushNotificationState != PushNotificationState.Unknown
0114                     onTriggered: {
0115                         room.pushNotificationState = PushNotificationState.Mute
0116                     }
0117                 }
0118             }
0119 
0120             QQC2.MenuItem {
0121                 text: i18n("Room Settings")
0122                 icon.name: "configure"
0123                 onTriggered: QQC2.ApplicationWindow.window.pageStack.pushDialogLayer('qrc:/org/kde/neochat/qml/Categories.qml', {room: room, connection: connection}, { title: i18n("Room Settings") })
0124             }
0125 
0126             QQC2.MenuSeparator {}
0127 
0128             QQC2.MenuItem {
0129                 text: i18n("Leave Room")
0130                 icon.name: "go-previous"
0131                 onTriggered: RoomManager.leaveRoom(room)
0132             }
0133 
0134             onClosed: {
0135                 root.closed()
0136             }
0137         }
0138     }
0139 
0140     Component {
0141         id: mobileMenu
0142 
0143         Kirigami.OverlayDrawer {
0144             id: drawer
0145 
0146             parent: applicationWindow().overlay
0147             edge: Qt.BottomEdge
0148 
0149             height: popupContent.implicitHeight
0150 
0151             leftPadding: 0
0152             rightPadding: 0
0153             bottomPadding: 0
0154             topPadding: 0
0155 
0156             ColumnLayout {
0157                 id: popupContent
0158 
0159                 width: parent.width
0160                 spacing: 0
0161 
0162                 RowLayout {
0163                     id: headerLayout
0164                     Layout.fillWidth: true
0165                     Layout.margins: Kirigami.Units.largeSpacing
0166                     spacing: Kirigami.Units.largeSpacing
0167                     KirigamiComponents.Avatar {
0168                         id: avatar
0169                         source: room.avatarMediaId ? ("image://mxc/" + room.avatarMediaId) : ""
0170                         name: room.displayName
0171                         Layout.preferredWidth: Kirigami.Units.gridUnit * 3
0172                         Layout.preferredHeight: Kirigami.Units.gridUnit * 3
0173                         Layout.alignment: Qt.AlignTop
0174                     }
0175                     Kirigami.Heading {
0176                         level: 5
0177                         Layout.fillWidth: true
0178                         text: room.displayName
0179                         elide: Text.ElideRight
0180                     }
0181                     QQC2.ToolButton {
0182                         checked: room.isFavourite
0183                         checkable: true
0184                         icon.name: 'favorite'
0185                         Accessible.name: room.isFavourite ? i18n("Remove from Favourites") : i18n("Add to Favourites")
0186                         onClicked: room.isFavourite ? room.removeTag("m.favourite") : room.addTag("m.favourite", 1.0)
0187                     }
0188 
0189                     QQC2.ToolButton {
0190                         icon.name: 'settings-configure'
0191                         onClicked: {
0192                             QQC2.ApplicationWindow.window.pageStack.pushDialogLayer('qrc:/org/kde/neochat/qml/Categories.qml', {room: room, connection: root.connection}, { title: i18n("Room Settings") })
0193                             drawer.close()
0194                         }
0195                     }
0196                 }
0197 
0198                 Delegates.RoundedItemDelegate {
0199                     text: room.isLowPriority ? i18n("Reprioritize") : i18n("Deprioritize")
0200                     icon.name: room.isLowPriority ? "arrow-up" : "arrow-down"
0201                     onClicked: room.isLowPriority ? room.removeTag("m.lowpriority") : room.addTag("m.lowpriority", 1.0)
0202                     Layout.fillWidth: true
0203                 }
0204 
0205                 Delegates.RoundedItemDelegate {
0206                     text: i18n("Mark as Read")
0207                     icon.name: "checkmark"
0208                     onClicked: room.markAllMessagesAsRead()
0209                     Layout.fillWidth: true
0210                 }
0211 
0212                 Delegates.RoundedItemDelegate {
0213                     text: i18n("Leave Room")
0214                     icon.name: "go-previous"
0215                     onClicked: {
0216                         RoomManager.leaveRoom(room)
0217                         drawer.close()
0218                     }
0219                     Layout.fillWidth: true
0220                 }
0221             }
0222 
0223             onClosed: root.closed()
0224         }
0225     }
0226 
0227     asynchronous: true
0228     sourceComponent: Kirigami.Settings.isMobile ? mobileMenu : regularMenu
0229 
0230     function open() {
0231         active = true;
0232     }
0233 
0234     onStatusChanged: if (status == Loader.Ready) {
0235         if (Kirigami.Settings.isMobile) {
0236             item.open();
0237         } else {
0238             item.popup();
0239         }
0240     }
0241 }