[partition] Initial implementation of VolumeGroupBaseDialog.

This commit is contained in:
Caio 2018-06-04 16:31:58 -03:00
parent f72f7bd8fe
commit d15ce56c97
14 changed files with 580 additions and 1 deletions

View File

@ -38,6 +38,7 @@ if ( KPMcore_FOUND )
gui/DeviceInfoWidget.cpp
gui/EditExistingPartitionDialog.cpp
gui/EncryptWidget.cpp
gui/ListPhysicalVolumeWidgetItem.cpp
gui/PartitionPage.cpp
gui/PartitionBarsView.cpp
gui/PartitionLabelsView.cpp
@ -47,10 +48,12 @@ if ( KPMcore_FOUND )
gui/PrettyRadioButton.cpp
gui/ScanningDialog.cpp
gui/ReplaceWidget.cpp
gui/VolumeGroupBaseDialog.cpp
jobs/ClearMountsJob.cpp
jobs/ClearTempMountsJob.cpp
jobs/CreatePartitionJob.cpp
jobs/CreatePartitionTableJob.cpp
jobs/CreateVolumeGroupJob.cpp
jobs/DeletePartitionJob.cpp
jobs/FillGlobalStorageJob.cpp
jobs/FormatPartitionJob.cpp
@ -65,6 +68,7 @@ if ( KPMcore_FOUND )
gui/EncryptWidget.ui
gui/PartitionPage.ui
gui/ReplaceWidget.ui
gui/VolumeGroupBaseDialog.ui
LINK_PRIVATE_LIBRARIES
kpmcore
calamaresui

View File

