diff --git a/src/modules/partition/gui/CreatePartitionDialog.cpp b/src/modules/partition/gui/CreatePartitionDialog.cpp index 994e60010..90545fe80 100644 --- a/src/modules/partition/gui/CreatePartitionDialog.cpp +++ b/src/modules/partition/gui/CreatePartitionDialog.cpp @@ -40,8 +40,9 @@ // Qt #include #include -#include #include +#include +#include static QSet< FileSystem::Type > s_unmountableFS( { @@ -52,12 +53,13 @@ static QSet< FileSystem::Type > s_unmountableFS( FileSystem::Lvm2_PV } ); -CreatePartitionDialog::CreatePartitionDialog( Device* device, PartitionNode* parentPartition, QWidget* parentWidget ) +CreatePartitionDialog::CreatePartitionDialog( Device* device, PartitionNode* parentPartition, const QStringList& usedMountPoints, QWidget* parentWidget ) : QDialog( parentWidget ) , m_ui( new Ui_CreatePartitionDialog ) , m_partitionSizeController( new PartitionSizeController( this ) ) , m_device( device ) , m_parent( parentPartition ) + , m_usedMountPoints( usedMountPoints ) { m_ui->setupUi( this ); m_ui->encryptWidget->setText( tr( "En&crypt" ) ); @@ -101,11 +103,15 @@ CreatePartitionDialog::CreatePartitionDialog( Device* device, PartitionNode* par connect( m_ui->fsComboBox, SIGNAL( activated( int ) ), SLOT( updateMountPointUi() ) ); connect( m_ui->extendedRadioButton, SIGNAL( toggled( bool ) ), SLOT( updateMountPointUi() ) ); + connect( m_ui->mountPointComboBox, &QComboBox::currentTextChanged, this, &CreatePartitionDialog::checkMountPointSelection ); + // Select a default m_ui->fsComboBox->setCurrentIndex( defaultFsIndex ); updateMountPointUi(); setupFlagsList(); + // Checks the initial selection. + checkMountPointSelection(); } CreatePartitionDialog::~CreatePartitionDialog() @@ -252,6 +258,20 @@ CreatePartitionDialog::updateMountPointUi() m_ui->mountPointComboBox->setCurrentText( QString() ); } +void +CreatePartitionDialog::checkMountPointSelection() +{ + const QString& selection = m_ui->mountPointComboBox->currentText(); + + if (m_usedMountPoints.contains(selection)) { + m_ui->labelMountPoint->setText("Mountpoint already in use. Please select another one."); + m_ui->buttonBox->button(QDialogButtonBox::Ok)->setEnabled(false); + } else { + m_ui->labelMountPoint->setText( QString() ); + m_ui->buttonBox->button(QDialogButtonBox::Ok)->setEnabled(true); + } +} + void CreatePartitionDialog::initPartResizerWidget( Partition* partition ) { diff --git a/src/modules/partition/gui/CreatePartitionDialog.h b/src/modules/partition/gui/CreatePartitionDialog.h index aca7ed6a0..641616e3f 100644 --- a/src/modules/partition/gui/CreatePartitionDialog.h +++ b/src/modules/partition/gui/CreatePartitionDialog.h @@ -42,7 +42,7 @@ class CreatePartitionDialog : public QDialog { Q_OBJECT public: - CreatePartitionDialog( Device* device, PartitionNode* parentPartition, QWidget* parentWidget = nullptr ); + CreatePartitionDialog( Device* device, PartitionNode* parentPartition, const QStringList& usedMountPoints, QWidget* parentWidget = nullptr ); ~CreatePartitionDialog(); /** @@ -61,6 +61,7 @@ public: private Q_SLOTS: void updateMountPointUi(); + void checkMountPointSelection(); private: void setupFlagsList(); @@ -69,6 +70,7 @@ private: Device* m_device; PartitionNode* m_parent; PartitionRole m_role = PartitionRole( PartitionRole::None ); + QStringList m_usedMountPoints; void initGptPartitionTypeUi(); void initMbrPartitionTypeUi(); diff --git a/src/modules/partition/gui/CreatePartitionDialog.ui b/src/modules/partition/gui/CreatePartitionDialog.ui index 28961c543..bad15a4cf 100644 --- a/src/modules/partition/gui/CreatePartitionDialog.ui +++ b/src/modules/partition/gui/CreatePartitionDialog.ui @@ -108,7 +108,7 @@ 20 - 12 + 13 @@ -126,6 +126,9 @@ + + + @@ -162,14 +165,26 @@ - + + + + + true + + + + + + + + Flags: - + true @@ -182,7 +197,7 @@ - + Qt::Vertical @@ -195,9 +210,6 @@ - - - diff --git a/src/modules/partition/gui/EditExistingPartitionDialog.cpp b/src/modules/partition/gui/EditExistingPartitionDialog.cpp index 2652567d2..5aa1e21f6 100644 --- a/src/modules/partition/gui/EditExistingPartitionDialog.cpp +++ b/src/modules/partition/gui/EditExistingPartitionDialog.cpp @@ -43,13 +43,15 @@ // Qt #include #include +#include -EditExistingPartitionDialog::EditExistingPartitionDialog( Device* device, Partition* partition, QWidget* parentWidget ) +EditExistingPartitionDialog::EditExistingPartitionDialog( Device* device, Partition* partition, const QStringList& usedMountPoints, QWidget* parentWidget ) : QDialog( parentWidget ) , m_ui( new Ui_EditExistingPartitionDialog ) , m_device( device ) , m_partition( partition ) , m_partitionSizeController( new PartitionSizeController( this ) ) + , m_usedMountPoints( usedMountPoints ) { m_ui->setupUi( this ); @@ -65,6 +67,7 @@ EditExistingPartitionDialog::EditExistingPartitionDialog( Device* device, Partit m_partitionSizeController->setSpinBox( m_ui->sizeSpinBox ); m_ui->mountPointComboBox->setCurrentText( PartitionInfo::mountPoint( partition ) ); + connect( m_ui->mountPointComboBox, &QComboBox::currentTextChanged, this, &EditExistingPartitionDialog::checkMountPointSelection ); replacePartResizerWidget(); @@ -291,3 +294,17 @@ EditExistingPartitionDialog::updateMountPointPicker() if ( !canMount ) m_ui->mountPointComboBox->setCurrentText( QString() ); } + +void +EditExistingPartitionDialog::checkMountPointSelection() +{ + const QString& selection = m_ui->mountPointComboBox->currentText(); + + if (m_usedMountPoints.contains(selection)) { + m_ui->labelMountPoint->setText("Mountpoint already in use. Please select another one."); + m_ui->buttonBox->button(QDialogButtonBox::Ok)->setEnabled(false); + } else { + m_ui->labelMountPoint->setText( QString() ); + m_ui->buttonBox->button(QDialogButtonBox::Ok)->setEnabled(true); + } +} diff --git a/src/modules/partition/gui/EditExistingPartitionDialog.h b/src/modules/partition/gui/EditExistingPartitionDialog.h index 0aa89bb98..83552fe55 100644 --- a/src/modules/partition/gui/EditExistingPartitionDialog.h +++ b/src/modules/partition/gui/EditExistingPartitionDialog.h @@ -40,16 +40,20 @@ class EditExistingPartitionDialog : public QDialog { Q_OBJECT public: - EditExistingPartitionDialog( Device* device, Partition* partition, QWidget* parentWidget = nullptr ); + EditExistingPartitionDialog( Device* device, Partition* partition, const QStringList& usedMountPoints, QWidget* parentWidget = nullptr ); ~EditExistingPartitionDialog(); void applyChanges( PartitionCoreModule* module ); +private slots: + void checkMountPointSelection(); + private: QScopedPointer< Ui_EditExistingPartitionDialog > m_ui; Device* m_device; Partition* m_partition; PartitionSizeController* m_partitionSizeController; + QStringList m_usedMountPoints; PartitionTable::Flags newFlags() const; void setupFlagsList(); diff --git a/src/modules/partition/gui/EditExistingPartitionDialog.ui b/src/modules/partition/gui/EditExistingPartitionDialog.ui index 9ed7e1bb4..27e930fda 100644 --- a/src/modules/partition/gui/EditExistingPartitionDialog.ui +++ b/src/modules/partition/gui/EditExistingPartitionDialog.ui @@ -139,14 +139,14 @@ - + Flags: - + true @@ -159,6 +159,18 @@ + + + + + true + + + + + + + diff --git a/src/modules/partition/gui/PartitionPage.cpp b/src/modules/partition/gui/PartitionPage.cpp index 17867a644..6306c7a67 100644 --- a/src/modules/partition/gui/PartitionPage.cpp +++ b/src/modules/partition/gui/PartitionPage.cpp @@ -23,6 +23,7 @@ #include "core/BootLoaderModel.h" #include "core/DeviceModel.h" #include "core/PartitionCoreModule.h" +#include "core/PartitionInfo.h" #include "core/PartitionModel.h" #include "core/KPMHelpers.h" #include "gui/CreatePartitionDialog.h" @@ -176,7 +177,7 @@ PartitionPage::onCreateClicked() Partition* partition = model->partitionForIndex( index ); Q_ASSERT( partition ); - QPointer dlg = new CreatePartitionDialog( model->device(), partition->parent(), this ); + QPointer dlg = new CreatePartitionDialog( model->device(), partition->parent(), getCurrentUsedMountpoints(), this ); dlg->initFromFreeSpace( partition ); if ( dlg->exec() == QDialog::Accepted ) { @@ -265,7 +266,10 @@ PartitionPage::onPartitionViewActivated() void PartitionPage::updatePartitionToCreate( Device* device, Partition* partition ) { - QPointer dlg = new CreatePartitionDialog( device, partition->parent(), this ); + QStringList mountPoints = getCurrentUsedMountpoints(); + mountPoints.removeOne( PartitionInfo::mountPoint( partition ) ); + + QPointer dlg = new CreatePartitionDialog( device, partition->parent(), mountPoints, this ); dlg->initFromPartitionToCreate( partition ); if ( dlg->exec() == QDialog::Accepted ) { @@ -279,7 +283,10 @@ PartitionPage::updatePartitionToCreate( Device* device, Partition* partition ) void PartitionPage::editExistingPartition( Device* device, Partition* partition ) { - QPointer dlg = new EditExistingPartitionDialog( device, partition, this ); + QStringList mountPoints = getCurrentUsedMountpoints(); + mountPoints.removeOne( PartitionInfo::mountPoint( partition ) ); + + QPointer dlg = new EditExistingPartitionDialog( device, partition, mountPoints, this ); if ( dlg->exec() == QDialog::Accepted ) dlg->applyChanges( m_core ); delete dlg; @@ -376,3 +383,24 @@ PartitionPage::updateBootLoaderIndex() m_ui->bootLoaderComboBox->setCurrentIndex( m_lastSelectedBootLoaderIndex ); } } + +QStringList +PartitionPage::getCurrentUsedMountpoints() +{ + QModelIndex index = m_core->deviceModel()->index( m_ui->deviceComboBox->currentIndex(), 0 ); + if ( !index.isValid() ) + return QStringList(); + + Device* device = m_core->deviceModel()->deviceForIndex( index ); + QStringList mountPoints; + + for (Partition* partition : device->partitionTable()->children()) { + const QString& mountPoint = PartitionInfo::mountPoint( partition ); + + if (!mountPoint.isEmpty()) { + mountPoints << mountPoint; + } + } + + return mountPoints; +} diff --git a/src/modules/partition/gui/PartitionPage.h b/src/modules/partition/gui/PartitionPage.h index 2dc02159d..59453ce18 100644 --- a/src/modules/partition/gui/PartitionPage.h +++ b/src/modules/partition/gui/PartitionPage.h @@ -62,6 +62,8 @@ private: void updateFromCurrentDevice(); void updateBootLoaderIndex(); + QStringList getCurrentUsedMountpoints(); + QMutex m_revertMutex; int m_lastSelectedBootLoaderIndex; };