Compare commits
	
		
			15 Commits
		
	
	
		
			services-d
			...
			issue-1847
		
	
	| Author | SHA1 | Date | |
|---|---|---|---|
| 
						 | 
					3aa4b7368c | ||
| 
						 | 
					288674a924 | ||
| 
						 | 
					30b5be0fd4 | ||
| 
						 | 
					10334ab14f | ||
| 
						 | 
					46d69b04d4 | ||
| 
						 | 
					f1185d38d8 | ||
| 
						 | 
					2c16d812cd | ||
| 
						 | 
					7a071207a2 | ||
| 
						 | 
					3edfa5ebb5 | ||
| 
						 | 
					898f4498e8 | ||
| 
						 | 
					e2d5f01aa1 | ||
| 
						 | 
					8d7c08612f | ||
| 
						 | 
					febc5f5b41 | ||
| 
						 | 
					35a4273127 | ||
| 
						 | 
					4402ebd8e8 | 
@@ -19,6 +19,7 @@
 | 
			
		||||
#include <kpmcore/util/report.h>
 | 
			
		||||
 | 
			
		||||
#include <QList>
 | 
			
		||||
#include <QVector>
 | 
			
		||||
 | 
			
		||||
#include <functional>
 | 
			
		||||
 | 
			
		||||
@@ -37,6 +38,8 @@ class PartitionRole;
 | 
			
		||||
#define KPM_PARTITION_FLAG_ESP PartitionTable::FlagEsp
 | 
			
		||||
#endif
 | 
			
		||||
 | 
			
		||||
using PartitionVector = QVector< const Partition* >;
 | 
			
		||||
 | 
			
		||||
/**
 | 
			
		||||
 * Helper functions to manipulate partitions
 | 
			
		||||
 */
 | 
			
		||||
 
 | 
			
		||||
