From e76e6329cdf4f1613c6303debd3ca43493147f7b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Petr=20Mr=C3=A1zek?= Date: Wed, 3 May 2017 23:11:52 +0200 Subject: NOISSUE Revert all recent changes to NetAction and NetJob --- api/logic/net/NetJob.h | 68 ++++++++++++++++++++++++++++++++++++++------------ 1 file changed, 52 insertions(+), 16 deletions(-) (limited to 'api/logic/net/NetJob.h') diff --git a/api/logic/net/NetJob.h b/api/logic/net/NetJob.h index 5503cd24..ca4f5df1 100644 --- a/api/logic/net/NetJob.h +++ b/api/logic/net/NetJob.h @@ -32,12 +32,52 @@ class MULTIMC_LOGIC_EXPORT NetJob : public Task public: explicit NetJob(QString job_name) : Task(), m_job_name(job_name) {} virtual ~NetJob() {} + bool addNetAction(NetActionPtr action) + { + action->m_index_within_job = downloads.size(); + downloads.append(action); + part_info pi; + { + pi.current_progress = action->currentProgress(); + pi.total_progress = action->totalProgress(); + pi.failures = action->numberOfFailures(); + } + parts_progress.append(pi); + total_progress += pi.total_progress; + // if this is already running, the action needs to be started right away! + if (isRunning()) + { + setProgress(current_progress, total_progress); + connect(action.get(), SIGNAL(succeeded(int)), SLOT(partSucceeded(int))); + connect(action.get(), SIGNAL(failed(int)), SLOT(partFailed(int))); + connect(action.get(), SIGNAL(netActionProgress(int, qint64, qint64)), + SLOT(partProgress(int, qint64, qint64))); + action->start(); + } + return true; + } - void addNetAction(NetActionPtr action); - + NetActionPtr operator[](int index) + { + return downloads[index]; + } + const NetActionPtr at(const int index) + { + return downloads.at(index); + } + NetActionPtr first() + { + if (downloads.size()) + return downloads[0]; + return NetActionPtr(); + } int size() const { - return m_parts.size(); + return downloads.size(); + } + virtual bool isRunning() const override + { + return m_running; } QStringList getFailedFiles(); @@ -51,32 +91,28 @@ public slots: virtual bool abort() override; private slots: - void partProgress(qint64 bytesReceived, qint64 bytesTotal); - void partSucceeded(); - void partFailed(); - void partAborted(); - -private: - void setPartProgress(int index, qint64 bytesReceived, qint64 bytesTotal); - void connectAction(NetAction * action); + void partProgress(int index, qint64 bytesReceived, qint64 bytesTotal); + void partSucceeded(int index); + void partFailed(int index); + void partAborted(int index); private: struct part_info { - NetActionPtr download; qint64 current_progress = 0; qint64 total_progress = 1; int failures = 0; bool connected = false; }; QString m_job_name; - QVector m_parts; - QMap m_partsIndex; + QList downloads; + QList parts_progress; QQueue m_todo; QSet m_doing; QSet m_done; QSet m_failed; - //qint64 current_progress = 0; - //qint64 total_progress = 0; + qint64 current_progress = 0; + qint64 total_progress = 0; + bool m_running = false; bool m_aborted = false; }; -- cgit v1.2.3