sneedmc/launcher/tasks/SequentialTask.h
flow 9a44c92211
feat: add MultipleOptionsTask
This is a variation of a Sequential Task, in which a subtask failing
will prompt the next one to execute, and a subtask being successful will
stop the task.

This way, this can be used for easily managing fallbacks with tasks. :D

Signed-off-by: flow <flowlnlnln@gmail.com>
2022-07-17 11:33:41 -03:00

50 lines
1.2 KiB
C++

#pragma once
#include "Task.h"
#include "QObjectPtr.h"
#include <QQueue>
class SequentialTask : public Task
{
Q_OBJECT
public:
explicit SequentialTask(QObject *parent = nullptr, const QString& task_name = "");
virtual ~SequentialTask();
inline auto isMultiStep() const -> bool override { return m_queue.size() > 1; };
auto getStepProgress() const -> qint64 override;
auto getStepTotalProgress() const -> qint64 override;
inline auto getStepStatus() const -> QString override { return m_step_status; }
void addTask(Task::Ptr task);
public slots:
bool abort() override;
protected
slots:
void executeTask() override;
virtual void startNext();
virtual void subTaskFailed(const QString &msg);
virtual void subTaskStatus(const QString &msg);
virtual void subTaskProgress(qint64 current, qint64 total);
protected:
void setStepStatus(QString status) { m_step_status = status; emit stepStatus(status); };
protected:
QString m_name;
QString m_step_status;
QQueue<Task::Ptr > m_queue;
int m_currentIndex;
qint64 m_stepProgress = 0;
qint64 m_stepTotalProgress = 100;
bool m_aborted = false;
};