@@ -262,11 +262,9 @@ PartitionCoreModule::doInit()
 | 
			
		||||
            // Gives ownership of the Device* to the DeviceInfo object
 | 
			
		||||
            auto deviceInfo = new DeviceInfo( device );
 | 
			
		||||
            m_deviceInfos << deviceInfo;
 | 
			
		||||
            cDebug() << Logger::SubEntry
 | 
			
		||||
                << device->deviceNode()
 | 
			
		||||
                << device->capacity()
 | 
			
		||||
                << Logger::RedactedName( "DevName", device->name() )
 | 
			
		||||
                << Logger::RedactedName( "DevNamePretty", device->prettyName() );
 | 
			
		||||
            cDebug() << Logger::SubEntry << device->deviceNode() << device->capacity()
 | 
			
		||||
                     << Logger::RedactedName( "DevName", device->name() )
 | 
			
		||||
                     << Logger::RedactedName( "DevNamePretty", device->prettyName() );
 | 
			
		||||
        }
 | 
			
		||||
        else
 | 
			
		||||
        {
 | 
			
		||||
@@ -360,7 +358,12 @@ PartitionModel*
 | 
			
		||||
PartitionCoreModule::partitionModelForDevice( const Device* device ) const
 | 
			
		||||
{
 | 
			
		||||
    DeviceInfo* info = infoForDevice( device );
 | 
			
		||||
    Q_ASSERT( info );
 | 
			
		||||
    if ( !info )
 | 
			
		||||
    {
 | 
			
		||||
        cWarning() << "No DeviceInfo for" << Logger::Pointer( device )
 | 
			
		||||
                   << ( device ? device->deviceNode() : QStringLiteral( "<null>" ) );
 | 
			
		||||
        return nullptr;
 | 
			
		||||
    }
 | 
			
		||||
    return info->partitionModel.data();
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
@@ -411,15 +414,16 @@ PartitionCoreModule::createPartition( Device* device, Partition* partition, Part
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void
 | 
			
		||||
PartitionCoreModule::createVolumeGroup( QString& vgName, QVector< const Partition* > pvList, qint32 peSize )
 | 
			
		||||
PartitionCoreModule::createVolumeGroup( const QString& vgName, const PartitionVector& pvList, qint32 peSize )
 | 
			
		||||
{
 | 
			
		||||
    QString actualName( vgName );
 | 
			
		||||
    // Appending '_' character in case of repeated VG name
 | 
			
		||||
    while ( hasVGwithThisName( vgName ) )
 | 
			
		||||
    while ( hasVGwithThisName( actualName ) )
 | 
			
		||||
    {
 | 
			
		||||
        vgName.append( '_' );
 | 
			
		||||
        actualName.append( '_' );
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    LvmDevice* device = new LvmDevice( vgName );
 | 
			
		||||
    LvmDevice* device = new LvmDevice( actualName );
 | 
			
		||||
    for ( const Partition* p : pvList )
 | 
			
		||||
    {
 | 
			
		||||
        device->physicalVolumes() << p;
 | 
			
		||||
@@ -430,12 +434,12 @@ PartitionCoreModule::createVolumeGroup( QString& vgName, QVector< const Partitio
 | 
			
		||||
    m_deviceModel->addDevice( device );
 | 
			
		||||
    m_deviceInfos << deviceInfo;
 | 
			
		||||
 | 
			
		||||
    deviceInfo->makeJob< CreateVolumeGroupJob >( vgName, pvList, peSize );
 | 
			
		||||
    deviceInfo->makeJob< CreateVolumeGroupJob >( actualName, pvList, peSize );
 | 
			
		||||
    refreshAfterModelChange();
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void
 | 
			
		||||
PartitionCoreModule::resizeVolumeGroup( LvmDevice* device, QVector< const Partition* >& pvList )
 | 
			
		||||
PartitionCoreModule::resizeVolumeGroup( LvmDevice* device, const PartitionVector& pvList )
 | 
			
		||||
{
 | 
			
		||||
    auto* deviceInfo = infoForDevice( device );
 | 
			
		||||
    Q_ASSERT( deviceInfo );
 | 
			
		||||
@@ -676,7 +680,7 @@ PartitionCoreModule::efiSystemPartitions() const
 | 
			
		||||
    return m_efiSystemPartitions;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
QVector< const Partition* >
 | 
			
		||||
PartitionVector
 | 
			
		||||
PartitionCoreModule::lvmPVs() const
 | 
			
		||||
{
 | 
			
		||||
    return m_lvmPVs;
 | 
			
		||||
 
 | 
			
		||||
@@ -136,25 +136,18 @@ public:
 | 
			
		||||
     */
 | 
			
		||||
    void
 | 
			
		||||
    createPartition( Device* device, Partition* partition, PartitionTable::Flags flags = KPM_PARTITION_FLAG( None ) );
 | 
			
		||||
    void deletePartition( Device* device, Partition* partition );
 | 
			
		||||
    void formatPartition( Device* device, Partition* partition );
 | 
			
		||||
    void resizePartition( Device* device, Partition* partition, qint64 first, qint64 last );
 | 
			
		||||
    void setPartitionFlags( Device* device, Partition* partition, PartitionTable::Flags flags );
 | 
			
		||||
 | 
			
		||||
    void createVolumeGroup( QString& vgName, QVector< const Partition* > pvList, qint32 peSize );
 | 
			
		||||
 | 
			
		||||
    void resizeVolumeGroup( LvmDevice* device, QVector< const Partition* >& pvList );
 | 
			
		||||
 | 
			
		||||
    void createVolumeGroup( const QString& vgName, const PartitionVector& pvList, qint32 peSize );
 | 
			
		||||
    void resizeVolumeGroup( LvmDevice* device, const PartitionVector& pvList );
 | 
			
		||||
    void deactivateVolumeGroup( LvmDevice* device );
 | 
			
		||||
 | 
			
		||||
    void removeVolumeGroup( LvmDevice* device );
 | 
			
		||||
 | 
			
		||||
    void deletePartition( Device* device, Partition* partition );
 | 
			
		||||
 | 
			
		||||
    void formatPartition( Device* device, Partition* partition );
 | 
			
		||||
 | 
			
		||||
    void setFilesystemLabel( Device* device, Partition* partition, const QString& newLabel );
 | 
			
		||||
 | 
			
		||||
    void resizePartition( Device* device, Partition* partition, qint64 first, qint64 last );
 | 
			
		||||
 | 
			
		||||
    void setPartitionFlags( Device* device, Partition* partition, PartitionTable::Flags flags );
 | 
			
		||||
 | 
			
		||||
    /// @brief Retrieve the path where the bootloader will be installed
 | 
			
		||||
    QString bootLoaderInstallPath() const { return m_bootLoaderInstallPath; }
 | 
			
		||||
    /// @brief Set the path where the bootloader will be installed
 | 
			
		||||
@@ -185,7 +178,7 @@ public:
 | 
			
		||||
 | 
			
		||||
    QList< Partition* > efiSystemPartitions() const;
 | 
			
		||||
 | 
			
		||||
    QVector< const Partition* > lvmPVs() const;
 | 
			
		||||
    PartitionVector lvmPVs() const;
 | 
			
		||||
 | 
			
		||||
    bool hasVGwithThisName( const QString& name ) const;
 | 
			
		||||
 | 
			
		||||
@@ -255,7 +248,7 @@ private:
 | 
			
		||||
 | 
			
		||||
    QList< DeviceInfo* > m_deviceInfos;
 | 
			
		||||
    QList< Partition* > m_efiSystemPartitions;
 | 
			
		||||
    QVector< const Partition* > m_lvmPVs;
 | 
			
		||||
    PartitionVector m_lvmPVs;
 | 
			
		||||
 | 
			
		||||
    DeviceModel* m_deviceModel;
 | 
			
		||||
    BootLoaderModel* m_bootLoaderModel;
 | 
			
		||||
 
 | 
			
		||||
@@ -66,19 +66,22 @@ CreatePartitionDialog::CreatePartitionDialog( Device* device,
 | 
			
		||||
    m_ui->encryptWidget->setText( tr( "En&crypt" ) );
 | 
			
		||||
    m_ui->encryptWidget->hide();
 | 
			
		||||
 | 
			
		||||
    if ( m_device->type() != Device::Type::LVM_Device )
 | 
			
		||||
    {
 | 
			
		||||
        m_ui->lvNameLabel->hide();
 | 
			
		||||
        m_ui->lvNameLineEdit->hide();
 | 
			
		||||
    }
 | 
			
		||||
    if ( m_device->type() == Device::Type::LVM_Device )
 | 
			
		||||
    {
 | 
			
		||||
        m_ui->lvNameLabel->show();
 | 
			
		||||
        m_ui->lvNameLineEdit->show();
 | 
			
		||||
        /* LVM logical volume 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 );
 | 
			
		||||
        m_ui->lvNameLineEdit->setValidator( validator );
 | 
			
		||||
        connect( m_ui->lvNameLineEdit, &QLineEdit::textChanged, this, &CreatePartitionDialog::updateOkButton );
 | 
			
		||||
    }
 | 
			
		||||
    else
 | 
			
		||||
    {
 | 
			
		||||
        m_ui->lvNameLabel->hide();
 | 
			
		||||
        m_ui->lvNameLineEdit->hide();
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    if ( device->partitionTable()->type() == PartitionTable::msdos
 | 
			
		||||
@@ -347,3 +350,13 @@ CreatePartitionDialog::initPartResizerWidget( Partition* partition )
 | 
			
		||||
    m_partitionSizeController->setPartResizerWidget( m_ui->partResizerWidget );
 | 
			
		||||
    m_partitionSizeController->setSpinBox( m_ui->sizeSpinBox );
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void
 | 
			
		||||
CreatePartitionDialog::updateOkButton()
 | 
			
		||||
{
 | 
			
		||||
    if ( m_device->type() == Device::Type::LVM_Device )
 | 
			
		||||
    {
 | 
			
		||||
        QString lvName = m_ui->lvNameLineEdit->text();
 | 
			
		||||
        cDebug() << "LVName" << lvName << m_ui->lvNameLineEdit->hasAcceptableInput();
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
 
 | 
			
		||||
@@ -45,10 +45,12 @@ private:
 | 
			
		||||
                           QWidget* parentWidget );
 | 
			
		||||
 | 
			
		||||
public:
 | 
			
		||||
    /// @brief Tag-type for creating partition from free space
 | 
			
		||||
    struct FreeSpace
 | 
			
		||||
    {
 | 
			
		||||
        Partition* p;
 | 
			
		||||
    };
 | 
			
		||||
    /// @brief Tag-type for editing (re-creating) a new partition
 | 
			
		||||
    struct FreshPartition
 | 
			
		||||
    {
 | 
			
		||||
        Partition* p;
 | 
			
		||||
@@ -81,6 +83,7 @@ public:
 | 
			
		||||
private Q_SLOTS:
 | 
			
		||||
    void updateMountPointUi();
 | 
			
		||||
    void checkMountPointSelection();
 | 
			
		||||
    void updateOkButton();  // Check if dialog can be accepted
 | 
			
		||||
 | 
			
		||||
private:
 | 
			
		||||
    QScopedPointer< Ui_CreatePartitionDialog > m_ui;
 | 
			
		||||
 
 | 
			
		||||
@@ -16,32 +16,13 @@
 | 
			
		||||
#include <QLineEdit>
 | 
			
		||||
#include <QSpinBox>
 | 
			
		||||
 | 
			
		||||
CreateVolumeGroupDialog::CreateVolumeGroupDialog( QString& vgName,
 | 
			
		||||
                                                  QVector< const Partition* >& selectedPVs,
 | 
			
		||||
                                                  QVector< const Partition* > pvList,
 | 
			
		||||
                                                  qint64& pSize,
 | 
			
		||||
CreateVolumeGroupDialog::CreateVolumeGroupDialog( const PartitionVector& pvList,
 | 
			
		||||
                                                  qint32 physicalExtentSize,
 | 
			
		||||
                                                  QWidget* parent )
 | 
			
		||||
    : VolumeGroupBaseDialog( vgName, pvList, parent )
 | 
			
		||||
    , m_selectedPVs( selectedPVs )
 | 
			
		||||
    , m_peSize( pSize )
 | 
			
		||||
    : VolumeGroupBaseDialog( parent, QString(), pvList )
 | 
			
		||||
{
 | 
			
		||||
    setWindowTitle( tr( "Create Volume Group" ) );
 | 
			
		||||
 | 
			
		||||
    peSize()->setValue( pSize );
 | 
			
		||||
 | 
			
		||||
    vgType()->setEnabled( false );
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void
 | 
			
		||||
CreateVolumeGroupDialog::accept()
 | 
			
		||||
{
 | 
			
		||||
    QString& name = vgNameValue();
 | 
			
		||||
    name = vgName()->text();
 | 
			
		||||
 | 
			
		||||
    m_selectedPVs << checkedItems();
 | 
			
		||||
 | 
			
		||||
    qint64& pe = m_peSize;
 | 
			
		||||
    pe = peSize()->value();
 | 
			
		||||
 | 
			
		||||
    QDialog::accept();
 | 
			
		||||
    peSizeWidget()->setValue( physicalExtentSize );
 | 
			
		||||
    vgTypeWidget()->setEnabled( false );
 | 
			
		||||
}
 | 
			
		||||
 
 | 
			
		||||
@@ -16,18 +16,7 @@ class CreateVolumeGroupDialog : public VolumeGroupBaseDialog
 | 
			
		||||
{
 | 
			
		||||
    Q_OBJECT
 | 
			
		||||
public:
 | 
			
		||||
    CreateVolumeGroupDialog( QString& vgName,
 | 
			
		||||
                             QVector< const Partition* >& selectedPVs,
 | 
			
		||||
                             QVector< const Partition* > pvList,
 | 
			
		||||
                             qint64& pSize,
 | 
			
		||||
                             QWidget* parent );
 | 
			
		||||
 | 
			
		||||
    void accept() override;
 | 
			
		||||
 | 
			
		||||
private:
 | 
			
		||||
    QVector< const Partition* >& m_selectedPVs;
 | 
			
		||||
 | 
			
		||||
    qint64& m_peSize;
 | 
			
		||||
    CreateVolumeGroupDialog( const PartitionVector& pvList, qint32 physicalExtentSize, QWidget* parent );
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
#endif  // CREATEVOLUMEGROUPDIALOG_H
 | 
			
		||||
 
 | 
			
		||||
@@ -278,26 +278,30 @@ PartitionPage::checkCanCreate( Device* device )
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void
 | 
			
		||||
PartitionPage::onNewVolumeGroupClicked()
 | 
			
		||||
static inline PartitionVector
 | 
			
		||||
availablePVs( PartitionCoreModule* core )
 | 
			
		||||
{
 | 
			
		||||
    QString vgName;
 | 
			
		||||
    QVector< const Partition* > selectedPVs;
 | 
			
		||||
    qint64 peSize = 4;
 | 
			
		||||
    PartitionVector availablePVs;
 | 
			
		||||
 | 
			
		||||
    QVector< const Partition* > availablePVs;
 | 
			
		||||
 | 
			
		||||
    for ( const Partition* p : m_core->lvmPVs() )
 | 
			
		||||
        if ( !m_core->isInVG( p ) )
 | 
			
		||||
    for ( const Partition* p : core->lvmPVs() )
 | 
			
		||||
    {
 | 
			
		||||
        if ( !core->isInVG( p ) )
 | 
			
		||||
        {
 | 
			
		||||
            availablePVs << p;
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
    return availablePVs;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
    QPointer< CreateVolumeGroupDialog > dlg
 | 
			
		||||
        = new CreateVolumeGroupDialog( vgName, selectedPVs, availablePVs, peSize, this );
 | 
			
		||||
 | 
			
		||||
void
 | 
			
		||||
PartitionPage::onNewVolumeGroupClicked()
 | 
			
		||||
{
 | 
			
		||||
    QPointer< CreateVolumeGroupDialog > dlg = new CreateVolumeGroupDialog( availablePVs( m_core ), 4, this );
 | 
			
		||||
 | 
			
		||||
    if ( dlg->exec() == QDialog::Accepted )
 | 
			
		||||
    {
 | 
			
		||||
        const PartitionVector selectedPVs = dlg->selectedPVs();
 | 
			
		||||
        QModelIndex partitionIndex = m_ui->partitionTreeView->currentIndex();
 | 
			
		||||
 | 
			
		||||
        if ( partitionIndex.isValid() )
 | 
			
		||||
@@ -321,7 +325,7 @@ PartitionPage::onNewVolumeGroupClicked()
 | 
			
		||||
        QVariant previousIndexDeviceData = m_core->deviceModel()->data( deviceIndex, Qt::ToolTipRole );
 | 
			
		||||
 | 
			
		||||
        // Creating new VG
 | 
			
		||||
        m_core->createVolumeGroup( vgName, selectedPVs, peSize );
 | 
			
		||||
        m_core->createVolumeGroup( dlg->volumeGroupName(), selectedPVs, dlg->physicalExtentSize() );
 | 
			
		||||
 | 
			
		||||
        // As createVolumeGroup method call resets deviceModel,
 | 
			
		||||
        // is needed to set the current index in deviceComboBox as the previous one
 | 
			
		||||
@@ -342,20 +346,11 @@ PartitionPage::onResizeVolumeGroupClicked()
 | 
			
		||||
 | 
			
		||||
    Q_ASSERT( device && device->type() == Device::Type::LVM_Device );
 | 
			
		||||
 | 
			
		||||
    QVector< const Partition* > availablePVs;
 | 
			
		||||
    QVector< const Partition* > selectedPVs;
 | 
			
		||||
 | 
			
		||||
    for ( const Partition* p : m_core->lvmPVs() )
 | 
			
		||||
        if ( !m_core->isInVG( p ) )
 | 
			
		||||
        {
 | 
			
		||||
            availablePVs << p;
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
    QPointer< ResizeVolumeGroupDialog > dlg = new ResizeVolumeGroupDialog( device, availablePVs, selectedPVs, this );
 | 
			
		||||
    QPointer< ResizeVolumeGroupDialog > dlg = new ResizeVolumeGroupDialog( device, availablePVs( m_core ), this );
 | 
			
		||||
 | 
			
		||||
    if ( dlg->exec() == QDialog::Accepted )
 | 
			
		||||
    {
 | 
			
		||||
        m_core->resizeVolumeGroup( device, selectedPVs );
 | 
			
		||||
        m_core->resizeVolumeGroup( device, dlg->selectedPVs() );
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    delete dlg;
 | 
			
		||||
 
 | 
			
		||||
@@ -22,38 +22,28 @@
 | 
			
		||||
 | 
			
		||||
ResizeVolumeGroupDialog::ResizeVolumeGroupDialog( LvmDevice* device,
 | 
			
		||||
                                                  const PartitionVector& availablePVs,
 | 
			
		||||
                                                  PartitionVector& selectedPVs,
 | 
			
		||||
                                                  QWidget* parent )
 | 
			
		||||
    : VolumeGroupBaseDialog( device->name(), device->physicalVolumes(), parent )
 | 
			
		||||
    , m_selectedPVs( selectedPVs )
 | 
			
		||||
    : VolumeGroupBaseDialog( parent, device->name(), device->physicalVolumes() )
 | 
			
		||||
{
 | 
			
		||||
    setWindowTitle( tr( "Resize Volume Group" ) );
 | 
			
		||||
 | 
			
		||||
    for ( int i = 0; i < pvList()->count(); i++ )
 | 
			
		||||
    for ( int i = 0; i < pvListWidget()->count(); i++ )
 | 
			
		||||
    {
 | 
			
		||||
        pvList()->item( i )->setCheckState( Qt::Checked );
 | 
			
		||||
        pvListWidget()->item( i )->setCheckState( Qt::Checked );
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    for ( const Partition* p : availablePVs )
 | 
			
		||||
    {
 | 
			
		||||
        pvList()->addItem( new ListPhysicalVolumeWidgetItem( p, false ) );
 | 
			
		||||
        pvListWidget()->addItem( new ListPhysicalVolumeWidgetItem( p, false ) );
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    peSize()->setValue(
 | 
			
		||||
    peSizeWidget()->setValue(
 | 
			
		||||
        static_cast< int >( device->peSize() / Capacity::unitFactor( Capacity::Unit::Byte, Capacity::Unit::MiB ) ) );
 | 
			
		||||
 | 
			
		||||
    vgName()->setEnabled( false );
 | 
			
		||||
    peSize()->setEnabled( false );
 | 
			
		||||
    vgType()->setEnabled( false );
 | 
			
		||||
    vgNameWidget()->setEnabled( false );
 | 
			
		||||
    peSizeWidget()->setEnabled( false );
 | 
			
		||||
    vgTypeWidget()->setEnabled( false );
 | 
			
		||||
 | 
			
		||||
    setUsedSizeValue( device->allocatedPE() * device->peSize() );
 | 
			
		||||
    setLVQuantity( device->partitionTable()->children().count() );
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void
 | 
			
		||||
ResizeVolumeGroupDialog::accept()
 | 
			
		||||
{
 | 
			
		||||
    m_selectedPVs << checkedItems();
 | 
			
		||||
 | 
			
		||||
    QDialog::accept();
 | 
			
		||||
}
 | 
			
		||||
 
 | 
			
		||||
@@ -19,17 +19,7 @@ class ResizeVolumeGroupDialog : public VolumeGroupBaseDialog
 | 
			
		||||
{
 | 
			
		||||
    Q_OBJECT
 | 
			
		||||
public:
 | 
			
		||||
    using PartitionVector = QVector< const Partition* >;
 | 
			
		||||
 | 
			
		||||
    ResizeVolumeGroupDialog( LvmDevice* device,
 | 
			
		||||
                             const PartitionVector& availablePVs,
 | 
			
		||||
                             PartitionVector& selectedPVs,
 | 
			
		||||
                             QWidget* parent );
 | 
			
		||||
 | 
			
		||||
    void accept() override;
 | 
			
		||||
 | 
			
		||||
private:
 | 
			
		||||
    PartitionVector& m_selectedPVs;
 | 
			
		||||
    ResizeVolumeGroupDialog( LvmDevice* device, const PartitionVector& availablePVs, QWidget* parent );
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
#endif  // RESIZEVOLUMEGROUPDIALOG_H
 | 
			
		||||
 
 | 
			
		||||
@@ -10,6 +10,7 @@
 | 
			
		||||
#include "VolumeGroupBaseDialog.h"
 | 
			
		||||
#include "ui_VolumeGroupBaseDialog.h"
 | 
			
		||||
 | 
			
		||||
#include "core/PartitionCoreModule.h"
 | 
			
		||||
#include "core/SizeUtils.h"
 | 
			
		||||
#include "gui/ListPhysicalVolumeWidgetItem.h"
 | 
			
		||||
 | 
			
		||||
@@ -20,10 +21,11 @@
 | 
			
		||||
#include <QPushButton>
 | 
			
		||||
#include <QSpinBox>
 | 
			
		||||
 | 
			
		||||
VolumeGroupBaseDialog::VolumeGroupBaseDialog( QString& vgName, QVector< const Partition* > pvList, QWidget* parent )
 | 
			
		||||
// Keeping the sources consistent
 | 
			
		||||
VolumeGroupBaseDialog::VolumeGroupBaseDialog( QWidget* parent, const QString& vgName, PartitionVector pvList )
 | 
			
		||||
    : QDialog( parent )
 | 
			
		||||
    , ui( new Ui::VolumeGroupBaseDialog )
 | 
			
		||||
    , m_vgNameValue( vgName )
 | 
			
		||||
    , m_volumeGroupName( vgName )
 | 
			
		||||
    , m_totalSizeValue( 0 )
 | 
			
		||||
    , m_usedSizeValue( 0 )
 | 
			
		||||
{
 | 
			
		||||
@@ -34,13 +36,12 @@ VolumeGroupBaseDialog::VolumeGroupBaseDialog( QString& vgName, QVector< const Pa
 | 
			
		||||
        ui->pvList->addItem( new ListPhysicalVolumeWidgetItem( p, false ) );
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    ui->vgType->addItems( QStringList() << "LVM"
 | 
			
		||||
                                        << "RAID" );
 | 
			
		||||
    ui->vgType->addItems( { "LVM", "RAID" } );
 | 
			
		||||
    ui->vgType->setCurrentIndex( 0 );
 | 
			
		||||
 | 
			
		||||
    QRegularExpression re( R"(^(?!_|\.)[\w\-.+]+)" );
 | 
			
		||||
    ui->vgName->setValidator( new QRegularExpressionValidator( re, this ) );
 | 
			
		||||
    ui->vgName->setText( m_vgNameValue );
 | 
			
		||||
    ui->vgName->setText( vgName );
 | 
			
		||||
 | 
			
		||||
    updateOkButton();
 | 
			
		||||
    updateTotalSize();
 | 
			
		||||
@@ -55,7 +56,10 @@ VolumeGroupBaseDialog::VolumeGroupBaseDialog( QString& vgName, QVector< const Pa
 | 
			
		||||
        updateOkButton();
 | 
			
		||||
    } );
 | 
			
		||||
 | 
			
		||||
    connect( ui->vgName, &QLineEdit::textChanged, this, [&]( const QString& ) { updateOkButton(); } );
 | 
			
		||||
    connect( ui->vgName, &QLineEdit::textChanged, this, [&]( const QString& s ) {
 | 
			
		||||
        m_volumeGroupName = s;
 | 
			
		||||
        updateOkButton();
 | 
			
		||||
    } );
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
VolumeGroupBaseDialog::~VolumeGroupBaseDialog()
 | 
			
		||||
@@ -63,10 +67,10 @@ VolumeGroupBaseDialog::~VolumeGroupBaseDialog()
 | 
			
		||||
    delete ui;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
QVector< const Partition* >
 | 
			
		||||
VolumeGroupBaseDialog::checkedItems() const
 | 
			
		||||
PartitionVector
 | 
			
		||||
VolumeGroupBaseDialog::selectedPVs() const
 | 
			
		||||
{
 | 
			
		||||
    QVector< const Partition* > items;
 | 
			
		||||
    PartitionVector items;
 | 
			
		||||
 | 
			
		||||
    for ( int i = 0; i < ui->pvList->count(); i++ )
 | 
			
		||||
    {
 | 
			
		||||
@@ -90,8 +94,8 @@ VolumeGroupBaseDialog::isSizeValid() const
 | 
			
		||||
void
 | 
			
		||||
VolumeGroupBaseDialog::updateOkButton()
 | 
			
		||||
{
 | 
			
		||||
    okButton()->setEnabled( isSizeValid() && !checkedItems().empty() && !ui->vgName->text().isEmpty()
 | 
			
		||||
                            && ui->peSize->value() > 0 );
 | 
			
		||||
    okButtonWidget()->setEnabled( isSizeValid() && !selectedPVs().empty() && !ui->vgName->text().isEmpty()
 | 
			
		||||
                                  && ui->peSize->value() > 0 );
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void
 | 
			
		||||
@@ -111,13 +115,14 @@ VolumeGroupBaseDialog::setLVQuantity( qint32 lvQuantity )
 | 
			
		||||
void
 | 
			
		||||
VolumeGroupBaseDialog::updateTotalSize()
 | 
			
		||||
{
 | 
			
		||||
    m_physicalExtentSize = peSizeWidget()->value();
 | 
			
		||||
    m_totalSizeValue = 0;
 | 
			
		||||
 | 
			
		||||
    for ( const Partition* p : checkedItems() )
 | 
			
		||||
    for ( const Partition* p : selectedPVs() )
 | 
			
		||||
    {
 | 
			
		||||
        m_totalSizeValue += p->capacity()
 | 
			
		||||
            - p->capacity()
 | 
			
		||||
                % ( ui->peSize->value() * Capacity::unitFactor( Capacity::Unit::Byte, Capacity::Unit::MiB ) );
 | 
			
		||||
                % ( m_physicalExtentSize * Capacity::unitFactor( Capacity::Unit::Byte, Capacity::Unit::MiB ) );
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    ui->totalSize->setText( formatByteSize( m_totalSizeValue ) );
 | 
			
		||||
@@ -128,9 +133,10 @@ VolumeGroupBaseDialog::updateTotalSize()
 | 
			
		||||
void
 | 
			
		||||
VolumeGroupBaseDialog::updateTotalSectors()
 | 
			
		||||
{
 | 
			
		||||
    qint64 totalSectors = 0;
 | 
			
		||||
    m_physicalExtentSize = peSizeWidget()->value();
 | 
			
		||||
 | 
			
		||||
    qint64 extentSize = ui->peSize->value() * Capacity::unitFactor( Capacity::Unit::Byte, Capacity::Unit::MiB );
 | 
			
		||||
    qint64 totalSectors = 0;
 | 
			
		||||
    qint64 extentSize = m_physicalExtentSize * Capacity::unitFactor( Capacity::Unit::Byte, Capacity::Unit::MiB );
 | 
			
		||||
 | 
			
		||||
    if ( extentSize > 0 )
 | 
			
		||||
    {
 | 
			
		||||
@@ -140,38 +146,32 @@ VolumeGroupBaseDialog::updateTotalSectors()
 | 
			
		||||
    ui->totalSectors->setText( QString::number( totalSectors ) );
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
QString&
 | 
			
		||||
VolumeGroupBaseDialog::vgNameValue() const
 | 
			
		||||
{
 | 
			
		||||
    return m_vgNameValue;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
QLineEdit*
 | 
			
		||||
VolumeGroupBaseDialog::vgName() const
 | 
			
		||||
VolumeGroupBaseDialog::vgNameWidget() const
 | 
			
		||||
{
 | 
			
		||||
    return ui->vgName;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
QComboBox*
 | 
			
		||||
VolumeGroupBaseDialog::vgType() const
 | 
			
		||||
VolumeGroupBaseDialog::vgTypeWidget() const
 | 
			
		||||
{
 | 
			
		||||
    return ui->vgType;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
QSpinBox*
 | 
			
		||||
VolumeGroupBaseDialog::peSize() const
 | 
			
		||||
VolumeGroupBaseDialog::peSizeWidget() const
 | 
			
		||||
{
 | 
			
		||||
    return ui->peSize;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
QListWidget*
 | 
			
		||||
VolumeGroupBaseDialog::pvList() const
 | 
			
		||||
VolumeGroupBaseDialog::pvListWidget() const
 | 
			
		||||
{
 | 
			
		||||
    return ui->pvList;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
QPushButton*
 | 
			
		||||
VolumeGroupBaseDialog::okButton() const
 | 
			
		||||
VolumeGroupBaseDialog::okButtonWidget() const
 | 
			
		||||
{
 | 
			
		||||
    return ui->buttonBox->button( QDialogButtonBox::StandardButton::Ok );
 | 
			
		||||
}
 | 
			
		||||
 
 | 
			
		||||
@@ -10,7 +10,7 @@
 | 
			
		||||
#ifndef VOLUMEGROUPBASEDIALOG_H
 | 
			
		||||
#define VOLUMEGROUPBASEDIALOG_H
 | 
			
		||||
 | 
			
		||||
#include <kpmcore/core/partition.h>
 | 
			
		||||
#include "core/KPMHelpers.h"
 | 
			
		||||
 | 
			
		||||
#include <QDialog>
 | 
			
		||||
 | 
			
		||||
@@ -29,43 +29,46 @@ class VolumeGroupBaseDialog : public QDialog
 | 
			
		||||
    Q_OBJECT
 | 
			
		||||
 | 
			
		||||
public:
 | 
			
		||||
    explicit VolumeGroupBaseDialog( QString& vgName, QVector< const Partition* > pvList, QWidget* parent = nullptr );
 | 
			
		||||
    explicit VolumeGroupBaseDialog( QWidget* parent, const QString& vgName, PartitionVector pvList );
 | 
			
		||||
    ~VolumeGroupBaseDialog() override;
 | 
			
		||||
 | 
			
		||||
    qint32 physicalExtentSize() const { return m_physicalExtentSize; }
 | 
			
		||||
    QString volumeGroupName() const { return m_volumeGroupName; }
 | 
			
		||||
    /** @brief Which PVs (partitions) are selected for this VG
 | 
			
		||||
     *
 | 
			
		||||
     * The vector contains non-owned pointers.
 | 
			
		||||
     */
 | 
			
		||||
    PartitionVector selectedPVs() const;
 | 
			
		||||
 | 
			
		||||
protected:
 | 
			
		||||
    virtual void updateOkButton();
 | 
			
		||||
 | 
			
		||||
    void setUsedSizeValue( qint64 usedSize );
 | 
			
		||||
 | 
			
		||||
    void setLVQuantity( qint32 lvQuantity );
 | 
			
		||||
 | 
			
		||||
    void updateTotalSize();
 | 
			
		||||
 | 
			
		||||
    void updateTotalSectors();
 | 
			
		||||
 | 
			
		||||
    QVector< const Partition* > checkedItems() const;
 | 
			
		||||
 | 
			
		||||
    bool isSizeValid() const;
 | 
			
		||||
 | 
			
		||||
    QString& vgNameValue() const;
 | 
			
		||||
    void updateTotalSize();
 | 
			
		||||
    void updateTotalSectors();
 | 
			
		||||
 | 
			
		||||
    QLineEdit* vgName() const;
 | 
			
		||||
 | 
			
		||||
    QComboBox* vgType() const;
 | 
			
		||||
 | 
			
		||||
    QSpinBox* peSize() const;
 | 
			
		||||
 | 
			
		||||
    QListWidget* pvList() const;
 | 
			
		||||
 | 
			
		||||
    QPushButton* okButton() const;
 | 
			
		||||
    /** @section UI-widget accessors
 | 
			
		||||
     *
 | 
			
		||||
     * These methods get UI internal widgets, so that subclasses
 | 
			
		||||
     * can manipulate the values in those widgets.
 | 
			
		||||
     */
 | 
			
		||||
    QLineEdit* vgNameWidget() const;
 | 
			
		||||
    QComboBox* vgTypeWidget() const;
 | 
			
		||||
    QSpinBox* peSizeWidget() const;
 | 
			
		||||
    QListWidget* pvListWidget() const;
 | 
			
		||||
    QPushButton* okButtonWidget() const;
 | 
			
		||||
 | 
			
		||||
private:
 | 
			
		||||
    Ui::VolumeGroupBaseDialog* ui;
 | 
			
		||||
 | 
			
		||||
    QString& m_vgNameValue;
 | 
			
		||||
 | 
			
		||||
    QString m_volumeGroupName;
 | 
			
		||||
    qint64 m_totalSizeValue;
 | 
			
		||||
    qint64 m_usedSizeValue;
 | 
			
		||||
    qint32 m_physicalExtentSize;
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
#endif  // VOLUMEGROUPBASEDIALOG_H
 | 
			
		||||
 
 | 
			
		||||
@@ -17,12 +17,12 @@
 | 
			
		||||
#include <kpmcore/util/report.h>
 | 
			
		||||
 | 
			
		||||
CreateVolumeGroupJob::CreateVolumeGroupJob( Device*,
 | 
			
		||||
                                            QString& vgName,
 | 
			
		||||
                                            QVector< const Partition* > pvList,
 | 
			
		||||
                                            const QString& vgName,
 | 
			
		||||
                                            const PartitionVector& pvList,
 | 
			
		||||
                                            const qint32 peSize )
 | 
			
		||||
    : m_vgName( vgName )
 | 
			
		||||
    , m_pvList( pvList )
 | 
			
		||||
    , m_peSize( peSize )
 | 
			
		||||
    , m_physicalExtentSize( peSize )
 | 
			
		||||
{
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
@@ -47,7 +47,7 @@ CreateVolumeGroupJob::prettyStatusMessage() const
 | 
			
		||||
Calamares::JobResult
 | 
			
		||||
CreateVolumeGroupJob::exec()
 | 
			
		||||
{
 | 
			
		||||
    return KPMHelpers::execute( CreateVolumeGroupOperation( m_vgName, m_pvList, m_peSize ),
 | 
			
		||||
    return KPMHelpers::execute( CreateVolumeGroupOperation( m_vgName, m_pvList, m_physicalExtentSize ),
 | 
			
		||||
                                tr( "The installer failed to create a volume group named '%1'." ).arg( m_vgName ) );
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
 
 | 
			
		||||
@@ -10,19 +10,23 @@
 | 
			
		||||
#ifndef CREATEVOLUMEGROUPJOB_H
 | 
			
		||||
#define CREATEVOLUMEGROUPJOB_H
 | 
			
		||||
 | 
			
		||||
#include "core/KPMHelpers.h"
 | 
			
		||||
 | 
			
		||||
#include "Job.h"
 | 
			
		||||
#include "partition/KPMManager.h"
 | 
			
		||||
 | 
			
		||||
#include <QVector>
 | 
			
		||||
 | 
			
		||||
class Device;
 | 
			
		||||
class Partition;
 | 
			
		||||
 | 
			
		||||
class CreateVolumeGroupJob : public Calamares::Job
 | 
			
		||||
{
 | 
			
		||||
    Q_OBJECT
 | 
			
		||||
public:
 | 
			
		||||
    CreateVolumeGroupJob( Device*, QString& vgName, QVector< const Partition* > pvList, const qint32 peSize );
 | 
			
		||||
    /** @brief Make a job that will create a volume group
 | 
			
		||||
     *
 | 
			
		||||
     * The @p physicalExtentSize is given in MiB; typically this is 4 (MiB).
 | 
			
		||||
     */
 | 
			
		||||
    CreateVolumeGroupJob( Device*,
 | 
			
		||||
                          const QString& vgName,
 | 
			
		||||
                          const PartitionVector& pvList,
 | 
			
		||||
                          const qint32 physicalExtentSize );
 | 
			
		||||
 | 
			
		||||
    QString prettyName() const override;
 | 
			
		||||
    QString prettyDescription() const override;
 | 
			
		||||
@@ -35,8 +39,8 @@ public:
 | 
			
		||||
private:
 | 
			
		||||
    CalamaresUtils::Partition::KPMManager m_kpmcore;
 | 
			
		||||
    QString m_vgName;
 | 
			
		||||
    QVector< const Partition* > m_pvList;
 | 
			
		||||
    qint32 m_peSize;
 | 
			
		||||
    PartitionVector m_pvList;
 | 
			
		||||
    qint32 m_physicalExtentSize;
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
#endif  // CREATEVOLUMEGROUPJOB_H
 | 
			
		||||
 
 | 
			
		||||
@@ -9,14 +9,12 @@
 | 
			
		||||
 | 
			
		||||
#include "ResizeVolumeGroupJob.h"
 | 
			
		||||
 | 
			
		||||
#include "core/KPMHelpers.h"
 | 
			
		||||
 | 
			
		||||
#include <kpmcore/core/lvmdevice.h>
 | 
			
		||||
#include <kpmcore/core/partition.h>
 | 
			
		||||
#include <kpmcore/ops/resizevolumegroupoperation.h>
 | 
			
		||||
#include <kpmcore/util/report.h>
 | 
			
		||||
 | 
			
		||||
ResizeVolumeGroupJob::ResizeVolumeGroupJob( Device*, LvmDevice* device, QVector< const Partition* >& partitionList )
 | 
			
		||||
ResizeVolumeGroupJob::ResizeVolumeGroupJob( Device*, LvmDevice* device, const PartitionVector& partitionList )
 | 
			
		||||
    : m_device( device )
 | 
			
		||||
    , m_partitionList( partitionList )
 | 
			
		||||
{
 | 
			
		||||
 
 | 
			
		||||
@@ -10,20 +10,19 @@
 | 
			
		||||
#ifndef RESIZEVOLUMEGROUPJOB_H
 | 
			
		||||
#define RESIZEVOLUMEGROUPJOB_H
 | 
			
		||||
 | 
			
		||||
#include "core/KPMHelpers.h"
 | 
			
		||||
 | 
			
		||||
#include "Job.h"
 | 
			
		||||
#include "partition/KPMManager.h"
 | 
			
		||||
 | 
			
		||||
#include <QVector>
 | 
			
		||||
 | 
			
		||||
class Device;
 | 
			
		||||
class LvmDevice;
 | 
			
		||||
class Partition;
 | 
			
		||||
 | 
			
		||||
class ResizeVolumeGroupJob : public Calamares::Job
 | 
			
		||||
{
 | 
			
		||||
    Q_OBJECT
 | 
			
		||||
public:
 | 
			
		||||
    ResizeVolumeGroupJob( Device*, LvmDevice* device, QVector< const Partition* >& partitionList );
 | 
			
		||||
    ResizeVolumeGroupJob( Device*, LvmDevice* device, const PartitionVector& partitionList );
 | 
			
		||||
 | 
			
		||||
    QString prettyName() const override;
 | 
			
		||||
    QString prettyDescription() const override;
 | 
			
		||||
@@ -37,7 +36,7 @@ private:
 | 
			
		||||
private:
 | 
			
		||||
    CalamaresUtils::Partition::KPMManager m_kpmcore;
 | 
			
		||||
    LvmDevice* m_device;
 | 
			
		||||
    QVector< const Partition* > m_partitionList;
 | 
			
		||||
    PartitionVector m_partitionList;
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
#endif  // RESIZEVOLUMEGROUPJOB_H
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user