diff options
author | Petr Mrázek <peterix@gmail.com> | 2014-01-01 19:21:58 +0100 |
---|---|---|
committer | Petr Mrázek <peterix@gmail.com> | 2014-01-01 19:21:58 +0100 |
commit | 0e78d34d4cbed0ceb913ee70e89f36462bfe1dc6 (patch) | |
tree | 93a26eb1fa534984230e871253faaf3ec142f373 /logic/tasks | |
parent | cf7335186d1aa3d99a32adb04a55c066161760c3 (diff) | |
download | MultiMC-0e78d34d4cbed0ceb913ee70e89f36462bfe1dc6.tar MultiMC-0e78d34d4cbed0ceb913ee70e89f36462bfe1dc6.tar.gz MultiMC-0e78d34d4cbed0ceb913ee70e89f36462bfe1dc6.tar.lz MultiMC-0e78d34d4cbed0ceb913ee70e89f36462bfe1dc6.tar.xz MultiMC-0e78d34d4cbed0ceb913ee70e89f36462bfe1dc6.zip |
ThreadTask for all your ThreadNeeds
Use only when absolutely required.
Diffstat (limited to 'logic/tasks')
-rw-r--r-- | logic/tasks/ThreadTask.cpp | 41 | ||||
-rw-r--r-- | logic/tasks/ThreadTask.h | 25 |
2 files changed, 66 insertions, 0 deletions
diff --git a/logic/tasks/ThreadTask.cpp b/logic/tasks/ThreadTask.cpp new file mode 100644 index 00000000..ddd1dee5 --- /dev/null +++ b/logic/tasks/ThreadTask.cpp @@ -0,0 +1,41 @@ +#include "ThreadTask.h" +#include <QtConcurrentRun> +ThreadTask::ThreadTask(Task * internal, QObject *parent) : Task(parent), m_internal(internal) +{ +} + +void ThreadTask::start() +{ + connect(m_internal, SIGNAL(failed(QString)), SLOT(iternal_failed(QString))); + connect(m_internal, SIGNAL(progress(qint64,qint64)), SLOT(iternal_progress(qint64,qint64))); + connect(m_internal, SIGNAL(started()), SLOT(iternal_started())); + connect(m_internal, SIGNAL(status(QString)), SLOT(iternal_status(QString))); + connect(m_internal, SIGNAL(succeeded()), SLOT(iternal_succeeded())); + m_running = true; + QtConcurrent::run(m_internal, &Task::start); +} + +void ThreadTask::iternal_failed(QString reason) +{ + emitFailed(reason); +} + +void ThreadTask::iternal_progress(qint64 current, qint64 total) +{ + progress(current, total); +} + +void ThreadTask::iternal_started() +{ + emit started(); +} + +void ThreadTask::iternal_status(QString status) +{ + setStatus(status); +} + +void ThreadTask::iternal_succeeded() +{ + emitSucceeded(); +} diff --git a/logic/tasks/ThreadTask.h b/logic/tasks/ThreadTask.h new file mode 100644 index 00000000..718dbc91 --- /dev/null +++ b/logic/tasks/ThreadTask.h @@ -0,0 +1,25 @@ +#pragma once + +#include "Task.h" + +class ThreadTask : public Task +{ + Q_OBJECT +public: + explicit ThreadTask(Task * internal, QObject * parent = nullptr); + +protected: + void executeTask() {}; + +public slots: + virtual void start(); + +private slots: + void iternal_started(); + void iternal_progress(qint64 current, qint64 total); + void iternal_succeeded(); + void iternal_failed(QString reason); + void iternal_status(QString status); +private: + Task * m_internal; +};
\ No newline at end of file |