From a72547096f6015761781d4c2cd9ea4746a7479e0 Mon Sep 17 00:00:00 2001 From: Samoilenko Yuri Date: Mon, 3 Feb 2014 21:06:47 +0400 Subject: [PATCH] browse button moved to separate class --- .../kdeconnectdeclarativeplugin.cpp | 2 +- plasmoid/package/contents/ui/BrowseButton.qml | 94 +++++++++++++++++++ .../package/contents/ui/DeviceDelegate.qml | 64 +------------ 3 files changed, 99 insertions(+), 61 deletions(-) create mode 100644 plasmoid/package/contents/ui/BrowseButton.qml diff --git a/plasmoid/declarativeplugin/kdeconnectdeclarativeplugin.cpp b/plasmoid/declarativeplugin/kdeconnectdeclarativeplugin.cpp index 9fb0f80a5..7c63a5c13 100644 --- a/plasmoid/declarativeplugin/kdeconnectdeclarativeplugin.cpp +++ b/plasmoid/declarativeplugin/kdeconnectdeclarativeplugin.cpp @@ -54,7 +54,7 @@ void KdeConnectDeclarativePlugin::registerTypes(const char* uri) qmlRegisterType("org.kde.kdeconnect", 1, 0, "NotificationsModel"); qmlRegisterType("org.kde.kdeconnect", 1, 0, "BatteryInterface"); - qmlRegisterType("org.kde.kdeconnect", 1, 0, "DBusResponse"); + qmlRegisterType("org.kde.kdeconnect", 1, 0, "DBusAsyncResponse"); } void KdeConnectDeclarativePlugin::initializeEngine(QDeclarativeEngine* engine, const char* uri) diff --git a/plasmoid/package/contents/ui/BrowseButton.qml b/plasmoid/package/contents/ui/BrowseButton.qml new file mode 100644 index 000000000..bba9644a8 --- /dev/null +++ b/plasmoid/package/contents/ui/BrowseButton.qml @@ -0,0 +1,94 @@ +/** + * Copyright 2014 Samoilenko Yuri + * + * 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 . + */ + +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() + } + +} diff --git a/plasmoid/package/contents/ui/DeviceDelegate.qml b/plasmoid/package/contents/ui/DeviceDelegate.qml index 8851bf878..d37cfc12c 100644 --- a/plasmoid/package/contents/ui/DeviceDelegate.qml +++ b/plasmoid/package/contents/ui/DeviceDelegate.qml @@ -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