File indexing completed on 2024-05-12 04:58:51

0001 /**
0002  * SPDX-FileCopyrightText: 2018 Erik Duisters <e.duisters1@gmail.com>
0003  *
0004  * SPDX-License-Identifier: GPL-2.0-only OR GPL-3.0-only OR LicenseRef-KDE-Accepted-GPL
0005  */
0006 
0007 #ifndef COMPOSITEUPLOADJOB_H
0008 #define COMPOSITEUPLOADJOB_H
0009 
0010 #include "kdeconnectcore_export.h"
0011 #include "server.h"
0012 #include "uploadjob.h"
0013 #include <KCompositeJob>
0014 
0015 class KDECONNECTCORE_EXPORT CompositeUploadJob : public KCompositeJob
0016 {
0017     Q_OBJECT
0018 
0019 public:
0020     explicit CompositeUploadJob(const QString &deviceId, bool displayNotification);
0021 
0022     void start() override;
0023     QVariantMap transferInfo();
0024     bool isRunning();
0025     bool addSubjob(KJob *job) override;
0026 
0027 private:
0028     bool startListening();
0029     void emitDescription(const QString &currentFileName);
0030 
0031 protected:
0032     bool doKill() override;
0033 
0034 private:
0035     enum { NoPortAvailable = UserDefinedError, SendingNetworkPacketFailed, SocketError, SslError };
0036 
0037     Server *const m_server;
0038     QSslSocket *m_socket;
0039     quint16 m_port;
0040     QString m_deviceId;
0041     bool m_running;
0042     int m_currentJobNum;
0043     int m_totalJobs;
0044     quint64 m_currentJobSendPayloadSize;
0045     quint64 m_totalSendPayloadSize;
0046     quint64 m_totalPayloadSize;
0047     UploadJob *m_currentJob;
0048     QElapsedTimer m_timer;
0049     quint64 m_prevElapsedTime;
0050     bool m_updatePacketPending;
0051 
0052     const static quint16 MIN_PORT = 1739;
0053     const static quint16 MAX_PORT = 1764;
0054 
0055 private Q_SLOTS:
0056     void newConnection();
0057     void slotProcessedAmount(KJob *job, KJob::Unit unit, qulonglong amount);
0058     void slotResult(KJob *job) override;
0059     void startNextSubJob();
0060     void sendUpdatePacket();
0061 };
0062 
0063 #endif // COMPOSITEUPLOADJOB_H