summaryrefslogtreecommitdiffstats
path: root/libutil
diff options
context:
space:
mode:
authorPetr Mrázek <peterix@gmail.com>2013-08-04 04:19:10 +0200
committerPetr Mrázek <peterix@gmail.com>2013-08-04 04:19:10 +0200
commit0adf1828b047699b9d15e2abf08a1ae0b89da73b (patch)
treeb29fd7a91a33a1706367560288d67fb12329fd4c /libutil
parent4f73091bb5bdbdb91329b9a4ef647fc8286d423c (diff)
downloadMultiMC-0adf1828b047699b9d15e2abf08a1ae0b89da73b.tar
MultiMC-0adf1828b047699b9d15e2abf08a1ae0b89da73b.tar.gz
MultiMC-0adf1828b047699b9d15e2abf08a1ae0b89da73b.tar.lz
MultiMC-0adf1828b047699b9d15e2abf08a1ae0b89da73b.tar.xz
MultiMC-0adf1828b047699b9d15e2abf08a1ae0b89da73b.zip
Download assets for 1.6 on application start (background task).
Diffstat (limited to 'libutil')
-rw-r--r--libutil/include/dlqueue.h15
-rw-r--r--libutil/src/dlqueue.cpp35
2 files changed, 46 insertions, 4 deletions
diff --git a/libutil/include/dlqueue.h b/libutil/include/dlqueue.h
index 69fc22a6..cdb6a818 100644
--- a/libutil/include/dlqueue.h
+++ b/libutil/include/dlqueue.h
@@ -9,9 +9,22 @@ class LIBUTIL_EXPORT DownloadJob : public Job
{
Q_OBJECT
public:
- DownloadJob(QUrl url, QString rel_target_path = QString(), QString expected_md5 = QString());
+ DownloadJob(QUrl url,
+ QString rel_target_path = QString(),
+ QString expected_md5 = QString()
+ );
static JobPtr create(QUrl url, QString rel_target_path = QString(), QString expected_md5 = QString());
+ DownloadJob(QSharedPointer<QNetworkAccessManager> net_mgr,
+ QUrl url,
+ QString rel_target_path = QString(),
+ QString expected_md5 = QString()
+ );
+ static JobPtr create(QSharedPointer<QNetworkAccessManager> net_mgr,
+ QUrl url,
+ QString rel_target_path = QString(),
+ QString expected_md5 = QString()
+ );
public:
static bool ensurePathExists(QString filenamepath);
diff --git a/libutil/src/dlqueue.cpp b/libutil/src/dlqueue.cpp
index 1ef8e212..d73dc356 100644
--- a/libutil/src/dlqueue.cpp
+++ b/libutil/src/dlqueue.cpp
@@ -1,6 +1,8 @@
#include "include/dlqueue.h"
-DownloadJob::DownloadJob ( QUrl url, QString target_path, QString expected_md5 )
+DownloadJob::DownloadJob (QUrl url,
+ QString target_path,
+ QString expected_md5 )
:Job()
{
m_url = url;
@@ -11,13 +13,41 @@ DownloadJob::DownloadJob ( QUrl url, QString target_path, QString expected_md5 )
m_save_to_file = m_target_path.size();
m_status = Job_NotStarted;
m_opened_for_saving = false;
+ m_manager.reset(new QNetworkAccessManager());
}
-JobPtr DownloadJob::create ( QUrl url, QString target_path, QString expected_md5 )
+JobPtr DownloadJob::create (QUrl url,
+ QString target_path,
+ QString expected_md5 )
{
return JobPtr ( new DownloadJob ( url, target_path, expected_md5 ) );
}
+DownloadJob::DownloadJob (QSharedPointer<QNetworkAccessManager> net_mgr,
+ QUrl url,
+ QString target_path,
+ QString expected_md5 )
+ :Job()
+{
+ m_url = url;
+ m_target_path = target_path;
+ m_expected_md5 = expected_md5;
+
+ m_check_md5 = m_expected_md5.size();
+ m_save_to_file = m_target_path.size();
+ m_status = Job_NotStarted;
+ m_opened_for_saving = false;
+ m_manager = net_mgr;
+}
+
+JobPtr DownloadJob::create (QSharedPointer<QNetworkAccessManager> net_mgr,
+ QUrl url,
+ QString target_path,
+ QString expected_md5 )
+{
+ return JobPtr ( new DownloadJob ( net_mgr, url, target_path, expected_md5 ) );
+}
+
bool DownloadJob::ensurePathExists(QString filenamepath)
{
QFileInfo a ( filenamepath );
@@ -27,7 +57,6 @@ bool DownloadJob::ensurePathExists(QString filenamepath)
void DownloadJob::start()
{
- m_manager.reset ( new QNetworkAccessManager() );
if ( m_save_to_file )
{
QString filename = m_target_path;