diff --git a/kded/daemon.cpp b/kded/daemon.cpp index fd4d60352..7f1a1579b 100644 --- a/kded/daemon.cpp +++ b/kded/daemon.cpp @@ -94,7 +94,7 @@ Daemon::Daemon(QObject *parent) : QObject(parent) //Load backends (hardcoded by now, should be plugins in a future) mLinkProviders.insert(new LanLinkProvider()); -// mLinkProviders.insert(new LoopbackLinkProvider()); + mLinkProviders.insert(new LoopbackLinkProvider()); //Read remebered paired devices const KConfigGroup& known = config->group("trusted_devices"); diff --git a/kded/plugins/sftp/sftpplugin.cpp b/kded/plugins/sftp/sftpplugin.cpp index efa5fea3b..8c39f806c 100644 --- a/kded/plugins/sftp/sftpplugin.cpp +++ b/kded/plugins/sftp/sftpplugin.cpp @@ -130,12 +130,13 @@ bool SftpPlugin::isMounted() return m_d->mounter; } -void SftpPlugin::startBrowsing() +bool SftpPlugin::startBrowsing() { if (mountAndWait()) { - new KRun(KUrl::fromLocalFile(mountPoint()), 0); + return new KRun(KUrl::fromLocalFile(mountPoint()), 0); } + return false; } bool SftpPlugin::receivePackage(const NetworkPackage& np) diff --git a/kded/plugins/sftp/sftpplugin.h b/kded/plugins/sftp/sftpplugin.h index abfc29991..7035fa11c 100644 --- a/kded/plugins/sftp/sftpplugin.h +++ b/kded/plugins/sftp/sftpplugin.h @@ -56,7 +56,7 @@ public Q_SLOTS: Q_SCRIPTABLE bool mountAndWait(); Q_SCRIPTABLE bool isMounted(); - Q_SCRIPTABLE void startBrowsing(); + Q_SCRIPTABLE bool startBrowsing(); Q_SCRIPTABLE QString mountPoint(); private Q_SLOTS: diff --git a/plasmoid/declarativeplugin/kdeconnectdeclarativeplugin.cpp b/plasmoid/declarativeplugin/kdeconnectdeclarativeplugin.cpp index b85f2cffc..03916503a 100644 --- a/plasmoid/declarativeplugin/kdeconnectdeclarativeplugin.cpp +++ b/plasmoid/declarativeplugin/kdeconnectdeclarativeplugin.cpp @@ -23,6 +23,8 @@ #include #include #include +#include +#include #include "libkdeconnect/devicesmodel.h" #include "libkdeconnect/notificationsmodel.h" @@ -30,21 +32,68 @@ Q_EXPORT_PLUGIN2(kdeconnectdeclarativeplugin, KdeConnectDeclarativePlugin); +// Q_DECLARE_METATYPE(QDBusPendingCall) +Q_DECLARE_METATYPE(QDBusPendingReply<>) +Q_DECLARE_METATYPE(QDBusPendingReply) +Q_DECLARE_METATYPE(QDBusPendingReply) +Q_DECLARE_METATYPE(QDBusPendingReply) QObject* createSftpInterface(QVariant deviceId) { - return new SyncSftpDbusInterface(deviceId.toString()); + return new SftpDbusInterface(deviceId.toString()); +} + +const QDBusPendingCall* extractPendingCall(QVariant& variant) +{ + if (variant.canConvert >()) + {} + else if (variant.canConvert >()) + {} + else if (variant.canConvert >()) + {} + else if (variant.canConvert >()) + {} + else + { + return 0; + } + + return reinterpret_cast(variant.constData()); +} + +QVariant DBusResponseWaiter::waitForReply(QVariant variant) const +{ + if (QDBusPendingCall* call = const_cast(extractPendingCall(variant))) + { + call->waitForFinished(); + QDBusMessage reply = call->reply(); + + if (reply.arguments().count() > 0) + { + qDebug() < >("QDBusPendingReply<>"); + qRegisterMetaType >("QDBusPendingReply"); + qRegisterMetaType >("QDBusPendingReply"); + qRegisterMetaType >("QDBusPendingReply"); + qmlRegisterType("org.kde.kdeconnect", 1, 0, "DevicesModel"); qmlRegisterType("org.kde.kdeconnect", 1, 0, "NotificationsModel"); qmlRegisterType("org.kde.kdeconnect", 1, 0, "BatteryInterface"); - - //qmlRegisterUncreatableType("org.kde.kdeconnect", 1, 0, "SftpDbusInterface", "no create"); } void KdeConnectDeclarativePlugin::initializeEngine(QDeclarativeEngine* engine, const char* uri) @@ -53,4 +102,7 @@ void KdeConnectDeclarativePlugin::initializeEngine(QDeclarativeEngine* engine, c engine->rootContext()->setContextProperty("SftpDbusInterfaceFactory" , new ObjectFactory(engine, createSftpInterface)); + + engine->rootContext()->setContextProperty("ResponseWaiter" + , new DBusResponseWaiter()); } diff --git a/plasmoid/declarativeplugin/kdeconnectdeclarativeplugin.h b/plasmoid/declarativeplugin/kdeconnectdeclarativeplugin.h index a6abf907b..3589fe78a 100644 --- a/plasmoid/declarativeplugin/kdeconnectdeclarativeplugin.h +++ b/plasmoid/declarativeplugin/kdeconnectdeclarativeplugin.h @@ -24,22 +24,18 @@ #include #include - -//FIXME HACK Force some slot to be synchronous -#include - -class SyncSftpDbusInterface : public SftpDbusInterface +class DBusResponseWaiter : public QObject { Q_OBJECT public: - SyncSftpDbusInterface(const QString& id) : SftpDbusInterface(id) {} - ~SyncSftpDbusInterface(){} + DBusResponseWaiter() {} - Q_INVOKABLE bool isMounted() { - return SftpDbusInterface::isMounted(); - } + virtual ~DBusResponseWaiter(){}; + + Q_INVOKABLE QVariant waitForReply(QVariant variant) const; }; + class ObjectFactory : public QObject { Q_OBJECT @@ -85,4 +81,6 @@ class KdeConnectDeclarativePlugin : public QDeclarativeExtensionPlugin + + #endif // ANALITZADECLARATIVEPLUGIN_H diff --git a/plasmoid/package/contents/ui/DeviceDelegate.qml b/plasmoid/package/contents/ui/DeviceDelegate.qml index 3cb85e75a..35f39c0a7 100644 --- a/plasmoid/package/contents/ui/DeviceDelegate.qml +++ b/plasmoid/package/contents/ui/DeviceDelegate.qml @@ -31,11 +31,12 @@ PlasmaComponents.ListItem Component.onCompleted: { sftp = SftpDbusInterfaceFactory.create(deviceId) - console.debug("hello") - //console.debug(sftp.isMounted()) - if (sftp.isMounted()) { + if (ResponseWaiter.waitForReply(sftp.isMounted())) { browse.state = "MOUNTED" } + + console.debug(ResponseWaiter.waitForReply(sftp.mountPoint())) + } Column { @@ -57,7 +58,6 @@ PlasmaComponents.ListItem if (state == "UNMOUNTED") { sftp.startBrowsing() state = "MOUNTED" - console.debug(sftp.mountPoint()) } else { sftp.umount()