partitionmanager/src/gui/resizevolumegroupdialog.cpp

89 lines
3.6 KiB
C++
Raw Normal View History

2016-07-09 01:12:31 +01:00
/*************************************************************************
* Copyright (C) 2016 by Chantara Tith <tith.chantara@gmail.com> *
2016-11-04 14:14:05 +00:00
* Copyright (C) 2016 by Andrius Štikonas <andrius@stikonas.eu> *
2016-07-09 01:12:31 +01:00
* *
* 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/>.*
*************************************************************************/
2016-09-04 12:25:43 +01:00
#include "gui/resizevolumegroupdialog.h"
#include "gui/volumegroupwidget.h"
2016-07-09 01:12:31 +01:00
#include <core/lvmdevice.h>
#include <core/volumemanagerdevice.h>
#include <core/partitiontable.h>
2016-07-09 01:12:31 +01:00
#include <fs/lvm2_pv.h>
#include <util/capacity.h>
#include <util/helpers.h>
2016-08-23 16:40:16 +01:00
#include <KConfigGroup>
2016-07-09 01:12:31 +01:00
#include <KLocalizedString>
#include <KSharedConfig>
2016-09-04 12:25:43 +01:00
/** Creates a new ResizeVolumeGroupDialog
2016-07-09 01:12:31 +01:00
@param parent pointer to the parent widget
2016-09-08 01:42:13 +01:00
@param d the Device to show properties for
2016-07-09 01:12:31 +01:00
*/
ResizeVolumeGroupDialog::ResizeVolumeGroupDialog(QWidget* parent, VolumeManagerDevice* d, std::vector<const Partition*>& partList)
: VolumeGroupDialog(parent, d->name(), partList)
, m_Device(d)
2016-07-09 01:12:31 +01:00
{
setWindowTitle(xi18nc("@title:window", "Resize Volume Group"));
setupDialog();
setupConstraints();
KConfigGroup kcg(KSharedConfig::openConfig(), "resizeVolumeDialog");
restoreGeometry(kcg.readEntry<QByteArray>("Geometry", QByteArray()));
}
2016-09-04 12:25:43 +01:00
void ResizeVolumeGroupDialog::setupDialog()
2016-07-09 01:12:31 +01:00
{
if (dialogWidget().volumeType().currentText() == QStringLiteral("LVM")) {
2017-01-05 19:11:32 +00:00
for (const auto &p : qAsConst(LVM::pvList)) {
if (p.isLuks())
continue;
if (p.vgName() == device()->name())
dialogWidget().listPV().addPartition(*p.partition(), true);
else if (p.vgName() == QString() && !LvmDevice::s_DirtyPVs.contains(p.partition())) // TODO: Remove LVM PVs in current VG
dialogWidget().listPV().addPartition(*p.partition(), false);
}
}
//update used size and LV infos
qint32 totalLV = 0;
LvmDevice *lvmDevice = dynamic_cast<LvmDevice *>(device());
if (lvmDevice != nullptr) {
m_TotalUsedSize = lvmDevice->allocatedPE() * lvmDevice->peSize();
totalLV = lvmDevice->partitionTable()->children().count();
}
dialogWidget().totalUsedSize().setText(Capacity::formatByteSize(m_TotalUsedSize));
dialogWidget().totalLV().setText(QString::number(totalLV));
2016-07-09 01:12:31 +01:00
}
2016-09-04 12:25:43 +01:00
void ResizeVolumeGroupDialog::setupConstraints()
2016-07-09 01:12:31 +01:00
{
dialogWidget().vgName().setEnabled(false);
dialogWidget().spinPESize().setEnabled(false);
dialogWidget().volumeType().setEnabled(false);
2016-09-04 12:25:43 +01:00
VolumeGroupDialog::setupConstraints();
2016-07-09 01:12:31 +01:00
}
2016-09-04 12:25:43 +01:00
void ResizeVolumeGroupDialog::accept()
2016-07-09 01:12:31 +01:00
{
targetPVList().insert(targetPVList().end(), dialogWidget().listPV().checkedItems().begin(), dialogWidget().listPV().checkedItems().end());
2016-07-09 01:12:31 +01:00
QDialog::accept();
}