1 /*
2  * SPDX-FileCopyrightText: 2013 Albert Vaca <albertvaka@gmail.com>
3  * SPDX-FileCopyrightText: 2015 Aleix Pol i Gonzalez <aleixpol@kde.org>
4  *
5  * SPDX-License-Identifier: GPL-2.0-only OR GPL-3.0-only OR LicenseRef-KDE-Accepted-GPL
6  */
7 
8 #ifndef FILETRANSFERJOB_H
9 #define FILETRANSFERJOB_H
10 
11 #include <KJob>
12 
13 #include <QElapsedTimer>
14 #include <QIODevice>
15 #include <QSharedPointer>
16 #include <QUrl>
17 #include <QNetworkReply>
18 
19 #include "kdeconnectcore_export.h"
20 
21 class NetworkPacket;
22 /**
23  * @short It will stream a device into a url destination
24  *
25  * Given a QIODevice, the file transfer job will use the system's QNetworkAccessManager
26  * for putting the stream into the requested location.
27  */
28 class KDECONNECTCORE_EXPORT FileTransferJob
29     : public KJob
30 {
31     Q_OBJECT
32 
33 public:
34     /**
35      * @p origin specifies the data to read from.
36      * @p size specifies the expected size of the stream we're reading.
37      * @p destination specifies where these contents should be stored
38      */
39     FileTransferJob(const NetworkPacket* np, const QUrl& destination);
40     void start() override;
destination()41     QUrl destination() const { return m_destination; }
setOriginName(const QString & from)42     void setOriginName(const QString& from) { m_from = from; }
networkPacket()43     const NetworkPacket* networkPacket() { return m_np;}
44 
45 private Q_SLOTS:
46     void doStart();
47 
48 protected:
49     bool doKill() override;
50 
51 private:
52     void startTransfer();
53     void transferFailed(QNetworkReply::NetworkError error);
54     void transferFinished();
55     void deleteDestinationFile();
56 
57     QSharedPointer<QIODevice> m_origin;
58     QNetworkReply* m_reply;
59     QString m_from;
60     QUrl m_destination;
61     QElapsedTimer m_timer;
62     qulonglong m_speedBytes;
63     qint64 m_written;
64     qint64 m_size;
65     const NetworkPacket* m_np;
66 };
67 
68 #endif
69