Redo partition type UI and enable/disable mount point UI when appropriate

This commit is contained in:
Aurélien Gâteau 2014-07-04 18:32:35 +02:00
parent f27ff4c717
commit 15c5142d09
3 changed files with 151 additions and 52 deletions

View File

@ -29,6 +29,7 @@
// Qt // Qt
#include <QComboBox> #include <QComboBox>
#include <QSet>
CreatePartitionDialog::CreatePartitionDialog( Device* device, Partition* freePartition, QWidget* parent ) CreatePartitionDialog::CreatePartitionDialog( Device* device, Partition* freePartition, QWidget* parent )
: QDialog( parent ) : QDialog( parent )
@ -40,25 +41,31 @@ CreatePartitionDialog::CreatePartitionDialog( Device* device, Partition* freePar
FileSystemFactory::init(); FileSystemFactory::init();
bool hidePartitionType = false; // Partition types
QString fixedPartitionType;
if ( freePartition->roles().has( PartitionRole::Logical ) ) if ( freePartition->roles().has( PartitionRole::Logical ) )
{ {
m_role = PartitionRole( PartitionRole::Logical ); m_role = PartitionRole( PartitionRole::Logical );
hidePartitionType = true; fixedPartitionType = tr( "Logical" );
} }
else if ( m_device->partitionTable()->hasExtended() ) else if ( m_device->partitionTable()->hasExtended() )
{ {
m_role = PartitionRole( PartitionRole::Primary ); m_role = PartitionRole( PartitionRole::Primary );
hidePartitionType = true; fixedPartitionType = tr( "Primary" );
} }
if ( hidePartitionType ) if ( fixedPartitionType.isEmpty() )
{ {
m_ui->partitionTypeLabel->hide(); m_ui->fixedPartitionLabel->hide();
}
else
{
m_ui->fixedPartitionLabel->setText( fixedPartitionType );
m_ui->primaryRadioButton->hide(); m_ui->primaryRadioButton->hide();
m_ui->extendedRadioButton->hide(); m_ui->extendedRadioButton->hide();
} }
// File system
QStringList fsNames; QStringList fsNames;
for ( auto fs : FileSystemFactory::map() ) for ( auto fs : FileSystemFactory::map() )
{ {
@ -69,10 +76,15 @@ CreatePartitionDialog::CreatePartitionDialog( Device* device, Partition* freePar
} }
m_ui->fsComboBox->addItems( fsNames ); m_ui->fsComboBox->addItems( fsNames );
// Size
qint64 maxSize = ( freePartition->lastSector() - freePartition->firstSector() + 1 ) * device->logicalSectorSize(); qint64 maxSize = ( freePartition->lastSector() - freePartition->firstSector() + 1 ) * device->logicalSectorSize();
m_ui->sizeSpinBox->setMaximum( maxSize / 1024 / 1024 ); m_ui->sizeSpinBox->setMaximum( maxSize / 1024 / 1024 );
m_ui->sizeSpinBox->setValue( m_ui->sizeSpinBox->maximum() ); m_ui->sizeSpinBox->setValue( m_ui->sizeSpinBox->maximum() );
// Connections
connect( m_ui->fsComboBox, SIGNAL( activated( int ) ), SLOT( updateMountPointUi() ) );
connect( m_ui->extendedRadioButton, SIGNAL( toggled( bool ) ), SLOT( updateMountPointUi() ) );
} }
CreatePartitionDialog::~CreatePartitionDialog() CreatePartitionDialog::~CreatePartitionDialog()
@ -118,3 +130,18 @@ CreatePartitionDialog::createPartitionInfo()
info->format = true; info->format = true;
return info; return info;
} }
void
CreatePartitionDialog::updateMountPointUi()
{
static QSet< FileSystem::Type > unmountableFS( { FileSystem::Unformatted, FileSystem::LinuxSwap } );
bool enabled = m_ui->primaryRadioButton->isChecked();
if ( enabled )
{
FileSystem::Type type = FileSystem::typeForName( m_ui->fsComboBox->currentText() );
enabled = !unmountableFS.contains( type );
}
m_ui->mountPointLabel->setEnabled( enabled );
m_ui->mountPointComboBox->setEnabled( enabled );
}

View File

