/************************************************************************* * Copyright (C) 2016 by Chantara Tith * * Copyright (C) 2016 by Andrius Štikonas * * * * 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 .* *************************************************************************/ #include "jobs/resizevolumegroupjob.h" #include "core/lvmdevice.h" #include "fs/luks.h" #include "util/report.h" #include /** Creates a new ResizeVolumeGroupJob */ ResizeVolumeGroupJob::ResizeVolumeGroupJob(LvmDevice& dev, const QList & partlist, const Type type) : Job(), m_Device(dev), m_PartList(partlist), m_Type(type) { } bool ResizeVolumeGroupJob::run(Report& parent) { bool rval = false; Report* report = jobStarted(parent); for (const auto &p : partList()) { const QString deviceNode = p->roles().has(PartitionRole::Luks) ? static_cast(&p->fileSystem())->mapperName() : p->partitionPath(); if (type() == ResizeVolumeGroupJob::Type::Grow) rval = LvmDevice::insertPV(*report, device(), deviceNode); else if (type() == ResizeVolumeGroupJob::Type::Shrink) rval = LvmDevice::removePV(*report, device(), deviceNode); if (rval == false) break; } jobFinished(*report, rval); return rval; } QString ResizeVolumeGroupJob::description() const { QString partitionList = QString(); for (const auto &p : partList()) { partitionList += p->deviceNode() + QStringLiteral(", "); } partitionList.chop(2); const qint32 count = partList().count(); if (type() == ResizeVolumeGroupJob::Type::Grow) { return xi18ncp("@info/plain", "Adding LVM Physical Volume %2 to %3.", "Adding LVM Physical Volumes %2 to %3.", count, partitionList, device().name()); } if (type() == ResizeVolumeGroupJob::Type::Shrink) { return xi18ncp("@info/plain", "Removing LVM Physical Volume %2 from %3.", "Removing LVM Physical Volumes %2 from %3.", count, partitionList, device().name()); } return xi18nc("@info/plain", "Resizing Volume Group %1 to %2.", device().name(), partitionList); }