File indexing completed on 2024-05-05 05:48:51

0001 /*
0002     SPDX-FileCopyrightText: 2008-2010 Volker Lanz <vl@fidra.de>
0003     SPDX-FileCopyrightText: 2014-2018 Andrius Štikonas <andrius@stikonas.eu>
0004     SPDX-FileCopyrightText: 2015 Chris Campbell <c.j.campbell@ed.ac.uk>
0005     SPDX-FileCopyrightText: 2015 Teo Mrnjavac <teo@kde.org>
0006     SPDX-FileCopyrightText: 2018 Caio Jordão Carvalho <caiojcarvalho@gmail.com>
0007 
0008     SPDX-License-Identifier: GPL-3.0-or-later
0009 */
0010 
0011 #ifndef KPMCORE_DELETEOPERATION_H
0012 #define KPMCORE_DELETEOPERATION_H
0013 
0014 #include "util/libpartitionmanagerexport.h"
0015 
0016 #include "ops/operation.h"
0017 
0018 #include <QString>
0019 
0020 class Device;
0021 class OperationStack;
0022 class Partition;
0023 
0024 class Job;
0025 class DeletePartitionJob;
0026 
0027 /** Delete a Partition.
0028     @author Volker Lanz <vl@fidra.de>
0029 */
0030 class LIBKPMCORE_EXPORT DeleteOperation : public Operation
0031 {
0032     friend class OperationStack;
0033 
0034     Q_DISABLE_COPY(DeleteOperation)
0035 
0036 public:
0037     enum class ShredAction {
0038         NoShred,
0039         ZeroShred,
0040         RandomShred
0041     };
0042 
0043     DeleteOperation(Device& d, Partition* p, ShredAction shred = ShredAction::NoShred);
0044     ~DeleteOperation();
0045 
0046 public:
0047     QString iconName() const override {
0048         return shredAction() == ShredAction::NoShred ?
0049                QStringLiteral("edit-delete") :
0050                QStringLiteral("edit-delete-shred");
0051     }
0052     QString description() const override;
0053     void preview() override;
0054     void undo() override;
0055     ShredAction shredAction() const {
0056         return m_ShredAction;
0057     }
0058 
0059     bool targets(const Device& d) const override;
0060     bool targets(const Partition& p) const override;
0061 
0062     static bool canDelete(const Partition* p);
0063 
0064 protected:
0065     Device& targetDevice() {
0066         return m_TargetDevice;
0067     }
0068     const Device& targetDevice() const {
0069         return m_TargetDevice;
0070     }
0071 
0072     Partition& deletedPartition() {
0073         return *m_DeletedPartition;
0074     }
0075     const Partition& deletedPartition() const {
0076         return *m_DeletedPartition;
0077     }
0078 
0079     void checkAdjustLogicalNumbers(Partition& p, bool undo);
0080 
0081     void setDeletedPartition(Partition* p) {
0082         m_DeletedPartition = p;
0083     }
0084 
0085     Job* deleteFileSystemJob() {
0086         return m_DeleteFileSystemJob;
0087     }
0088     DeletePartitionJob* deletePartitionJob() {
0089         return m_DeletePartitionJob;
0090     }
0091 
0092 private:
0093     Device& m_TargetDevice;
0094     Partition* m_DeletedPartition;
0095     ShredAction m_ShredAction;
0096     Job* m_DeleteFileSystemJob;
0097     DeletePartitionJob* m_DeletePartitionJob;
0098 };
0099 
0100 #endif