mirror of
https://github.com/parchlinux/calamares.git
synced 2025-06-30 02:45:37 -04:00
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:
parent
e5f5bb99d7
commit
c8dbeb5341
5 changed files with 63 additions and 12 deletions
|
@ -40,8 +40,9 @@
|
||||||
// Qt
|
// Qt
|
||||||
#include <QComboBox>
|
#include <QComboBox>
|
||||||
#include <QDir>
|
#include <QDir>
|
||||||
#include <QSet>
|
|
||||||
#include <QListWidgetItem>
|
#include <QListWidgetItem>
|
||||||
|
#include <QPushButton>
|
||||||
|
#include <QSet>
|
||||||
|
|
||||||
static QSet< FileSystem::Type > s_unmountableFS(
|
static QSet< FileSystem::Type > s_unmountableFS(
|
||||||
{
|
{
|
||||||
|
@ -52,12 +53,13 @@ static QSet< FileSystem::Type > s_unmountableFS(
|
||||||
FileSystem::Lvm2_PV
|
FileSystem::Lvm2_PV
|
||||||
} );
|
} );
|
||||||
|
|
||||||
CreatePartitionDialog::CreatePartitionDialog( Device* device, PartitionNode* parentPartition, QWidget* parentWidget )
|
CreatePartitionDialog::CreatePartitionDialog( Device* device, PartitionNode* parentPartition, const QStringList& usedMountPoints, QWidget* parentWidget )
|
||||||
: QDialog( parentWidget )
|
: QDialog( parentWidget )
|
||||||
, m_ui( new Ui_CreatePartitionDialog )
|
, m_ui( new Ui_CreatePartitionDialog )
|
||||||
, m_partitionSizeController( new PartitionSizeController( this ) )
|
, m_partitionSizeController( new PartitionSizeController( this ) )
|
||||||
, m_device( device )
|
, m_device( device )
|
||||||
, m_parent( parentPartition )
|
, m_parent( parentPartition )
|
||||||
|
, m_usedMountPoints( usedMountPoints )
|
||||||
{
|
{
|
||||||
m_ui->setupUi( this );
|
m_ui->setupUi( this );
|
||||||
m_ui->encryptWidget->setText( tr( "En&crypt" ) );
|
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->fsComboBox, SIGNAL( activated( int ) ), SLOT( updateMountPointUi() ) );
|
||||||
connect( m_ui->extendedRadioButton, SIGNAL( toggled( bool ) ), SLOT( updateMountPointUi() ) );
|
connect( m_ui->extendedRadioButton, SIGNAL( toggled( bool ) ), SLOT( updateMountPointUi() ) );
|
||||||
|
|
||||||
|
connect( m_ui->mountPointComboBox, &QComboBox::currentTextChanged, this, &CreatePartitionDialog::checkMountPointSelection );
|
||||||
|
|
||||||
// Select a default
|
// Select a default
|
||||||
m_ui->fsComboBox->setCurrentIndex( defaultFsIndex );
|
m_ui->fsComboBox->setCurrentIndex( defaultFsIndex );
|
||||||
updateMountPointUi();
|
updateMountPointUi();
|
||||||
|
@ -252,6 +256,18 @@ CreatePartitionDialog::updateMountPointUi()
|
||||||
m_ui->mountPointComboBox->setCurrentText( QString() );
|
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
|
void
|
||||||
CreatePartitionDialog::initPartResizerWidget( Partition* partition )
|
CreatePartitionDialog::initPartResizerWidget( Partition* partition )
|
||||||
{
|
{
|
||||||
|
|
|
@ -42,7 +42,7 @@ class CreatePartitionDialog : public QDialog
|
||||||
{
|
{
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
public:
|
public:
|
||||||
CreatePartitionDialog( Device* device, PartitionNode* parentPartition, QWidget* parentWidget = nullptr );
|
CreatePartitionDialog( Device* device, PartitionNode* parentPartition, const QStringList& usedMountPoints, QWidget* parentWidget = nullptr );
|
||||||
~CreatePartitionDialog();
|
~CreatePartitionDialog();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -61,6 +61,7 @@ public:
|
||||||
|
|
||||||
private Q_SLOTS:
|
private Q_SLOTS:
|
||||||
void updateMountPointUi();
|
void updateMountPointUi();
|
||||||
|
void checkMountPointSelection(const QString &);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
void setupFlagsList();
|
void setupFlagsList();
|
||||||
|
@ -69,6 +70,7 @@ private:
|
||||||
Device* m_device;
|
Device* m_device;
|
||||||
PartitionNode* m_parent;
|
PartitionNode* m_parent;
|
||||||
PartitionRole m_role = PartitionRole( PartitionRole::None );
|
PartitionRole m_role = PartitionRole( PartitionRole::None );
|
||||||
|
QStringList m_usedMountPoints;
|
||||||
|
|
||||||
void initGptPartitionTypeUi();
|
void initGptPartitionTypeUi();
|
||||||
void initMbrPartitionTypeUi();
|
void initMbrPartitionTypeUi();
|
||||||
|
|
|
@ -108,7 +108,7 @@
|
||||||
<property name="sizeHint" stdset="0">
|
<property name="sizeHint" stdset="0">
|
||||||
<size>
|
<size>
|
||||||
<width>20</width>
|
<width>20</width>
|
||||||
<height>12</height>
|
<height>13</height>
|
||||||
</size>
|
</size>
|
||||||
</property>
|
</property>
|
||||||
</spacer>
|
</spacer>
|
||||||
|
@ -126,6 +126,9 @@
|
||||||
<item row="3" column="1">
|
<item row="3" column="1">
|
||||||
<widget class="QComboBox" name="fsComboBox"/>
|
<widget class="QComboBox" name="fsComboBox"/>
|
||||||
</item>
|
</item>
|
||||||
|
<item row="4" column="1">
|
||||||
|
<widget class="EncryptWidget" name="encryptWidget" native="true"/>
|
||||||
|
</item>
|
||||||
<item row="5" column="1">
|
<item row="5" column="1">
|
||||||
<spacer name="verticalSpacer_2">
|
<spacer name="verticalSpacer_2">
|
||||||
<property name="orientation">
|
<property name="orientation">
|
||||||
|
@ -162,14 +165,26 @@
|
||||||
</property>
|
</property>
|
||||||
</widget>
|
</widget>
|
||||||
</item>
|
</item>
|
||||||
<item row="7" column="0">
|
<item row="7" column="1">
|
||||||
|
<widget class="QLabel" name="labelMountPoint">
|
||||||
|
<property name="font">
|
||||||
|
<font>
|
||||||
|
<italic>true</italic>
|
||||||
|
</font>
|
||||||
|
</property>
|
||||||
|
<property name="text">
|
||||||
|
<string/>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
|
<item row="8" column="0">
|
||||||
<widget class="QLabel" name="label_3">
|
<widget class="QLabel" name="label_3">
|
||||||
<property name="text">
|
<property name="text">
|
||||||
<string>Flags:</string>
|
<string>Flags:</string>
|
||||||
</property>
|
</property>
|
||||||
</widget>
|
</widget>
|
||||||
</item>
|
</item>
|
||||||
<item row="7" column="1">
|
<item row="8" column="1">
|
||||||
<widget class="QListWidget" name="m_listFlags">
|
<widget class="QListWidget" name="m_listFlags">
|
||||||
<property name="alternatingRowColors">
|
<property name="alternatingRowColors">
|
||||||
<bool>true</bool>
|
<bool>true</bool>
|
||||||
|
@ -182,7 +197,7 @@
|
||||||
</property>
|
</property>
|
||||||
</widget>
|
</widget>
|
||||||
</item>
|
</item>
|
||||||
<item row="8" column="0">
|
<item row="9" column="0">
|
||||||
<spacer name="verticalSpacer">
|
<spacer name="verticalSpacer">
|
||||||
<property name="orientation">
|
<property name="orientation">
|
||||||
<enum>Qt::Vertical</enum>
|
<enum>Qt::Vertical</enum>
|
||||||
|
@ -195,9 +210,6 @@
|
||||||
</property>
|
</property>
|
||||||
</spacer>
|
</spacer>
|
||||||
</item>
|
</item>
|
||||||
<item row="4" column="1">
|
|
||||||
<widget class="EncryptWidget" name="encryptWidget" native="true"/>
|
|
||||||
</item>
|
|
||||||
</layout>
|
</layout>
|
||||||
</item>
|
</item>
|
||||||
<item>
|
<item>
|
||||||
|
|
|
@ -176,7 +176,7 @@ PartitionPage::onCreateClicked()
|
||||||
Partition* partition = model->partitionForIndex( index );
|
Partition* partition = model->partitionForIndex( index );
|
||||||
Q_ASSERT( partition );
|
Q_ASSERT( partition );
|
||||||
|
|
||||||
QPointer<CreatePartitionDialog> dlg = new CreatePartitionDialog( model->device(), partition->parent(), this );
|
QPointer<CreatePartitionDialog> dlg = new CreatePartitionDialog( model->device(), partition->parent(), getCurrentUsedMountpoints(), this );
|
||||||
dlg->initFromFreeSpace( partition );
|
dlg->initFromFreeSpace( partition );
|
||||||
if ( dlg->exec() == QDialog::Accepted )
|
if ( dlg->exec() == QDialog::Accepted )
|
||||||
{
|
{
|
||||||
|
@ -265,7 +265,7 @@ PartitionPage::onPartitionViewActivated()
|
||||||
void
|
void
|
||||||
PartitionPage::updatePartitionToCreate( Device* device, Partition* partition )
|
PartitionPage::updatePartitionToCreate( Device* device, Partition* partition )
|
||||||
{
|
{
|
||||||
QPointer<CreatePartitionDialog> dlg = new CreatePartitionDialog( device, partition->parent(), this );
|
QPointer<CreatePartitionDialog> dlg = new CreatePartitionDialog( device, partition->parent(), getCurrentUsedMountpoints(), this );
|
||||||
dlg->initFromPartitionToCreate( partition );
|
dlg->initFromPartitionToCreate( partition );
|
||||||
if ( dlg->exec() == QDialog::Accepted )
|
if ( dlg->exec() == QDialog::Accepted )
|
||||||
{
|
{
|
||||||
|
@ -375,3 +375,22 @@ PartitionPage::updateBootLoaderIndex()
|
||||||
m_ui->bootLoaderComboBox->setCurrentIndex( m_lastSelectedBootLoaderIndex );
|
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;
|
||||||
|
}
|
||||||
|
|
|
@ -62,6 +62,8 @@ private:
|
||||||
void updateFromCurrentDevice();
|
void updateFromCurrentDevice();
|
||||||
void updateBootLoaderIndex();
|
void updateBootLoaderIndex();
|
||||||
|
|
||||||
|
QStringList getCurrentUsedMountpoints();
|
||||||
|
|
||||||
QMutex m_revertMutex;
|
QMutex m_revertMutex;
|
||||||
int m_lastSelectedBootLoaderIndex;
|
int m_lastSelectedBootLoaderIndex;
|
||||||
};
|
};
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue