File indexing completed on 2024-04-28 05:45:45
0001 /* 0002 SPDX-FileCopyrightText: 2008-2010 Volker Lanz <vl@fidra.de> 0003 SPDX-FileCopyrightText: 2008 Laurent Montel <montel@kde.org> 0004 SPDX-FileCopyrightText: 2014-2016 Andrius Štikonas <andrius@stikonas.eu> 0005 SPDX-FileCopyrightText: 2015 Teo Mrnjavac <teo@kde.org> 0006 SPDX-FileCopyrightText: 2015 Chris Campbell <c.j.campbell@ed.ac.uk> 0007 SPDX-FileCopyrightText: 2019 Yuri Chornoivan <yurchor@ukr.net> 0008 0009 SPDX-License-Identifier: GPL-3.0-or-later 0010 */ 0011 0012 #ifndef KPMCORE_OPERATIONSTACK_H 0013 #define KPMCORE_OPERATIONSTACK_H 0014 0015 #include "util/libpartitionmanagerexport.h" 0016 0017 #include <QObject> 0018 #include <QList> 0019 #include <QReadWriteLock> 0020 0021 #include <QtGlobal> 0022 0023 class Device; 0024 class Partition; 0025 class Operation; 0026 class DeviceScanner; 0027 0028 /** The list of Operations the user wants to have performed. 0029 0030 OperationStack also handles the Devices that were found on this computer and the merging of 0031 Operations, e.g., when the user first creates a Partition, then deletes it. 0032 0033 @author Volker Lanz <vl@fidra.de> 0034 */ 0035 class LIBKPMCORE_EXPORT OperationStack : public QObject 0036 { 0037 Q_OBJECT 0038 Q_DISABLE_COPY(OperationStack) 0039 0040 friend class DeviceScanner; 0041 0042 public: 0043 typedef QList<Device*> Devices; 0044 typedef QList<Operation*> Operations; 0045 0046 public: 0047 explicit OperationStack(QObject* parent = nullptr); 0048 ~OperationStack() override; 0049 0050 Q_SIGNALS: 0051 void operationsChanged(); 0052 void devicesChanged(); 0053 0054 public: 0055 void push(Operation* o); 0056 void pop(); 0057 bool contains(const Partition* p) const; 0058 void clearOperations(); 0059 int size() const { 0060 return operations().size(); /**< @return number of operations */ 0061 } 0062 0063 Devices& previewDevices() { 0064 return m_PreviewDevices; /**< @return the list of Devices */ 0065 } 0066 const Devices& previewDevices() const { 0067 return m_PreviewDevices; /**< @return the list of Devices */ 0068 } 0069 0070 Operations& operations() { 0071 return m_Operations; /**< @return the list of operations */ 0072 } 0073 const Operations& operations() const { 0074 return m_Operations; /**< @return the list of operations */ 0075 } 0076 0077 Device* findDeviceForPartition(const Partition* p); 0078 0079 QReadWriteLock& lock() { 0080 return m_Lock; 0081 } 0082 0083 protected: 0084 void clearDevices(); 0085 void addDevice(Device* d); 0086 void sortDevices(); 0087 0088 bool mergeNewOperation(Operation*& currentOp, Operation*& pushedOp); 0089 bool mergeCopyOperation(Operation*& currentOp, Operation*& pushedOp); 0090 bool mergeRestoreOperation(Operation*& currentOp, Operation*& pushedOp); 0091 bool mergePartFlagsOperation(Operation*& currentOp, Operation*& pushedOp); 0092 bool mergePartLabelOperation(Operation*& currentOp, Operation*& pushedOp); 0093 bool mergeCreatePartitionTableOperation(Operation*& currentOp, Operation*& pushedOp); 0094 bool mergeResizeVolumeGroupResizeOperation(Operation*& pushedOp); 0095 0096 private: 0097 Operations m_Operations; 0098 mutable Devices m_PreviewDevices; 0099 QReadWriteLock m_Lock; 0100 }; 0101 0102 #endif