2020-09-30 23:28:47 +01:00
/*
SPDX - FileCopyrightText : 2008 - 2010 Volker Lanz < vl @ fidra . de >
SPDX - FileCopyrightText : 2014 - 2016 Andrius Š tikonas < andrius @ stikonas . eu >
SPDX - License - Identifier : GPL - 3.0 - or - later
*/
2015-06-04 01:29:22 +01:00
# include "ops/setpartflagsoperation.h"
# include "core/partition.h"
# include "core/partitionnode.h"
# include "core/partitiontable.h"
# include "core/device.h"
# include "jobs/setpartflagsjob.h"
# include "fs/filesystem.h"
# include <QString>
# include <KLocalizedString>
/** Creates a new SetPartFlagsOperation.
2015-07-13 15:16:36 +01:00
@ param d the Device on which the Partition to set flags for is
@ param p the Partition to set new flags for
@ param flags the new flags to set
2015-06-04 01:29:22 +01:00
*/
SetPartFlagsOperation : : SetPartFlagsOperation ( Device & d , Partition & p , const PartitionTable : : Flags & flags ) :
2015-07-13 15:16:36 +01:00
Operation ( ) ,
m_TargetDevice ( d ) ,
m_FlagPartition ( p ) ,
m_OldFlags ( flagPartition ( ) . activeFlags ( ) ) ,
m_NewFlags ( flags ) ,
m_FlagsJob ( new SetPartFlagsJob ( targetDevice ( ) , flagPartition ( ) , newFlags ( ) ) )
2015-06-04 01:29:22 +01:00
{
2015-07-13 15:16:36 +01:00
addJob ( flagsJob ( ) ) ;
2015-06-04 01:29:22 +01:00
}
bool SetPartFlagsOperation : : targets ( const Device & d ) const
{
2015-07-13 15:16:36 +01:00
return d = = targetDevice ( ) ;
2015-06-04 01:29:22 +01:00
}
bool SetPartFlagsOperation : : targets ( const Partition & p ) const
{
2015-07-13 15:16:36 +01:00
return p = = flagPartition ( ) ;
2015-06-04 01:29:22 +01:00
}
void SetPartFlagsOperation : : preview ( )
{
2015-07-13 15:16:36 +01:00
flagPartition ( ) . setFlags ( newFlags ( ) ) ;
2015-06-04 01:29:22 +01:00
}
void SetPartFlagsOperation : : undo ( )
{
2015-07-13 15:16:36 +01:00
flagPartition ( ) . setFlags ( oldFlags ( ) ) ;
2015-06-04 01:29:22 +01:00
}
QString SetPartFlagsOperation : : description ( ) const
{
2015-07-13 15:16:36 +01:00
if ( PartitionTable : : flagNames ( newFlags ( ) ) . size ( ) = = 0 )
2016-07-17 23:41:00 +01:00
return xi18nc ( " @info:status " , " Clear flags for partition <filename>%1</filename> " , flagPartition ( ) . deviceNode ( ) ) ;
2015-06-04 01:29:22 +01:00
2016-07-17 23:41:00 +01:00
return xi18nc ( " @info:status " , " Set flags for partition <filename>%1</filename> to \" %2 \" " , flagPartition ( ) . deviceNode ( ) , PartitionTable : : flagNames ( newFlags ( ) ) . join ( QStringLiteral ( " , " ) ) ) ;
2015-06-04 01:29:22 +01:00
}