[partition] Including CreateVolumeGroupDialog and fixing some of its GUI issues.

This commit is contained in:
Caio 2018-06-07 17:22:22 -03:00
parent d15ce56c97
commit 208d58bcd9
12 changed files with 409 additions and 37 deletions

View File

@ -35,6 +35,7 @@ if ( KPMcore_FOUND )
gui/BootInfoWidget.cpp gui/BootInfoWidget.cpp
gui/ChoicePage.cpp gui/ChoicePage.cpp
gui/CreatePartitionDialog.cpp gui/CreatePartitionDialog.cpp
gui/CreateVolumeGroupDialog.cpp
gui/DeviceInfoWidget.cpp gui/DeviceInfoWidget.cpp
gui/EditExistingPartitionDialog.cpp gui/EditExistingPartitionDialog.cpp
gui/EncryptWidget.cpp gui/EncryptWidget.cpp

View File

@ -25,10 +25,12 @@
// KPMcore // KPMcore
#include <kpmcore/core/device.h> #include <kpmcore/core/device.h>
#include <kpmcore/core/lvmdevice.h>
// KF5 // KF5
#include <KFormat> #include <KFormat>
#include <QStandardItemModel>
#include <QIcon> #include <QIcon>
// STL // STL
@ -116,3 +118,17 @@ DeviceModel::swapDevice( Device* oldDevice, Device* newDevice )
emit dataChanged( index( indexOfOldDevice ), index( indexOfOldDevice ) ); emit dataChanged( index( indexOfOldDevice ), index( indexOfOldDevice ) );
} }
void
DeviceModel::addDevice( Device *device )
{
beginResetModel();
m_devices << device;
std::sort( m_devices.begin(), m_devices.end(), []( const Device* dev1, const Device* dev2 )
{
return dev1->deviceNode() < dev2->deviceNode();
} );
endResetModel();
}

View File

@ -49,6 +49,8 @@ public:
void swapDevice( Device* oldDevice, Device* newDevice ); void swapDevice( Device* oldDevice, Device* newDevice );
void addDevice( Device* device );
private: private:
QList< Device* > m_devices; QList< Device* > m_devices;
}; };

View File

