From 62d706543b7f80d1755f3f41218aa57a7565c7b4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Aur=C3=A9lien=20G=C3=A2teau?= Date: Mon, 28 Jul 2014 11:45:13 +0200 Subject: [PATCH] Do not let the user pick a partition type when creating a partition of a GPT disk Fixes #27 --- .../partition/CreatePartitionDialog.cpp | 59 ++++++++++++------- src/modules/partition/CreatePartitionDialog.h | 2 + 2 files changed, 40 insertions(+), 21 deletions(-) diff --git a/src/modules/partition/CreatePartitionDialog.cpp b/src/modules/partition/CreatePartitionDialog.cpp index a4abfbcfe..d908514a9 100644 --- a/src/modules/partition/CreatePartitionDialog.cpp +++ b/src/modules/partition/CreatePartitionDialog.cpp @@ -48,28 +48,10 @@ CreatePartitionDialog::CreatePartitionDialog( Device* device, PartitionNode* par FileSystemFactory::init(); - bool parentIsPartitionTable = parentPartition->isRoot(); - // Partition types - QString fixedPartitionType; - if ( !parentIsPartitionTable ) - { - m_role = PartitionRole( PartitionRole::Logical ); - fixedPartitionType = tr( "Logical" ); - } - else if ( m_device->partitionTable()->hasExtended() ) - { - m_role = PartitionRole( PartitionRole::Primary ); - fixedPartitionType = tr( "Primary" ); - } - - if ( fixedPartitionType.isEmpty() ) - m_ui->fixedPartitionLabel->hide(); + if ( device->partitionTable()->type() == PartitionTable::msdos ) + initMbrPartitionTypeUi(); else - { - m_ui->fixedPartitionLabel->setText( fixedPartitionType ); - m_ui->primaryRadioButton->hide(); - m_ui->extendedRadioButton->hide(); - } + initGptPartitionTypeUi(); // File system QStringList fsNames; @@ -88,6 +70,41 @@ CreatePartitionDialog::CreatePartitionDialog( Device* device, PartitionNode* par CreatePartitionDialog::~CreatePartitionDialog() {} +void +CreatePartitionDialog::initMbrPartitionTypeUi() +{ + QString fixedPartitionString; + bool parentIsPartitionTable = m_parent->isRoot(); + if ( !parentIsPartitionTable ) + { + m_role = PartitionRole( PartitionRole::Logical ); + fixedPartitionString = tr( "Logical" ); + } + else if ( m_device->partitionTable()->hasExtended() ) + { + m_role = PartitionRole( PartitionRole::Primary ); + fixedPartitionString = tr( "Primary" ); + } + + if ( fixedPartitionString.isEmpty() ) + m_ui->fixedPartitionLabel->hide(); + else + { + m_ui->fixedPartitionLabel->setText( fixedPartitionString ); + m_ui->primaryRadioButton->hide(); + m_ui->extendedRadioButton->hide(); + } +} + +void +CreatePartitionDialog::initGptPartitionTypeUi() +{ + m_role = PartitionRole( PartitionRole::Primary ); + m_ui->fixedPartitionLabel->setText( tr( "GPT" ) ); + m_ui->primaryRadioButton->hide(); + m_ui->extendedRadioButton->hide(); +} + Partition* CreatePartitionDialog::createPartition() { diff --git a/src/modules/partition/CreatePartitionDialog.h b/src/modules/partition/CreatePartitionDialog.h index 4ed8740ac..c21e4d12a 100644 --- a/src/modules/partition/CreatePartitionDialog.h +++ b/src/modules/partition/CreatePartitionDialog.h @@ -52,6 +52,8 @@ private: PartitionNode* m_parent; PartitionRole m_role = PartitionRole( PartitionRole::None ); + void initGptPartitionTypeUi(); + void initMbrPartitionTypeUi(); void initSectorRange( Partition* ); qint64 mbSizeForSectorRange( qint64 first, qint64 last ) const;