Browse button on plasmoid only visible if sftp plugin enabled

This commit is contained in:
Albert Vaca 2014-02-19 16:28:17 +01:00
parent c6354f194f
commit 182da7bfc5
3 changed files with 49 additions and 23 deletions

View file

@ -28,12 +28,12 @@ QtObject {
id: root
property string deviceId: ""
property variant device: DeviceDbusInterfaceFactory.create(deviceId)
property bool available: false
property bool charging: false
property int charge: -1
property string displayString: (available && charge > -1) ? ((charging) ? (i18n("Charging, %1").arg(charge)) : (i18n("Discharging, %1").arg(charge))) : i18n("No info")
property variant device: DeviceDbusInterfaceFactory.create(deviceId)
property variant battery: null
property variant nested1: DBusAsyncResponse {
@ -48,6 +48,7 @@ QtObject {
onSuccess: root.charge = result
}
/* Note: magically called by qml */
onAvailableChanged: {
if (available) {
battery = DeviceBatteryDbusInterfaceFactory.create(deviceId)

View file

@ -36,21 +36,22 @@ PlasmaComponents.ListItem
Row
{
PlasmaComponents.Label {
width: parent.width - browse.width
width: browse.visible? parent.width - browse.width : parent.width
horizontalAlignment: Text.AlignHCenter
text: display
}
PlasmaComponents.Button
{
id: browse
iconSource: "document-open-folder"
Sftp {
id: sftp
deviceId: root.deviceId
}
id: browse
iconSource: "document-open-folder"
visible: sftp.available
onClicked: {
sftp.browse()
}
@ -122,11 +123,9 @@ PlasmaComponents.ListItem
onClicked: dbusInterface.dismiss();
}
}
//FIXME
//Repeater.onItemAdded: plasmoid.status = "NeedsAttentionStatus";
}
//TODO: Other information could be displayed here
//NOTE: More information could be displayed here
}
}

View file

@ -28,9 +28,11 @@ QtObject {
id: root
property string deviceId: ""
property bool isMounted: false
property variant sftp: SftpDbusInterfaceFactory.create(deviceId)
property variant device: DeviceDbusInterfaceFactory.create(deviceId)
property bool available: false
property bool isMounted: false
property variant sftp: null
property variant nested: DBusAsyncResponse {
id: startupCheck
onSuccess: (result) ? root.mounted() : root.unmounted()
@ -44,13 +46,6 @@ QtObject {
onMounted: isMounted = true
onUnmounted: isMounted = false
Component.onCompleted: {
sftp.mounted.connect(mounted)
sftp.unmounted.connect(unmounted)
startupCheck.setPendingCall(sftp.isMounted())
}
function browse() {
startupCheck.setPendingCall(sftp.startBrowsing())
}
@ -59,4 +54,35 @@ QtObject {
sftp.unmount()
}
Component.onCompleted: {
device.pluginsChanged.connect(pluginsChanged)
device.pluginsChanged()
}
/* Note: magically called by qml */
onAvailableChanged: {
if (available) {
sftp = SftpDbusInterfaceFactory.create(deviceId)
sftp.mounted.connect(mounted)
sftp.unmounted.connect(unmounted)
startupCheck.setPendingCall(sftp.isMounted())
}
else {
sftp = null
}
}
function pluginsChanged() {
var result = DBusResponseWaiter.waitForReply(device.hasPlugin("kdeconnect_sftp"))
if (result && result != "error") {
available = true
}
else {
available = false
}
}
}