almost work...
This commit is contained in:
parent
1d8ea764b1
commit
55c1221223
6 changed files with 72 additions and 21 deletions
|
@ -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");
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -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:
|
||||
|
|
|
@ -23,6 +23,8 @@
|
|||
#include <QtDeclarative/QDeclarativeItem>
|
||||
#include <QtDeclarative/QDeclarativeEngine>
|
||||
#include <QtDeclarative/QDeclarativeContext>
|
||||
#include <QDBusPendingCall>
|
||||
#include <QDBusPendingReply>
|
||||
|
||||
#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<QVariant>)
|
||||
Q_DECLARE_METATYPE(QDBusPendingReply<bool>)
|
||||
Q_DECLARE_METATYPE(QDBusPendingReply<QString>)
|
||||
|
||||
QObject* createSftpInterface(QVariant deviceId)
|
||||
{
|
||||
return new SyncSftpDbusInterface(deviceId.toString());
|
||||
return new SftpDbusInterface(deviceId.toString());
|
||||
}
|
||||
|
||||
const QDBusPendingCall* extractPendingCall(QVariant& variant)
|
||||
{
|
||||
if (variant.canConvert<QDBusPendingReply<> >())
|
||||
{}
|
||||
else if (variant.canConvert<QDBusPendingReply<QVariant> >())
|
||||
{}
|
||||
else if (variant.canConvert<QDBusPendingReply<bool> >())
|
||||
{}
|
||||
else if (variant.canConvert<QDBusPendingReply<QString> >())
|
||||
{}
|
||||
else
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
return reinterpret_cast<const QDBusPendingCall*>(variant.constData());
|
||||
}
|
||||
|
||||
QVariant DBusResponseWaiter::waitForReply(QVariant variant) const
|
||||
{
|
||||
if (QDBusPendingCall* call = const_cast<QDBusPendingCall*>(extractPendingCall(variant)))
|
||||
{
|
||||
call->waitForFinished();
|
||||
QDBusMessage reply = call->reply();
|
||||
|
||||
if (reply.arguments().count() > 0)
|
||||
{
|
||||
qDebug() <<reply.arguments().first();
|
||||
return reply.arguments().first();
|
||||
}
|
||||
else
|
||||
{
|
||||
return QVariant();
|
||||
}
|
||||
}
|
||||
return QVariant();
|
||||
}
|
||||
|
||||
void KdeConnectDeclarativePlugin::registerTypes(const char* uri)
|
||||
{
|
||||
Q_UNUSED(uri);
|
||||
|
||||
qRegisterMetaType<QDBusPendingReply<> >("QDBusPendingReply<>");
|
||||
qRegisterMetaType<QDBusPendingReply<QVariant> >("QDBusPendingReply<QVariant>");
|
||||
qRegisterMetaType<QDBusPendingReply<bool> >("QDBusPendingReply<bool>");
|
||||
qRegisterMetaType<QDBusPendingReply<QString> >("QDBusPendingReply<QString>");
|
||||
|
||||
qmlRegisterType<DevicesModel>("org.kde.kdeconnect", 1, 0, "DevicesModel");
|
||||
qmlRegisterType<NotificationsModel>("org.kde.kdeconnect", 1, 0, "NotificationsModel");
|
||||
qmlRegisterType<BatteryInterface>("org.kde.kdeconnect", 1, 0, "BatteryInterface");
|
||||
|
||||
//qmlRegisterUncreatableType<TestT>("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());
|
||||
}
|
||||
|
|
|
@ -24,22 +24,18 @@
|
|||
#include <QVariant>
|
||||
#include <QDeclarativeExtensionPlugin>
|
||||
|
||||
|
||||
//FIXME HACK Force some slot to be synchronous
|
||||
#include <libkdeconnect/dbusinterfaces.h>
|
||||
|
||||
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
|
||||
|
|
|
@ -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()
|
||||
|
|
Loading…
Reference in a new issue