2015-06-04 01:29:22 +01:00
|
|
|
/*************************************************************************
|
|
|
|
* Copyright (C) 2008 by Volker Lanz <vl@fidra.de> *
|
|
|
|
* *
|
|
|
|
* This program is free software; you can redistribute it and/or *
|
|
|
|
* modify it under the terms of the GNU General Public License as *
|
|
|
|
* published by the Free Software Foundation; either version 3 of *
|
|
|
|
* the License, or (at your option) any later version. *
|
|
|
|
* *
|
|
|
|
* This program is distributed in the hope that it will be useful, *
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
|
|
|
|
* GNU General Public License for more details. *
|
|
|
|
* *
|
|
|
|
* You should have received a copy of the GNU General Public License *
|
|
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.*
|
|
|
|
*************************************************************************/
|
|
|
|
|
|
|
|
#if !defined(OPERATIONRUNNER__H)
|
|
|
|
|
|
|
|
#define OPERATIONRUNNER__H
|
|
|
|
|
2016-05-06 22:36:24 +01:00
|
|
|
#include "util/libpartitionmanagerexport.h"
|
2015-06-04 01:29:22 +01:00
|
|
|
|
|
|
|
#include <QThread>
|
|
|
|
#include <QMutex>
|
2016-04-18 17:14:31 +01:00
|
|
|
#include <QtGlobal>
|
2015-06-04 01:29:22 +01:00
|
|
|
|
|
|
|
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-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 OperationRunner : public QThread
|
|
|
|
{
|
2015-07-13 15:16:36 +01:00
|
|
|
Q_OBJECT
|
|
|
|
Q_DISABLE_COPY(OperationRunner)
|
2015-06-04 01:29:22 +01:00
|
|
|
|
2015-07-13 15:16:36 +01:00
|
|
|
public:
|
|
|
|
OperationRunner(QObject* parent, OperationStack& ostack);
|
2015-06-04 01:29:22 +01:00
|
|
|
|
2015-07-13 15:16:36 +01:00
|
|
|
public:
|
|
|
|
void run();
|
|
|
|
LIBKPMCORE_EXPORT qint32 numJobs() const;
|
|
|
|
LIBKPMCORE_EXPORT qint32 numOperations() const;
|
|
|
|
LIBKPMCORE_EXPORT qint32 numProgressSub() const;
|
|
|
|
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-06-04 01:29:22 +01:00
|
|
|
|
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-06-04 01:29:22 +01:00
|
|
|
|
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-06-04 01:29:22 +01:00
|
|
|
|
2015-07-13 15:16:36 +01:00
|
|
|
private:
|
|
|
|
OperationStack& m_OperationStack;
|
|
|
|
Report* m_Report;
|
|
|
|
mutable QMutex m_SuspendMutex;
|
|
|
|
mutable volatile bool m_Cancelling;
|
2015-06-04 01:29:22 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
#endif
|