Make it possible to send files from the kded plugin

Expose the share plugin on dbus
Add a shareUrl method that will send the file if it's a local url and just
send a URL otherwise.

REVIEW: 113344
This commit is contained in:
Aleix Pol 2014-03-03 04:53:11 +01:00
parent ab8ea93812
commit 566a671b15
2 changed files with 32 additions and 3 deletions

View file

@ -30,6 +30,7 @@
#include <qprocess.h>
#include <QDir>
#include <QDesktopServices>
#include <QDBusConnection>
#include "../../kdebugnamespace.h"
#include "../../filetransferjob.h"
@ -41,7 +42,6 @@ K_EXPORT_PLUGIN( KdeConnectPluginFactory("kdeconnect_share", "kdeconnect-kded")
SharePlugin::SharePlugin(QObject* parent, const QVariantList& args)
: KdeConnectPlugin(parent, args)
{
}
KUrl SharePlugin::destinationDir() const
@ -140,3 +140,26 @@ void SharePlugin::openDestinationFolder()
{
QDesktopServices::openUrl(destinationDir());
}
void SharePlugin::shareUrl(const QUrl& url)
{
NetworkPackage package(PACKAGE_TYPE_SHARE);
if(url.isLocalFile()) {
QSharedPointer<QIODevice> ioFile(new QFile(url.toLocalFile()));
package.setPayload(ioFile, ioFile->size());
package.set<QString>("filename", KUrl(url).fileName());
} else {
package.set<QString>("url", url.toString());
}
device()->sendPackage(package);
}
void SharePlugin::connected()
{
QDBusConnection::sessionBus().registerObject(dbusPath(), this, QDBusConnection::ExportAllContents);
}
QString SharePlugin::dbusPath() const
{
return "/modules/kdeconnect/devices/" + device()->id() + "/share";
}

View file

@ -32,19 +32,25 @@ class SharePlugin
: public KdeConnectPlugin
{
Q_OBJECT
Q_CLASSINFO("D-Bus Interface", "org.kde.kdeconnect.device.share")
public:
explicit SharePlugin(QObject *parent, const QVariantList &args);
///Helper method, QDBus won't recognize QUrl
Q_SCRIPTABLE void shareUrl(const QString& url) { shareUrl(QUrl(url)); }
public Q_SLOTS:
virtual bool receivePackage(const NetworkPackage& np);
virtual void connected() { }
void finished(KJob*);
virtual void connected();
private Q_SLOTS:
void finished(KJob*);
void openDestinationFolder();
private:
void shareUrl(const QUrl& url);
QString dbusPath() const;
KUrl destinationDir() const;
};