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 icon.name: "notifications"
0074
0075 QQC2.MenuItem {
0076 text: i18n("Follow Global Setting")
0077 icon.name: "globe"
0078 checkable: true
0079 autoExclusive: true
0080 checked: room.pushNotificationState === PushNotificationState.Default
0081 enabled: room.pushNotificationState != PushNotificationState.Unknown
0082 onTriggered: {
0083 room.pushNotificationState = PushNotificationState.Default;
0084 }
0085 }
0086 QQC2.MenuItem {
0087 text: i18nc("As in 'notify for all messages'", "All")
0088 icon.name: "notifications"
0089 checkable: true
0090 autoExclusive: true
0091 checked: room.pushNotificationState === PushNotificationState.All
0092 enabled: room.pushNotificationState != PushNotificationState.Unknown
0093 onTriggered: {
0094 room.pushNotificationState = PushNotificationState.All;
0095 }
0096 }
0097 QQC2.MenuItem {
0098 text: i18nc("As in 'notify when the user is mentioned or the message contains a set keyword'", "@Mentions and Keywords")
0099 icon.name: "im-user"
0100 checkable: true
0101 autoExclusive: true
0102 checked: room.pushNotificationState === PushNotificationState.MentionKeyword
0103 enabled: room.pushNotificationState != PushNotificationState.Unknown
0104 onTriggered: {
0105 room.pushNotificationState = PushNotificationState.MentionKeyword;
0106 }
0107 }
0108 QQC2.MenuItem {
0109 text: i18nc("As in 'do not notify for any messages'", "Off")
0110 icon.name: "notifications-disabled"
0111 checkable: true
0112 autoExclusive: true
0113 checked: room.pushNotificationState === PushNotificationState.Mute
0114 enabled: room.pushNotificationState != PushNotificationState.Unknown
0115 onTriggered: {
0116 room.pushNotificationState = PushNotificationState.Mute;
0117 }
0118 }
0119 }
0120
0121 QQC2.MenuItem {
0122 text: i18n("Room Settings")
0123 icon.name: "configure"
0124 onTriggered: QQC2.ApplicationWindow.window.pageStack.pushDialogLayer('qrc:/org/kde/neochat/qml/Categories.qml', {
0125 room: room,
0126 connection: connection
0127 }, {
0128 title: i18n("Room Settings")
0129 })
0130 }
0131
0132 QQC2.MenuSeparator {}
0133
0134 QQC2.MenuItem {
0135 text: i18n("Leave Room")
0136 icon.name: "go-previous"
0137 onTriggered: RoomManager.leaveRoom(room)
0138 }
0139
0140 onClosed: {
0141 root.closed();
0142 }
0143 }
0144 }
0145
0146 Component {
0147 id: mobileMenu
0148
0149 Kirigami.OverlayDrawer {
0150 id: drawer
0151
0152 parent: applicationWindow().overlay
0153 edge: Qt.BottomEdge
0154
0155 height: popupContent.implicitHeight
0156
0157 leftPadding: 0
0158 rightPadding: 0
0159 bottomPadding: 0
0160 topPadding: 0
0161
0162 ColumnLayout {
0163 id: popupContent
0164
0165 width: parent.width
0166 spacing: 0
0167
0168 RowLayout {
0169 id: headerLayout
0170 Layout.fillWidth: true
0171 Layout.margins: Kirigami.Units.largeSpacing
0172 spacing: Kirigami.Units.largeSpacing
0173 KirigamiComponents.Avatar {
0174 id: avatar
0175 source: room.avatarMediaId ? ("image://mxc/" + room.avatarMediaId) : ""
0176 name: room.displayName
0177 Layout.preferredWidth: Kirigami.Units.gridUnit * 3
0178 Layout.preferredHeight: Kirigami.Units.gridUnit * 3
0179 Layout.alignment: Qt.AlignTop
0180 }
0181 Kirigami.Heading {
0182 level: 5
0183 Layout.fillWidth: true
0184 text: room.displayName
0185 elide: Text.ElideRight
0186 }
0187 QQC2.ToolButton {
0188 checked: room.isFavourite
0189 checkable: true
0190 icon.name: 'favorite'
0191 Accessible.name: room.isFavourite ? i18n("Remove from Favourites") : i18n("Add to Favourites")
0192 onClicked: room.isFavourite ? room.removeTag("m.favourite") : room.addTag("m.favourite", 1.0)
0193 }
0194
0195 QQC2.ToolButton {
0196 icon.name: 'settings-configure'
0197 onClicked: {
0198 QQC2.ApplicationWindow.window.pageStack.pushDialogLayer('qrc:/org/kde/neochat/qml/Categories.qml', {
0199 room: room,
0200 connection: root.connection
0201 }, {
0202 title: i18n("Room Settings")
0203 });
0204 drawer.close();
0205 }
0206 }
0207 }
0208
0209 Delegates.RoundedItemDelegate {
0210 text: room.isLowPriority ? i18n("Reprioritize") : i18n("Deprioritize")
0211 icon.name: room.isLowPriority ? "arrow-up" : "arrow-down"
0212 onClicked: room.isLowPriority ? room.removeTag("m.lowpriority") : room.addTag("m.lowpriority", 1.0)
0213 Layout.fillWidth: true
0214 }
0215
0216 Delegates.RoundedItemDelegate {
0217 text: i18n("Mark as Read")
0218 icon.name: "checkmark"
0219 onClicked: room.markAllMessagesAsRead()
0220 Layout.fillWidth: true
0221 }
0222
0223 Delegates.RoundedItemDelegate {
0224 text: i18n("Leave Room")
0225 icon.name: "go-previous"
0226 onClicked: {
0227 RoomManager.leaveRoom(room);
0228 drawer.close();
0229 }
0230 Layout.fillWidth: true
0231 }
0232 }
0233
0234 onClosed: root.closed()
0235 }
0236 }
0237
0238 asynchronous: true
0239 sourceComponent: Kirigami.Settings.isMobile ? mobileMenu : regularMenu
0240
0241 function open() {
0242 active = true;
0243 }
0244
0245 onStatusChanged: if (status == Loader.Ready) {
0246 if (Kirigami.Settings.isMobile) {
0247 item.open();
0248 } else {
0249 item.popup();
0250 }
0251 }
0252 }