partitionmanager/src/gui/createvolumegroupdialog.cpp

91 lines
3.3 KiB
C++
Raw Normal View History

/*************************************************************************
* Copyright (C) 2016 by Chantara Tith <tith.chantara@gmail.com> *
* *
* 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/createvolumegroupdialog.h"
#include "gui/volumegroupwidget.h"
#include <core/lvmdevice.h>
#include <util/capacity.h>
#include <util/helpers.h>
2016-08-23 16:40:16 +01:00
#include <KConfigGroup>
#include <KLocalizedString>
#include <KSharedConfig>
CreateVolumeGroupDialog::CreateVolumeGroupDialog(QWidget* parent, FS::lvm2_pv::PhysicalVolumes physicalVolumes, QString& vgName, QStringList& pvList, qint32& peSize)
: VolumeGroupDialog(parent, vgName, pvList)
, m_PESize(peSize)
, m_SystemVGList(LvmDevice::getVGs())
, m_PhysicalVolumes(physicalVolumes)
{
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()
{
for (const auto &p : m_PhysicalVolumes)
if (p.first == QString() && !LvmDevice::s_DirtyPVs.contains(p.second->deviceNode()))
dialogWidget().listPV().addPartition(*p.second, 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);
connect(&dialogWidget().spinPESize(), static_cast<void(QSpinBox::*)(int)>(&QSpinBox::valueChanged), this, &CreateVolumeGroupDialog::onSpinPESizeChanged);
}
2016-09-04 12:25:43 +01:00
void CreateVolumeGroupDialog::accept()
{
QString& tname = targetName();
tname = dialogWidget().vgName().text();
targetPVList() << dialogWidget().listPV().checkedItems();
qint32& pesize = peSize();
pesize = dialogWidget().spinPESize().value();
QDialog::accept();
}
2016-09-04 12:25:43 +01:00
void CreateVolumeGroupDialog::onVGNameChanged(const QString& vgname)
{
if (m_SystemVGList.contains(vgname)) {
m_IsValidName = false;
} else {
m_IsValidName = true;
}
updateOkButtonStatus();
}
2016-09-04 12:25:43 +01:00
void CreateVolumeGroupDialog::onSpinPESizeChanged(int newsize)
{
Q_UNUSED(newsize);
updateOkButtonStatus();
updateSectorInfos();
}