Merge pull request #276 from shainer/mountpoint

Disallow assigning the same mountpoint to two partitions
main
Lisa 8 years ago committed by GitHub
commit 02abc0d0a7

@ -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,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 )
{

@ -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();

@ -108,7 +108,7 @@
<property name="sizeHint" stdset="0">
<size>
<width>20</width>
<height>12</height>
<height>13</height>
</size>
</property>
</spacer>
@ -126,6 +126,9 @@
<item row="3" column="1">
<widget class="QComboBox" name="fsComboBox"/>
</item>
<item row="4" column="1">
<widget class="EncryptWidget" name="encryptWidget" native="true"/>
</item>
<item row="5" column="1">
<spacer name="verticalSpacer_2">
<property name="orientation">
@ -162,14 +165,26 @@
</property>
</widget>
</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">
<property name="text">
<string>Flags:</string>
</property>
</widget>
</item>
<item row="7" column="1">
<item row="8" column="1">
<widget class="QListWidget" name="m_listFlags">
<property name="alternatingRowColors">
<bool>true</bool>
@ -182,7 +197,7 @@
</property>
</widget>
</item>
<item row="8" column="0">
<item row="9" column="0">
<spacer name="verticalSpacer">
<property name="orientation">
<enum>Qt::Vertical</enum>
@ -195,9 +210,6 @@
</property>
</spacer>
</item>
<item row="4" column="1">
<widget class="EncryptWidget" name="encryptWidget" native="true"/>
</item>
</layout>
</item>
<item>

@ -43,13 +43,15 @@
// Qt
#include <QComboBox>
#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 )
, 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);
}
}

@ -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();

@ -139,14 +139,14 @@
<item row="5" column="1">
<widget class="QComboBox" name="fileSystemComboBox"/>
</item>
<item row="7" column="0">
<item row="8" column="0">
<widget class="QLabel" name="label_4">
<property name="text">
<string>Flags:</string>
</property>
</widget>
</item>
<item row="7" column="1">
<item row="8" column="1">
<widget class="QListWidget" name="m_listFlags">
<property name="alternatingRowColors">
<bool>true</bool>
@ -159,6 +159,18 @@
</property>
</widget>
</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>
</item>
<item>

@ -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<CreatePartitionDialog> dlg = new CreatePartitionDialog( model->device(), partition->parent(), this );
QPointer<CreatePartitionDialog> 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<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 );
if ( dlg->exec() == QDialog::Accepted )
{
@ -279,7 +283,10 @@ PartitionPage::updatePartitionToCreate( Device* device, Partition* partition )
void
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 )
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;
}

@ -62,6 +62,8 @@ private:
void updateFromCurrentDevice();
void updateBootLoaderIndex();
QStringList getCurrentUsedMountpoints();
QMutex m_revertMutex;
int m_lastSelectedBootLoaderIndex;
};

Loading…
Cancel
Save