kpmcore/src/ops/setfilesystemlabeloperation...

73 lines
2.8 KiB
C++
Raw Normal View History

/*************************************************************************
* Copyright (C) 2008 by Volker Lanz <vl@fidra.de> *
2016-03-02 19:00:31 +00:00
* Copyright (C) 2016 by Andrius Štikonas <andrius@stikonas.eu> *
* *
* This program is free software; you can redistribute it and/or *
* modify it under the terms of the GNU General Public License as *
* published by the Free Software Foundation; either version 3 of *
* the License, or (at your option) any later version. *
* *
* This program is distributed in the hope that it will be useful, *
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
* GNU General Public License for more details. *
* *
* You should have received a copy of the GNU General Public License *
* along with this program. If not, see <http://www.gnu.org/licenses/>.*
*************************************************************************/
#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
*/
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-07-13 15:16:36 +01:00
addJob(labelJob());
}
bool SetFileSystemLabelOperation::targets(const Device& d) const
{
2015-07-13 15:16:36 +01:00
return labeledPartition().devicePath() == d.deviceNode();
}
bool SetFileSystemLabelOperation::targets(const Partition& p) const
{
2015-07-13 15:16:36 +01:00
return p == labeledPartition();
}
void SetFileSystemLabelOperation::preview()
{
2015-07-13 15:16:36 +01:00
labeledPartition().fileSystem().setLabel(newLabel());
}
void SetFileSystemLabelOperation::undo()
{
2015-07-13 15:16:36 +01:00
labeledPartition().fileSystem().setLabel(oldLabel());
}
QString SetFileSystemLabelOperation::description() const
{
2015-07-13 15:16:36 +01:00
if (oldLabel().isEmpty())
return xi18nc("@info:status", "Set label for partition <filename>%1</filename> to \"%2\"", labeledPartition().deviceNode(), newLabel());
return xi18nc("@info:status", "Set label for partition <filename>%1</filename> from \"%2\" to \"%3\"", labeledPartition().deviceNode(), oldLabel(), newLabel());
}