2020-09-29 23:55:11 +01:00
|
|
|
/*
|
|
|
|
SPDX-FileCopyrightText: 2008-2010 Volker Lanz <vl@fidra.de>
|
|
|
|
SPDX-FileCopyrightText: 2016-2018 Andrius Štikonas <andrius@stikonas.eu>
|
|
|
|
SPDX-FileCopyrightText: 2018 Huzaifa Faruqui <huzaifafaruqui@gmail.com>
|
|
|
|
|
|
|
|
SPDX-License-Identifier: GPL-3.0-or-later
|
|
|
|
*/
|
2015-06-04 01:29:22 +01:00
|
|
|
|
2018-04-12 13:18:50 +01:00
|
|
|
#ifndef KPMCORE_JOB_H
|
2017-09-10 20:12:52 +01:00
|
|
|
#define KPMCORE_JOB_H
|
2015-06-04 01:29:22 +01:00
|
|
|
|
2016-05-06 22:36:24 +01:00
|
|
|
#include "fs/filesystem.h"
|
2015-06-04 01:29:22 +01:00
|
|
|
|
2016-05-06 22:36:24 +01:00
|
|
|
#include "util/libpartitionmanagerexport.h"
|
2015-06-04 01:29:22 +01:00
|
|
|
|
|
|
|
#include <QObject>
|
2016-04-18 17:14:31 +01:00
|
|
|
#include <QtGlobal>
|
2015-06-04 01:29:22 +01:00
|
|
|
|
|
|
|
class QString;
|
|
|
|
class QIcon;
|
|
|
|
|
|
|
|
class CopySource;
|
|
|
|
class CopyTarget;
|
|
|
|
class Report;
|
|
|
|
|
|
|
|
/** Base class for all Jobs.
|
|
|
|
|
2015-07-13 15:16:36 +01:00
|
|
|
Each Operation is made up of one or more Jobs. Usually, an Operation will run each Job it is
|
|
|
|
made up of and only complete successfully if each Job could be run without error. Jobs are
|
|
|
|
all-or-nothing and try to be as atomic as possible: A Job is either successfully run or not, there
|
|
|
|
is no case where a Job finishes with a warning.
|
2015-06-04 01:29:22 +01:00
|
|
|
|
2015-07-13 15:16:36 +01:00
|
|
|
@author Volker Lanz <vl@fidra.de>
|
2015-06-04 01:29:22 +01:00
|
|
|
*/
|
|
|
|
class LIBKPMCORE_EXPORT Job : public QObject
|
|
|
|
{
|
2015-07-13 15:16:36 +01:00
|
|
|
Q_OBJECT
|
|
|
|
Q_DISABLE_COPY(Job)
|
2015-06-04 01:29:22 +01:00
|
|
|
|
2015-07-13 15:16:36 +01:00
|
|
|
public:
|
|
|
|
/** Status of this Job */
|
2018-04-12 13:18:50 +01:00
|
|
|
enum class Status : int {
|
|
|
|
Pending, /**< Pending, not yet run */
|
|
|
|
Success, /**< Successfully run */
|
|
|
|
Error /**< Running generated an error */
|
2015-07-13 15:16:36 +01:00
|
|
|
};
|
2015-06-04 01:29:22 +01:00
|
|
|
|
2015-07-13 15:16:36 +01:00
|
|
|
protected:
|
|
|
|
Job();
|
2015-06-04 01:29:22 +01:00
|
|
|
|
2015-07-13 15:16:36 +01:00
|
|
|
public:
|
|
|
|
virtual ~Job() {}
|
2015-06-04 01:29:22 +01:00
|
|
|
|
2015-07-13 15:16:36 +01:00
|
|
|
Q_SIGNALS:
|
|
|
|
void started();
|
|
|
|
void progress(int);
|
|
|
|
void finished();
|
2015-06-04 01:29:22 +01:00
|
|
|
|
2015-07-13 15:16:36 +01:00
|
|
|
public:
|
|
|
|
virtual qint32 numSteps() const {
|
|
|
|
return 1; /**< @return the number of steps the job takes to complete */
|
|
|
|
}
|
|
|
|
virtual QString description() const = 0; /**< @return the Job's description */
|
|
|
|
virtual bool run(Report& parent) = 0; /**< @param parent parent Report to add new child to for this Job @return true if successfully run */
|
2015-06-04 01:29:22 +01:00
|
|
|
|
2017-09-08 15:05:55 +01:00
|
|
|
virtual QString statusIcon() const;
|
2015-07-13 15:16:36 +01:00
|
|
|
virtual QString statusText() const;
|
2015-06-04 01:29:22 +01:00
|
|
|
|
2018-04-12 13:18:50 +01:00
|
|
|
Status status() const {
|
2015-07-13 15:16:36 +01:00
|
|
|
return m_Status; /**< @return the Job's current status */
|
|
|
|
}
|
2015-06-04 01:29:22 +01:00
|
|
|
|
2015-07-13 15:16:36 +01:00
|
|
|
void emitProgress(int i);
|
2020-10-11 23:46:20 +01:00
|
|
|
void updateReport(const QString& report);
|
2015-06-04 01:29:22 +01:00
|
|
|
|
2015-07-13 15:16:36 +01:00
|
|
|
protected:
|
|
|
|
bool copyBlocks(Report& report, CopyTarget& target, CopySource& source);
|
|
|
|
bool rollbackCopyBlocks(Report& report, CopyTarget& origTarget, CopySource& origSource);
|
2015-06-04 01:29:22 +01:00
|
|
|
|
2015-07-13 15:16:36 +01:00
|
|
|
Report* jobStarted(Report& parent);
|
|
|
|
void jobFinished(Report& report, bool b);
|
2015-06-04 01:29:22 +01:00
|
|
|
|
2018-04-12 13:18:50 +01:00
|
|
|
void setStatus(Status s) {
|
2015-07-13 15:16:36 +01:00
|
|
|
m_Status = s;
|
|
|
|
}
|
2015-06-04 01:29:22 +01:00
|
|
|
|
2015-07-13 15:16:36 +01:00
|
|
|
private:
|
2018-01-27 18:54:48 +00:00
|
|
|
Report *m_Report;
|
2018-04-12 13:18:50 +01:00
|
|
|
Status m_Status;
|
2015-06-04 01:29:22 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
#endif
|