From 45dda6fa17f0c919a17a2d9f0d6fd4a004b52177 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Aur=C3=A9lien=20G=C3=A2teau?= Date: Wed, 16 Jul 2014 10:34:56 +0200 Subject: [PATCH] Factorize size computations --- src/modules/partition/CreatePartitionDialog.cpp | 13 ++++++++----- src/modules/partition/CreatePartitionDialog.h | 2 ++ 2 files changed, 10 insertions(+), 5 deletions(-) diff --git a/src/modules/partition/CreatePartitionDialog.cpp b/src/modules/partition/CreatePartitionDialog.cpp index 17ec65765..eec0e3f0c 100644 --- a/src/modules/partition/CreatePartitionDialog.cpp +++ b/src/modules/partition/CreatePartitionDialog.cpp @@ -142,9 +142,7 @@ CreatePartitionDialog::initSectorRange( Partition* partition ) m_minSector = partition->firstSector() - table->freeSectorsBefore( *partition ); m_maxSector = partition->lastSector() + table->freeSectorsAfter( *partition ); - qint64 maxSize = ( m_maxSector - m_minSector + 1 ) * m_device->logicalSectorSize(); - - m_ui->sizeSpinBox->setMaximum( maxSize / 1024 / 1024 ); + m_ui->sizeSpinBox->setMaximum( mbSizeForSectorRange( m_minSector, m_maxSector ) ); m_ui->sizeSpinBox->setValue( m_ui->sizeSpinBox->maximum() ); } @@ -162,8 +160,13 @@ CreatePartitionDialog::initFromPartitionInfo( PartitionInfo* partitionInfo ) initSectorRange( partition ); - qint64 maxSize = ( partition->lastSector() - partition->firstSector() + 1 ) * m_device->logicalSectorSize(); - m_ui->sizeSpinBox->setValue( maxSize / 1024 / 1024 ); + m_ui->sizeSpinBox->setValue( mbSizeForSectorRange( partition->firstSector(), partition->lastSector() ) ); m_ui->mountPointComboBox->setCurrentText( partitionInfo->mountPoint ); } + +qint64 +CreatePartitionDialog::mbSizeForSectorRange( qint64 first, qint64 last ) const +{ + return ( last - first + 1 ) * m_device->logicalSectorSize() / 1024 / 1024; +} diff --git a/src/modules/partition/CreatePartitionDialog.h b/src/modules/partition/CreatePartitionDialog.h index 1f8e0c88a..dd700f558 100644 --- a/src/modules/partition/CreatePartitionDialog.h +++ b/src/modules/partition/CreatePartitionDialog.h @@ -54,6 +54,8 @@ private: PartitionRole m_role = PartitionRole( PartitionRole::None ); void initSectorRange( Partition* ); + + qint64 mbSizeForSectorRange( qint64 first, qint64 last ) const; }; #endif /* CREATEPARTITIONDIALOG_H */