browse button moved to separate class

This commit is contained in:
Samoilenko Yuri 2014-02-03 21:06:47 +04:00
parent 749b54c42f
commit a72547096f
3 changed files with 99 additions and 61 deletions

View file

@ -54,7 +54,7 @@ void KdeConnectDeclarativePlugin::registerTypes(const char* uri)
qmlRegisterType<NotificationsModel>("org.kde.kdeconnect", 1, 0, "NotificationsModel");
qmlRegisterType<BatteryInterface>("org.kde.kdeconnect", 1, 0, "BatteryInterface");
qmlRegisterType<DBusAsyncResponse>("org.kde.kdeconnect", 1, 0, "DBusResponse");
qmlRegisterType<DBusAsyncResponse>("org.kde.kdeconnect", 1, 0, "DBusAsyncResponse");
}
void KdeConnectDeclarativePlugin::initializeEngine(QDeclarativeEngine* engine, const char* uri)

View file

@ -0,0 +1,94 @@
/**
* Copyright 2014 Samoilenko Yuri <kinnalru@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 QtQuick 1.1
import org.kde.plasma.core 0.1 as PlasmaCore
import org.kde.plasma.components 0.1 as PlasmaComponents
import org.kde.kdeconnect 1.0
PlasmaComponents.Button
{
id: button
checkable: true
property string deviceId: ""
property variant sftp: SftpDbusInterfaceFactory.create(deviceId)
state: "UNMOUNTED"
states: [
State {
name: "UNMOUNTED"
PropertyChanges { target: button; checked: false; text: "Browse" }
},
State {
name: "MOUNTING"
PropertyChanges { target: button; checked: true; text: "Mounting..." }
},
State {
name: "MOUNTED"
PropertyChanges { target: button; checked: false; text: "Unmount" }
}
]
onClicked: {
if (state == "UNMOUNTED") {
state = "MOUNTING"
sftp.startBrowsing()
}
else if (state == "MOUNTED") {
sftp.umount()
state = "UNMOUNTED"
}
}
DBusAsyncResponse {
id: startupCheck
onSuccess: {
console.log("222SUCC:" + result)
if (result) {
button.state = "MOUNTED"
}
else {
button.state = "UNMOUNTED"
}
}
onError: {
console.log("Error:" + message)
state = "UNMOUNTED"
}
}
Component.onCompleted: {
console.log("onCompleted device:" + deviceId)
sftp.mounted.connect(function() {
browse.state = "MOUNTED"
})
sftp.unmounted.connect(function() {
browse.state = "UNMOUNTED"
})
startupCheck.pendingCall = sftp.isMounted()
}
}

View file

@ -27,38 +27,9 @@ PlasmaComponents.ListItem
{
id: root
property string deviceId: model.deviceId
property variant sftp: SftpDbusInterfaceFactory.create(deviceId)
Component.onCompleted: {
sftp.mounted.connect( function() {
browse.state = "MOUNTED"
})
sftp.unmounted.connect( function() {
console.log(222)
browse.state = "UNMOUNTED"
})
var response = DBusResponseFactory.create()
response.success.connect( function(result) {
if (result) {
browse.state = "MOUNTED"
}
else {
browse.state = "UNMOUNTED"
}
})
response.error.connect( function(message) {
console.error("Error:" + message)
state = "UNMOUNTED"
})
response.pendingCall = sftp.isMounted()
}
Column {
width: parent.width
@ -70,36 +41,9 @@ PlasmaComponents.ListItem
text: display
}
PlasmaComponents.Button {
BrowseButton {
id: browse
checkable: true
state: "UNMOUNTED"
onClicked: {
if (state == "UNMOUNTED") {
state = "MOUNTING"
sftp.startBrowsing()
}
else {
sftp.umount()
}
}
states: [
State {
name: "UNMOUNTED"
PropertyChanges { target: browse; checked: false; text: "Browse"}
},
State {
name: "MOUNTING"
PropertyChanges { target: browse; checked: true; text: "Mounting..."}
},
State {
name: "MOUNTED"
PropertyChanges { target: browse; checked: false; text: "Unmount"}
}
]
deviceId: root.deviceId
}
height: browse.height