diff --git a/src/modules/partition/gui/EditExistingPartitionDialog.cpp b/src/modules/partition/gui/EditExistingPartitionDialog.cpp index 9c79f5da9..f9998fa6a 100644 --- a/src/modules/partition/gui/EditExistingPartitionDialog.cpp +++ b/src/modules/partition/gui/EditExistingPartitionDialog.cpp @@ -1,6 +1,11 @@ /* === This file is part of Calamares - === * * Copyright 2014, Aurélien Gâteau + * Copyright 2016, Teo Mrnjavac + * + * Flags handling originally from KDE Partition Manager, + * Copyright 2008-2009, Volker Lanz + * Copyright 2016, Andrius Štikonas * * Calamares is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -99,19 +104,61 @@ EditExistingPartitionDialog::EditExistingPartitionDialog( Device* device, Partit m_ui->fileSystemLabel->setEnabled( m_ui->formatRadioButton->isChecked() ); m_ui->fileSystemComboBox->setEnabled( m_ui->formatRadioButton->isChecked() ); + + setupFlagsList(); } + EditExistingPartitionDialog::~EditExistingPartitionDialog() {} + +PartitionTable::Flags +EditExistingPartitionDialog::newFlags() const +{ + PartitionTable::Flags flags; + + for ( int i = 0; i < m_ui->m_listFlags->count(); i++ ) + if ( m_ui->m_listFlags->item( i )->checkState() == Qt::Checked ) + flags |= static_cast< PartitionTable::Flag >( + m_ui->m_listFlags->item( i )->data( Qt::UserRole ).toInt() ); + + return flags; +} + + +void +EditExistingPartitionDialog::setupFlagsList() +{ + int f = 1; + QString s; + while ( !( s = PartitionTable::flagName( static_cast< PartitionTable::Flag >( f ) ) ).isEmpty() ) + { + if ( m_partition->availableFlags() & f ) + { + QListWidgetItem* item = new QListWidgetItem( s ); + m_ui->m_listFlags->addItem( item ); + item->setFlags( Qt::ItemIsUserCheckable | Qt::ItemIsEnabled ); + item->setData( Qt::UserRole, f ); + item->setCheckState( ( m_partition->activeFlags() & f ) ? + Qt::Checked : + Qt::Unchecked ); + } + + f <<= 1; + } +} + + void EditExistingPartitionDialog::applyChanges( PartitionCoreModule* core ) { PartitionInfo::setMountPoint( m_partition, m_ui->mountPointComboBox->currentText() ); qint64 newFirstSector = m_partitionSizeController->firstSector(); - qint64 newLastSector = m_partitionSizeController->lastSector(); - bool partitionChanged = newFirstSector != m_partition->firstSector() || newLastSector != m_partition->lastSector(); + qint64 newLastSector = m_partitionSizeController->lastSector(); + bool partResizedMoved = newFirstSector != m_partition->firstSector() || + newLastSector != m_partition->lastSector(); FileSystem::Type fsType = FileSystem::Unknown; if ( m_ui->formatRadioButton->isChecked() ) @@ -121,7 +168,7 @@ EditExistingPartitionDialog::applyChanges( PartitionCoreModule* core ) : FileSystem::typeForName( m_ui->fileSystemComboBox->currentText() ); } - if ( partitionChanged ) + if ( partResizedMoved ) { if ( m_ui->formatRadioButton->isChecked() ) { @@ -131,12 +178,14 @@ EditExistingPartitionDialog::applyChanges( PartitionCoreModule* core ) m_partition->roles(), fsType, newFirstSector, - newLastSector ); + newLastSector, + newFlags() ); PartitionInfo::setMountPoint( newPartition, PartitionInfo::mountPoint( m_partition ) ); PartitionInfo::setFormat( newPartition, true ); core->deletePartition( m_device, m_partition ); core->createPartition( m_device, newPartition ); + core->setPartitionFlags( m_device, newPartition, newFlags() ); } else { @@ -144,6 +193,8 @@ EditExistingPartitionDialog::applyChanges( PartitionCoreModule* core ) m_partition, newFirstSector, newLastSector ); + if ( m_partition->activeFlags() != newFlags() ) + core->setPartitionFlags( m_device, m_partition, newFlags() ); } } else @@ -155,6 +206,8 @@ EditExistingPartitionDialog::applyChanges( PartitionCoreModule* core ) if ( m_partition->fileSystem().type() == fsType ) { core->formatPartition( m_device, m_partition ); + if ( m_partition->activeFlags() != newFlags() ) + core->setPartitionFlags( m_device, m_partition, newFlags() ); } else // otherwise, we delete and recreate the partition with new fs type { @@ -164,21 +217,26 @@ EditExistingPartitionDialog::applyChanges( PartitionCoreModule* core ) m_partition->roles(), fsType, m_partition->firstSector(), - m_partition->lastSector() ); + m_partition->lastSector(), + newFlags() ); PartitionInfo::setMountPoint( newPartition, PartitionInfo::mountPoint( m_partition ) ); PartitionInfo::setFormat( newPartition, true ); core->deletePartition( m_device, m_partition ); core->createPartition( m_device, newPartition ); + core->setPartitionFlags( m_device, newPartition, newFlags() ); } } else { core->refreshPartition( m_device, m_partition ); + if ( m_partition->activeFlags() != newFlags() ) + core->setPartitionFlags( m_device, m_partition, newFlags() ); } } } + void EditExistingPartitionDialog::replacePartResizerWidget() { @@ -197,6 +255,7 @@ EditExistingPartitionDialog::replacePartResizerWidget() m_partitionSizeController->setPartResizerWidget( widget, m_ui->formatRadioButton->isChecked() ); } + void EditExistingPartitionDialog::updateMountPointPicker() { diff --git a/src/modules/partition/gui/EditExistingPartitionDialog.h b/src/modules/partition/gui/EditExistingPartitionDialog.h index 6ea0300f9..0aa89bb98 100644 --- a/src/modules/partition/gui/EditExistingPartitionDialog.h +++ b/src/modules/partition/gui/EditExistingPartitionDialog.h @@ -19,6 +19,8 @@ #ifndef EDITEXISTINGPARTITIONDIALOG_H #define EDITEXISTINGPARTITIONDIALOG_H +#include + #include #include @@ -49,6 +51,8 @@ private: Partition* m_partition; PartitionSizeController* m_partitionSizeController; + PartitionTable::Flags newFlags() const; + void setupFlagsList(); void replacePartResizerWidget(); void updateMountPointPicker(); }; diff --git a/src/modules/partition/gui/EditExistingPartitionDialog.ui b/src/modules/partition/gui/EditExistingPartitionDialog.ui index ae7988c7f..9ed7e1bb4 100644 --- a/src/modules/partition/gui/EditExistingPartitionDialog.ui +++ b/src/modules/partition/gui/EditExistingPartitionDialog.ui @@ -7,7 +7,7 @@ 0 0 450 - 430 + 579 @@ -139,6 +139,26 @@ + + + + Flags: + + + + + + + true + + + QAbstractItemView::NoSelection + + + true + + +