Allow changing the filesystem type when editing a partition.

main
Teo Mrnjavac 10 years ago
parent 53692feeaf
commit 9f2086a648

@ -63,10 +63,31 @@ EditExistingPartitionDialog::EditExistingPartitionDialog( Device* device, Partit
replacePartResizerWidget(); replacePartResizerWidget();
connect( m_ui->formatRadioButton, &QAbstractButton::toggled, [ this ]( bool ) connect( m_ui->formatRadioButton, &QAbstractButton::toggled,
[ this ]( bool doFormat )
{ {
replacePartResizerWidget(); replacePartResizerWidget();
m_ui->fileSystemLabel->setEnabled( doFormat );
m_ui->fileSystemComboBox->setEnabled( doFormat );
} ); } );
// File system
QStringList fsNames;
for ( auto fs : FileSystemFactory::map() )
{
if ( fs->supportCreate() != FileSystem::cmdSupportNone && fs->type() != FileSystem::Extended )
fsNames << fs->name();
}
m_ui->fileSystemComboBox->addItems( fsNames );
if ( fsNames.contains( m_partition->fileSystem().name() ) )
m_ui->fileSystemComboBox->setCurrentText( m_partition->fileSystem().name() );
else
m_ui->fileSystemComboBox->setCurrentText( FileSystem::nameForType( FileSystem::Ext4 ) );
m_ui->fileSystemLabel->setEnabled( m_ui->formatRadioButton->isChecked() );
m_ui->fileSystemComboBox->setEnabled( m_ui->formatRadioButton->isChecked() );
} }
EditExistingPartitionDialog::~EditExistingPartitionDialog() EditExistingPartitionDialog::~EditExistingPartitionDialog()
@ -81,6 +102,14 @@ EditExistingPartitionDialog::applyChanges( PartitionCoreModule* core )
qint64 newLastSector = m_partitionSizeController->lastSector(); qint64 newLastSector = m_partitionSizeController->lastSector();
bool partitionChanged = newFirstSector != m_partition->firstSector() || newLastSector != m_partition->lastSector(); bool partitionChanged = newFirstSector != m_partition->firstSector() || newLastSector != m_partition->lastSector();
FileSystem::Type fsType = FileSystem::Unknown;
if ( m_ui->formatRadioButton->isChecked() )
{
fsType = m_partition->roles().has( PartitionRole::Extended )
? FileSystem::Extended
: FileSystem::typeForName( m_ui->fileSystemComboBox->currentText() );
}
if ( partitionChanged ) if ( partitionChanged )
{ {
if ( m_ui->formatRadioButton->isChecked() ) if ( m_ui->formatRadioButton->isChecked() )
@ -89,7 +118,7 @@ EditExistingPartitionDialog::applyChanges( PartitionCoreModule* core )
m_partition->parent(), m_partition->parent(),
*m_device, *m_device,
m_partition->roles(), m_partition->roles(),
m_partition->fileSystem().type(), fsType,
newFirstSector, newFirstSector,
newLastSector ); newLastSector );
PartitionInfo::setMountPoint( newPartition, PartitionInfo::mountPoint( m_partition ) ); PartitionInfo::setMountPoint( newPartition, PartitionInfo::mountPoint( m_partition ) );
@ -99,15 +128,43 @@ EditExistingPartitionDialog::applyChanges( PartitionCoreModule* core )
core->createPartition( m_device, newPartition ); core->createPartition( m_device, newPartition );
} }
else else
core->resizePartition( m_device, m_partition, newFirstSector, newLastSector ); {
core->resizePartition( m_device,
m_partition,
newFirstSector,
newLastSector );
}
} }
else else
{ {
// No size changes // No size changes
if ( m_ui->formatRadioButton->isChecked() ) if ( m_ui->formatRadioButton->isChecked() )
core->formatPartition( m_device, m_partition ); {
// if the FS type is unchanged, we just format
if ( m_partition->fileSystem().type() == fsType )
{
core->formatPartition( m_device, m_partition );
}
else // otherwise, we delete and recreate the partition with new fs type
{
Partition* newPartition = PMUtils::createNewPartition(
m_partition->parent(),
*m_device,
m_partition->roles(),
fsType,
m_partition->firstSector(),
m_partition->lastSector() );
PartitionInfo::setMountPoint( newPartition, PartitionInfo::mountPoint( m_partition ) );
PartitionInfo::setFormat( newPartition, true );
core->deletePartition( m_device, m_partition );
core->createPartition( m_device, newPartition );
}
}
else else
{
core->refreshPartition( m_device, m_partition ); core->refreshPartition( m_device, m_partition );
}
} }
} }

@ -6,8 +6,8 @@
<rect> <rect>
<x>0</x> <x>0</x>
<y>0</y> <y>0</y>
<width>350</width> <width>437</width>
<height>236</height> <height>430</height>
</rect> </rect>
</property> </property>
<property name="sizePolicy"> <property name="sizePolicy">
@ -57,7 +57,7 @@
<item row="2" column="1"> <item row="2" column="1">
<widget class="QRadioButton" name="keepRadioButton"> <widget class="QRadioButton" name="keepRadioButton">
<property name="text"> <property name="text">
<string>Keep</string> <string>&amp;Keep</string>
</property> </property>
<property name="checked"> <property name="checked">
<bool>true</bool> <bool>true</bool>
@ -87,7 +87,7 @@
</property> </property>
</widget> </widget>
</item> </item>
<item row="5" column="0"> <item row="6" column="0">
<widget class="QLabel" name="mountPointLabel"> <widget class="QLabel" name="mountPointLabel">
<property name="text"> <property name="text">
<string>&amp;Mount Point:</string> <string>&amp;Mount Point:</string>
@ -97,7 +97,7 @@
</property> </property>
</widget> </widget>
</item> </item>
<item row="5" column="1"> <item row="6" column="1">
<widget class="QComboBox" name="mountPointComboBox"> <widget class="QComboBox" name="mountPointComboBox">
<property name="editable"> <property name="editable">
<bool>true</bool> <bool>true</bool>
@ -110,7 +110,7 @@
<item row="1" column="0"> <item row="1" column="0">
<widget class="QLabel" name="label"> <widget class="QLabel" name="label">
<property name="text"> <property name="text">
<string>Size:</string> <string>Si&amp;ze:</string>
</property> </property>
<property name="buddy"> <property name="buddy">
<cstring>sizeSpinBox</cstring> <cstring>sizeSpinBox</cstring>
@ -120,6 +120,19 @@
<item row="1" column="1"> <item row="1" column="1">
<widget class="QSpinBox" name="sizeSpinBox"/> <widget class="QSpinBox" name="sizeSpinBox"/>
</item> </item>
<item row="5" column="0">
<widget class="QLabel" name="fileSystemLabel">
<property name="text">
<string>Fi&amp;le System:</string>
</property>
<property name="buddy">
<cstring>fileSystemComboBox</cstring>
</property>
</widget>
</item>
<item row="5" column="1">
<widget class="QComboBox" name="fileSystemComboBox"/>
</item>
</layout> </layout>
</item> </item>
<item> <item>

Loading…
Cancel
Save