[partition] Refactor common validate-the-mount-point logic
This commit is contained in:
parent
d8be9a9443
commit
82dcc1b57b
@ -325,22 +325,7 @@ CreatePartitionDialog::updateMountPointUi()
|
||||
void
|
||||
CreatePartitionDialog::checkMountPointSelection()
|
||||
{
|
||||
const QString mountPoint = selectedMountPoint( m_ui->mountPointComboBox );
|
||||
if ( m_usedMountPoints.contains( mountPoint ) )
|
||||
{
|
||||
m_ui->labelMountPoint->setText( tr( "Mountpoint already in use. Please select another one." ) );
|
||||
m_ui->buttonBox->button( QDialogButtonBox::Ok )->setEnabled( false );
|
||||
}
|
||||
else if ( !mountPoint.isEmpty() && !mountPoint.startsWith( '/' ) )
|
||||
{
|
||||
m_ui->labelMountPoint->setText( tr( "Mountpoint must start with a <pre>/</pre>." ) );
|
||||
m_ui->buttonBox->button( QDialogButtonBox::Ok )->setEnabled( false );
|
||||
}
|
||||
else
|
||||
{
|
||||
m_ui->labelMountPoint->setText( QString() );
|
||||
m_ui->buttonBox->button( QDialogButtonBox::Ok )->setEnabled( true );
|
||||
}
|
||||
validateMountPoint( selectedMountPoint( m_ui->mountPointComboBox ), m_usedMountPoints, m_ui->labelMountPoint, m_ui->buttonBox->button( QDialogButtonBox::Ok ));
|
||||
}
|
||||
|
||||
void
|
||||
|
@ -295,20 +295,5 @@ EditExistingPartitionDialog::updateMountPointPicker()
|
||||
void
|
||||
EditExistingPartitionDialog::checkMountPointSelection()
|
||||
{
|
||||
const QString mountPoint = selectedMountPoint( m_ui->mountPointComboBox );
|
||||
if ( m_usedMountPoints.contains( mountPoint ) )
|
||||
{
|
||||
m_ui->labelMountPoint->setText( tr( "Mountpoint already in use. Please select another one." ) );
|
||||
m_ui->buttonBox->button( QDialogButtonBox::Ok )->setEnabled( false );
|
||||
}
|
||||
else if ( !mountPoint.isEmpty() && !mountPoint.startsWith( '/' ) )
|
||||
{
|
||||
m_ui->labelMountPoint->setText( tr( "Mountpoint must start with a <pre>/</pre>." ) );
|
||||
m_ui->buttonBox->button( QDialogButtonBox::Ok )->setEnabled( false );
|
||||
}
|
||||
else
|
||||
{
|
||||
m_ui->labelMountPoint->setText( QString() );
|
||||
m_ui->buttonBox->button( QDialogButtonBox::Ok )->setEnabled( true );
|
||||
}
|
||||
validateMountPoint( selectedMountPoint( m_ui->mountPointComboBox ), m_usedMountPoints, m_ui->labelMountPoint, m_ui->buttonBox->button( QDialogButtonBox::Ok ));
|
||||
}
|
||||
|
@ -12,14 +12,17 @@
|
||||
#include "PartitionDialogHelpers.h"
|
||||
|
||||
#include "core/PartUtils.h"
|
||||
#include "gui/CreatePartitionDialog.h"
|
||||
|
||||
#include "GlobalStorage.h"
|
||||
#include "JobQueue.h"
|
||||
#include "utils/Logger.h"
|
||||
|
||||
#include <QComboBox>
|
||||
#include <QLabel>
|
||||
#include <QLineEdit>
|
||||
#include <QListWidget>
|
||||
#include <QPushButton>
|
||||
|
||||
QStringList
|
||||
standardMountPoints()
|
||||
@ -81,6 +84,33 @@ setSelectedMountPoint( QComboBox& combo, const QString& selected )
|
||||
}
|
||||
}
|
||||
|
||||
bool validateMountPoint( const QString& mountPoint, const QStringList& inUse, QLabel* label, QPushButton* button )
|
||||
{
|
||||
QString msg;
|
||||
bool ok = true;
|
||||
|
||||
if ( inUse.contains( mountPoint ) )
|
||||
{
|
||||
msg = CreatePartitionDialog::tr( "Mountpoint already in use. Please select another one." );
|
||||
ok = false;
|
||||
}
|
||||
else if ( !mountPoint.isEmpty() && !mountPoint.startsWith( '/' ) )
|
||||
{
|
||||
msg = CreatePartitionDialog::tr( "Mountpoint must start with a <pre>/</pre>." );
|
||||
ok = false;
|
||||
}
|
||||
|
||||
if ( label )
|
||||
{
|
||||
label->setText( msg );
|
||||
}
|
||||
if ( button )
|
||||
{
|
||||
button->setEnabled( ok );
|
||||
}
|
||||
return ok;
|
||||
}
|
||||
|
||||
|
||||
PartitionTable::Flags
|
||||
flagsFromList( const QListWidget& list )
|
||||
|
@ -16,7 +16,9 @@
|
||||
|
||||
#include <QStringList>
|
||||
|
||||
class QPushButton;
|
||||
class QComboBox;
|
||||
class QLabel;
|
||||
class QListWidget;
|
||||
|
||||
/**
|
||||
@ -58,6 +60,16 @@ setSelectedMountPoint( QComboBox* combo, const QString& selected )
|
||||
setSelectedMountPoint( *combo, selected );
|
||||
}
|
||||
|
||||
/** @brief Validate a @p mountPoint and adjust the UI
|
||||
*
|
||||
* If @p mountPoint is valid -- unused and starts with a /, for instance --
|
||||
* then the button is enabled, label is cleared, and returns @c true.
|
||||
*
|
||||
* If it is not valid, returns @c false and sets the UI
|
||||
* to explain why.
|
||||
*/
|
||||
bool validateMountPoint( const QString& mountPoint, const QStringList& inUse, QLabel* label, QPushButton* button );
|
||||
|
||||
/**
|
||||
* Get the flags that have been checked in the list widget.
|
||||
*/
|
||||
|
Loading…
Reference in New Issue
Block a user