@ -32,12 +32,16 @@ class Ui_CreatePartitionDialog;
class CreatePartitionDialog : public QDialog class CreatePartitionDialog : public QDialog
{ {
Q_OBJECT
public: public:
CreatePartitionDialog( Device* device, Partition* freePartition, QWidget* parent = nullptr ); CreatePartitionDialog( Device* device, Partition* freePartition, QWidget* parent = nullptr );
~CreatePartitionDialog(); ~CreatePartitionDialog();
PartitionInfo* createPartitionInfo(); PartitionInfo* createPartitionInfo();
private Q_SLOTS:
void updateMountPointUi();
private: private:
QScopedPointer< Ui_CreatePartitionDialog > m_ui; QScopedPointer< Ui_CreatePartitionDialog > m_ui;
Device* m_device; Device* m_device;

View File

@ -7,7 +7,7 @@
<x>0</x> <x>0</x>
<y>0</y> <y>0</y>
<width>425</width> <width>425</width>
<height>321</height> <height>208</height>
</rect> </rect>
</property> </property>
<property name="windowTitle"> <property name="windowTitle">
@ -16,6 +16,57 @@
<layout class="QVBoxLayout" name="verticalLayout"> <layout class="QVBoxLayout" name="verticalLayout">
<item> <item>
<layout class="QFormLayout" name="formLayout"> <layout class="QFormLayout" name="formLayout">
<item row="0" column="0">
<widget class="QLabel" name="partitionTypeLabel">
<property name="text">
<string>Partition &amp;Type:</string>
</property>
<property name="buddy">
<cstring>primaryRadioButton</cstring>
</property>
</widget>
</item>
<item row="0" column="1">
<layout class="QHBoxLayout" name="horizontalLayout">
<item>
<widget class="QRadioButton" name="primaryRadioButton">
<property name="text">
<string>&amp;Primary</string>
</property>
<property name="checked">
<bool>true</bool>
</property>
</widget>
</item>
<item>
<widget class="QRadioButton" name="extendedRadioButton">
<property name="text">
<string>E&amp;xtended</string>
</property>
</widget>
</item>
<item>
<widget class="QLabel" name="fixedPartitionLabel">
<property name="text">
<string>TextLabel</string>
</property>
</widget>
</item>
<item>
<spacer name="horizontalSpacer">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>40</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
</layout>
</item>
<item row="2" column="0"> <item row="2" column="0">
<widget class="QLabel" name="label_2"> <widget class="QLabel" name="label_2">
<property name="text"> <property name="text">
@ -39,19 +90,6 @@
</property> </property>
</widget> </widget>
</item> </item>
<item row="5" column="0">
<spacer name="verticalSpacer">
<property name="orientation">
<enum>Qt::Vertical</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>20</width>
<height>40</height>
</size>
</property>
</spacer>
</item>
<item row="3" column="1"> <item row="3" column="1">
<widget class="QSpinBox" name="sizeSpinBox"> <widget class="QSpinBox" name="sizeSpinBox">
<property name="suffix"> <property name="suffix">
@ -59,35 +97,24 @@
</property> </property>
</widget> </widget>
</item> </item>
<item row="0" column="1"> <item row="4" column="1">
<widget class="QRadioButton" name="primaryRadioButton"> <spacer name="verticalSpacer_2">
<property name="text"> <property name="orientation">
<string>&amp;Primary</string> <enum>Qt::Vertical</enum>
</property> </property>
<property name="checked"> <property name="sizeType">
<bool>true</bool> <enum>QSizePolicy::Fixed</enum>
</property> </property>
</widget> <property name="sizeHint" stdset="0">
<size>
<width>20</width>
<height>13</height>
</size>
</property>
</spacer>
</item> </item>
<item row="1" column="1"> <item row="5" column="0">
<widget class="QRadioButton" name="extendedRadioButton"> <widget class="QLabel" name="mountPointLabel">
<property name="text">
<string>E&amp;xtended</string>
</property>
</widget>
</item>
<item row="0" column="0">
<widget class="QLabel" name="partitionTypeLabel">
<property name="text">
<string>Partition &amp;Type:</string>
</property>
<property name="buddy">
<cstring>primaryRadioButton</cstring>
</property>
</widget>
</item>
<item row="4" column="0">
<widget class="QLabel" name="label_3">
<property name="text"> <property name="text">
<string>&amp;Mount Point:</string> <string>&amp;Mount Point:</string>
</property> </property>
@ -96,7 +123,7 @@
</property> </property>
</widget> </widget>
</item> </item>
<item row="4" column="1"> <item row="5" column="1">
<widget class="QComboBox" name="mountPointComboBox"> <widget class="QComboBox" name="mountPointComboBox">
<property name="editable"> <property name="editable">
<bool>true</bool> <bool>true</bool>
@ -136,6 +163,32 @@
</item> </item>
</widget> </widget>
</item> </item>
<item row="6" column="0">
<spacer name="verticalSpacer">
<property name="orientation">
<enum>Qt::Vertical</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>17</width>
<height>13</height>
</size>
</property>
</spacer>
</item>
<item row="1" column="1">
<spacer name="verticalSpacer_3">
<property name="orientation">
<enum>Qt::Vertical</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>20</width>
<height>12</height>
</size>
</property>
</spacer>
</item>
</layout> </layout>
</item> </item>
<item> <item>
@ -152,7 +205,6 @@
</widget> </widget>
<tabstops> <tabstops>
<tabstop>primaryRadioButton</tabstop> <tabstop>primaryRadioButton</tabstop>
<tabstop>extendedRadioButton</tabstop>
<tabstop>fsComboBox</tabstop> <tabstop>fsComboBox</tabstop>
<tabstop>sizeSpinBox</tabstop> <tabstop>sizeSpinBox</tabstop>
</tabstops> </tabstops>
@ -165,8 +217,8 @@
<slot>accept()</slot> <slot>accept()</slot>
<hints> <hints>
<hint type="sourcelabel"> <hint type="sourcelabel">
<x>181</x> <x>185</x>
<y>165</y> <y>203</y>
</hint> </hint>
<hint type="destinationlabel"> <hint type="destinationlabel">
<x>157</x> <x>157</x>
@ -181,11 +233,11 @@
<slot>reject()</slot> <slot>reject()</slot>
<hints> <hints>
<hint type="sourcelabel"> <hint type="sourcelabel">
<x>181</x> <x>185</x>
<y>165</y> <y>203</y>
</hint> </hint>
<hint type="destinationlabel"> <hint type="destinationlabel">
<x>262</x> <x>243</x>
<y>178</y> <y>178</y>
</hint> </hint>
</hints> </hints>
@ -206,5 +258,21 @@
</hint> </hint>
</hints> </hints>
</connection> </connection>
<connection>
<sender>extendedRadioButton</sender>
<signal>toggled(bool)</signal>
<receiver>label_2</receiver>
<slot>setDisabled(bool)</slot>
<hints>
<hint type="sourcelabel">
<x>109</x>
<y>43</y>
</hint>
<hint type="destinationlabel">
<x>79</x>
<y>64</y>
</hint>
</hints>
</connection>
</connections> </connections>
</ui> </ui>