diff --git a/src/gui/volumegroupdialog.cpp b/src/gui/volumegroupdialog.cpp index dc01ad4..c6715e0 100644 --- a/src/gui/volumegroupdialog.cpp +++ b/src/gui/volumegroupdialog.cpp @@ -1,176 +1,191 @@ /************************************************************************* * 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/volumegroupdialog.h" #include "gui/volumegroupwidget.h" #include #include #include #include #include #include #include #include #include #include #include /** Creates a new VolumeGroupDialog @param parent pointer to the parent widget @param vgName Volume Group name @param pvList List of LVM Physical Volumes used to create Volume Group */ VolumeGroupDialog::VolumeGroupDialog(QWidget* parent, QString& vgName, QVector& pvList) : QDialog(parent), m_DialogWidget(new VolumeGroupWidget(this)), m_TargetName(vgName), m_TargetPVList(pvList), m_IsValidSize(false), m_IsValidName(true), m_TotalSize(0), m_TotalUsedSize(0), m_ExtentSize(0) { 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); cancelButton->setFocus(); cancelButton->setDefault(true); setupDialog(); setupConstraints(); setupConnections(); } /** Destroys a VolumeGroupDialog */ VolumeGroupDialog::~VolumeGroupDialog() { KConfigGroup kcg(KSharedConfig::openConfig(), "createVolumeGroupDialog"); kcg.writeEntry("Geometry", saveGeometry()); } void VolumeGroupDialog::setupDialog() { - dialogWidget().volumeType().addItem(QStringLiteral("LVM")); - dialogWidget().volumeType().addItem(QStringLiteral("RAID")); + dialogWidget().volumeType().addItems({ QStringLiteral("LVM"), QStringLiteral("RAID") }); dialogWidget().volumeType().setCurrentIndex(0); + dialogWidget().raidLevel().addItems({ QStringLiteral("0"), QStringLiteral("1"), + QStringLiteral("4"), QStringLiteral("5"), + QStringLiteral("6"), QStringLiteral("10") }); + updateNameValidator(); + updateComponents(); setMinimumSize(dialogWidget().size()); resize(dialogWidget().size()); } void VolumeGroupDialog::setupConnections() { connect(dialogButtonBox, &QDialogButtonBox::accepted, this, &VolumeGroupDialog::accept); connect(dialogButtonBox, &QDialogButtonBox::rejected, this, &VolumeGroupDialog::reject); connect(&dialogWidget().volumeType(), qOverload(&QComboBox::currentIndexChanged), this, &VolumeGroupDialog::onVolumeTypeChanged); connect(&dialogWidget().listPV().listPhysicalVolumes(), &QListWidget::itemChanged, this, [=] ( QListWidgetItem*) { updateSizeInfos(); }); } void VolumeGroupDialog::setupConstraints() { updateSizeInfos(); updateOkButtonStatus(); } void VolumeGroupDialog::updateOkButtonStatus() { bool enable = isValidSize(); if (dialogWidget().vgName().text().isEmpty() || !isValidName()) { enable = false; } if (dialogWidget().spinPESize().value() <= 0) { enable = false; } okButton->setEnabled(enable); } void VolumeGroupDialog::updateSectorInfos() { qint32 totalSectors = 0; // we can't use LvmDevice mothod here because pv that is not in any VG will return 0 m_ExtentSize = dialogWidget().spinPESize().value() * Capacity::unitFactor(Capacity::Unit::Byte, Capacity::Unit::MiB); if (m_ExtentSize > 0) { totalSectors = m_TotalSize / m_ExtentSize; } dialogWidget().totalSectors().setText(QString::number(totalSectors)); } void VolumeGroupDialog::updateSizeInfos() { const QVector checkedPartitions = dialogWidget().listPV().checkedItems(); m_TotalSize = 0; for (const auto &p : checkedPartitions) m_TotalSize += p->capacity() - p->capacity() % (dialogWidget().spinPESize().value() * Capacity::unitFactor(Capacity::Unit::Byte, Capacity::Unit::MiB)); // subtract space which is too small to hold PE dialogWidget().totalSize().setText(Capacity::formatByteSize(m_TotalSize)); //Probably a bad design for updating state here; the state should be changed inside the update button function. m_IsValidSize = m_TotalSize >= m_TotalUsedSize; updateSectorInfos(); updateOkButtonStatus(); } void VolumeGroupDialog::updatePartitionList() { } void VolumeGroupDialog::updateNameValidator() { if (dialogWidget().volumeType().currentText() == QStringLiteral("LVM")) { /* LVM Volume group name can consist of: letters numbers _ . - + * It cannot start with underscore _ and must not be equal to . or .. or any entry in /dev/ * QLineEdit accepts QValidator::Intermediate, so we just disable . at the beginning */ QRegularExpression re(QStringLiteral(R"(^(?!_|\.)[\w\-.+]+)")); QRegularExpressionValidator *validator = new QRegularExpressionValidator(re, this); dialogWidget().vgName().setValidator(validator); dialogWidget().vgName().setText(targetName()); } else if (dialogWidget().volumeType().currentText() == QStringLiteral("RAID")) { // TODO: See how Software RAID names should be validated. } } void VolumeGroupDialog::onPartitionListChanged() { } void VolumeGroupDialog::onVolumeTypeChanged(int index) { Q_UNUSED(index) updateNameValidator(); updatePartitionList(); + updateComponents(); +} + +void VolumeGroupDialog::updateComponents() +{ + dialogWidget().spinPESize().setVisible(dialogWidget().volumeType().currentText() == QStringLiteral("LVM")); + dialogWidget().textTotalPESize().setVisible(dialogWidget().volumeType().currentText() == QStringLiteral("LVM")); + dialogWidget().raidLevel().setVisible(dialogWidget().volumeType().currentText() == QStringLiteral("RAID")); + dialogWidget().textRaidLevel().setVisible(dialogWidget().volumeType().currentText() == QStringLiteral("RAID")); + dialogWidget().chunkSize().setVisible(dialogWidget().volumeType().currentText() == QStringLiteral("RAID")); + dialogWidget().textChunkSize().setVisible(dialogWidget().volumeType().currentText() == QStringLiteral("RAID")); } diff --git a/src/gui/volumegroupdialog.h b/src/gui/volumegroupdialog.h index e9660f1..0876f3a 100644 --- a/src/gui/volumegroupdialog.h +++ b/src/gui/volumegroupdialog.h @@ -1,109 +1,108 @@ /************************************************************************* * 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 .* *************************************************************************/ #if !defined(VOLUMEGROUPDIALOG_H) #define VOLUMEGROUPDIALOG_H #include #include #include #include #include class VolumeGroupWidget; class Partition; class VolumeGroupDialog : public QDialog { Q_DISABLE_COPY(VolumeGroupDialog) public: VolumeGroupDialog(QWidget* parent, QString& vgName, QVector& pvList); ~VolumeGroupDialog(); protected: virtual void setupDialog(); virtual void setupConstraints(); virtual void setupConnections(); virtual void updateOkButtonStatus(); virtual void updateSizeInfos(); virtual void updateSectorInfos(); virtual void updatePartitionList(); + virtual void updateNameValidator(); + virtual void onPartitionListChanged(); virtual void onVolumeTypeChanged(int index); VolumeGroupWidget& dialogWidget() { Q_ASSERT(m_DialogWidget); return *m_DialogWidget; } const VolumeGroupWidget& dialogWidget() const { Q_ASSERT(m_DialogWidget); return *m_DialogWidget; } QString& targetName() { return m_TargetName; } const QString& targetName() const { return m_TargetName; } QVector& targetPVList() { return m_TargetPVList; } const QVector& targetPVList() const { return m_TargetPVList; } bool isValidSize() const { return m_IsValidSize; } bool isValidName() const { return m_IsValidName; } -protected: - virtual void onPartitionListChanged(); - private: - virtual void updateNameValidator(); + void updateComponents(); protected: VolumeGroupWidget* m_DialogWidget; QString& m_TargetName; QVector& m_TargetPVList; bool m_IsValidSize; bool m_IsValidName; qint64 m_TotalSize; qint64 m_TotalUsedSize; qint32 m_ExtentSize; QDialogButtonBox* dialogButtonBox; QPushButton* okButton; QPushButton* cancelButton; QVBoxLayout *mainLayout; }; #endif diff --git a/src/gui/volumegroupwidget.h b/src/gui/volumegroupwidget.h index 7263d13..7bea738 100644 --- a/src/gui/volumegroupwidget.h +++ b/src/gui/volumegroupwidget.h @@ -1,115 +1,134 @@ /************************************************************************* * Copyright (C) 2016 by Chantara Tith * * * * 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 .* *************************************************************************/ #if !defined(VOLUMEGROUPWIDGET_H) #define VOLUMEGROUPWIDGET_H #include "ui_volumegroupwidgetbase.h" #include class VolumeGroupWidget : public QWidget, public Ui::VolumeGroupWidgetBase { public: VolumeGroupWidget(QWidget* parent) : QWidget(parent), Ui::VolumeGroupWidgetBase() { setupUi(this); } public: - QLineEdit& vgName() { + QLineEdit& vgName() const { Q_ASSERT(m_EditVGName); return *m_EditVGName; } - QComboBox& volumeType() { + QComboBox& volumeType() const { Q_ASSERT(m_ComboVolumeType); return *m_ComboVolumeType; } - QSpinBox& spinPESize() { + QSpinBox& spinPESize() const { Q_ASSERT(m_SpinPESize); return *m_SpinPESize; - } - ListPhysicalVolumes& listPV() { + + ListPhysicalVolumes& listPV() const { Q_ASSERT(m_ListPV); return *m_ListPV; } - QLabel& totalSize() { + QLabel& totalSize() const { Q_ASSERT(m_LabelTotalSize); return *m_LabelTotalSize; } - - QLabel& totalSectors() { + QLabel& totalSectors() const { Q_ASSERT(m_LabelTotalSectors); return *m_LabelTotalSectors; } - QLabel& totalUsedSize() { + QLabel& totalUsedSize() const { Q_ASSERT(m_LabelTotalUsedSize); return *m_LabelTotalUsedSize; } - QLabel& totalLV() { + QLabel& totalLV() const { Q_ASSERT(m_LabelTotalLV); return *m_LabelTotalLV; } - QLabel& textVGName() { + QLabel& textVGName() const { Q_ASSERT(m_LabelTextVGName); return *m_LabelTextVGName; } - QLabel& textVolumeType() { + QLabel& textVolumeType() const { Q_ASSERT(m_LabelTextVolumeType); return *m_LabelTextVolumeType; } - QLabel& textTotalSize() { + QLabel& textTotalSize() const { Q_ASSERT(m_LabelTextTotalSize); return *m_LabelTextTotalSize; } - QLabel& textTotalSectors() { + QLabel& textTotalSectors() const { Q_ASSERT(m_LabelTextTotalSectors); return *m_LabelTextTotalSectors; } - QLabel& textTotalUsedSize() { + QLabel& textTotalUsedSize() const { Q_ASSERT(m_LabelTextTotalUsedSize); return *m_LabelTextTotalUsedSize; } - QLabel& textTotalLV() { + QLabel& textTotalLV() const { Q_ASSERT(m_LabelTextTotalLV); return *m_LabelTextTotalLV; } - QLabel& textTotalPESize() { + QLabel& textTotalPESize() const { Q_ASSERT(m_LabelTextPESize); return *m_LabelTextPESize; } + QSpinBox& chunkSize() const { + Q_ASSERT(m_ChunkSize); + return *m_ChunkSize; + } + + QComboBox& raidLevel() const { + Q_ASSERT(m_RaidLevel); + return *m_RaidLevel; + } + + QLabel& textChunkSize() const { + Q_ASSERT(m_LabelChunkSize); + return *m_LabelChunkSize; + } + + QLabel& textRaidLevel() const { + Q_ASSERT(m_LabelRaidLevel); + return *m_LabelRaidLevel; + } + }; #endif diff --git a/src/gui/volumegroupwidgetbase.ui b/src/gui/volumegroupwidgetbase.ui index 570bfb5..2deb9b0 100644 --- a/src/gui/volumegroupwidgetbase.ui +++ b/src/gui/volumegroupwidgetbase.ui @@ -1,263 +1,259 @@ VolumeGroupWidgetBase 0 0 831 418 652 0 - + 250 400 Volume Group Name: Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter Qt::LinksAccessibleByMouse|Qt::TextSelectableByKeyboard|Qt::TextSelectableByMouse Volume Group Type: Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter - - - RAID level: - - - Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter - - - - - + - + + + Physical Extent Size: + + + Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter + + + Qt::LinksAccessibleByMouse|Qt::TextSelectableByKeyboard|Qt::TextSelectableByMouse + + + + + + + RAID level: + + + Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter + + + + + + + Chunk Size: + + + Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter + + - - - - Physical Extent Size: - - - Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter - - - Qt::LinksAccessibleByMouse|Qt::TextSelectableByKeyboard|Qt::TextSelectableByMouse - - - - - + + MiB 1 1000 4 - - - - - - Chunk Size: - - - Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter - - - - - - + + + + KiB 1 2048 512 - + Total Size: Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter Qt::LinksAccessibleByMouse|Qt::TextSelectableByKeyboard|Qt::TextSelectableByMouse - + --- Qt::AlignCenter Qt::LinksAccessibleByMouse|Qt::TextSelectableByKeyboard|Qt::TextSelectableByMouse - + Used Size: Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter Qt::LinksAccessibleByMouse|Qt::TextSelectableByKeyboard|Qt::TextSelectableByMouse - + --- Qt::AlignCenter Qt::LinksAccessibleByMouse|Qt::TextSelectableByKeyboard|Qt::TextSelectableByMouse - + Total Sectors: Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter Qt::LinksAccessibleByMouse|Qt::TextSelectableByKeyboard|Qt::TextSelectableByMouse - + --- Qt::AlignCenter Qt::LinksAccessibleByMouse|Qt::TextSelectableByKeyboard|Qt::TextSelectableByMouse - + Total LV: Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter Qt::LinksAccessibleByMouse|Qt::TextSelectableByKeyboard|Qt::TextSelectableByMouse - + --- Qt::AlignCenter Qt::LinksAccessibleByMouse|Qt::TextSelectableByKeyboard|Qt::TextSelectableByMouse ListPhysicalVolumes QWidget
gui/listphysicalvolumes.h
1