Warning, /plasma/plasma-thunderbolt/src/kcm/ui/DeviceView.qml is written in an unsupported language. File is not indexed.

0001 /*
0002  * SPDX-FileCopyrightText: 2018-2019 Daniel Vrátil <dvratil@kde.org>
0003  *
0004  * SPDX-License-Identifier: GPL-2.0-only OR GPL-3.0-only OR LicenseRef-KDE-Accepted-GPL
0005  */
0006 
0007 import QtQuick 2.7
0008 import QtQuick.Layouts 1.1
0009 import QtQuick.Controls 2.3
0010 
0011 import org.kde.kirigami 2.4 as Kirigami
0012 import org.kde.bolt 0.1 as Bolt
0013 import "utils.js" as Utils
0014 
0015 Kirigami.ScrollablePage {
0016     id: page
0017 
0018     property Bolt.Manager manager: null
0019     property Bolt.Device device: null
0020 
0021     property int _evalTrigger: 0
0022 
0023     Timer {
0024         interval: 2000
0025         running: device != null
0026         repeat: true
0027         onTriggered: page._evalTrigger++;
0028     }
0029 
0030     ColumnLayout {
0031         spacing: Kirigami.Units.smallSpacing * 5
0032 
0033         RowLayout {
0034             Button {
0035                 icon.name: "draw-arrow-back"
0036                 visible: !pageRow.wideMode
0037                 onClicked: pageRow.pop()
0038             }
0039 
0040             Kirigami.Heading {
0041                 level: 2
0042                 text: _evalTrigger, device ? device.name : ""
0043             }
0044         }
0045 
0046         Kirigami.InlineMessage {
0047             id: errorMessage
0048 
0049             Layout.fillWidth: true
0050 
0051             type: Kirigami.MessageType.Error
0052             showCloseButton: true
0053 
0054             function show(msg) {
0055                 text = msg;
0056                 visible = true;
0057             }
0058         }
0059 
0060         Kirigami.FormLayout {
0061             Label {
0062                 text: _evalTrigger, device ? device.vendor : ""
0063                 Kirigami.FormData.label: i18n("Vendor:")
0064             }
0065             Label {
0066                 text: _evalTrigger, device ? device.uid : ""
0067                 Kirigami.FormData.label: i18n("UID:")
0068             }
0069             Label {
0070                 text: _evalTrigger, device ? Utils.deviceStatus(device, false).text : ""
0071                 Kirigami.FormData.label: i18n("Status:")
0072             }
0073             Label {
0074                 visible: device && device.status == Bolt.Bolt.Status.Authorized
0075                 text: _evalTrigger, device ? Qt.formatDateTime(device.authorizeTime) : ""
0076                 Kirigami.FormData.label: i18n("Authorized at:")
0077             }
0078             Label {
0079                 visible: device && device.status == Bolt.Bolt.Status.Connected
0080                 text: _evalTrigger, device ? Qt.formatDateTime(device.connectTime) : ""
0081                 Kirigami.FormData.label: i18n("Connected at:")
0082             }
0083             Label {
0084                 visible: device && device.status == Bolt.Bolt.Status.Disconnected
0085                 text: _evalTrigger, device ? Qt.formatDateTime(device.storeTime) : ""
0086                 Kirigami.FormData.label: i18n("Enrolled at:")
0087             }
0088             Label {
0089                 visible: device && (device.status == Bolt.Bolt.Status.Authorized || device.status == Bolt.Bolt.Status.Disconnected)
0090                 text: _evalTrigger, device && device.stored ? i18n("Yes") : i18n("No")
0091                 Kirigami.FormData.label: i18n("Trusted:")
0092             }
0093         }
0094 
0095         RowLayout {
0096             Layout.alignment: Qt.AlignHCenter
0097 
0098             Button {
0099                 id: authorizeBtn
0100                 text: device && device.status == Bolt.Bolt.Status.Authorizing ? i18n("Authorizing...") : i18n("Authorize")
0101                 enabled: device && device.status != Bolt.Bolt.Status.Authorizing
0102                 visible: device && (device.status == Bolt.Bolt.Status.Connected || device.status == Bolt.Bolt.Status.AuthError)
0103                 onClicked: {
0104                     Bolt.QMLHelper.enrollDevice(
0105                         manager, device.uid, Bolt.Bolt.Policy.Default,
0106                         Bolt.Bolt.Auth.Boot | Bolt.Bolt.Auth.NoKey,
0107                         function() {
0108                             console.log("Thunderbolt device " + device.uid + " (" + device.name + ") enrolled successfully");
0109                         },
0110                         function(error) {
0111                             errorMessage.show(i18n("Failed to enroll device <b>%1</b>: %2", device.name, error));
0112                         }
0113                     );
0114                 }
0115             }
0116             Button {
0117                 id: storeBtn
0118                 text: i18n("Trust this Device")
0119                 visible: device && device.status == Bolt.Bolt.Status.Authorized && device.stored == false
0120                 onClicked: {
0121                     enabled = false;
0122                     Bolt.QMLHelper.enrollDevice(
0123                         manager, device.uid, Bolt.Bolt.Policy.Default,
0124                         Bolt.Bolt.Auth.Boot | Bolt.Bolt.Auth.NoKey,
0125                         function() {
0126                             enabled = true;
0127                             console.log("Thunderbolt Device " + device.uid + " (" + device.name + ") enrolled successfully");
0128                         },
0129                         function(error) {
0130                             enabled = true;
0131                             errorMessage.show(i18n("Failed to enroll device <b>%1</b>: %2", device.name, error));
0132                         }
0133                     );
0134                 }
0135             }
0136 
0137             Button {
0138                 id: forgetBtn
0139                 text: i18n("Revoke Trust")
0140                 visible: device && device.stored
0141                 onClicked: {
0142                     enabled = false
0143                     Bolt.QMLHelper.forgetDevice(
0144                         manager, device.uid,
0145                         function() {
0146                             enabled = true;
0147                             console.log("Device " + device.uid + " successfully forgotten.");
0148                         },
0149                         function(error) {
0150                             enabled = true;
0151                             errorMessage.show(i18n("Error changing device trust: <b>%1</b>: %2", device.name, error));
0152                         }
0153                     );
0154                     // If the device is not connected it will cease to exist
0155                     // once forgotten, so we should pop this view
0156                     if (device.status == Bolt.Bolt.Status.Disconnected) {
0157                         pageRow.pop();
0158                     }
0159                 }
0160             }
0161         }
0162 
0163         Label {
0164             Layout.alignment: Qt.AlignHCenter
0165             Layout.fillWidth: true
0166 
0167             text: device && !device.stored
0168                 ? i18n("Hint: trusted device will be automatically authorized the next time it is connected to the computer.")
0169                 : i18n("Hint: an untrusted device needs to be manually authorized each time it is connected to the computer.")
0170             visible: storeBtn.visible || forgetBtn.visible
0171             wrapMode: Text.WordWrap
0172             horizontalAlignment: Qt.AlignHCenter
0173         }
0174     }
0175 }