From a9958eca74a64c323d4bfad1ae1a7407a02e69b1 Mon Sep 17 00:00:00 2001 From: Erik Duisters Date: Sat, 26 Jan 2019 17:43:09 +0100 Subject: [PATCH] Add packet type "kdeconnect.share.request.update" to allow android to update the share notification --- core/backends/lan/compositeuploadjob.cpp | 17 +++++++++++++++++ core/backends/lan/compositeuploadjob.h | 2 ++ plugins/share/kdeconnect_share.json | 3 ++- plugins/share/shareplugin.h | 1 + 4 files changed, 22 insertions(+), 1 deletion(-) diff --git a/core/backends/lan/compositeuploadjob.cpp b/core/backends/lan/compositeuploadjob.cpp index 581cc849b..3c77a4e72 100644 --- a/core/backends/lan/compositeuploadjob.cpp +++ b/core/backends/lan/compositeuploadjob.cpp @@ -25,6 +25,7 @@ #include #include "lanlinkprovider.h" #include +#include "plugins/share/shareplugin.h" CompositeUploadJob::CompositeUploadJob(const QString& deviceId, bool displayNotification) : KCompositeJob() @@ -39,6 +40,7 @@ CompositeUploadJob::CompositeUploadJob(const QString& deviceId, bool displayNoti , m_totalSendPayloadSize(0) , m_totalPayloadSize(0) , m_currentJob(nullptr) + , m_updatePacketPending(false) { setCapabilities(Killable); @@ -204,6 +206,11 @@ bool CompositeUploadJob::addSubjob(KJob* job) emitDescription(filename); + if (m_running && !m_updatePacketPending) { + m_updatePacketPending = true; + QMetaObject::invokeMethod(this, "sendUpdatePacket", Qt::QueuedConnection); + } + return KCompositeJob::addSubjob(job); } else { qCDebug(KDECONNECT_CORE) << "CompositeUploadJob::addSubjob() - you can only add UploadJob's, ignoring"; @@ -211,6 +218,16 @@ bool CompositeUploadJob::addSubjob(KJob* job) } } +void CompositeUploadJob::sendUpdatePacket() { + NetworkPacket np(PACKET_TYPE_SHARE_REQUEST_UPDATE); + np.set(QStringLiteral("numberOfFiles"), m_totalJobs); + np.set(QStringLiteral("totalPayloadSize"), m_totalPayloadSize); + + Daemon::instance()->getDevice(m_deviceId)->sendPacket(np); + + m_updatePacketPending = false; +} + bool CompositeUploadJob::doKill() { if (m_running) { diff --git a/core/backends/lan/compositeuploadjob.h b/core/backends/lan/compositeuploadjob.h index d4d65d871..4cb588634 100644 --- a/core/backends/lan/compositeuploadjob.h +++ b/core/backends/lan/compositeuploadjob.h @@ -66,6 +66,7 @@ private: quint64 m_totalPayloadSize; UploadJob *m_currentJob; QElapsedTimer m_timer; + bool m_updatePacketPending; const static quint16 MIN_PORT = 1739; const static quint16 MAX_PORT = 1764; @@ -79,6 +80,7 @@ private Q_SLOTS: void slotProcessedAmount(KJob *job, KJob::Unit unit, qulonglong amount); void slotResult(KJob *job) override; void startNextSubJob(); + void sendUpdatePacket(); }; #endif //COMPOSITEUPLOADJOB_H diff --git a/plugins/share/kdeconnect_share.json b/plugins/share/kdeconnect_share.json index 1a23ad6a7..75ad96485 100644 --- a/plugins/share/kdeconnect_share.json +++ b/plugins/share/kdeconnect_share.json @@ -123,7 +123,8 @@ "Website": "http://albertvaka.wordpress.com" }, "X-KdeConnect-OutgoingPacketType": [ - "kdeconnect.share.request" + "kdeconnect.share.request", + "kdeconnect.share.request.update" ], "X-KdeConnect-SupportedPacketType": [ "kdeconnect.share.request" diff --git a/plugins/share/shareplugin.h b/plugins/share/shareplugin.h index 58c63459c..584cb937c 100644 --- a/plugins/share/shareplugin.h +++ b/plugins/share/shareplugin.h @@ -26,6 +26,7 @@ #include #define PACKET_TYPE_SHARE_REQUEST QStringLiteral("kdeconnect.share.request") +#define PACKET_TYPE_SHARE_REQUEST_UPDATE QStringLiteral("kdeconnect.share.request.update") class SharePlugin : public KdeConnectPlugin