diff options
Diffstat (limited to 'api/logic/net/NetJob.h')
-rw-r--r-- | api/logic/net/NetJob.h | 68 |
1 files changed, 52 insertions, 16 deletions
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<part_info> m_parts; - QMap<NetAction *, int> m_partsIndex; + QList<NetActionPtr> downloads; + QList<part_info> parts_progress; QQueue<int> m_todo; QSet<int> m_doing; QSet<int> m_done; QSet<int> 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; }; |