Commit 566a671b authored by Aleix Pol Gonzalez's avatar Aleix Pol Gonzalez 🐧

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
parent ab8ea938
......@@ -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";
}
......@@ -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;
};
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment