summaryrefslogtreecommitdiffstats
path: root/logic/net/DownloadJob.h
diff options
context:
space:
mode:
authorPetr Mrázek <peterix@gmail.com>2013-09-08 02:15:20 +0200
committerPetr Mrázek <peterix@gmail.com>2013-09-08 02:15:20 +0200
commit6bea4ec988b7caeac63353fb9d2a354f2fd47dad (patch)
tree77dc597c82ff3952d9f34f4ca13da1c36ca89bd8 /logic/net/DownloadJob.h
parent6892c11e9f287dcfb1e698f8f46233a01fb7abb6 (diff)
downloadMultiMC-6bea4ec988b7caeac63353fb9d2a354f2fd47dad.tar
MultiMC-6bea4ec988b7caeac63353fb9d2a354f2fd47dad.tar.gz
MultiMC-6bea4ec988b7caeac63353fb9d2a354f2fd47dad.tar.lz
MultiMC-6bea4ec988b7caeac63353fb9d2a354f2fd47dad.tar.xz
MultiMC-6bea4ec988b7caeac63353fb9d2a354f2fd47dad.zip
Use HttpMetaCache to minimize network use.
Diffstat (limited to 'logic/net/DownloadJob.h')
-rw-r--r--logic/net/DownloadJob.h95
1 files changed, 13 insertions, 82 deletions
diff --git a/logic/net/DownloadJob.h b/logic/net/DownloadJob.h
index adeef646..71466282 100644
--- a/logic/net/DownloadJob.h
+++ b/logic/net/DownloadJob.h
@@ -1,98 +1,28 @@
#pragma once
#include <QtNetwork>
+#include "Download.h"
+#include "ByteArrayDownload.h"
+#include "FileDownload.h"
+#include "CacheDownload.h"
+#include "HttpMetaCache.h"
class DownloadJob;
-class Download;
typedef QSharedPointer<DownloadJob> DownloadJobPtr;
-typedef QSharedPointer<Download> DownloadPtr;
-
-enum JobStatus
-{
- Job_NotStarted,
- Job_InProgress,
- Job_Finished,
- Job_Failed
-};
-
-class Job : public QObject
-{
- Q_OBJECT
-protected:
- explicit Job(): QObject(0){};
-public:
- virtual ~Job() {};
-
-public slots:
- virtual void start() = 0;
-};
-
-class Download: public Job
-{
- friend class DownloadJob;
- Q_OBJECT
-protected:
- Download(QUrl url, QString rel_target_path = QString(), QString expected_md5 = QString());
-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;
- /// is the saving file already open?
- bool m_opened_for_saving;
- /// if saving to file, use the one specified in this string
- QString m_target_path;
- /// this is the output file, if any
- QFile m_output_file;
- /// if not saving to file, downloaded data is placed here
- QByteArray m_data;
-
- int currentProgress = 0;
- int totalProgress = 0;
-
- /// The file's status
- JobStatus m_status;
-
- int index_within_job = 0;
-signals:
- void started(int index);
- void progress(int index, qint64 current, qint64 total);
- void succeeded(int index);
- void failed(int index);
-public slots:
- virtual void start();
-
-private slots:
- void downloadProgress(qint64 bytesReceived, qint64 bytesTotal);;
- void downloadError(QNetworkReply::NetworkError error);
- void downloadFinished();
- void downloadReadyRead();
-};
/**
* A single file for the downloader/cache to process.
*/
-class DownloadJob : public Job
+class DownloadJob : public QObject
{
Q_OBJECT
public:
- explicit DownloadJob()
- :Job(){};
- explicit DownloadJob(QUrl url, QString rel_target_path = QString(), QString expected_md5 = QString())
- :Job()
- {
- add(url, rel_target_path, expected_md5);
- };
+ explicit DownloadJob(QString job_name)
+ :QObject(), m_job_name(job_name){};
+
+ ByteArrayDownloadPtr add(QUrl url);
+ FileDownloadPtr add(QUrl url, QString rel_target_path);
+ CacheDownloadPtr add(QUrl url, MetaEntryPtr entry);
- DownloadPtr add(QUrl url, QString rel_target_path = QString(), QString expected_md5 = QString());
DownloadPtr operator[](int index)
{
return downloads[index];
@@ -119,6 +49,7 @@ private slots:
void partSucceeded(int index);
void partFailed(int index);
private:
+ QString m_job_name;
QList<DownloadPtr> downloads;
int num_succeeded = 0;
int num_failed = 0;