Introduce QML component to check for plugin availability
Remove those checks from three different places and put them into a reusable component, which can be used for different plugins. REVIEW: 127583
This commit is contained in:
parent
aefa51fa86
commit
8d7dad3604
4 changed files with 69 additions and 49 deletions
|
@ -27,9 +27,14 @@ QtObject {
|
||||||
|
|
||||||
id: root
|
id: root
|
||||||
|
|
||||||
property string deviceId: ""
|
property alias deviceId: checker.deviceId
|
||||||
property variant device: DeviceDbusInterfaceFactory.create(deviceId)
|
readonly property alias device: checker.device
|
||||||
property bool available: false
|
readonly property alias available: checker.available
|
||||||
|
|
||||||
|
readonly property PluginChecker pluginChecker: PluginChecker {
|
||||||
|
id: checker
|
||||||
|
pluginName: "battery"
|
||||||
|
}
|
||||||
|
|
||||||
property bool charging: false
|
property bool charging: false
|
||||||
property int charge: -1
|
property int charge: -1
|
||||||
|
@ -48,7 +53,6 @@ QtObject {
|
||||||
onSuccess: root.charge = result
|
onSuccess: root.charge = result
|
||||||
}
|
}
|
||||||
|
|
||||||
// Note: magically called by qml
|
|
||||||
onAvailableChanged: {
|
onAvailableChanged: {
|
||||||
if (available) {
|
if (available) {
|
||||||
battery = DeviceBatteryDbusInterfaceFactory.create(deviceId)
|
battery = DeviceBatteryDbusInterfaceFactory.create(deviceId)
|
||||||
|
@ -62,19 +66,4 @@ QtObject {
|
||||||
battery = null
|
battery = null
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function pluginsChanged() {
|
|
||||||
var result = DBusResponseWaiter.waitForReply(device.hasPlugin("kdeconnect_battery"))
|
|
||||||
|
|
||||||
if (result && result != "error") {
|
|
||||||
available = true
|
|
||||||
} else {
|
|
||||||
available = false
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
Component.onCompleted: {
|
|
||||||
device.pluginsChanged.connect(pluginsChanged)
|
|
||||||
device.pluginsChanged()
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -27,9 +27,14 @@ QtObject {
|
||||||
|
|
||||||
id: root
|
id: root
|
||||||
|
|
||||||
property string deviceId: ""
|
property alias deviceId: checker.deviceId
|
||||||
property variant device: DeviceDbusInterfaceFactory.create(deviceId)
|
readonly property alias device: checker.device
|
||||||
property bool available: false
|
readonly property alias available: checker.available
|
||||||
|
|
||||||
|
readonly property PluginChecker pluginChecker: PluginChecker {
|
||||||
|
id: checker
|
||||||
|
pluginName: "findmyphone"
|
||||||
|
}
|
||||||
|
|
||||||
property variant findMyPhone: null
|
property variant findMyPhone: null
|
||||||
|
|
||||||
|
@ -39,12 +44,6 @@ QtObject {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Component.onCompleted: {
|
|
||||||
device.pluginsChanged.connect(pluginsChanged)
|
|
||||||
pluginsChanged()
|
|
||||||
}
|
|
||||||
|
|
||||||
// Note: magically called by qml
|
|
||||||
onAvailableChanged: {
|
onAvailableChanged: {
|
||||||
if (available) {
|
if (available) {
|
||||||
findMyPhone = FindMyPhoneDbusInterfaceFactory.create(deviceId)
|
findMyPhone = FindMyPhoneDbusInterfaceFactory.create(deviceId)
|
||||||
|
@ -52,10 +51,4 @@ QtObject {
|
||||||
findMyPhone = null
|
findMyPhone = null
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function pluginsChanged() {
|
|
||||||
var result = DBusResponseWaiter.waitForReply(device.hasPlugin("kdeconnect_findmyphone"))
|
|
||||||
available = (result && result != "error");
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
45
plasmoid/package/contents/ui/PluginChecker.qml
Normal file
45
plasmoid/package/contents/ui/PluginChecker.qml
Normal file
|
@ -0,0 +1,45 @@
|
||||||
|
/**
|
||||||
|
* Copyright 2014 Samoilenko Yuri <kinnalru@gmail.com>
|
||||||
|
* Copyright 2016 David Kahles <david.kahles96@gmail.com>
|
||||||
|
*
|
||||||
|
* This program is free software; you can redistribute it and/or
|
||||||
|
* modify it under the terms of the GNU General Public License as
|
||||||
|
* published by the Free Software Foundation; either version 2 of
|
||||||
|
* the License or (at your option) version 3 or any later version
|
||||||
|
* accepted by the membership of KDE e.V. (or its successor approved
|
||||||
|
* by the membership of KDE e.V.), which shall act as a proxy
|
||||||
|
* defined in Section 14 of version 3 of the license.
|
||||||
|
*
|
||||||
|
* This program is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
* GNU General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU General Public License
|
||||||
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
import QtQml 2.2
|
||||||
|
import org.kde.kdeconnect 1.0
|
||||||
|
|
||||||
|
QtObject {
|
||||||
|
|
||||||
|
id: root
|
||||||
|
|
||||||
|
property string deviceId: ""
|
||||||
|
property string pluginName: ""
|
||||||
|
readonly property variant device: DeviceDbusInterfaceFactory.create(deviceId)
|
||||||
|
property bool available: false
|
||||||
|
|
||||||
|
property Connections connection: Connections {
|
||||||
|
target: device
|
||||||
|
onPluginsChanged: pluginsChanged()
|
||||||
|
}
|
||||||
|
|
||||||
|
Component.onCompleted: pluginsChanged()
|
||||||
|
|
||||||
|
function pluginsChanged() {
|
||||||
|
var result = DBusResponseWaiter.waitForReply(device.hasPlugin("kdeconnect_" + pluginName))
|
||||||
|
available = (result && result != "error");
|
||||||
|
}
|
||||||
|
}
|
|
@ -27,9 +27,14 @@ QtObject {
|
||||||
|
|
||||||
id: root
|
id: root
|
||||||
|
|
||||||
property string deviceId: ""
|
property alias deviceId: checker.deviceId
|
||||||
property variant device: DeviceDbusInterfaceFactory.create(deviceId)
|
readonly property alias device: checker.device
|
||||||
property bool available: false
|
readonly property alias available: checker.available
|
||||||
|
|
||||||
|
readonly property PluginChecker pluginChecker: PluginChecker {
|
||||||
|
id: checker
|
||||||
|
pluginName: "sftp"
|
||||||
|
}
|
||||||
|
|
||||||
property variant sftp: null
|
property variant sftp: null
|
||||||
|
|
||||||
|
@ -38,12 +43,6 @@ QtObject {
|
||||||
sftp.startBrowsing();
|
sftp.startBrowsing();
|
||||||
}
|
}
|
||||||
|
|
||||||
Component.onCompleted: {
|
|
||||||
device.pluginsChanged.connect(pluginsChanged)
|
|
||||||
pluginsChanged()
|
|
||||||
}
|
|
||||||
|
|
||||||
// Note: magically called by qml
|
|
||||||
onAvailableChanged: {
|
onAvailableChanged: {
|
||||||
if (available) {
|
if (available) {
|
||||||
sftp = SftpDbusInterfaceFactory.create(deviceId)
|
sftp = SftpDbusInterfaceFactory.create(deviceId)
|
||||||
|
@ -51,10 +50,4 @@ QtObject {
|
||||||
sftp = null
|
sftp = null
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function pluginsChanged() {
|
|
||||||
var result = DBusResponseWaiter.waitForReply(device.hasPlugin("kdeconnect_sftp"))
|
|
||||||
available = (result && result != "error");
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue