partitionmanager/src/gui/createvolumegroupdialog.cpp

146 lines
4.7 KiB
C++
Raw Normal View History

2020-09-16 00:35:12 +01:00
/*
SPDX-FileCopyrightText: 2016 Chantara Tith <tith.chantara@gmail.com>
2020-10-24 22:15:02 +01:00
SPDX-FileCopyrightText: 2016-2020 Andrius Štikonas <andrius@stikonas.eu>
2020-09-16 00:35:12 +01:00
SPDX-FileCopyrightText: 2018 Caio Jordão Carvalho <caiojcarvalho@gmail.com>
SPDX-FileCopyrightText: 2019 Yuri Chornoivan <yurchor@ukr.net>
SPDX-License-Identifier: GPL-3.0-or-later
*/
2016-09-04 12:25:43 +01:00
#include "gui/createvolumegroupdialog.h"
#include "gui/volumegroupwidget.h"
#include <core/device.h>
#include <core/lvmdevice.h>
#include <core/partitiontable.h>
#include <fs/lvm2_pv.h>
#include <ops/deleteoperation.h>
#include <util/capacity.h>
#include <util/helpers.h>
2020-10-24 22:15:02 +01:00
#include <utility>
2017-10-09 13:54:31 +01:00
#include <QtGlobal>
2016-08-23 16:40:16 +01:00
#include <KConfigGroup>
#include <KLocalizedString>
#include <KSharedConfig>
CreateVolumeGroupDialog::CreateVolumeGroupDialog(QWidget* parent, QString& vgName, QVector<const Partition*>& partList, qint32& peSize, QList<Device*> devices, QList<Operation*> pendingOps)
: VolumeGroupDialog(parent, vgName, partList)
, m_PESize(peSize)
, m_Devices(devices)
, m_PendingOps(pendingOps)
{
2016-07-25 16:48:54 +01:00
setWindowTitle(xi18nc("@title:window", "Create new Volume Group"));
setupDialog();
setupConstraints();
setupConnections();
// disable volume type and PE size for now, until the features are implemented.
dialogWidget().volumeType().setEnabled(false);
KConfigGroup kcg(KSharedConfig::openConfig(), "createVolumeDialog");
restoreGeometry(kcg.readEntry<QByteArray>("Geometry", QByteArray()));
}
2016-09-04 12:25:43 +01:00
void CreateVolumeGroupDialog::setupDialog()
{
2020-10-24 22:15:02 +01:00
for (const auto &p : std::as_const(LVM::pvList::list())) {
bool toBeDeleted = false;
// Ignore partitions that are going to be deleted
2020-10-24 22:15:02 +01:00
for (const auto &o : std::as_const(m_PendingOps)) {
if (dynamic_cast<DeleteOperation *>(o) && o->targets(*p.partition())) {
toBeDeleted = true;
break;
}
}
if (toBeDeleted)
continue;
2019-12-09 16:33:04 +00:00
if (!p.isLuks() && p.vgName().isEmpty() && !LvmDevice::s_DirtyPVs.contains(p.partition()))
dialogWidget().listPV().addPartition(*p.partition(), false);
}
2020-10-24 22:15:02 +01:00
for (const Device *d : std::as_const(m_Devices)) {
if (d->partitionTable() != nullptr) {
2020-10-24 22:15:02 +01:00
for (const Partition *p : std::as_const(d->partitionTable()->children())) {
// Looking if there is another VG creation that contains this partition
if (LvmDevice::s_DirtyPVs.contains(p))
continue;
// Including new LVM PVs (that are currently in OperationStack and that aren't at other VG creation)
if (p->state() == Partition::State::New) {
if (p->fileSystem().type() == FileSystem::Type::Lvm2_PV)
dialogWidget().listPV().addPartition(*p, false);
else if (p->fileSystem().type() == FileSystem::Type::Luks || p->fileSystem().type() == FileSystem::Type::Luks2) {
FileSystem *fs = static_cast<const FS::luks *>(&p->fileSystem())->innerFS();
if (fs->type() == FileSystem::Type::Lvm2_PV)
dialogWidget().listPV().addPartition(*p, false);
}
}
}
}
}
2020-10-24 22:15:02 +01:00
for (const Partition *p : std::as_const(LvmDevice::s_OrphanPVs))
if (!LvmDevice::s_DirtyPVs.contains(p))
dialogWidget().listPV().addPartition(*p, false);
}
2016-09-04 12:25:43 +01:00
void CreateVolumeGroupDialog::setupConnections()
{
2016-09-04 12:25:43 +01:00
connect(&dialogWidget().vgName(), &QLineEdit::textChanged, this, &CreateVolumeGroupDialog::onVGNameChanged);
2017-10-09 13:54:31 +01:00
connect(&dialogWidget().spinPESize(), qOverload<int>(&QSpinBox::valueChanged), this, &CreateVolumeGroupDialog::onSpinPESizeChanged);
}
2016-09-04 12:25:43 +01:00
void CreateVolumeGroupDialog::accept()
{
QString& tname = targetName();
tname = dialogWidget().vgName().text();
2017-08-31 10:34:58 +01:00
targetPVList().append(dialogWidget().listPV().checkedItems());
qint32& pesize = peSize();
pesize = dialogWidget().spinPESize().value();
QDialog::accept();
}
void CreateVolumeGroupDialog::updateOkButtonStatus()
{
VolumeGroupDialog::updateOkButtonStatus();
if (okButton->isEnabled())
okButton->setEnabled(!dialogWidget().listPV().checkedItems().empty());
}
void CreateVolumeGroupDialog::onVGNameChanged(const QString& vgName)
{
for (const auto &d : m_Devices) {
if (dynamic_cast<LvmDevice*>(d)) {
if (d->name() == vgName) {
m_IsValidName = false;
break;
}
else
m_IsValidName = true;
}
}
updateOkButtonStatus();
}
2016-09-04 12:25:43 +01:00
void CreateVolumeGroupDialog::onSpinPESizeChanged(int newsize)
{
2020-11-14 01:33:28 +00:00
Q_UNUSED(newsize)
updateOkButtonStatus();
updateSectorInfos();
}