Add packet type "kdeconnect.share.request.update" to allow android to update the share notification

This commit is contained in:
Erik Duisters 2019-01-26 17:43:09 +01:00
parent 205eb8f497
commit 0f2a60065a
4 changed files with 22 additions and 1 deletions

View file

@ -25,6 +25,7 @@
#include <KJobTrackerInterface> #include <KJobTrackerInterface>
#include "lanlinkprovider.h" #include "lanlinkprovider.h"
#include <daemon.h> #include <daemon.h>
#include "plugins/share/shareplugin.h"
CompositeUploadJob::CompositeUploadJob(const QString& deviceId, bool displayNotification) CompositeUploadJob::CompositeUploadJob(const QString& deviceId, bool displayNotification)
: KCompositeJob() : KCompositeJob()
@ -40,6 +41,7 @@ CompositeUploadJob::CompositeUploadJob(const QString& deviceId, bool displayNoti
, m_totalPayloadSize(0) , m_totalPayloadSize(0)
, m_currentJob(nullptr) , m_currentJob(nullptr)
, m_prevElapsedTime(0) , m_prevElapsedTime(0)
, m_updatePacketPending(false)
{ {
setCapabilities(Killable); setCapabilities(Killable);
@ -205,6 +207,11 @@ bool CompositeUploadJob::addSubjob(KJob* job)
emitDescription(filename); emitDescription(filename);
if (m_running && !m_updatePacketPending) {
m_updatePacketPending = true;
QMetaObject::invokeMethod(this, "sendUpdatePacket", Qt::QueuedConnection);
}
return KCompositeJob::addSubjob(job); return KCompositeJob::addSubjob(job);
} else { } else {
qCDebug(KDECONNECT_CORE) << "CompositeUploadJob::addSubjob() - you can only add UploadJob's, ignoring"; qCDebug(KDECONNECT_CORE) << "CompositeUploadJob::addSubjob() - you can only add UploadJob's, ignoring";
@ -212,6 +219,16 @@ bool CompositeUploadJob::addSubjob(KJob* job)
} }
} }
void CompositeUploadJob::sendUpdatePacket() {
NetworkPacket np(PACKET_TYPE_SHARE_REQUEST_UPDATE);
np.set<int>(QStringLiteral("numberOfFiles"), m_totalJobs);
np.set<quint64>(QStringLiteral("totalPayloadSize"), m_totalPayloadSize);
Daemon::instance()->getDevice(m_deviceId)->sendPacket(np);
m_updatePacketPending = false;
}
bool CompositeUploadJob::doKill() bool CompositeUploadJob::doKill()
{ {
if (m_running) { if (m_running) {

View file

@ -67,6 +67,7 @@ private:
UploadJob *m_currentJob; UploadJob *m_currentJob;
QElapsedTimer m_timer; QElapsedTimer m_timer;
quint64 m_prevElapsedTime; quint64 m_prevElapsedTime;
bool m_updatePacketPending;
const static quint16 MIN_PORT = 1739; const static quint16 MIN_PORT = 1739;
const static quint16 MAX_PORT = 1764; const static quint16 MAX_PORT = 1764;
@ -80,6 +81,7 @@ private Q_SLOTS:
void slotProcessedAmount(KJob *job, KJob::Unit unit, qulonglong amount); void slotProcessedAmount(KJob *job, KJob::Unit unit, qulonglong amount);
void slotResult(KJob *job) override; void slotResult(KJob *job) override;
void startNextSubJob(); void startNextSubJob();
void sendUpdatePacket();
}; };
#endif //COMPOSITEUPLOADJOB_H #endif //COMPOSITEUPLOADJOB_H

View file

@ -123,7 +123,8 @@
"Website": "http://albertvaka.wordpress.com" "Website": "http://albertvaka.wordpress.com"
}, },
"X-KdeConnect-OutgoingPacketType": [ "X-KdeConnect-OutgoingPacketType": [
"kdeconnect.share.request" "kdeconnect.share.request",
"kdeconnect.share.request.update"
], ],
"X-KdeConnect-SupportedPacketType": [ "X-KdeConnect-SupportedPacketType": [
"kdeconnect.share.request" "kdeconnect.share.request"

View file

@ -26,6 +26,7 @@
#include <core/kdeconnectplugin.h> #include <core/kdeconnectplugin.h>
#define PACKET_TYPE_SHARE_REQUEST QStringLiteral("kdeconnect.share.request") #define PACKET_TYPE_SHARE_REQUEST QStringLiteral("kdeconnect.share.request")
#define PACKET_TYPE_SHARE_REQUEST_UPDATE QStringLiteral("kdeconnect.share.request.update")
class SharePlugin class SharePlugin
: public KdeConnectPlugin : public KdeConnectPlugin