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/setfilesystemlabeloperation.h"
# include "core/partition.h"
# include "core/device.h"
# include "jobs/setfilesystemlabeljob.h"
# include "fs/filesystem.h"
# include <QString>
# include <KLocalizedString>
/** Creates a new SetFileSystemLabelOperation.
2015-07-13 15:16:36 +01:00
@ param p the Partition with the FileSystem to set the label for
@ param newlabel the new label
2015-06-04 01:29:22 +01:00
*/
SetFileSystemLabelOperation : : SetFileSystemLabelOperation ( Partition & p , const QString & newlabel ) :
2015-07-13 15:16:36 +01:00
Operation ( ) ,
m_LabeledPartition ( p ) ,
m_OldLabel ( labeledPartition ( ) . fileSystem ( ) . label ( ) ) ,
m_NewLabel ( newlabel ) ,
m_LabelJob ( new SetFileSystemLabelJob ( labeledPartition ( ) , newLabel ( ) ) )
2015-06-04 01:29:22 +01:00
{
2015-07-13 15:16:36 +01:00
addJob ( labelJob ( ) ) ;
2015-06-04 01:29:22 +01:00
}
bool SetFileSystemLabelOperation : : targets ( const Device & d ) const
{
2015-07-13 15:16:36 +01:00
return labeledPartition ( ) . devicePath ( ) = = d . deviceNode ( ) ;
2015-06-04 01:29:22 +01:00
}
bool SetFileSystemLabelOperation : : targets ( const Partition & p ) const
{
2015-07-13 15:16:36 +01:00
return p = = labeledPartition ( ) ;
2015-06-04 01:29:22 +01:00
}
void SetFileSystemLabelOperation : : preview ( )
{
2015-07-13 15:16:36 +01:00
labeledPartition ( ) . fileSystem ( ) . setLabel ( newLabel ( ) ) ;
2015-06-04 01:29:22 +01:00
}
void SetFileSystemLabelOperation : : undo ( )
{
2015-07-13 15:16:36 +01:00
labeledPartition ( ) . fileSystem ( ) . setLabel ( oldLabel ( ) ) ;
2015-06-04 01:29:22 +01:00
}
QString SetFileSystemLabelOperation : : description ( ) const
{
2015-07-13 15:16:36 +01:00
if ( oldLabel ( ) . isEmpty ( ) )
2016-07-17 23:41:00 +01:00
return xi18nc ( " @info:status " , " Set label for partition <filename>%1</filename> to \" %2 \" " , labeledPartition ( ) . deviceNode ( ) , newLabel ( ) ) ;
2015-06-04 01:29:22 +01:00
2016-07-17 23:41:00 +01:00
return xi18nc ( " @info:status " , " Set label for partition <filename>%1</filename> from \" %2 \" to \" %3 \" " , labeledPartition ( ) . deviceNode ( ) , oldLabel ( ) , newLabel ( ) ) ;
2015-06-04 01:29:22 +01:00
}