2017-09-20 15:43:43 +00:00
|
|
|
#ifndef TASKINFO_H
|
|
|
|
#define TASKINFO_H
|
|
|
|
|
|
|
|
#include <QObject>
|
|
|
|
#include <QDateTime>
|
|
|
|
|
2017-09-21 13:24:45 +00:00
|
|
|
class TaskWorker;
|
|
|
|
|
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:
|
|
|
|
enum TaskType {
|
|
|
|
TypeNone = -1,
|
2017-10-25 09:51:35 +00:00
|
|
|
Tasix = 0,
|
|
|
|
Uzonline
|
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);
|
|
|
|
|
2017-09-21 14:16:50 +00:00
|
|
|
static QDateTime now();
|
|
|
|
|
2017-09-20 15:43:43 +00:00
|
|
|
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();
|
|
|
|
void cancel();
|
|
|
|
|
|
|
|
private slots:
|
|
|
|
void handleFinished(bool success);
|
|
|
|
|
|
|
|
private:
|
|
|
|
TaskWorker *createWorker();
|
2017-09-20 15:43:43 +00:00
|
|
|
|
|
|
|
private:
|
|
|
|
uint m_enabled : 1;
|
2017-10-01 03:11:38 +00:00
|
|
|
uint m_canceled : 1; // transient
|
2017-09-20 15:43:43 +00:00
|
|
|
uint m_intervalHours : 16;
|
|
|
|
|
|
|
|
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
|