@ -33,6 +33,7 @@
#include "jobs/ClearTempMountsJob.h"
#include "jobs/CreatePartitionJob.h"
#include "jobs/CreatePartitionTableJob.h"
#include "jobs/CreateVolumeGroupJob.h"
#include "jobs/DeletePartitionJob.h"
#include "jobs/FillGlobalStorageJob.h"
#include "jobs/FormatPartitionJob.h"
@ -44,10 +45,12 @@
// KPMcore
#include <kpmcore/core/device.h>
#include <kpmcore/core/lvmdevice.h>
#include <kpmcore/core/partition.h>
#include <kpmcore/backend/corebackend.h>
#include <kpmcore/backend/corebackendmanager.h>
#include <kpmcore/fs/filesystemfactory.h>
#include <kpmcore/fs/lvm2_pv.h>
// Qt
#include <QStandardItemModel>
@ -177,6 +180,8 @@ PartitionCoreModule::doInit()
m_bootLoaderModel->init( bootLoaderDevices );
scanForLVMPVs();
//FIXME: this should be removed in favor of
// proper KPM support for EFI
if ( PartUtils::isEfiSystem() )
@ -263,6 +268,27 @@ PartitionCoreModule::createPartition( Device* device,
refresh();
}
void
PartitionCoreModule::createVolumeGroup( QString &vgName,
QVector< const Partition* > pvList,
qint32 peSize )
{
CreateVolumeGroupJob* job = new CreateVolumeGroupJob( vgName, pvList, peSize );
job->updatePreview();
LvmDevice* device = new LvmDevice(vgName);
for ( const Partition* p : pvList )
device->physicalVolumes() << p;
DeviceInfo* deviceInfo = new DeviceInfo( device );
m_deviceInfos << deviceInfo;
deviceInfo->jobs << Calamares::job_ptr( job );
refresh();
}
void
PartitionCoreModule::deletePartition( Device* device, Partition* partition )
{
@ -432,6 +458,12 @@ PartitionCoreModule::efiSystemPartitions() const
return m_efiSystemPartitions;
}
QList< const Partition* >
PartitionCoreModule::lvmPVs() const
{
return m_lvmPVs;
}
void
PartitionCoreModule::dumpQueue() const
{
@ -523,6 +555,22 @@ PartitionCoreModule::scanForEfiSystemPartitions()
m_efiSystemPartitions = efiSystemPartitions;
}
void
PartitionCoreModule::scanForLVMPVs()
{
m_lvmPVs.clear();
QList< Device* > devices;
for ( DeviceInfo* deviceInfo : m_deviceInfos )
devices << deviceInfo->device.data();
LvmDevice::scanSystemLVM( devices );
for ( auto p : LVM::pvList )
m_lvmPVs << p.partition().data();
}
PartitionCoreModule::DeviceInfo*
PartitionCoreModule::infoForDevice( const Device* device ) const
{

View File

@ -111,6 +111,8 @@ public:
void createPartition( Device* device, Partition* partition,
PartitionTable::Flags flags = PartitionTable::FlagNone );
void createVolumeGroup( QString &vgName, QVector< const Partition* > pvList, qint32 peSize );
void deletePartition( Device* device, Partition* partition );
void formatPartition( Device* device, Partition* partition );
@ -132,6 +134,8 @@ public:
QList< Partition* > efiSystemPartitions() const;
QList< const Partition* > lvmPVs() const;
/**
* @brief findPartitionByMountPoint returns a Partition* for a given mount point.
* @param mountPoint the mount point to find a partition for.
@ -194,6 +198,7 @@ private:
};
QList< DeviceInfo* > m_deviceInfos;
QList< Partition* > m_efiSystemPartitions;
QList< const Partition* > m_lvmPVs;
DeviceModel* m_deviceModel;
BootLoaderModel* m_bootLoaderModel;
@ -205,6 +210,7 @@ private:
void updateHasRootMountPoint();
void updateIsDirty();
void scanForEfiSystemPartitions();
void scanForLVMPVs();
DeviceInfo* infoForDevice( const Device* ) const;

View File

@ -19,6 +19,7 @@
#include "core/PartitionInfo.h"
// KPMcore
#include <kpmcore/core/lvmdevice.h>
#include <kpmcore/core/partition.h>
// Qt
@ -64,6 +65,9 @@ reset( Partition* partition )
bool
isDirty( Partition* partition )
{
if ( LvmDevice::s_DirtyPVs.contains( partition ) )
return true;
return !mountPoint( partition ).isEmpty()
|| format( partition );
}

View File

@ -0,0 +1,36 @@
/* === 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 "ListPhysicalVolumeWidgetItem.h"
#include <kpmcore/util/capacity.h>
ListPhysicalVolumeWidgetItem::ListPhysicalVolumeWidgetItem( const Partition* partition, bool checked )
: QListWidgetItem(QString("%1 | %2").arg( partition->deviceNode(), Capacity::formatByteSize( partition->capacity() )))
, m_partition(partition)
{
setToolTip( partition->deviceNode() );
setSizeHint( QSize(0, 32) );
setCheckState( checked ? Qt::Checked : Qt::Unchecked );
}
const Partition*
ListPhysicalVolumeWidgetItem::partition() const
{
return m_partition;
}

View File

@ -0,0 +1,37 @@
/* === 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 LISTPHYSICALVOLUMEWIDGETITEM_H
#define LISTPHYSICALVOLUMEWIDGETITEM_H
#include <kpmcore/core/partition.h>
#include <QListWidgetItem>
class ListPhysicalVolumeWidgetItem : public QListWidgetItem
{
public:
ListPhysicalVolumeWidgetItem( const Partition* partition, bool checked );
const Partition* partition() const;
private:
const Partition* m_partition;
};
#endif // LISTPHYSICALVOLUMEWIDGETITEM_H

View File

@ -30,6 +30,7 @@
#include "gui/CreatePartitionDialog.h"
#include "gui/EditExistingPartitionDialog.h"
#include "gui/ScanningDialog.h"
#include "gui/VolumeGroupBaseDialog.h"
#include "ui_PartitionPage.h"
#include "ui_CreatePartitionTableDialog.h"
@ -99,6 +100,7 @@ PartitionPage::PartitionPage( PartitionCoreModule* core, QWidget* parent )
connect( m_ui->partitionTreeView, &QAbstractItemView::doubleClicked, this, &PartitionPage::onPartitionViewActivated );
connect( m_ui->revertButton, &QAbstractButton::clicked, this, &PartitionPage::onRevertClicked );
connect( m_ui->newVolumeGroupButton, &QAbstractButton::clicked, this, &PartitionPage::onNewVolumeGroupClicked );
connect( m_ui->newPartitionTableButton, &QAbstractButton::clicked, this, &PartitionPage::onNewPartitionTableClicked );
connect( m_ui->createButton, &QAbstractButton::clicked, this, &PartitionPage::onCreateClicked );
connect( m_ui->editButton, &QAbstractButton::clicked, this, &PartitionPage::onEditClicked );
@ -178,6 +180,22 @@ PartitionPage::onNewPartitionTableClicked()
updateBootLoaderIndex();
}
void
PartitionPage::onNewVolumeGroupClicked()
{
QString vgName;
qint32 peSize = 4;
QPointer< VolumeGroupBaseDialog > dlg = new VolumeGroupBaseDialog( vgName, m_core->lvmPVs(), peSize, this );
if ( dlg->exec() == QDialog::Accepted )
{
}
delete dlg;
}
void
PartitionPage::onCreateClicked()
{

View File

@ -50,6 +50,7 @@ private:
PartitionCoreModule* m_core;
void updateButtons();
void onNewPartitionTableClicked();
void onNewVolumeGroupClicked();
void onCreateClicked();
void onEditClicked();
void onDeleteClicked();

View File

@ -88,6 +88,13 @@
</property>
</widget>
</item>
<item>
<widget class="QPushButton" name="newVolumeGroupButton">
<property name="text">
<string>New Volume Group</string>
</property>
</widget>
</item>
<item>
<spacer name="horizontalSpacer">
<property name="orientation">
@ -145,7 +152,7 @@
<item>
<widget class="QLabel" name="label_3">
<property name="text">
<string>Install boot &amp;loader on:</string>
<string>I&amp;nstall boot loader on:</string>
</property>
<property name="buddy">
<cstring>bootLoaderComboBox</cstring>

View File

@ -0,0 +1,42 @@
/* === 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 "VolumeGroupBaseDialog.h"
#include "ui_VolumeGroupBaseDialog.h"
#include "gui/ListPhysicalVolumeWidgetItem.h"
VolumeGroupBaseDialog::VolumeGroupBaseDialog( QString& vgName,
QList< const Partition* > pvList,
qint32& peSize,
QWidget *parent)
: QDialog(parent)
, ui(new Ui::VolumeGroupBaseDialog)
, m_vgName(vgName)
, m_peSize(peSize)
{
ui->setupUi(this);
for ( const Partition* p : pvList )
ui->pvList->addItem( new ListPhysicalVolumeWidgetItem(p, false) );
}
VolumeGroupBaseDialog::~VolumeGroupBaseDialog()
{
delete ui;
}

View File

@ -0,0 +1,48 @@
/* === 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 VOLUMEGROUPBASEDIALOG_H
#define VOLUMEGROUPBASEDIALOG_H
#include <kpmcore/core/partition.h>
#include <QDialog>
namespace Ui {
class VolumeGroupBaseDialog;
}
class VolumeGroupBaseDialog : public QDialog
{
Q_OBJECT
public:
explicit VolumeGroupBaseDialog(QString& vgName,
QList< const Partition* > pvList,
qint32& peSize,
QWidget* parent = 0);
~VolumeGroupBaseDialog();
private:
Ui::VolumeGroupBaseDialog *ui;
QString &m_vgName;
qint32 &m_peSize;
};
#endif // VOLUMEGROUPBASEDIALOG_H

View File

@ -0,0 +1,193 @@
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>VolumeGroupBaseDialog</class>
<widget class="QDialog" name="VolumeGroupBaseDialog">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>611</width>
<height>367</height>
</rect>
</property>
<property name="windowTitle">
<string>VolumeGroupDialog</string>
</property>
<layout class="QGridLayout" name="gridLayout">
<item row="0" column="0">
<widget class="QLabel" name="pvListLabel">
<property name="text">
<string>List of Physical Volumes</string>
</property>
</widget>
</item>
<item row="1" column="0" rowspan="7">
<widget class="QListWidget" name="pvList"/>
</item>
<item row="1" column="1">
<widget class="QLabel" name="label_2">
<property name="text">
<string>Volume Group Name:</string>
</property>
<property name="alignment">
<set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
</property>
</widget>
</item>
<item row="1" column="2">
<widget class="QLineEdit" name="lineEdit"/>
</item>
<item row="2" column="1">
<widget class="QLabel" name="label_3">
<property name="text">
<string>Volume Group Type:</string>
</property>
<property name="alignment">
<set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
</property>
</widget>
</item>
<item row="2" column="2">
<widget class="QComboBox" name="comboBox"/>
</item>
<item row="3" column="1">
<widget class="QLabel" name="label_4">
<property name="text">
<string>Physical Extent Size:</string>
</property>
<property name="alignment">
<set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
</property>
</widget>
</item>
<item row="3" column="2">
<widget class="QSpinBox" name="spinBox"/>
</item>
<item row="4" column="1">
<widget class="QLabel" name="label_5">
<property name="text">
<string>Total Size:</string>
</property>
<property name="alignment">
<set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
</property>
</widget>
</item>
<item row="4" column="2">
<widget class="QLabel" name="label_9">
<property name="text">
<string>---</string>
</property>
<property name="alignment">
<set>Qt::AlignCenter</set>
</property>
</widget>
</item>
<item row="5" column="1">
<widget class="QLabel" name="label_6">
<property name="text">
<string>Used Size:</string>
</property>
<property name="alignment">
<set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
</property>
</widget>
</item>
<item row="5" column="2">
<widget class="QLabel" name="label_10">
<property name="text">
<string>---</string>
</property>
<property name="alignment">
<set>Qt::AlignCenter</set>
</property>
</widget>
</item>
<item row="6" column="1">
<widget class="QLabel" name="label_7">
<property name="text">
<string>Total Sectors:</string>
</property>
<property name="alignment">
<set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
</property>
</widget>
</item>
<item row="6" column="2">
<widget class="QLabel" name="label_11">
<property name="text">
<string>---</string>
</property>
<property name="alignment">
<set>Qt::AlignCenter</set>
</property>
</widget>
</item>
<item row="7" column="1">
<widget class="QLabel" name="label_8">
<property name="text">
<string>Quantity of LVs:</string>
</property>
<property name="alignment">
<set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
</property>
</widget>
</item>
<item row="7" column="2">
<widget class="QLabel" name="label_12">
<property name="text">
<string>---</string>
</property>
<property name="alignment">
<set>Qt::AlignCenter</set>
</property>
</widget>
</item>
<item row="8" column="0" colspan="3">
<widget class="QDialogButtonBox" name="buttonBox">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="standardButtons">
<set>QDialogButtonBox::Cancel|QDialogButtonBox::Ok</set>
</property>
</widget>
</item>
</layout>
</widget>
<resources/>
<connections>
<connection>
<sender>buttonBox</sender>
<signal>accepted()</signal>
<receiver>VolumeGroupBaseDialog</receiver>
<slot>accept()</slot>
<hints>
<hint type="sourcelabel">
<x>248</x>
<y>254</y>
</hint>
<hint type="destinationlabel">
<x>157</x>
<y>274</y>
</hint>
</hints>
</connection>
<connection>
<sender>buttonBox</sender>
<signal>rejected()</signal>
<receiver>VolumeGroupBaseDialog</receiver>
<slot>reject()</slot>
<hints>
<hint type="sourcelabel">
<x>316</x>
<y>260</y>
</hint>
<hint type="destinationlabel">
<x>286</x>
<y>274</y>
</hint>
</hints>
</connection>
</connections>
</ui>

View File

@ -0,0 +1,88 @@
/* === 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 "CreateVolumeGroupJob.h"
// KPMcore
#include <kpmcore/core/lvmdevice.h>
#include <kpmcore/core/partition.h>
#include <kpmcore/ops/createvolumegroupoperation.h>
#include <kpmcore/util/report.h>
CreateVolumeGroupJob::CreateVolumeGroupJob( QString& vgName, QVector< const Partition* > pvList, const qint32 peSize )
: m_vgName(vgName)
, m_pvList(pvList)
, m_peSize(peSize)
{
}
QString
CreateVolumeGroupJob::prettyName() const
{
return tr( "Create new volume group named %1." )
.arg( m_vgName );
}
QString
CreateVolumeGroupJob::prettyDescription() const
{
return tr( "Create new volume group named <strong>%1</strong>." )
.arg( m_vgName );
}
QString
CreateVolumeGroupJob::prettyStatusMessage() const
{
return tr( "Creating new volume group named %1." )
.arg( m_vgName );
}
Calamares::JobResult
CreateVolumeGroupJob::exec()
{
Report report( nullptr );
QVector< const Partition* > pvList;
pvList << m_pvList;
CreateVolumeGroupOperation op( m_vgName, m_pvList, m_peSize );
op.setStatus( Operation::StatusRunning );
QString message = tr( "The installer failed to create a volume group named '%1'.").arg( m_vgName );
if (op.execute(report))
return Calamares::JobResult::ok();
return Calamares::JobResult::error(message, report.toText());
}
void
CreateVolumeGroupJob::updatePreview()
{
LvmDevice::s_DirtyPVs << m_pvList;
}
void
CreateVolumeGroupJob::undoPreview()
{
for ( const auto& pv : m_pvList )
if ( LvmDevice::s_DirtyPVs.contains( pv ))
LvmDevice::s_DirtyPVs.removeAll( pv );
}

View File

@ -0,0 +1,47 @@
/* === 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 CREATEVOLUMEGROUPJOB_H
#define CREATEVOLUMEGROUPJOB_H
#include <Job.h>
#include <kpmcore/core/partition.h>
#include <QVector>
class CreateVolumeGroupJob : public Calamares::Job
{
public:
CreateVolumeGroupJob( QString& vgName, QVector< const Partition* > pvList, const qint32 peSize );
QString prettyName() const override;
QString prettyDescription() const override;
QString prettyStatusMessage() const override;
Calamares::JobResult exec() override;
void updatePreview();
void undoPreview();
private:
QString m_vgName;
QVector< const Partition* > m_pvList;
qint32 m_peSize;
};
#endif // CREATEVOLUMEGROUPJOB_H