[partition] Disallow assigning the same mountpoint to two partitions
This commit is contained in:
parent
c29bca3fe0
commit
1727d2f267
@ -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,11 +103,15 @@ 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();
|
||||||
|
|
||||||
setupFlagsList();
|
setupFlagsList();
|
||||||
|
// Checks the initial selection.
|
||||||
|
checkMountPointSelection();
|
||||||
}
|
}
|
||||||
|
|
||||||
CreatePartitionDialog::~CreatePartitionDialog()
|
CreatePartitionDialog::~CreatePartitionDialog()
|
||||||
@ -252,6 +258,20 @@ CreatePartitionDialog::updateMountPointUi()
|
|||||||
m_ui->mountPointComboBox->setCurrentText( QString() );
|
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
|
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();
|
||||||
|
|
||||||
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>
|
||||||
|
@ -43,13 +43,15 @@
|
|||||||
// Qt
|
// Qt
|
||||||
#include <QComboBox>
|
#include <QComboBox>
|
||||||
#include <QDir>
|
#include <QDir>
|
||||||
|
#include <QPushButton>
|
||||||
|
|
||||||
EditExistingPartitionDialog::EditExistingPartitionDialog( Device* device, Partition* partition, QWidget* parentWidget )
|
EditExistingPartitionDialog::EditExistingPartitionDialog( Device* device, Partition* partition, const QStringList& usedMountPoints, QWidget* parentWidget )
|
||||||
: QDialog( parentWidget )
|
: QDialog( parentWidget )
|
||||||
, m_ui( new Ui_EditExistingPartitionDialog )
|
, m_ui( new Ui_EditExistingPartitionDialog )
|
||||||
, m_device( device )
|
, m_device( device )
|
||||||
, m_partition( partition )
|
, m_partition( partition )
|
||||||
, m_partitionSizeController( new PartitionSizeController( this ) )
|
, m_partitionSizeController( new PartitionSizeController( this ) )
|
||||||
|
, m_usedMountPoints( usedMountPoints )
|
||||||
{
|
{
|
||||||
m_ui->setupUi( this );
|
m_ui->setupUi( this );
|
||||||
|
|
||||||
@ -65,6 +67,7 @@ EditExistingPartitionDialog::EditExistingPartitionDialog( Device* device, Partit
|
|||||||
m_partitionSizeController->setSpinBox( m_ui->sizeSpinBox );
|
m_partitionSizeController->setSpinBox( m_ui->sizeSpinBox );
|
||||||
|
|
||||||
m_ui->mountPointComboBox->setCurrentText( PartitionInfo::mountPoint( partition ) );
|
m_ui->mountPointComboBox->setCurrentText( PartitionInfo::mountPoint( partition ) );
|
||||||
|
connect( m_ui->mountPointComboBox, &QComboBox::currentTextChanged, this, &EditExistingPartitionDialog::checkMountPointSelection );
|
||||||
|
|
||||||
replacePartResizerWidget();
|
replacePartResizerWidget();
|
||||||
|
|
||||||
@ -291,3 +294,17 @@ EditExistingPartitionDialog::updateMountPointPicker()
|
|||||||
if ( !canMount )
|
if ( !canMount )
|
||||||
m_ui->mountPointComboBox->setCurrentText( QString() );
|
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);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
@ -40,16 +40,20 @@ class EditExistingPartitionDialog : public QDialog
|
|||||||
{
|
{
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
public:
|
public:
|
||||||
EditExistingPartitionDialog( Device* device, Partition* partition, QWidget* parentWidget = nullptr );
|
EditExistingPartitionDialog( Device* device, Partition* partition, const QStringList& usedMountPoints, QWidget* parentWidget = nullptr );
|
||||||
~EditExistingPartitionDialog();
|
~EditExistingPartitionDialog();
|
||||||
|
|
||||||
void applyChanges( PartitionCoreModule* module );
|
void applyChanges( PartitionCoreModule* module );
|
||||||
|
|
||||||
|
private slots:
|
||||||
|
void checkMountPointSelection();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
QScopedPointer< Ui_EditExistingPartitionDialog > m_ui;
|
QScopedPointer< Ui_EditExistingPartitionDialog > m_ui;
|
||||||
Device* m_device;
|
Device* m_device;
|
||||||
Partition* m_partition;
|
Partition* m_partition;
|
||||||
PartitionSizeController* m_partitionSizeController;
|
PartitionSizeController* m_partitionSizeController;
|
||||||
|
QStringList m_usedMountPoints;
|
||||||
|
|
||||||
PartitionTable::Flags newFlags() const;
|
PartitionTable::Flags newFlags() const;
|
||||||
void setupFlagsList();
|
void setupFlagsList();
|
||||||
|
@ -139,14 +139,14 @@
|
|||||||
<item row="5" column="1">
|
<item row="5" column="1">
|
||||||
<widget class="QComboBox" name="fileSystemComboBox"/>
|
<widget class="QComboBox" name="fileSystemComboBox"/>
|
||||||
</item>
|
</item>
|
||||||
<item row="7" column="0">
|
<item row="8" column="0">
|
||||||
<widget class="QLabel" name="label_4">
|
<widget class="QLabel" name="label_4">
|
||||||
<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>
|
||||||
@ -159,6 +159,18 @@
|
|||||||
</property>
|
</property>
|
||||||
</widget>
|
</widget>
|
||||||
</item>
|
</item>
|
||||||
|
<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>
|
||||||
</layout>
|
</layout>
|
||||||
</item>
|
</item>
|
||||||
<item>
|
<item>
|
||||||
|
@ -23,6 +23,7 @@
|
|||||||
#include "core/BootLoaderModel.h"
|
#include "core/BootLoaderModel.h"
|
||||||
#include "core/DeviceModel.h"
|
#include "core/DeviceModel.h"
|
||||||
#include "core/PartitionCoreModule.h"
|
#include "core/PartitionCoreModule.h"
|
||||||
|
#include "core/PartitionInfo.h"
|
||||||
#include "core/PartitionModel.h"
|
#include "core/PartitionModel.h"
|
||||||
#include "core/KPMHelpers.h"
|
#include "core/KPMHelpers.h"
|
||||||
#include "gui/CreatePartitionDialog.h"
|
#include "gui/CreatePartitionDialog.h"
|
||||||
@ -176,7 +177,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 +266,10 @@ 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 );
|
QStringList mountPoints = getCurrentUsedMountpoints();
|
||||||
|
mountPoints.removeOne( PartitionInfo::mountPoint( partition ) );
|
||||||
|
|
||||||
|
QPointer<CreatePartitionDialog> dlg = new CreatePartitionDialog( device, partition->parent(), mountPoints, this );
|
||||||
dlg->initFromPartitionToCreate( partition );
|
dlg->initFromPartitionToCreate( partition );
|
||||||
if ( dlg->exec() == QDialog::Accepted )
|
if ( dlg->exec() == QDialog::Accepted )
|
||||||
{
|
{
|
||||||
@ -279,7 +283,10 @@ PartitionPage::updatePartitionToCreate( Device* device, Partition* partition )
|
|||||||
void
|
void
|
||||||
PartitionPage::editExistingPartition( Device* device, Partition* partition )
|
PartitionPage::editExistingPartition( Device* device, Partition* partition )
|
||||||
{
|
{
|
||||||
QPointer<EditExistingPartitionDialog> dlg = new EditExistingPartitionDialog( device, partition, this );
|
QStringList mountPoints = getCurrentUsedMountpoints();
|
||||||
|
mountPoints.removeOne( PartitionInfo::mountPoint( partition ) );
|
||||||
|
|
||||||
|
QPointer<EditExistingPartitionDialog> dlg = new EditExistingPartitionDialog( device, partition, mountPoints, this );
|
||||||
if ( dlg->exec() == QDialog::Accepted )
|
if ( dlg->exec() == QDialog::Accepted )
|
||||||
dlg->applyChanges( m_core );
|
dlg->applyChanges( m_core );
|
||||||
delete dlg;
|
delete dlg;
|
||||||
@ -376,3 +383,24 @@ 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()) {
|
||||||
|
const QString& mountPoint = PartitionInfo::mountPoint( partition );
|
||||||
|
|
||||||
|
if (!mountPoint.isEmpty()) {
|
||||||
|
mountPoints << 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…
Reference in New Issue
Block a user