diff --git a/plugins/share/shareplugin.h b/plugins/share/shareplugin.h --- a/plugins/share/shareplugin.h +++ b/plugins/share/shareplugin.h @@ -38,6 +38,7 @@ ///Helper method, QDBus won't recognize QUrl Q_SCRIPTABLE void shareUrl(const QString& url) { shareUrl(QUrl(url)); } + Q_SCRIPTABLE void openFile(const QString& file) { openFile(QUrl(file)); } bool receivePacket(const NetworkPacket& np) override; void connected() override {} @@ -52,6 +53,8 @@ private: void shareUrl(const QUrl& url); + void openFile(const QUrl& url); + QUrl destinationDir() const; diff --git a/plugins/share/shareplugin.cpp b/plugins/share/shareplugin.cpp --- a/plugins/share/shareplugin.cpp +++ b/plugins/share/shareplugin.cpp @@ -166,6 +166,19 @@ sendPacket(packet); } +void SharePlugin::openFile(const QUrl& url) +{ + NetworkPacket packet(PACKET_TYPE_SHARE_REQUEST); + if(url.isLocalFile()) { + QSharedPointer ioFile(new QFile(url.toLocalFile())); + packet.setPayload(ioFile, ioFile->size()); + packet.set(QStringLiteral("filename"), QUrl(url).fileName()); + packet.set(QStringLiteral("open"), true); + } + sendPacket(packet); +} + + QString SharePlugin::dbusPath() const { return "/modules/kdeconnect/devices/" + device()->id() + "/share"; diff --git a/urlhandler/kdeconnect-handler.cpp b/urlhandler/kdeconnect-handler.cpp --- a/urlhandler/kdeconnect-handler.cpp +++ b/urlhandler/kdeconnect-handler.cpp @@ -93,17 +93,22 @@ if (urlToShare.scheme() == QLatin1String("tel")) { uidialog.label->setText(i18n("Device to call this phone number with:")); uidialog.urlLabel->setText(urlToShare.toDisplayString(QUrl::RemoveScheme)); - } else { + } else if (urlToShare.isLocalFile()) { + uidialog.label->setText(i18n("Device to open this file with:")); + uidialog.urlLabel->setText(urlToShare.toDisplayString(QUrl::PreferLocalFile)); + } + else { uidialog.urlLabel->setText(urlToShare.toDisplayString()); } if (dialog.exec() == QDialog::Accepted) { QUrl url = urlToShare; const int currentDeviceIndex = uidialog.devicePicker->currentIndex(); if(!url.isEmpty() && currentDeviceIndex >= 0) { const QString device = proxyModel.index(currentDeviceIndex, 0).data(DevicesModel::IdModelRole).toString(); + const QString action = url.isLocalFile() ? QStringLiteral("openFile") : QStringLiteral("shareUrl"); - QDBusMessage msg = QDBusMessage::createMethodCall(QStringLiteral("org.kde.kdeconnect"), "/modules/kdeconnect/devices/"+device+"/share", QStringLiteral("org.kde.kdeconnect.device.share"), QStringLiteral("shareUrl")); + QDBusMessage msg = QDBusMessage::createMethodCall(QStringLiteral("org.kde.kdeconnect"), "/modules/kdeconnect/devices/"+device+"/share", QStringLiteral("org.kde.kdeconnect.device.share"), action); msg.setArguments({ url.toString() }); blockOnReply(QDBusConnection::sessionBus().asyncCall(msg)); return 0;