/* SPDX-FileCopyrightText: 2008-2010 Volker Lanz SPDX-FileCopyrightText: 2008 Laurent Montel SPDX-FileCopyrightText: 2014-2016 Andrius Štikonas SPDX-FileCopyrightText: 2015 Teo Mrnjavac SPDX-FileCopyrightText: 2015 Chris Campbell SPDX-FileCopyrightText: 2019 Yuri Chornoivan SPDX-License-Identifier: GPL-3.0-or-later */ #ifndef KPMCORE_OPERATIONSTACK_H #define KPMCORE_OPERATIONSTACK_H #include "util/libpartitionmanagerexport.h" #include #include #include #include class Device; class Partition; class Operation; class DeviceScanner; /** The list of Operations the user wants to have performed. OperationStack also handles the Devices that were found on this computer and the merging of Operations, e.g., when the user first creates a Partition, then deletes it. @author Volker Lanz */ class LIBKPMCORE_EXPORT OperationStack : public QObject { Q_OBJECT Q_DISABLE_COPY(OperationStack) friend class DeviceScanner; public: typedef QList Devices; typedef QList Operations; public: explicit OperationStack(QObject* parent = nullptr); ~OperationStack() override; Q_SIGNALS: void operationsChanged(); void devicesChanged(); public: void push(Operation* o); void pop(); bool contains(const Partition* p) const; void clearOperations(); int size() const { return operations().size(); /**< @return number of operations */ } Devices& previewDevices() { return m_PreviewDevices; /**< @return the list of Devices */ } const Devices& previewDevices() const { return m_PreviewDevices; /**< @return the list of Devices */ } Operations& operations() { return m_Operations; /**< @return the list of operations */ } const Operations& operations() const { return m_Operations; /**< @return the list of operations */ } Device* findDeviceForPartition(const Partition* p); QReadWriteLock& lock() { return m_Lock; } protected: void clearDevices(); void addDevice(Device* d); void sortDevices(); bool mergeNewOperation(Operation*& currentOp, Operation*& pushedOp); bool mergeCopyOperation(Operation*& currentOp, Operation*& pushedOp); bool mergeRestoreOperation(Operation*& currentOp, Operation*& pushedOp); bool mergePartFlagsOperation(Operation*& currentOp, Operation*& pushedOp); bool mergePartLabelOperation(Operation*& currentOp, Operation*& pushedOp); bool mergeCreatePartitionTableOperation(Operation*& currentOp, Operation*& pushedOp); bool mergeResizeVolumeGroupResizeOperation(Operation*& pushedOp); private: Operations m_Operations; mutable Devices m_PreviewDevices; QReadWriteLock m_Lock; }; #endif