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/setfilesystemlabeloperation.h"
0009 
0010 #include "core/partition.h"
0011 #include "core/device.h"
0012 
0013 #include "jobs/setfilesystemlabeljob.h"
0014 
0015 #include "fs/filesystem.h"
0016 
0017 #include <QString>
0018 
0019 #include <KLocalizedString>
0020 
0021 /** Creates a new SetFileSystemLabelOperation.
0022     @param p the Partition with the FileSystem to set the label for
0023     @param newlabel the new label
0024 */
0025 SetFileSystemLabelOperation::SetFileSystemLabelOperation(Partition& p, const QString& newlabel) :
0026     Operation(),
0027     m_LabeledPartition(p),
0028     m_OldLabel(labeledPartition().fileSystem().label()),
0029     m_NewLabel(newlabel),
0030     m_LabelJob(new SetFileSystemLabelJob(labeledPartition(), newLabel()))
0031 {
0032     addJob(labelJob());
0033 }
0034 
0035 bool SetFileSystemLabelOperation::targets(const Device& d) const
0036 {
0037     return labeledPartition().devicePath() == d.deviceNode();
0038 }
0039 
0040 bool SetFileSystemLabelOperation::targets(const Partition& p) const
0041 {
0042     return p == labeledPartition();
0043 }
0044 
0045 void SetFileSystemLabelOperation::preview()
0046 {
0047     labeledPartition().fileSystem().setLabel(newLabel());
0048 }
0049 
0050 void SetFileSystemLabelOperation::undo()
0051 {
0052     labeledPartition().fileSystem().setLabel(oldLabel());
0053 }
0054 
0055 QString SetFileSystemLabelOperation::description() const
0056 {
0057     if (oldLabel().isEmpty())
0058         return xi18nc("@info:status", "Set label for partition <filename>%1</filename> to \"%2\"", labeledPartition().deviceNode(), newLabel());
0059 
0060     return xi18nc("@info:status", "Set label for partition <filename>%1</filename> from \"%2\" to \"%3\"", labeledPartition().deviceNode(), oldLabel(), newLabel());
0061 }