diff options
author | Petr Mrázek <peterix@gmail.com> | 2018-12-10 20:50:15 +0100 |
---|---|---|
committer | Petr Mrázek <peterix@gmail.com> | 2018-12-10 20:50:15 +0100 |
commit | de568b32b85b24fb24fdec2bc90066bf00b2f013 (patch) | |
tree | b582dd380f535de5222bd459d7efe66fd9d892a5 /api/logic | |
parent | fb29e45bd0e8f4e696c4c71f43adb3fd9690d1d4 (diff) | |
download | MultiMC-de568b32b85b24fb24fdec2bc90066bf00b2f013.tar MultiMC-de568b32b85b24fb24fdec2bc90066bf00b2f013.tar.gz MultiMC-de568b32b85b24fb24fdec2bc90066bf00b2f013.tar.lz MultiMC-de568b32b85b24fb24fdec2bc90066bf00b2f013.tar.xz MultiMC-de568b32b85b24fb24fdec2bc90066bf00b2f013.zip |
NOISSUE model Task states as one enum instead of multiple flags
This adds Task::State::AbortedByUser as a possibility
Diffstat (limited to 'api/logic')
-rw-r--r-- | api/logic/modplatform/ftb/FtbPackInstallTask.cpp | 1 | ||||
-rw-r--r-- | api/logic/tasks/Task.cpp | 56 | ||||
-rw-r--r-- | api/logic/tasks/Task.h | 14 |
3 files changed, 51 insertions, 20 deletions
diff --git a/api/logic/modplatform/ftb/FtbPackInstallTask.cpp b/api/logic/modplatform/ftb/FtbPackInstallTask.cpp index 253c2f05..ecacda02 100644 --- a/api/logic/modplatform/ftb/FtbPackInstallTask.cpp +++ b/api/logic/modplatform/ftb/FtbPackInstallTask.cpp @@ -58,6 +58,7 @@ void FtbPackInstallTask::onDownloadSucceeded() void FtbPackInstallTask::onDownloadFailed(QString reason) { + abortable = false; emitFailed(reason); } diff --git a/api/logic/tasks/Task.cpp b/api/logic/tasks/Task.cpp index f7f2d491..6b8a7341 100644 --- a/api/logic/tasks/Task.cpp +++ b/api/logic/tasks/Task.cpp @@ -39,23 +39,49 @@ void Task::setProgress(qint64 current, qint64 total) void Task::start() { - m_running = true; + switch(m_state) + { + case State::Inactive: + { + qDebug() << "Task" << describe() << "starting for the first time"; + break; + } + case State::AbortedByUser: + { + qDebug() << "Task" << describe() << "restarting for after being aborted by user"; + break; + } + case State::Failed: + { + qDebug() << "Task" << describe() << "restarting for after failing at first"; + break; + } + case State::Succeeded: + { + qDebug() << "Task" << describe() << "restarting for after succeeding at first"; + break; + } + case State::Running: + { + qWarning() << "MultiMC tried to start task" << describe() << "while it was already running!"; + return; + } + } + // NOTE: only fall thorugh to here in end states + m_state = State::Running; emit started(); - qDebug() << "Task" << describe() << "started"; executeTask(); } void Task::emitFailed(QString reason) { // Don't fail twice. - if (!m_running) + if (!isRunning()) { qCritical() << "Task" << describe() << "failed while not running!!!!: " << reason; return; } - m_running = false; - m_finished = true; - m_succeeded = false; + m_state = State::Failed; m_failReason = reason; qCritical() << "Task" << describe() << "failed: " << reason; emit failed(reason); @@ -65,14 +91,12 @@ void Task::emitFailed(QString reason) void Task::emitAborted() { // Don't abort twice. - if (!m_running) + if (!isRunning()) { qCritical() << "Task" << describe() << "aborted while not running!!!!"; return; } - m_running = false; - m_finished = true; - m_succeeded = false; + m_state = State::AbortedByUser; m_failReason = "Aborted."; qDebug() << "Task" << describe() << "aborted."; emit failed(m_failReason); @@ -82,14 +106,12 @@ void Task::emitAborted() void Task::emitSucceeded() { // Don't succeed twice. - if (!m_running) + if (!isRunning()) { qCritical() << "Task" << describe() << "succeeded while not running!!!!"; return; } - m_running = false; - m_finished = true; - m_succeeded = true; + m_state = State::Succeeded; qDebug() << "Task" << describe() << "succeeded"; emit succeeded(); emit finished(); @@ -116,17 +138,17 @@ QString Task::describe() bool Task::isRunning() const { - return m_running; + return m_state == State::Running; } bool Task::isFinished() const { - return m_finished; + return m_state != State::Running && m_state != State::Inactive; } bool Task::wasSuccessful() const { - return m_succeeded; + return m_state == State::Succeeded; } QString Task::failReason() const diff --git a/api/logic/tasks/Task.h b/api/logic/tasks/Task.h index 58dbc4ca..c66622aa 100644 --- a/api/logic/tasks/Task.h +++ b/api/logic/tasks/Task.h @@ -25,6 +25,16 @@ class MULTIMC_LOGIC_EXPORT Task : public QObject { Q_OBJECT public: + enum class State + { + Inactive, + Running, + Succeeded, + Failed, + AbortedByUser + }; + +public: explicit Task(QObject *parent = 0); virtual ~Task() {}; @@ -88,9 +98,7 @@ public slots: void setProgress(qint64 current, qint64 total); private: - bool m_running = false; - bool m_finished = false; - bool m_succeeded = false; + State m_state = State::Inactive; QStringList m_Warnings; QString m_failReason = ""; QString m_status; |