2017-09-20 15:43:43 +00:00
|
|
|
#ifndef TASKINFO_H
|
|
|
|
#define TASKINFO_H
|
|
|
|
|
|
|
|
#include <QDateTime>
|
2017-12-06 13:41:26 +00:00
|
|
|
#include <QObject>
|
2017-09-20 15:43:43 +00:00
|
|
|
|
2017-12-06 02:51:40 +00:00
|
|
|
QT_FORWARD_DECLARE_CLASS(TaskWorker)
|
2017-09-21 13:24:45 +00:00
|
|
|
|
2017-09-20 15:43:43 +00:00
|
|
|
class TaskInfo : public QObject
|
|
|
|
{
|
|
|
|
Q_OBJECT
|
|
|
|
Q_PROPERTY(bool enabled READ enabled WRITE setEnabled NOTIFY enabledChanged)
|
|
|
|
Q_PROPERTY(int intervalHours READ intervalHours WRITE setIntervalHours NOTIFY intervalHoursChanged)
|
|
|
|
Q_PROPERTY(QString title READ title CONSTANT)
|
|
|
|
Q_PROPERTY(TaskInfo::TaskType type READ type WRITE setType NOTIFY typeChanged)
|
|
|
|
Q_PROPERTY(QDateTime lastRun READ lastRun WRITE setLastRun NOTIFY lastRunChanged)
|
|
|
|
Q_PROPERTY(QDateTime lastSuccess READ lastSuccess WRITE setLastSuccess NOTIFY lastSuccessChanged)
|
2017-09-21 13:24:45 +00:00
|
|
|
Q_PROPERTY(bool running READ running NOTIFY taskWorkerChanged)
|
2017-09-20 15:43:43 +00:00
|
|
|
|
|
|
|
public:
|
2018-03-05 12:17:13 +00:00
|
|
|
enum TaskType : qint16 {
|
2017-09-20 15:43:43 +00:00
|
|
|
TypeNone = -1,
|
2017-12-21 14:46:22 +00:00
|
|
|
UpdateChecker = 0,
|
2018-08-28 01:33:35 +00:00
|
|
|
Tasix
|
2017-09-20 15:43:43 +00:00
|
|
|
};
|
|
|
|
Q_ENUM(TaskType)
|
|
|
|
|
|
|
|
explicit TaskInfo(TaskInfo::TaskType type, QObject *parent = nullptr);
|
2017-09-21 13:24:45 +00:00
|
|
|
virtual ~TaskInfo();
|
2017-09-20 15:43:43 +00:00
|
|
|
|
|
|
|
bool enabled() const { return m_enabled; }
|
|
|
|
void setEnabled(bool enabled);
|
|
|
|
|
|
|
|
int intervalHours() const { return m_intervalHours; }
|
|
|
|
void setIntervalHours(int intervalHours);
|
|
|
|
|
|
|
|
QString title() const;
|
|
|
|
|
|
|
|
TaskInfo::TaskType type() const { return m_type; }
|
|
|
|
void setType(TaskInfo::TaskType type);
|
|
|
|
|
|
|
|
QDateTime lastRun() const { return m_lastRun; }
|
|
|
|
void setLastRun(const QDateTime &lastRun);
|
|
|
|
|
2017-09-21 14:16:50 +00:00
|
|
|
QDateTime plannedRun() const;
|
|
|
|
|
2017-09-20 15:43:43 +00:00
|
|
|
QDateTime lastSuccess() const { return m_lastSuccess; }
|
|
|
|
void setLastSuccess(const QDateTime &lastSuccess);
|
|
|
|
|
2017-09-21 13:24:45 +00:00
|
|
|
TaskWorker *taskWorker() const { return m_taskWorker; }
|
|
|
|
void setTaskWorker(TaskWorker *taskWorker);
|
|
|
|
|
|
|
|
bool running() const { return m_taskWorker != nullptr; }
|
|
|
|
|
2017-09-20 15:43:43 +00:00
|
|
|
void rawData(QByteArray &data) const;
|
|
|
|
void setRawData(const QByteArray &data);
|
|
|
|
|
|
|
|
static QString typeToString(TaskInfo::TaskType type);
|
|
|
|
static TaskInfo::TaskType stringToType(const QString &name);
|
|
|
|
|
|
|
|
signals:
|
|
|
|
void enabledChanged();
|
|
|
|
void intervalHoursChanged();
|
|
|
|
void typeChanged();
|
|
|
|
void lastRunChanged();
|
|
|
|
void lastSuccessChanged();
|
2017-09-21 13:24:45 +00:00
|
|
|
void taskWorkerChanged();
|
|
|
|
|
|
|
|
void workFinished(bool success);
|
2017-09-20 15:43:43 +00:00
|
|
|
|
|
|
|
public slots:
|
2017-09-21 13:24:45 +00:00
|
|
|
void run();
|
2017-11-07 09:50:26 +00:00
|
|
|
void abort();
|
2017-09-21 13:24:45 +00:00
|
|
|
|
|
|
|
private slots:
|
|
|
|
void handleFinished(bool success);
|
|
|
|
|
|
|
|
private:
|
|
|
|
TaskWorker *createWorker();
|
2017-09-20 15:43:43 +00:00
|
|
|
|
|
|
|
private:
|
2018-03-05 12:17:13 +00:00
|
|
|
quint8 m_enabled : 1;
|
|
|
|
quint8 m_aborted : 1; // transient
|
|
|
|
|
|
|
|
quint16 m_intervalHours;
|
2017-09-20 15:43:43 +00:00
|
|
|
|
|
|
|
TaskType m_type;
|
|
|
|
|
|
|
|
QDateTime m_lastRun;
|
|
|
|
QDateTime m_lastSuccess;
|
2017-09-21 13:24:45 +00:00
|
|
|
|
|
|
|
TaskWorker *m_taskWorker;
|
2017-09-20 15:43:43 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
#endif // TASKINFO_H
|