Avoid creating a new partition with a used mountpoint.

We get the mountpoints already used by other partitions, and
disable the Ok button in the "Create new partition" dialog if
the user selects/writes a mountpoint which is already used.

We are going to do the same in the Edit partition dialog
after testing.
This commit is contained in:
shainer 2016-11-20 22:05:55 +00:00
parent e5f5bb99d7
commit c8dbeb5341
5 changed files with 63 additions and 12 deletions

View file

@ -40,8 +40,9 @@
// Qt
#include <QComboBox>
#include <QDir>
#include <QSet>
#include <QListWidgetItem>
#include <QPushButton>
#include <QSet>
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 )
{