2016-06-30 18:39:47 +01:00
|
|
|
/*************************************************************************
|
|
|
|
* 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/>.*
|
|
|
|
*************************************************************************/
|
|
|
|
|
|
|
|
#include "gui/volumedialog.h"
|
|
|
|
#include "gui/volumewidget.h"
|
|
|
|
|
2016-07-03 18:15:50 +01:00
|
|
|
#include <core/partitiontable.h>
|
2016-06-30 18:39:47 +01:00
|
|
|
#include <core/lvmdevice.h>
|
2016-07-03 18:15:50 +01:00
|
|
|
#include <fs/lvm2_pv.h>
|
2016-06-30 18:39:47 +01:00
|
|
|
|
|
|
|
#include <util/capacity.h>
|
|
|
|
#include <util/helpers.h>
|
|
|
|
|
|
|
|
#include <KLocalizedString>
|
|
|
|
#include <KSharedConfig>
|
|
|
|
#include <KConfigGroup>
|
|
|
|
#include <KIconLoader>
|
|
|
|
|
|
|
|
#include <QPointer>
|
|
|
|
#include <QPushButton>
|
2016-07-09 18:45:32 +01:00
|
|
|
#include <QListWidgetItem>
|
2016-06-30 18:39:47 +01:00
|
|
|
#include <QDialogButtonBox>
|
|
|
|
|
|
|
|
/** Creates a new VolumeDialog
|
|
|
|
@param parent pointer to the parent widget
|
|
|
|
@param d the Device to show properties for
|
|
|
|
*/
|
2016-07-03 18:15:50 +01:00
|
|
|
VolumeDialog::VolumeDialog(QWidget* parent, QString& vgname, QStringList& pvlist) :
|
2016-06-30 18:39:47 +01:00
|
|
|
QDialog(parent),
|
2016-07-02 09:27:20 +01:00
|
|
|
m_DialogWidget(new VolumeWidget(this)),
|
2016-07-03 18:15:50 +01:00
|
|
|
m_TargetName(vgname),
|
|
|
|
m_TargetPVList(pvlist)
|
2016-06-30 18:39:47 +01:00
|
|
|
{
|
2016-07-02 09:27:20 +01:00
|
|
|
Q_UNUSED(pvlist);
|
2016-06-30 18:39:47 +01:00
|
|
|
mainLayout = new QVBoxLayout(this);
|
|
|
|
setLayout(mainLayout);
|
|
|
|
mainLayout->addWidget(&dialogWidget());
|
|
|
|
|
|
|
|
dialogButtonBox = new QDialogButtonBox;
|
|
|
|
okButton = dialogButtonBox->addButton(QDialogButtonBox::Ok);
|
|
|
|
cancelButton = dialogButtonBox->addButton(QDialogButtonBox::Cancel);
|
|
|
|
mainLayout->addWidget(dialogButtonBox);
|
2016-07-02 09:27:20 +01:00
|
|
|
updateOkButtonStatus();
|
2016-06-30 18:39:47 +01:00
|
|
|
cancelButton->setFocus();
|
|
|
|
cancelButton->setDefault(true);
|
|
|
|
|
|
|
|
setupDialog();
|
2016-07-02 09:27:20 +01:00
|
|
|
setupConstraints();
|
2016-06-30 18:39:47 +01:00
|
|
|
setupConnections();
|
|
|
|
}
|
|
|
|
|
|
|
|
/** Destroys a VolumeDialog */
|
|
|
|
VolumeDialog::~VolumeDialog()
|
|
|
|
{
|
|
|
|
KConfigGroup kcg(KSharedConfig::openConfig(), "createVolumeDialog");
|
|
|
|
kcg.writeEntry("Geometry", saveGeometry());
|
|
|
|
}
|
|
|
|
|
|
|
|
void VolumeDialog::setupDialog()
|
|
|
|
{
|
2016-07-09 00:59:46 +01:00
|
|
|
dialogWidget().vgName().setText(targetName());
|
2016-07-03 18:15:50 +01:00
|
|
|
|
|
|
|
dialogWidget().volumeType().addItem(QStringLiteral("LVM"));
|
|
|
|
dialogWidget().volumeType().addItem(QStringLiteral("RAID"));
|
|
|
|
dialogWidget().volumeType().setCurrentIndex(0);
|
|
|
|
|
2016-06-30 18:39:47 +01:00
|
|
|
setMinimumSize(dialogWidget().size());
|
|
|
|
resize(dialogWidget().size());
|
2016-07-03 18:15:50 +01:00
|
|
|
|
|
|
|
updatePartTable();
|
2016-06-30 18:39:47 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void VolumeDialog::setupConnections()
|
|
|
|
{
|
2016-07-03 18:15:50 +01:00
|
|
|
connect(dialogButtonBox, &QDialogButtonBox::accepted, this, &VolumeDialog::accept);
|
|
|
|
connect(dialogButtonBox, &QDialogButtonBox::rejected, this, &VolumeDialog::reject);
|
|
|
|
connect(&dialogWidget().volumeType(), static_cast<void(QComboBox::*)(int)>(&QComboBox::currentIndexChanged), this, &VolumeDialog::onVolumeTypeChanged);
|
2016-07-09 18:45:32 +01:00
|
|
|
connect(&dialogWidget().listPV().listPhysicalVolumes(), &QListWidget::itemChanged,
|
|
|
|
this, [=] ( QListWidgetItem*) {
|
|
|
|
updateSizeInfos();
|
|
|
|
});
|
2016-06-30 18:39:47 +01:00
|
|
|
}
|
2016-07-02 09:27:20 +01:00
|
|
|
|
|
|
|
void VolumeDialog::setupConstraints()
|
|
|
|
{
|
2016-07-09 00:59:46 +01:00
|
|
|
updatePartTable();
|
|
|
|
updateSizeInfos();
|
|
|
|
updateOkButtonStatus();
|
2016-07-02 09:27:20 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void VolumeDialog::updateOkButtonStatus()
|
|
|
|
{
|
2016-07-15 22:29:34 +01:00
|
|
|
bool enable = isLegeSize();
|
2016-07-02 09:27:20 +01:00
|
|
|
|
|
|
|
if (dialogWidget().vgName().text().isEmpty()) {
|
|
|
|
enable = false;
|
|
|
|
}
|
|
|
|
if (dialogWidget().spinPESize().value() <= 0) {
|
|
|
|
enable = false;
|
|
|
|
}
|
|
|
|
|
|
|
|
okButton->setEnabled(enable);
|
|
|
|
}
|
|
|
|
|
|
|
|
void VolumeDialog::updatePartTable()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
void VolumeDialog::updateSizeInfos()
|
|
|
|
{
|
2016-07-09 15:37:19 +01:00
|
|
|
qint64 totalSize = 0;
|
|
|
|
qint64 totalUsedSize = 0;
|
|
|
|
qint32 totalSectors = 0;
|
|
|
|
qint32 totalLV = 0;
|
|
|
|
qint32 peSize = 0;
|
|
|
|
|
|
|
|
// we can't use LvmDevice mothod here because pv that is not in any VG will return 0
|
|
|
|
peSize = dialogWidget().spinPESize().value() * Capacity::unitFactor(Capacity::Byte, Capacity::MiB);
|
|
|
|
|
|
|
|
QStringList checkedPartitions = dialogWidget().listPV().checkedItems();
|
|
|
|
if (!checkedPartitions.isEmpty()) {
|
|
|
|
totalSize = FS::lvm2_pv::getPVSize(checkedPartitions);
|
|
|
|
if (peSize > 0) {
|
|
|
|
totalSectors = totalSize / peSize;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-07-09 18:45:32 +01:00
|
|
|
QString vgname = dialogWidget().vgName().text();
|
|
|
|
if (!vgname.isEmpty()) {
|
2016-07-15 21:58:46 +01:00
|
|
|
totalUsedSize = LvmDevice::getAllocatedPE(vgname) * LvmDevice::getPeSize(vgname);
|
2016-07-09 18:45:32 +01:00
|
|
|
QStringList lvlist = LvmDevice::getLVs(vgname);
|
2016-07-09 15:37:19 +01:00
|
|
|
if (!lvlist.isEmpty() ) {
|
|
|
|
totalLV = lvlist.count();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
dialogWidget().totalSize().setText(Capacity::formatByteSize(totalSize));
|
|
|
|
dialogWidget().totalUsedSize().setText(Capacity::formatByteSize(totalUsedSize));
|
|
|
|
dialogWidget().totalSectors().setText(QString::number(totalSectors));
|
|
|
|
dialogWidget().totalLV().setText(QString::number(totalLV));
|
2016-07-15 22:29:34 +01:00
|
|
|
|
|
|
|
//Probably a bad design for updating state here; the state should be changed inside the update button function.
|
|
|
|
m_IsLegalSize = totalSize > totalUsedSize;
|
|
|
|
updateOkButtonStatus();
|
2016-07-02 09:27:20 +01:00
|
|
|
}
|
|
|
|
|
2016-07-03 18:15:50 +01:00
|
|
|
void VolumeDialog::updatePartitionList()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2016-07-02 09:27:20 +01:00
|
|
|
void VolumeDialog::onPartitionListChanged()
|
|
|
|
{
|
|
|
|
}
|
2016-07-03 18:15:50 +01:00
|
|
|
|
|
|
|
|
|
|
|
void VolumeDialog::onVolumeTypeChanged(int index)
|
|
|
|
{
|
2016-07-09 18:45:32 +01:00
|
|
|
Q_UNUSED(index)
|
2016-07-03 18:15:50 +01:00
|
|
|
updatePartitionList();
|
|
|
|
}
|