From 0adf1828b047699b9d15e2abf08a1ae0b89da73b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Petr=20Mr=C3=A1zek?= Date: Sun, 4 Aug 2013 04:19:10 +0200 Subject: Download assets for 1.6 on application start (background task). --- libutil/include/dlqueue.h | 15 ++++++++++++++- libutil/src/dlqueue.cpp | 35 ++++++++++++++++++++++++++++++++--- 2 files changed, 46 insertions(+), 4 deletions(-) (limited to 'libutil') 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 net_mgr, + QUrl url, + QString rel_target_path = QString(), + QString expected_md5 = QString() + ); + static JobPtr create(QSharedPointer 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 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 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; -- cgit v1.2.3