2013-07-06 00:50:07 +01:00
|
|
|
#pragma once
|
2013-08-07 00:38:18 +01:00
|
|
|
#include "JobQueue.h"
|
2013-07-06 00:50:07 +01:00
|
|
|
#include <QtNetwork>
|
|
|
|
|
|
|
|
/**
|
|
|
|
* A single file for the downloader/cache to process.
|
|
|
|
*/
|
2013-08-26 01:53:29 +01:00
|
|
|
class DownloadJob : public Job
|
2013-07-06 00:50:07 +01:00
|
|
|
{
|
|
|
|
Q_OBJECT
|
|
|
|
public:
|
2013-08-04 03:19:10 +01:00
|
|
|
DownloadJob(QUrl url,
|
|
|
|
QString rel_target_path = QString(),
|
|
|
|
QString expected_md5 = QString()
|
|
|
|
);
|
2013-07-06 00:50:07 +01:00
|
|
|
static JobPtr create(QUrl url, QString rel_target_path = QString(), QString expected_md5 = QString());
|
|
|
|
public slots:
|
|
|
|
virtual void start();
|
|
|
|
|
|
|
|
private slots:
|
|
|
|
void downloadProgress(qint64 bytesReceived, qint64 bytesTotal);;
|
|
|
|
void downloadError(QNetworkReply::NetworkError error);
|
|
|
|
void downloadFinished();
|
|
|
|
void downloadReadyRead();
|
|
|
|
|
|
|
|
public:
|
|
|
|
/// the network reply
|
|
|
|
QSharedPointer<QNetworkReply> m_reply;
|
|
|
|
/// source URL
|
|
|
|
QUrl m_url;
|
|
|
|
|
|
|
|
/// if true, check the md5sum against a provided md5sum
|
|
|
|
/// also, if a file exists, perform an md5sum first and don't download only if they don't match
|
|
|
|
bool m_check_md5;
|
|
|
|
/// the expected md5 checksum
|
|
|
|
QString m_expected_md5;
|
|
|
|
|
|
|
|
/// save to file?
|
|
|
|
bool m_save_to_file;
|
2013-07-14 17:33:31 +01:00
|
|
|
/// is the saving file already open?
|
|
|
|
bool m_opened_for_saving;
|
2013-07-06 00:50:07 +01:00
|
|
|
/// if saving to file, use the one specified in this string
|
2013-07-07 22:51:26 +01:00
|
|
|
QString m_target_path;
|
2013-07-06 00:50:07 +01:00
|
|
|
/// this is the output file, if any
|
|
|
|
QFile m_output_file;
|
|
|
|
/// if not saving to file, downloaded data is placed here
|
|
|
|
QByteArray m_data;
|
|
|
|
|
|
|
|
/// The file's status
|
|
|
|
JobStatus m_status;
|
|
|
|
};
|