File indexing completed on 2024-04-28 08:49:01
0001 /* 0002 * SPDX-FileCopyrightText: 2013 Albert Vaca <albertvaka@gmail.com> 0003 * SPDX-FileCopyrightText: 2015 Aleix Pol i Gonzalez <aleixpol@kde.org> 0004 * 0005 * SPDX-License-Identifier: GPL-2.0-only OR GPL-3.0-only OR LicenseRef-KDE-Accepted-GPL 0006 */ 0007 0008 #ifndef FILETRANSFERJOB_H 0009 #define FILETRANSFERJOB_H 0010 0011 #include <KJob> 0012 0013 #include <QElapsedTimer> 0014 #include <QIODevice> 0015 #include <QNetworkReply> 0016 #include <QSharedPointer> 0017 #include <QUrl> 0018 0019 #include "kdeconnectcore_export.h" 0020 0021 class NetworkPacket; 0022 /** 0023 * @short It will stream a device into a url destination 0024 * 0025 * Given a QIODevice, the file transfer job will use the system's QNetworkAccessManager 0026 * for putting the stream into the requested location. 0027 */ 0028 class KDECONNECTCORE_EXPORT FileTransferJob : public KJob 0029 { 0030 Q_OBJECT 0031 0032 public: 0033 /** 0034 * @p origin specifies the data to read from. 0035 * @p size specifies the expected size of the stream we're reading. 0036 * @p destination specifies where these contents should be stored 0037 */ 0038 FileTransferJob(const NetworkPacket *np, const QUrl &destination); 0039 void start() override; 0040 QUrl destination() const 0041 { 0042 return m_destination; 0043 } 0044 void setOriginName(const QString &from) 0045 { 0046 m_from = from; 0047 } 0048 void setAutoRenameIfDestinatinonExists(bool autoRename) 0049 { 0050 m_autoRename = autoRename; 0051 } 0052 const NetworkPacket *networkPacket() 0053 { 0054 return m_np; 0055 } 0056 0057 private Q_SLOTS: 0058 void doStart(); 0059 0060 protected: 0061 bool doKill() override; 0062 0063 private: 0064 void startTransfer(); 0065 void transferFailed(QNetworkReply::NetworkError error); 0066 void transferFinished(); 0067 void deleteDestinationFile(); 0068 0069 QSharedPointer<QIODevice> m_origin; 0070 QNetworkReply *m_reply; 0071 QString m_from; 0072 QUrl m_destination; 0073 QElapsedTimer m_timer; 0074 qint64 m_written; 0075 qint64 m_size; 0076 const NetworkPacket *m_np; 0077 bool m_autoRename; 0078 }; 0079 0080 #endif