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 <qprocess.h>
#include <QDir> #include <QDir>
#include <QDesktopServices> #include <QDesktopServices>
#include <QDBusConnection>
#include "../../kdebugnamespace.h" #include "../../kdebugnamespace.h"
#include "../../filetransferjob.h" #include "../../filetransferjob.h"
@ -41,7 +42,6 @@ K_EXPORT_PLUGIN( KdeConnectPluginFactory("kdeconnect_share", "kdeconnect-kded")
SharePlugin::SharePlugin(QObject* parent, const QVariantList& args) SharePlugin::SharePlugin(QObject* parent, const QVariantList& args)
: KdeConnectPlugin(parent, args) : KdeConnectPlugin(parent, args)
{ {
} }
KUrl SharePlugin::destinationDir() const KUrl SharePlugin::destinationDir() const
@ -140,3 +140,26 @@ void SharePlugin::openDestinationFolder()
{ {
QDesktopServices::openUrl(destinationDir()); 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 : public KdeConnectPlugin
{ {
Q_OBJECT Q_OBJECT
Q_CLASSINFO("D-Bus Interface", "org.kde.kdeconnect.device.share")
public: public:
explicit SharePlugin(QObject *parent, const QVariantList &args); 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: public Q_SLOTS:
virtual bool receivePackage(const NetworkPackage& np); virtual bool receivePackage(const NetworkPackage& np);
virtual void connected() { } virtual void connected();
void finished(KJob*);
private Q_SLOTS: private Q_SLOTS:
void finished(KJob*);
void openDestinationFolder(); void openDestinationFolder();
private: private:
void shareUrl(const QUrl& url);
QString dbusPath() const;
KUrl destinationDir() const; KUrl destinationDir() const;
}; };