Factorize size computations

main
Aurélien Gâteau 11 years ago
parent a70ab4ad60
commit 45dda6fa17

@ -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;
}

@ -54,6 +54,8 @@ private:
PartitionRole m_role = PartitionRole( PartitionRole::None );
void initSectorRange( Partition* );
qint64 mbSizeForSectorRange( qint64 first, qint64 last ) const;
};
#endif /* CREATEPARTITIONDIALOG_H */

Loading…
Cancel
Save