kpmcore/src/core/operationrunner.h

86 lines
2.1 KiB
C
Raw Permalink Normal View History

/*
SPDX-FileCopyrightText: 2008-2010 Volker Lanz <vl@fidra.de>
SPDX-FileCopyrightText: 2014-2018 Andrius Štikonas <andrius@stikonas.eu>
SPDX-FileCopyrightText: 2019 Albert Astals Cid <aacid@kde.org>
SPDX-License-Identifier: GPL-3.0-or-later
*/
#ifndef KPMCORE_OPERATIONRUNNER_H
#define KPMCORE_OPERATIONRUNNER_H
2016-05-06 22:36:24 +01:00
#include "util/libpartitionmanagerexport.h"
#include <QThread>
#include <QMutex>
2016-04-18 17:14:31 +01:00
#include <QtGlobal>
class Operation;
class OperationStack;
class Report;
/** Thread to run the Operations in the OperationStack.
2015-07-13 15:16:36 +01:00
Runs the OperationStack when the user applies operations.
2015-07-13 15:16:36 +01:00
@author Volker Lanz <vl@fidra.de>
*/
class LIBKPMCORE_EXPORT OperationRunner : public QThread
{
2015-07-13 15:16:36 +01:00
Q_OBJECT
Q_DISABLE_COPY(OperationRunner)
2015-07-13 15:16:36 +01:00
public:
OperationRunner(QObject* parent, OperationStack& ostack);
2015-07-13 15:16:36 +01:00
public:
2019-02-15 23:17:48 +00:00
void run() override;
qint32 numJobs() const;
qint32 numOperations() const;
qint32 numProgressSub() const;
2015-07-13 15:16:36 +01:00
bool isCancelling() const {
return m_Cancelling; /**< @return if the user has requested cancelling */
}
void cancel() const {
m_Cancelling = true; /**< Sets cancelling to true. */
}
QMutex& suspendMutex() const {
return m_SuspendMutex; /**< @return the QMutex used for syncing */
}
QString description(qint32 op) const;
void setReport(Report* report) {
m_Report = report; /**< @param report the Report to use while running */
}
2015-07-13 15:16:36 +01:00
Q_SIGNALS:
void progressSub(int);
void opStarted(int, Operation*);
void opFinished(int, Operation*);
void finished();
void cancelled();
void error();
2015-07-13 15:16:36 +01:00
protected:
OperationStack& operationStack() {
return m_OperationStack;
}
const OperationStack& operationStack() const {
return m_OperationStack;
}
void setCancelling(bool b) {
m_Cancelling = b;
}
Report& report() {
Q_ASSERT(m_Report);
return *m_Report;
}
2015-07-13 15:16:36 +01:00
private:
OperationStack& m_OperationStack;
Report* m_Report;
mutable QMutex m_SuspendMutex;
mutable volatile bool m_Cancelling;
};
#endif