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

0001 // SPDX-FileCopyrightText: 2020 - 2023 Tobias Fella <tobias.fella@kde.org>
0002 // SPDX-FileCopyrightText: 2022 James Graham <james.h.graham@protonmail.com>
0003 // SPDX-License-Identifier: GPL-2.0-or-later
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.formcard as FormCard
0011 
0012 import org.kde.neochat
0013 
0014 FormCard.AbstractFormDelegate {
0015     id: root
0016 
0017     required property string id
0018     required property string timestamp
0019     required property string displayName
0020 
0021     property bool editDeviceName: false
0022     property bool showVerifyButton
0023 
0024     onClicked: root.editDeviceName = true
0025 
0026     contentItem: RowLayout {
0027         spacing: Kirigami.Units.largeSpacing
0028 
0029         Kirigami.Icon {
0030             source: "network-connect"
0031             implicitWidth: Kirigami.Units.iconSizes.medium
0032             implicitHeight: Kirigami.Units.iconSizes.medium
0033         }
0034         ColumnLayout {
0035             id: deviceLabel
0036             Layout.fillWidth: true
0037             spacing: Kirigami.Units.smallSpacing
0038             visible: !root.editDeviceName
0039 
0040             QQC2.Label {
0041                 Layout.fillWidth: true
0042                 text: root.displayName
0043                 elide: Text.ElideRight
0044                 wrapMode: Text.Wrap
0045                 maximumLineCount: 2
0046             }
0047 
0048             QQC2.Label {
0049                 Layout.fillWidth: true
0050                 text: i18nc("@label", "%1, Last activity: %2", root.id, root.timestamp)
0051                 color: Kirigami.Theme.disabledTextColor
0052                 font: Kirigami.Theme.smallFont
0053                 elide: Text.ElideRight
0054                 visible: text.length > 0
0055             }
0056         }
0057         Kirigami.ActionTextField {
0058             id: nameField
0059             Accessible.description: i18n("New device name")
0060             Layout.fillWidth: true
0061             Layout.preferredHeight: deviceLabel.implicitHeight
0062             visible: root.editDeviceName
0063 
0064             text: root.displayName
0065 
0066             rightActions: [
0067                 Kirigami.Action {
0068                     text: i18n("Cancel editing display name")
0069                     icon.name: "edit-delete-remove"
0070                     onTriggered: {
0071                         root.editDeviceName = false;
0072                     }
0073                 },
0074                 Kirigami.Action {
0075                     text: i18n("Confirm new display name")
0076                     icon.name: "checkmark"
0077                     visible: nameField.text !== root.displayName
0078                     onTriggered: {
0079                         devicesModel.setName(root.id, nameField.text);
0080                     }
0081                 }
0082             ]
0083 
0084             onAccepted: devicesModel.setName(root.id, nameField.text)
0085         }
0086         QQC2.ToolButton {
0087             display: QQC2.AbstractButton.IconOnly
0088             action: Kirigami.Action {
0089                 id: editDeviceAction
0090                 text: i18n("Edit device name")
0091                 icon.name: "document-edit"
0092                 onTriggered: root.editDeviceName = true
0093             }
0094             QQC2.ToolTip {
0095                 text: editDeviceAction.text
0096                 delay: Kirigami.Units.toolTipDelay
0097             }
0098         }
0099         QQC2.ToolButton {
0100             display: QQC2.AbstractButton.IconOnly
0101             visible: root.showVerifyButton
0102             action: Kirigami.Action {
0103                 id: verifyDeviceAction
0104                 text: i18n("Verify device")
0105                 icon.name: "security-low-symbolic"
0106                 onTriggered: {
0107                     devicesModel.connection.startKeyVerificationSession(devicesModel.connection.localUserId, root.id);
0108                 }
0109             }
0110             QQC2.ToolTip {
0111                 text: verifyDeviceAction.text
0112                 delay: Kirigami.Units.toolTipDelay
0113             }
0114         }
0115         QQC2.ToolButton {
0116             display: QQC2.AbstractButton.IconOnly
0117             action: Kirigami.Action {
0118                 id: logoutDeviceAction
0119                 text: i18n("Logout device")
0120                 icon.name: "edit-delete-remove"
0121                 onTriggered: {
0122                     passwordSheet.deviceId = root.id;
0123                     passwordSheet.open();
0124                 }
0125             }
0126             QQC2.ToolTip {
0127                 text: logoutDeviceAction.text
0128                 delay: Kirigami.Units.toolTipDelay
0129             }
0130         }
0131     }
0132 }