summaryrefslogtreecommitdiffstats
path: root/logic/tasks
diff options
context:
space:
mode:
Diffstat (limited to 'logic/tasks')
-rw-r--r--logic/tasks/SequentialTask.cpp8
-rw-r--r--logic/tasks/Task.cpp19
-rw-r--r--logic/tasks/Task.h26
3 files changed, 41 insertions, 12 deletions
diff --git a/logic/tasks/SequentialTask.cpp b/logic/tasks/SequentialTask.cpp
index f744d273..ac0e7820 100644
--- a/logic/tasks/SequentialTask.cpp
+++ b/logic/tasks/SequentialTask.cpp
@@ -48,12 +48,8 @@ void SequentialTask::subTaskProgress(qint64 current, qint64 total)
{
if(total == 0)
{
- setProgress(0);
+ setProgress(0, 100);
return;
}
- 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);
+ setProgress(current, total);
}
diff --git a/logic/tasks/Task.cpp b/logic/tasks/Task.cpp
index eaeff4c2..3c4e3188 100644
--- a/logic/tasks/Task.cpp
+++ b/logic/tasks/Task.cpp
@@ -23,12 +23,18 @@ Task::Task(QObject *parent) : QObject(parent)
void Task::setStatus(const QString &new_status)
{
- emit status(new_status);
+ if(m_status != new_status)
+ {
+ m_status = new_status;
+ emit status(m_status);
+ }
}
-void Task::setProgress(int new_progress)
+void Task::setProgress(qint64 current, qint64 total)
{
- emit progress(new_progress, 100);
+ m_progress = current;
+ m_progressTotal = total;
+ emit progress(m_progress, m_progressTotal);
}
void Task::start()
@@ -41,6 +47,7 @@ void Task::start()
void Task::emitFailed(QString reason)
{
m_running = false;
+ m_finished = true;
m_succeeded = false;
m_failReason = reason;
qCritical() << "Task failed: " << reason;
@@ -52,6 +59,7 @@ void Task::emitSucceeded()
{
if (!m_running) { return; } // Don't succeed twice.
m_running = false;
+ m_finished = true;
m_succeeded = true;
qDebug() << "Task succeeded";
emit succeeded();
@@ -63,6 +71,11 @@ bool Task::isRunning() const
return m_running;
}
+bool Task::isFinished() const
+{
+ return m_finished;
+}
+
bool Task::successful() const
{
return m_succeeded;
diff --git a/logic/tasks/Task.h b/logic/tasks/Task.h
index 9362348a..04899c69 100644
--- a/logic/tasks/Task.h
+++ b/logic/tasks/Task.h
@@ -27,6 +27,8 @@ public:
virtual bool isRunning() const;
+ virtual bool isFinished() const;
+
/*!
* True if this task was successful.
* If the task failed or is still running, returns false.
@@ -41,6 +43,21 @@ public:
virtual bool canAbort() const { return false; }
+ QString getStatus()
+ {
+ return m_status;
+ }
+
+ qint64 getProgress()
+ {
+ return m_progress;
+ }
+
+ qint64 getTotalProgress()
+ {
+ return m_progressTotal;
+ }
+
signals:
void started();
void progress(qint64 current, qint64 total);
@@ -61,14 +78,17 @@ protected slots:
virtual void emitSucceeded();
virtual void emitFailed(QString reason);
-protected
-slots:
+public slots:
void setStatus(const QString &status);
- void setProgress(int progress);
+ void setProgress(qint64 current, qint64 total);
protected:
bool m_running = false;
+ bool m_finished = false;
bool m_succeeded = false;
QString m_failReason = "";
+ QString m_status;
+ int m_progress = 0;
+ int m_progressTotal = 100;
};