Warning, /plasma/bluedevil/src/applet/package/contents/ui/FullRepresentation.qml is written in an unsupported language. File is not indexed.

0001 /*
0002     SPDX-FileCopyrightText: 2013-2014 Jan Grulich <jgrulich@redhat.com>
0003     SPDX-FileCopyrightText: 2014-2015 David Rosca <nowrep@gmail.com>
0004 
0005     SPDX-License-Identifier: LGPL-2.1-only OR LGPL-3.0-only OR LicenseRef-KDE-Accepted-LGPL
0006 */
0007 
0008 import QtQuick 2.15
0009 import QtQuick.Controls 2.15
0010 
0011 import org.kde.plasma.components 3.0 as PlasmaComponents3
0012 import org.kde.kirigami 2.20 as Kirigami
0013 import org.kde.ksvg 1.0 as KSvg
0014 import org.kde.plasma.extras 2.0 as PlasmaExtras
0015 import org.kde.plasma.plasmoid 2.0
0016 import org.kde.plasma.private.bluetooth as PlasmaBt
0017 
0018 import org.kde.bluezqt 1.0 as BluezQt
0019 
0020 PlasmaExtras.Representation {
0021     id: root
0022 
0023     readonly property bool emptyList: btManager.devices.length === 0
0024 
0025     implicitWidth: Kirigami.Units.gridUnit * 24
0026     implicitHeight: Kirigami.Units.gridUnit * 24
0027 
0028     focus: true
0029     collapseMarginsHint: true
0030 
0031     Keys.onDownPressed: {
0032         if (listView.count === 0) {
0033             return;
0034         }
0035         if (listView.currentIndex < 0 || toolbar.onSwitch.activeFocus) {
0036             listView.incrementCurrentIndex();
0037             listView.currentItem.forceActiveFocus();
0038         } else {
0039             event.accepted = false;
0040         }
0041     }
0042 
0043     Action {
0044         id: addBluetoothDeviceAction
0045 
0046         enabled: root.emptyList
0047 
0048         text: bluetoothApplet.addDeviceAction.text
0049         icon.name: "list-add-symbolic"
0050 
0051         onTriggered: bluetoothApplet.addDeviceAction.trigger()
0052     }
0053 
0054     Action {
0055         id: enableBluetoothAction
0056 
0057         enabled: btManager.bluetoothBlocked
0058 
0059         text: i18n("Enable")
0060         icon.name: "preferences-system-bluetooth-symbolic"
0061 
0062         onTriggered: bluetoothApplet.toggleBluetooth()
0063     }
0064 
0065     header: Toolbar {
0066         id: toolbar
0067         visible: btManager.adapters.length > 0
0068         focus: true
0069     }
0070 
0071     PlasmaComponents3.ScrollView {
0072         id: scrollView
0073         anchors.fill: parent
0074 
0075         // HACK: workaround for https://bugreports.qt.io/browse/QTBUG-83890
0076         PlasmaComponents3.ScrollBar.horizontal.policy: PlasmaComponents3.ScrollBar.AlwaysOff
0077 
0078         contentWidth: availableWidth - contentItem.leftMargin - contentItem.rightMargin
0079 
0080         contentItem: ListView {
0081             id: listView
0082             readonly property var devicesModel: PlasmaBt.DevicesProxyModel {
0083                 id: devicesModel
0084                 sourceModel: BluezQt.DevicesModel { }
0085             }
0086             model: btManager.adapters.length > 0 && !btManager.bluetoothBlocked ? devicesModel : null
0087             currentIndex: -1
0088             boundsBehavior: Flickable.StopAtBounds
0089             topMargin: Kirigami.Units.smallSpacing * 2
0090             bottomMargin: Kirigami.Units.smallSpacing * 2
0091             leftMargin: Kirigami.Units.smallSpacing * 2
0092             rightMargin: Kirigami.Units.smallSpacing * 2
0093             spacing: Kirigami.Units.smallSpacing
0094 
0095             section.property: "Section"
0096             // We want to hide the section delegate for the "Connected"
0097             // group because it's unnecessary; all we want to do here is
0098             // separate the connected devices from the available ones
0099             section.delegate: Loader {
0100                 active: section !== "Connected" && bluetoothApplet.connectedDevices.length > 0
0101                 // Need to manually set the height or else the loader takes up
0102                 // space after the first time it unloads a previously-loaded item
0103                 height: active ? Kirigami.Units.gridUnit : 0
0104 
0105                 // give us 2 frames to try and figure out a layout, this reduces jumpyness quite a bit but doesn't
0106                 // entirely eliminate it https://bugs.kde.org/show_bug.cgi?id=438610
0107                 Behavior on height { PropertyAnimation { duration: 32 } }
0108 
0109                 sourceComponent: Item {
0110                     width: listView.width - Kirigami.Units.smallSpacing * 4
0111                     height: Kirigami.Units.gridUnit
0112 
0113                     KSvg.SvgItem {
0114                         width: parent.width - Kirigami.Units.gridUnit * 2
0115                         anchors.centerIn: parent
0116                         id: separatorLine
0117                         imagePath: "widgets/line"
0118                         elementId: "horizontal-line"
0119                     }
0120                 }
0121             }
0122             highlight: PlasmaExtras.Highlight {}
0123             highlightMoveDuration: 0
0124             highlightResizeDuration: 0
0125             delegate: DeviceItem {}
0126 
0127             Keys.onUpPressed: {
0128                 if (listView.currentIndex === 0) {
0129                     listView.currentIndex = -1;
0130                     toolbar.onSwitch.forceActiveFocus(Qt.BacktabFocusReason);
0131                 } else {
0132                     event.accepted = false;
0133                 }
0134             }
0135 
0136             Loader {
0137                 anchors.centerIn: parent
0138                 width: parent.width - (4 * Kirigami.Units.gridUnit)
0139                 active: BluezQt.Manager.rfkill.state === BluezQt.Rfkill.Unknown || btManager.bluetoothBlocked || root.emptyList
0140                 sourceComponent: PlasmaExtras.PlaceholderMessage {
0141                     iconName: BluezQt.Manager.rfkill.state === BluezQt.Rfkill.Unknown || btManager.bluetoothBlocked ? "network-bluetooth" : "edit-none"
0142 
0143                     text: {
0144                         // We cannot use the adapter count here because that can be zero when
0145                         // bluetooth is disabled even when there are physical devices
0146                         if (BluezQt.Manager.rfkill.state === BluezQt.Rfkill.Unknown) {
0147                             return i18n("No Bluetooth adapters available");
0148                         } else if (btManager.bluetoothBlocked) {
0149                             return i18n("Bluetooth is disabled");
0150                         } else if (root.emptyList) {
0151                             return i18n("No devices found");
0152                         } else {
0153                             return "";
0154                         }
0155                     }
0156 
0157                     helpfulAction: {
0158                         if (BluezQt.Manager.rfkill.state === BluezQt.Rfkill.Unknown) {
0159                             return null;
0160                         } else if (btManager.bluetoothBlocked) {
0161                             return enableBluetoothAction;
0162                         } else if (root.emptyList) {
0163                             return addBluetoothDeviceAction;
0164                         } else {
0165                             return null;
0166                         }
0167                     }
0168                 }
0169             }
0170         }
0171     }
0172 }