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

0001 /*
0002     SPDX-FileCopyrightText: 2008-2010 Volker Lanz <vl@fidra.de>
0003     SPDX-FileCopyrightText: 2014-2016 Andrius Štikonas <andrius@stikonas.eu>
0004 
0005     SPDX-License-Identifier: GPL-3.0-or-later
0006 */
0007 
0008 #include "ops/setpartflagsoperation.h"
0009 
0010 #include "core/partition.h"
0011 #include "core/partitionnode.h"
0012 #include "core/partitiontable.h"
0013 #include "core/device.h"
0014 
0015 #include "jobs/setpartflagsjob.h"
0016 
0017 #include "fs/filesystem.h"
0018 
0019 #include <QString>
0020 
0021 #include <KLocalizedString>
0022 
0023 /** Creates a new SetPartFlagsOperation.
0024     @param d the Device on which the Partition to set flags for is
0025     @param p the Partition to set new flags for
0026     @param flags the new flags to set
0027 */
0028 SetPartFlagsOperation::SetPartFlagsOperation(Device& d, Partition& p, const PartitionTable::Flags& flags) :
0029     Operation(),
0030     m_TargetDevice(d),
0031     m_FlagPartition(p),
0032     m_OldFlags(flagPartition().activeFlags()),
0033     m_NewFlags(flags),
0034     m_FlagsJob(new SetPartFlagsJob(targetDevice(), flagPartition(), newFlags()))
0035 {
0036     addJob(flagsJob());
0037 }
0038 
0039 bool SetPartFlagsOperation::targets(const Device& d) const
0040 {
0041     return d == targetDevice();
0042 }
0043 
0044 bool SetPartFlagsOperation::targets(const Partition& p) const
0045 {
0046     return p == flagPartition();
0047 }
0048 
0049 void SetPartFlagsOperation::preview()
0050 {
0051     flagPartition().setFlags(newFlags());
0052 }
0053 
0054 void SetPartFlagsOperation::undo()
0055 {
0056     flagPartition().setFlags(oldFlags());
0057 }
0058 
0059 QString SetPartFlagsOperation::description() const
0060 {
0061     if (PartitionTable::flagNames(newFlags()).size() == 0)
0062         return xi18nc("@info:status", "Clear flags for partition <filename>%1</filename>", flagPartition().deviceNode());
0063 
0064     return xi18nc("@info:status", "Set flags for partition <filename>%1</filename> to \"%2\"", flagPartition().deviceNode(), PartitionTable::flagNames(newFlags()).join(QStringLiteral(",")));
0065 }