diff --git a/src/gui/createvolumegroupdialog.cpp b/src/gui/createvolumegroupdialog.cpp index eab4681..b4c0ed2 100644 --- a/src/gui/createvolumegroupdialog.cpp +++ b/src/gui/createvolumegroupdialog.cpp @@ -1,146 +1,152 @@ /************************************************************************* * 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 "gui/createvolumegroupdialog.h" #include "gui/volumegroupwidget.h" #include #include #include #include #include #include #include #include #include #include #include CreateVolumeGroupDialog::CreateVolumeGroupDialog(QWidget* parent, QString& vgName, QVector& partList, qint32& peSize, QList devices, QList pendingOps) : VolumeGroupDialog(parent, vgName, partList) , m_PESize(peSize) , m_Devices(devices) , m_PendingOps(pendingOps) { 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("Geometry", QByteArray())); } void CreateVolumeGroupDialog::setupDialog() { for (const auto &p : qAsConst(LVM::pvList::list())) { bool toBeDeleted = false; // Ignore partitions that are going to be deleted for (const auto &o : qAsConst(m_PendingOps)) { if (dynamic_cast(o) && o->targets(*p.partition())) { toBeDeleted = true; break; } } if (toBeDeleted) continue; if (!p.isLuks() && p.vgName() == QString() && !LvmDevice::s_DirtyPVs.contains(p.partition())) dialogWidget().listPV().addPartition(*p.partition(), false); } for (const Device *d : qAsConst(m_Devices)) { - for (const Partition *p : qAsConst(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(&p->fileSystem())->innerFS(); - - if (fs->type() == FileSystem::Type::Lvm2_PV) + if (d->partitionTable() != nullptr) { + for (const Partition *p : qAsConst(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(&p->fileSystem())->innerFS(); + + if (fs->type() == FileSystem::Type::Lvm2_PV) + dialogWidget().listPV().addPartition(*p, false); + } } } } } + + for (const Partition *p : qAsConst(LvmDevice::s_OrphanPVs)) + if (!LvmDevice::s_DirtyPVs.contains(p)) + dialogWidget().listPV().addPartition(*p, false); } void CreateVolumeGroupDialog::setupConnections() { connect(&dialogWidget().vgName(), &QLineEdit::textChanged, this, &CreateVolumeGroupDialog::onVGNameChanged); connect(&dialogWidget().spinPESize(), qOverload(&QSpinBox::valueChanged), this, &CreateVolumeGroupDialog::onSpinPESizeChanged); } void CreateVolumeGroupDialog::accept() { QString& tname = targetName(); tname = dialogWidget().vgName().text(); 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(d)) { if (d->name() == vgName) { m_IsValidName = false; break; } else m_IsValidName = true; } } updateOkButtonStatus(); } void CreateVolumeGroupDialog::onSpinPESizeChanged(int newsize) { Q_UNUSED(newsize); updateOkButtonStatus(); updateSectorInfos(); } diff --git a/src/gui/resizevolumegroupdialog.cpp b/src/gui/resizevolumegroupdialog.cpp index e0f856f..9acfc28 100644 --- a/src/gui/resizevolumegroupdialog.cpp +++ b/src/gui/resizevolumegroupdialog.cpp @@ -1,125 +1,131 @@ /************************************************************************* * 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 "gui/resizevolumegroupdialog.h" #include "gui/volumegroupwidget.h" #include #include #include #include #include #include #include #include #include #include /** Creates a new ResizeVolumeGroupDialog @param parent pointer to the parent widget @param d the Device to show properties for */ ResizeVolumeGroupDialog::ResizeVolumeGroupDialog(QWidget* parent, VolumeManagerDevice* d, QVector& partList, QList devices, QList pendingOps) : VolumeGroupDialog(parent, d->name(), partList) , m_Devices(devices) , m_Device(d) , m_PendingOps(pendingOps) { setWindowTitle(xi18nc("@title:window", "Resize Volume Group")); setupDialog(); setupConstraints(); KConfigGroup kcg(KSharedConfig::openConfig(), "resizeVolumeDialog"); restoreGeometry(kcg.readEntry("Geometry", QByteArray())); } void ResizeVolumeGroupDialog::setupDialog() { if (dialogWidget().volumeType().currentText() == QStringLiteral("LVM")) { for (const auto &p : qAsConst(LVM::pvList::list())) { bool toBeDeleted = false; // Ignore partitions that are going to be deleted for (const auto &o : qAsConst(m_PendingOps)) { if (dynamic_cast(o) && o->targets(*p.partition())) { toBeDeleted = true; break; } } if (toBeDeleted) continue; 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); } - for (const Device *d : qAsConst(m_Devices)) { - for (const Partition *p : qAsConst(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(&p->fileSystem())->innerFS(); - - if (fs->type() == FileSystem::Type::Lvm2_PV) - dialogWidget().listPV().addPartition(*p, false); + for (const Device *d : qAsConst(m_Devices)) { + if (d->partitionTable() != nullptr) { + for (const Partition *p : qAsConst(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(&p->fileSystem())->innerFS(); + + if (fs->type() == FileSystem::Type::Lvm2_PV) + dialogWidget().listPV().addPartition(*p, false); + } + } } } } - } + + for (const Partition *p : qAsConst(LvmDevice::s_OrphanPVs)) + if (!LvmDevice::s_DirtyPVs.contains(p)) + dialogWidget().listPV().addPartition(*p, false); } //update used size and LV infos qint32 totalLV = 0; LvmDevice *lvmDevice = dynamic_cast(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)); } void ResizeVolumeGroupDialog::setupConstraints() { dialogWidget().vgName().setEnabled(false); dialogWidget().spinPESize().setEnabled(false); dialogWidget().volumeType().setEnabled(false); VolumeGroupDialog::setupConstraints(); } void ResizeVolumeGroupDialog::accept() { targetPVList().append(dialogWidget().listPV().checkedItems()); QDialog::accept(); }