diff --git a/src/modules/partition/gui/CreatePartitionDialog.cpp b/src/modules/partition/gui/CreatePartitionDialog.cpp index 994e60010..788aa0355 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,6 +103,8 @@ 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(); @@ -252,6 +256,18 @@ CreatePartitionDialog::updateMountPointUi() m_ui->mountPointComboBox->setCurrentText( QString() ); } +void +CreatePartitionDialog::checkMountPointSelection(const QString& selection) +{ + if (m_usedMountPoints.contains(selection)) { + m_ui->labelMountPoint->setText("Mountpoint already used. 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..7773d5f8b 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(const QString &); 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/PartitionPage.cpp b/src/modules/partition/gui/PartitionPage.cpp index 2ba07606d..99dd1679b 100644 --- a/src/modules/partition/gui/PartitionPage.cpp +++ b/src/modules/partition/gui/PartitionPage.cpp @@ -176,7 +176,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 +265,7 @@ PartitionPage::onPartitionViewActivated() void PartitionPage::updatePartitionToCreate( Device* device, Partition* partition ) { - QPointer dlg = new CreatePartitionDialog( device, partition->parent(), this ); + QPointer dlg = new CreatePartitionDialog( device, partition->parent(), getCurrentUsedMountpoints(), this ); dlg->initFromPartitionToCreate( partition ); if ( dlg->exec() == QDialog::Accepted ) { @@ -375,3 +375,22 @@ 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()) { + if (!partition->mountPoint().isEmpty()) { + mountPoints << partition->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; };