File indexing completed on 2024-04-28 05:45:45
0001 /* 0002 SPDX-FileCopyrightText: 2008-2010 Volker Lanz <vl@fidra.de> 0003 SPDX-FileCopyrightText: 2014-2018 Andrius Štikonas <andrius@stikonas.eu> 0004 SPDX-FileCopyrightText: 2019 Albert Astals Cid <aacid@kde.org> 0005 0006 SPDX-License-Identifier: GPL-3.0-or-later 0007 */ 0008 0009 #ifndef KPMCORE_OPERATIONRUNNER_H 0010 #define KPMCORE_OPERATIONRUNNER_H 0011 0012 #include "util/libpartitionmanagerexport.h" 0013 0014 #include <QThread> 0015 #include <QMutex> 0016 #include <QtGlobal> 0017 0018 class Operation; 0019 class OperationStack; 0020 class Report; 0021 0022 /** Thread to run the Operations in the OperationStack. 0023 0024 Runs the OperationStack when the user applies operations. 0025 0026 @author Volker Lanz <vl@fidra.de> 0027 */ 0028 class LIBKPMCORE_EXPORT OperationRunner : public QThread 0029 { 0030 Q_OBJECT 0031 Q_DISABLE_COPY(OperationRunner) 0032 0033 public: 0034 OperationRunner(QObject* parent, OperationStack& ostack); 0035 0036 public: 0037 void run() override; 0038 qint32 numJobs() const; 0039 qint32 numOperations() const; 0040 qint32 numProgressSub() const; 0041 bool isCancelling() const { 0042 return m_Cancelling; /**< @return if the user has requested cancelling */ 0043 } 0044 void cancel() const { 0045 m_Cancelling = true; /**< Sets cancelling to true. */ 0046 } 0047 QMutex& suspendMutex() const { 0048 return m_SuspendMutex; /**< @return the QMutex used for syncing */ 0049 } 0050 QString description(qint32 op) const; 0051 void setReport(Report* report) { 0052 m_Report = report; /**< @param report the Report to use while running */ 0053 } 0054 0055 Q_SIGNALS: 0056 void progressSub(int); 0057 void opStarted(int, Operation*); 0058 void opFinished(int, Operation*); 0059 void finished(); 0060 void cancelled(); 0061 void error(); 0062 0063 protected: 0064 OperationStack& operationStack() { 0065 return m_OperationStack; 0066 } 0067 const OperationStack& operationStack() const { 0068 return m_OperationStack; 0069 } 0070 void setCancelling(bool b) { 0071 m_Cancelling = b; 0072 } 0073 Report& report() { 0074 Q_ASSERT(m_Report); 0075 return *m_Report; 0076 } 0077 0078 private: 0079 OperationStack& m_OperationStack; 0080 Report* m_Report; 0081 mutable QMutex m_SuspendMutex; 0082 mutable volatile bool m_Cancelling; 0083 }; 0084 0085 #endif