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