diff options
author | Petr Mrázek <peterix@gmail.com> | 2014-09-06 18:16:56 +0200 |
---|---|---|
committer | Petr Mrázek <peterix@gmail.com> | 2014-09-06 19:03:05 +0200 |
commit | 20cb97a35af5097e9d3b2062c0dfcb5f2e5fff5c (patch) | |
tree | 56bf51e681f2e73590a549499bd83d7b505c39f8 /logic/tasks | |
parent | 36efcf8d3c0cbd7823fc65569cfc2b011435db2c (diff) | |
download | MultiMC-20cb97a35af5097e9d3b2062c0dfcb5f2e5fff5c.tar MultiMC-20cb97a35af5097e9d3b2062c0dfcb5f2e5fff5c.tar.gz MultiMC-20cb97a35af5097e9d3b2062c0dfcb5f2e5fff5c.tar.lz MultiMC-20cb97a35af5097e9d3b2062c0dfcb5f2e5fff5c.tar.xz MultiMC-20cb97a35af5097e9d3b2062c0dfcb5f2e5fff5c.zip |
Sync from quickmods
Diffstat (limited to 'logic/tasks')
-rw-r--r-- | logic/tasks/ProgressProvider.h | 4 | ||||
-rw-r--r-- | logic/tasks/SequentialTask.cpp | 45 | ||||
-rw-r--r-- | logic/tasks/SequentialTask.h | 5 | ||||
-rw-r--r-- | logic/tasks/Task.cpp | 14 | ||||
-rw-r--r-- | logic/tasks/Task.h | 6 |
5 files changed, 15 insertions, 59 deletions
diff --git a/logic/tasks/ProgressProvider.h b/logic/tasks/ProgressProvider.h index dcb71139..f6928e1c 100644 --- a/logic/tasks/ProgressProvider.h +++ b/logic/tasks/ProgressProvider.h @@ -32,9 +32,7 @@ signals: void status(QString status); public: - virtual ~ProgressProvider() {}; - virtual QString getStatus() const = 0; - virtual void getProgress(qint64 ¤t, qint64 &total) = 0; + virtual ~ProgressProvider() {} virtual bool isRunning() const = 0; public slots: diff --git a/logic/tasks/SequentialTask.cpp b/logic/tasks/SequentialTask.cpp index e0f8fcdd..e08206f8 100644 --- a/logic/tasks/SequentialTask.cpp +++ b/logic/tasks/SequentialTask.cpp @@ -1,31 +1,7 @@ #include "SequentialTask.h" -SequentialTask::SequentialTask(QObject *parent) : - Task(parent), m_currentIndex(-1) +SequentialTask::SequentialTask(QObject *parent) : Task(parent), m_currentIndex(-1) { - -} - -QString SequentialTask::getStatus() const -{ - if (m_queue.isEmpty() || m_currentIndex >= m_queue.size()) - { - return QString(); - } - return m_queue.at(m_currentIndex)->getStatus(); -} - -void SequentialTask::getProgress(qint64 ¤t, qint64 &total) -{ - current = 0; - total = 0; - for (int i = 0; i < m_queue.size(); ++i) - { - qint64 subCurrent, subTotal; - m_queue.at(i)->getProgress(subCurrent, subTotal); - current += subCurrent; - total += subTotal; - } } void SequentialTask::addTask(std::shared_ptr<ProgressProvider> task) @@ -55,10 +31,9 @@ void SequentialTask::startNext() std::shared_ptr<ProgressProvider> next = m_queue[m_currentIndex]; connect(next.get(), SIGNAL(failed(QString)), this, SLOT(subTaskFailed(QString))); connect(next.get(), SIGNAL(status(QString)), this, SLOT(subTaskStatus(QString))); - connect(next.get(), SIGNAL(progress(qint64,qint64)), this, SLOT(subTaskProgress())); + connect(next.get(), SIGNAL(progress(qint64, qint64)), this, SLOT(subTaskProgress(qint64, qint64))); connect(next.get(), SIGNAL(succeeded()), this, SLOT(startNext())); next->start(); - emit status(getStatus()); } void SequentialTask::subTaskFailed(const QString &msg) @@ -69,16 +44,16 @@ void SequentialTask::subTaskStatus(const QString &msg) { setStatus(msg); } -void SequentialTask::subTaskProgress() +void SequentialTask::subTaskProgress(qint64 current, qint64 total) { - qint64 current, total; - getProgress(current, total); - if (total == 0) + if(total == 0) { setProgress(0); + return; } - else - { - setProgress(100 * current / total); - } + auto dcurrent = (double) current; + auto dtotal = (double) total; + auto partial = ((dcurrent / dtotal) * 100.0f)/* / double(m_queue.size())*/; + // auto bigpartial = double(m_currentIndex) * 100.0f / double(m_queue.size()); + setProgress(partial); } diff --git a/logic/tasks/SequentialTask.h b/logic/tasks/SequentialTask.h index c405dca3..f1fe9c72 100644 --- a/logic/tasks/SequentialTask.h +++ b/logic/tasks/SequentialTask.h @@ -11,9 +11,6 @@ class SequentialTask : public Task public: explicit SequentialTask(QObject *parent = 0); - virtual QString getStatus() const; - virtual void getProgress(qint64 ¤t, qint64 &total); - void addTask(std::shared_ptr<ProgressProvider> task); protected: @@ -24,7 +21,7 @@ slots: void startNext(); void subTaskFailed(const QString &msg); void subTaskStatus(const QString &msg); - void subTaskProgress(); + void subTaskProgress(qint64 current, qint64 total); private: QQueue<std::shared_ptr<ProgressProvider> > m_queue; diff --git a/logic/tasks/Task.cpp b/logic/tasks/Task.cpp index c980d6b3..f7a99cdf 100644 --- a/logic/tasks/Task.cpp +++ b/logic/tasks/Task.cpp @@ -20,29 +20,16 @@ Task::Task(QObject *parent) : ProgressProvider(parent) { } -QString Task::getStatus() const -{ - return m_statusString; -} - void Task::setStatus(const QString &new_status) { - m_statusString = new_status; emit status(new_status); } void Task::setProgress(int new_progress) { - m_progress = new_progress; emit progress(new_progress, 100); } -void Task::getProgress(qint64 ¤t, qint64 &total) -{ - current = m_progress; - total = 100; -} - void Task::start() { m_running = true; @@ -61,6 +48,7 @@ void Task::emitFailed(QString reason) void Task::emitSucceeded() { + if (!m_running) { return; } // Don't succeed twice. m_running = false; m_succeeded = true; QLOG_INFO() << "Task succeeded"; diff --git a/logic/tasks/Task.h b/logic/tasks/Task.h index 063eeeda..e6b09262 100644 --- a/logic/tasks/Task.h +++ b/logic/tasks/Task.h @@ -26,8 +26,6 @@ public: explicit Task(QObject *parent = 0); virtual ~Task() {}; - virtual QString getStatus() const; - virtual void getProgress(qint64 ¤t, qint64 &total); virtual bool isRunning() const; /*! @@ -50,6 +48,7 @@ slots: protected: virtual void executeTask() = 0; +protected slots: virtual void emitSucceeded(); virtual void emitFailed(QString reason); @@ -59,9 +58,8 @@ slots: void setProgress(int progress); protected: - QString m_statusString; - int m_progress = 0; bool m_running = false; bool m_succeeded = false; QString m_failReason = ""; }; + |