@ -273,6 +273,10 @@ PartitionCoreModule::createVolumeGroup( QString &vgName,
QVector< const Partition* > pvList, QVector< const Partition* > pvList,
qint32 peSize ) qint32 peSize )
{ {
// Appending '_' character in case of repeated VG name
while ( hasVGwithThisName( vgName ) )
vgName.append('_');
CreateVolumeGroupJob* job = new CreateVolumeGroupJob( vgName, pvList, peSize ); CreateVolumeGroupJob* job = new CreateVolumeGroupJob( vgName, pvList, peSize );
job->updatePreview(); job->updatePreview();
@ -283,6 +287,10 @@ PartitionCoreModule::createVolumeGroup( QString &vgName,
DeviceInfo* deviceInfo = new DeviceInfo( device ); DeviceInfo* deviceInfo = new DeviceInfo( device );
deviceInfo->partitionModel->init( device, osproberEntries() );
m_deviceModel->addDevice( device );
m_deviceInfos << deviceInfo; m_deviceInfos << deviceInfo;
deviceInfo->jobs << Calamares::job_ptr( job ); deviceInfo->jobs << Calamares::job_ptr( job );
@ -458,12 +466,37 @@ PartitionCoreModule::efiSystemPartitions() const
return m_efiSystemPartitions; return m_efiSystemPartitions;
} }
QList< const Partition* > QVector< const Partition* >
PartitionCoreModule::lvmPVs() const PartitionCoreModule::lvmPVs() const
{ {
return m_lvmPVs; return m_lvmPVs;
} }
bool
PartitionCoreModule::hasVGwithThisName( const QString& name ) const
{
for ( DeviceInfo* d : m_deviceInfos )
if ( dynamic_cast<LvmDevice*>(d->device.data()) &&
d->device.data()->name() == name)
return true;
return false;
}
bool
PartitionCoreModule::isInVG( const Partition *partition ) const
{
for ( DeviceInfo* d : m_deviceInfos )
{
LvmDevice* vg = dynamic_cast<LvmDevice*>( d->device.data() );
if ( vg && vg->physicalVolumes().contains( partition ))
return true;
}
return false;
}
void void
PartitionCoreModule::dumpQueue() const PartitionCoreModule::dumpQueue() const
{ {
@ -503,6 +536,8 @@ PartitionCoreModule::refresh()
updateIsDirty(); updateIsDirty();
m_bootLoaderModel->update(); m_bootLoaderModel->update();
scanForLVMPVs();
//FIXME: this should be removed in favor of //FIXME: this should be removed in favor of
// proper KPM support for EFI // proper KPM support for EFI
if ( PartUtils::isEfiSystem() ) if ( PartUtils::isEfiSystem() )

View File

@ -24,6 +24,7 @@
#include "Typedefs.h" #include "Typedefs.h"
// KPMcore // KPMcore
#include <kpmcore/core/lvmdevice.h>
#include <kpmcore/core/partitiontable.h> #include <kpmcore/core/partitiontable.h>
// Qt // Qt
@ -134,7 +135,11 @@ public:
QList< Partition* > efiSystemPartitions() const; QList< Partition* > efiSystemPartitions() const;
QList< const Partition* > lvmPVs() const; QVector< const Partition* > lvmPVs() const;
bool hasVGwithThisName( const QString& name ) const;
bool isInVG( const Partition* partition ) const;
/** /**
* @brief findPartitionByMountPoint returns a Partition* for a given mount point. * @brief findPartitionByMountPoint returns a Partition* for a given mount point.
@ -198,7 +203,7 @@ private:
}; };
QList< DeviceInfo* > m_deviceInfos; QList< DeviceInfo* > m_deviceInfos;
QList< Partition* > m_efiSystemPartitions; QList< Partition* > m_efiSystemPartitions;
QList< const Partition* > m_lvmPVs; QVector< const Partition* > m_lvmPVs;
DeviceModel* m_deviceModel; DeviceModel* m_deviceModel;
BootLoaderModel* m_bootLoaderModel; BootLoaderModel* m_bootLoaderModel;

View File

@ -0,0 +1,53 @@
/* === This file is part of Calamares - <https://github.com/calamares> ===
*
* Copyright 2018, Caio Jordão Carvalho <caiojcarvalho@gmail.com>
*
* Calamares 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.
*
* Calamares 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 Calamares. If not, see <http://www.gnu.org/licenses/>.
*/
#include "CreateVolumeGroupDialog.h"
#include <kpmcore/core/device.h>
#include <kpmcore/core/lvmdevice.h>
#include <QComboBox>
#include <QLineEdit>
#include <QSpinBox>
CreateVolumeGroupDialog::CreateVolumeGroupDialog( QString& vgName,
QVector< const Partition* >& selectedPVs,
QVector< const Partition* > pvList,
qint32& peSize,
QWidget* parent )
: VolumeGroupBaseDialog( vgName, pvList, peSize, parent )
, m_selectedPVs( selectedPVs )
{
setWindowTitle( "Create Volume Group" );
vgType()->setEnabled( false );
}
void
CreateVolumeGroupDialog::accept()
{
QString& name = vgNameValue();
name = vgName()->text();
m_selectedPVs << checkedItems();
qint32& pe = peSizeValue();
pe = peSize()->value();
QDialog::accept();
}

View File

@ -0,0 +1,39 @@
/* === This file is part of Calamares - <https://github.com/calamares> ===
*
* Copyright 2018, Caio Jordão Carvalho <caiojcarvalho@gmail.com>
*
* Calamares 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.
*
* Calamares 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 Calamares. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef CREATEVOLUMEGROUPDIALOG_H
#define CREATEVOLUMEGROUPDIALOG_H
#include "gui/VolumeGroupBaseDialog.h"
class CreateVolumeGroupDialog : public VolumeGroupBaseDialog
{
public:
CreateVolumeGroupDialog( QString& vgName,
QVector< const Partition* >& selectedPVs,
QVector< const Partition* > pvList,
qint32& peSize,
QWidget* parent );
void accept() override;
private:
QVector< const Partition* >& m_selectedPVs;
};
#endif // CREATEVOLUMEGROUPDIALOG_H

View File

@ -28,9 +28,9 @@
#include "core/PartUtils.h" #include "core/PartUtils.h"
#include "core/KPMHelpers.h" #include "core/KPMHelpers.h"
#include "gui/CreatePartitionDialog.h" #include "gui/CreatePartitionDialog.h"
#include "gui/CreateVolumeGroupDialog.h"
#include "gui/EditExistingPartitionDialog.h" #include "gui/EditExistingPartitionDialog.h"
#include "gui/ScanningDialog.h" #include "gui/ScanningDialog.h"
#include "gui/VolumeGroupBaseDialog.h"
#include "ui_PartitionPage.h" #include "ui_PartitionPage.h"
#include "ui_CreatePartitionTableDialog.h" #include "ui_CreatePartitionTableDialog.h"
@ -133,6 +133,8 @@ PartitionPage::updateButtons()
bool isFree = KPMHelpers::isPartitionFreeSpace( partition ); bool isFree = KPMHelpers::isPartitionFreeSpace( partition );
bool isExtended = partition->roles().has( PartitionRole::Extended ); bool isExtended = partition->roles().has( PartitionRole::Extended );
bool isInVG = m_core->isInVG( partition );
create = isFree; create = isFree;
// Keep it simple for now: do not support editing extended partitions as // Keep it simple for now: do not support editing extended partitions as
// it does not work with our current edit implementation which is // it does not work with our current edit implementation which is
@ -140,8 +142,9 @@ PartitionPage::updateButtons()
// because they need to be created *before* creating logical partitions // because they need to be created *before* creating logical partitions
// inside them, so an edit must be applied without altering the job // inside them, so an edit must be applied without altering the job
// order. // order.
// TODO: See if LVM PVs can be edited in Calamares
edit = !isFree && !isExtended; edit = !isFree && !isExtended;
del = !isFree; del = !isFree && !isInVG;
} }
if ( m_ui->deviceComboBox->currentIndex() >= 0 ) if ( m_ui->deviceComboBox->currentIndex() >= 0 )
@ -184,13 +187,51 @@ void
PartitionPage::onNewVolumeGroupClicked() PartitionPage::onNewVolumeGroupClicked()
{ {
QString vgName; QString vgName;
QVector< const Partition* > selectedPVs;
qint32 peSize = 4; qint32 peSize = 4;
QPointer< VolumeGroupBaseDialog > dlg = new VolumeGroupBaseDialog( vgName, m_core->lvmPVs(), peSize, this ); QVector< const Partition* > availablePVs;
for ( const Partition* p : m_core->lvmPVs() )
if ( !m_core->isInVG( p ) )
availablePVs << p;
QPointer< CreateVolumeGroupDialog > dlg = new CreateVolumeGroupDialog( vgName,
selectedPVs,
availablePVs,
peSize,
this );
if ( dlg->exec() == QDialog::Accepted ) if ( dlg->exec() == QDialog::Accepted )
{ {
QModelIndex partitionIndex = m_ui->partitionTreeView->currentIndex();
if ( partitionIndex.isValid() )
{
const PartitionModel* model = static_cast< const PartitionModel* >( partitionIndex.model() );
Q_ASSERT( model );
Partition* partition = model->partitionForIndex( partitionIndex );
Q_ASSERT( partition );
// Disable delete button if current partition was selected to be in VG
// TODO: Should Calamares edit LVM PVs which are in VGs?
if ( selectedPVs.contains( partition ) )
m_ui->deleteButton->setEnabled( false );
}
QModelIndex deviceIndex = m_core->deviceModel()->index( m_ui->deviceComboBox->currentIndex(), 0 );
Q_ASSERT( deviceIndex.isValid() );
QVariant previousDeviceData = m_core->deviceModel()->data( deviceIndex, Qt::ToolTipRole );
m_core->createVolumeGroup( vgName, selectedPVs, peSize );
// As createVolumeGroup method call resets deviceModel,
// is needed to set the current index in deviceComboBox as the previous one
int previousIndex = m_ui->deviceComboBox->findData( previousDeviceData, Qt::ToolTipRole );
if ( previousIndex != -1 )
m_ui->deviceComboBox->setCurrentIndex( previousIndex );
} }
delete dlg; delete dlg;

View File

@ -21,22 +21,160 @@
#include "gui/ListPhysicalVolumeWidgetItem.h" #include "gui/ListPhysicalVolumeWidgetItem.h"
#include <kpmcore/util/capacity.h>
#include <QComboBox>
#include <QDialogButtonBox>
#include <QLabel>
#include <QLineEdit>
#include <QPushButton>
#include <QSpinBox>
VolumeGroupBaseDialog::VolumeGroupBaseDialog( QString& vgName, VolumeGroupBaseDialog::VolumeGroupBaseDialog( QString& vgName,
QList< const Partition* > pvList, QVector< const Partition* > pvList,
qint32& peSize, qint32& peSize,
QWidget *parent) QWidget *parent )
: QDialog(parent) : QDialog(parent)
, ui(new Ui::VolumeGroupBaseDialog) , ui(new Ui::VolumeGroupBaseDialog)
, m_vgName(vgName) , m_vgNameValue(vgName)
, m_peSize(peSize) , m_peSizeValue(peSize)
, m_totalSizeValue(0)
, m_usedSizeValue(0)
{ {
ui->setupUi(this); ui->setupUi(this);
for ( const Partition* p : pvList ) for ( const Partition* p : pvList )
ui->pvList->addItem( new ListPhysicalVolumeWidgetItem(p, false) ); ui->pvList->addItem( new ListPhysicalVolumeWidgetItem( p, false ) );
ui->vgType->addItems( QStringList() << "LVM" << "RAID" );
ui->vgType->setCurrentIndex(0);
QRegularExpression re(R"(^(?!_|\.)[\w\-.+]+)");
ui->vgName->setValidator( new QRegularExpressionValidator( re, this ) );
ui->vgName->setText( m_vgNameValue );
ui->peSize->setValue( m_peSizeValue );
updateOkButton();
updateTotalSize();
connect( ui->pvList, &QListWidget::itemChanged, this,
[&](QListWidgetItem*) {
updateTotalSize();
updateOkButton();
} );
connect( ui->peSize, qOverload<int>(&QSpinBox::valueChanged), this,
[&](int) {
updateTotalSectors();
updateOkButton();
});
connect( ui->vgName, &QLineEdit::textChanged, this,
[&](const QString&) {
updateOkButton();
});
} }
VolumeGroupBaseDialog::~VolumeGroupBaseDialog() VolumeGroupBaseDialog::~VolumeGroupBaseDialog()
{ {
delete ui; delete ui;
} }
QVector< const Partition* >
VolumeGroupBaseDialog::checkedItems() const
{
QVector< const Partition* > items;
for ( int i = 0; i < ui->pvList->count(); i++) {
ListPhysicalVolumeWidgetItem* item = dynamic_cast< ListPhysicalVolumeWidgetItem* >( ui->pvList->item(i) );
if ( item && item->checkState() == Qt::Checked )
items << item->partition();
}
return items;
}
bool
VolumeGroupBaseDialog::isSizeValid() const
{
return m_totalSizeValue >= m_usedSizeValue;
}
void
VolumeGroupBaseDialog::updateOkButton()
{
okButton()->setEnabled(isSizeValid() &&
!checkedItems().empty() &&
!ui->vgName->text().isEmpty() &&
ui->peSize->value() > 0);
}
void
VolumeGroupBaseDialog::updateTotalSize()
{
m_totalSizeValue = 0;
for ( const Partition *p : checkedItems())
m_totalSizeValue += p->capacity() - p->capacity() % (ui->peSize->value() * Capacity::unitFactor(Capacity::Unit::Byte, Capacity::Unit::MiB));
ui->totalSize->setText(Capacity::formatByteSize(m_totalSizeValue));
updateTotalSectors();
}
void
VolumeGroupBaseDialog::updateTotalSectors()
{
qint32 totalSectors = 0;
qint32 extentSize = ui->peSize->value() * Capacity::unitFactor(Capacity::Unit::Byte, Capacity::Unit::MiB);
if ( extentSize > 0 )
totalSectors = m_totalSizeValue / extentSize;
ui->totalSectors->setText( QString::number( totalSectors ) );
}
QString&
VolumeGroupBaseDialog::vgNameValue() const
{
return m_vgNameValue;
}
qint32&
VolumeGroupBaseDialog::peSizeValue() const
{
return m_peSizeValue;
}
QLineEdit*
VolumeGroupBaseDialog::vgName() const
{
return ui->vgName;
}
QComboBox*
VolumeGroupBaseDialog::vgType() const
{
return ui->vgType;
}
QSpinBox*
VolumeGroupBaseDialog::peSize() const
{
return ui->peSize;
}
QListWidget*
VolumeGroupBaseDialog::pvList() const
{
return ui->pvList;
}
QPushButton*
VolumeGroupBaseDialog::okButton() const
{
return ui->buttonBox->button( QDialogButtonBox::StandardButton::Ok );
}

View File

@ -27,22 +27,55 @@ namespace Ui {
class VolumeGroupBaseDialog; class VolumeGroupBaseDialog;
} }
class QComboBox;
class QLineEdit;
class QListWidget;
class QSpinBox;
class VolumeGroupBaseDialog : public QDialog class VolumeGroupBaseDialog : public QDialog
{ {
Q_OBJECT Q_OBJECT
public: public:
explicit VolumeGroupBaseDialog(QString& vgName, explicit VolumeGroupBaseDialog( QString& vgName,
QList< const Partition* > pvList, QVector< const Partition* > pvList,
qint32& peSize, qint32& peSize,
QWidget* parent = 0); QWidget* parent = nullptr );
~VolumeGroupBaseDialog(); ~VolumeGroupBaseDialog();
private: protected:
Ui::VolumeGroupBaseDialog *ui; virtual void updateOkButton();
QString &m_vgName; void updateTotalSize();
qint32 &m_peSize;
void updateTotalSectors();
QVector< const Partition* > checkedItems() const;
bool isSizeValid() const;
QString& vgNameValue() const;
qint32& peSizeValue() const;
QLineEdit* vgName() const;
QComboBox* vgType() const;
QSpinBox* peSize() const;
QListWidget* pvList() const;
QPushButton* okButton() const;
private:
Ui::VolumeGroupBaseDialog* ui;
QString& m_vgNameValue;
qint32& m_peSizeValue;
qint64 m_totalSizeValue;
qint64 m_usedSizeValue;
}; };
#endif // VOLUMEGROUPBASEDIALOG_H #endif // VOLUMEGROUPBASEDIALOG_H

View File

@ -25,7 +25,7 @@
<widget class="QListWidget" name="pvList"/> <widget class="QListWidget" name="pvList"/>
</item> </item>
<item row="1" column="1"> <item row="1" column="1">
<widget class="QLabel" name="label_2"> <widget class="QLabel" name="vgNameLabel">
<property name="text"> <property name="text">
<string>Volume Group Name:</string> <string>Volume Group Name:</string>
</property> </property>
@ -35,10 +35,10 @@
</widget> </widget>
</item> </item>
<item row="1" column="2"> <item row="1" column="2">
<widget class="QLineEdit" name="lineEdit"/> <widget class="QLineEdit" name="vgName"/>
</item> </item>
<item row="2" column="1"> <item row="2" column="1">
<widget class="QLabel" name="label_3"> <widget class="QLabel" name="vgTypeLabel">
<property name="text"> <property name="text">
<string>Volume Group Type:</string> <string>Volume Group Type:</string>
</property> </property>
@ -48,10 +48,10 @@
</widget> </widget>
</item> </item>
<item row="2" column="2"> <item row="2" column="2">
<widget class="QComboBox" name="comboBox"/> <widget class="QComboBox" name="vgType"/>
</item> </item>
<item row="3" column="1"> <item row="3" column="1">
<widget class="QLabel" name="label_4"> <widget class="QLabel" name="peSizeLabel">
<property name="text"> <property name="text">
<string>Physical Extent Size:</string> <string>Physical Extent Size:</string>
</property> </property>
@ -61,10 +61,23 @@
</widget> </widget>
</item> </item>
<item row="3" column="2"> <item row="3" column="2">
<widget class="QSpinBox" name="spinBox"/> <widget class="QSpinBox" name="peSize">
<property name="suffix">
<string> MiB</string>
</property>
<property name="minimum">
<number>1</number>
</property>
<property name="maximum">
<number>999</number>
</property>
<property name="value">
<number>4</number>
</property>
</widget>
</item> </item>
<item row="4" column="1"> <item row="4" column="1">
<widget class="QLabel" name="label_5"> <widget class="QLabel" name="totalSizeLabel">
<property name="text"> <property name="text">
<string>Total Size:</string> <string>Total Size:</string>
</property> </property>
@ -74,7 +87,7 @@
</widget> </widget>
</item> </item>
<item row="4" column="2"> <item row="4" column="2">
<widget class="QLabel" name="label_9"> <widget class="QLabel" name="totalSize">
<property name="text"> <property name="text">
<string>---</string> <string>---</string>
</property> </property>
@ -84,7 +97,7 @@
</widget> </widget>
</item> </item>
<item row="5" column="1"> <item row="5" column="1">
<widget class="QLabel" name="label_6"> <widget class="QLabel" name="usedSizeLabel">
<property name="text"> <property name="text">
<string>Used Size:</string> <string>Used Size:</string>
</property> </property>
@ -94,7 +107,7 @@
</widget> </widget>
</item> </item>
<item row="5" column="2"> <item row="5" column="2">
<widget class="QLabel" name="label_10"> <widget class="QLabel" name="usedSize">
<property name="text"> <property name="text">
<string>---</string> <string>---</string>
</property> </property>
@ -104,7 +117,7 @@
</widget> </widget>
</item> </item>
<item row="6" column="1"> <item row="6" column="1">
<widget class="QLabel" name="label_7"> <widget class="QLabel" name="totalSectorsLabel">
<property name="text"> <property name="text">
<string>Total Sectors:</string> <string>Total Sectors:</string>
</property> </property>
@ -114,7 +127,7 @@
</widget> </widget>
</item> </item>
<item row="6" column="2"> <item row="6" column="2">
<widget class="QLabel" name="label_11"> <widget class="QLabel" name="totalSectors">
<property name="text"> <property name="text">
<string>---</string> <string>---</string>
</property> </property>
@ -124,7 +137,7 @@
</widget> </widget>
</item> </item>
<item row="7" column="1"> <item row="7" column="1">
<widget class="QLabel" name="label_8"> <widget class="QLabel" name="lvQuantityLabel">
<property name="text"> <property name="text">
<string>Quantity of LVs:</string> <string>Quantity of LVs:</string>
</property> </property>
@ -134,7 +147,7 @@
</widget> </widget>
</item> </item>
<item row="7" column="2"> <item row="7" column="2">
<widget class="QLabel" name="label_12"> <widget class="QLabel" name="lvQuantity">
<property name="text"> <property name="text">
<string>---</string> <string>---</string>
</property> </property>

View File

@ -58,10 +58,6 @@ CreateVolumeGroupJob::exec()
{ {
Report report( nullptr ); Report report( nullptr );
QVector< const Partition* > pvList;
pvList << m_pvList;
CreateVolumeGroupOperation op( m_vgName, m_pvList, m_peSize ); CreateVolumeGroupOperation op( m_vgName, m_pvList, m_peSize );
op.setStatus( Operation::StatusRunning ); op.setStatus( Operation::StatusRunning );