diff --git a/ci/HACKING.md b/ci/HACKING.md index ca3901f07..f2e6308d1 100644 --- a/ci/HACKING.md +++ b/ci/HACKING.md @@ -60,6 +60,8 @@ some PEP8 guidelines. * Function and class definitions have their braces on separate lines. * A function implementation's return type is on its own line. * `CamelCase.{cpp,h}` style file names. +* Lambdas are preferrably indented to a 4-space tab, even when passed as an + argument to functions. Example: ``` diff --git a/src/modules/partition/core/BootLoaderModel.cpp b/src/modules/partition/core/BootLoaderModel.cpp index 16c6ce3c8..e785050d2 100644 --- a/src/modules/partition/core/BootLoaderModel.cpp +++ b/src/modules/partition/core/BootLoaderModel.cpp @@ -23,9 +23,13 @@ #include "core/PartitionInfo.h" #include "core/KPMHelpers.h" +#include "utils/Logger.h" + // KPMcore #include +#include + static QStandardItem* createBootLoaderItem( const QString& description, const QString& path, bool isPartition ) { @@ -47,12 +51,12 @@ BootLoaderModel::~BootLoaderModel() void BootLoaderModel::init( const QList< Device* >& devices ) { + cDebug() << "BLM::init with" << devices.count() << "devices" << rowCount() << "rows"; beginResetModel(); blockSignals( true ); m_devices = devices; - clear(); - createMbrItems(); + updateInternal(); blockSignals( false ); endResetModel(); @@ -74,6 +78,7 @@ BootLoaderModel::createMbrItems() void BootLoaderModel::update() { + cDebug() << "BLM::update holds" << m_devices.count() << "devices" << rowCount() << "rows"; beginResetModel(); blockSignals( true ); updateInternal(); @@ -148,3 +153,48 @@ BootLoaderModel::data( const QModelIndex& index, int role ) const } return QStandardItemModel::data( index, role ); } + +namespace Calamares +{ +int +findBootloader( const QAbstractItemModel* model, const QString& path ) +{ + for ( int i = 0; i < model->rowCount(); ++i) + { + const auto index = model->index( i, 0, QModelIndex() ); + if ( !index.isValid() ) + continue; + QVariant var = model->data( index, BootLoaderModel::BootLoaderPathRole ); + if ( var.isValid() && var.toString() == path ) + return i; + } + + return -1; +} + +void +restoreSelectedBootLoader( QComboBox& combo, const QString& path ) +{ + const auto* model = combo.model(); + if ( model->rowCount() < 1 ) + { + cDebug() << "No items in BootLoaderModel"; + return; + } + + int r = -1; + if ( path.isEmpty() ) + { + combo.setCurrentIndex( 0 ); + } + else if ( (r = findBootloader( model, path )) >= 0 ) + { + combo.setCurrentIndex( r ); + } + else + { + combo.setCurrentIndex( 0 ); + } +} + +} // namespace diff --git a/src/modules/partition/core/BootLoaderModel.h b/src/modules/partition/core/BootLoaderModel.h index fbbb9deb2..a2befad00 100644 --- a/src/modules/partition/core/BootLoaderModel.h +++ b/src/modules/partition/core/BootLoaderModel.h @@ -25,6 +25,7 @@ #include class Device; +class QComboBox; /** * This model contains one entry for each device MBR plus one entry for the @@ -63,4 +64,20 @@ private: void updateInternal(); }; +namespace Calamares +{ + /** @brief Returns the row number of boot-loader @p path (e.g. /dev/sda) + * + * Assuming the @p model is a BootLoaderModel, will return a row number + * in the model. Returns -1 otherwise. + */ + int findBootloader( const QAbstractItemModel* model, const QString& path ); + + /** @brief Tries to set @p path as selected item in @p combo + * + * Matches a boot-loader install path (e.g. /dev/sda) with a model + * row and sets that as the current row. + */ + void restoreSelectedBootLoader( QComboBox& combo, const QString& path ); +} // namespace #endif /* BOOTLOADERMODEL_H */ diff --git a/src/modules/partition/core/ColorUtils.cpp b/src/modules/partition/core/ColorUtils.cpp index 40f65d2ba..ffe45d443 100644 --- a/src/modules/partition/core/ColorUtils.cpp +++ b/src/modules/partition/core/ColorUtils.cpp @@ -22,6 +22,8 @@ #include "core/KPMHelpers.h" #include "core/PartitionIterator.h" +#include "utils/Logger.h" + // KPMcore #include #include @@ -81,6 +83,12 @@ _findRootForPartition( PartitionNode* partition ) QColor colorForPartition( Partition* partition ) { + if ( !partition ) + { + cWarning() << "NULL partition"; + return FREE_SPACE_COLOR; + } + if ( KPMHelpers::isPartitionFreeSpace( partition ) ) return FREE_SPACE_COLOR; if ( partition->roles().has( PartitionRole::Extended ) ) diff --git a/src/modules/partition/core/PartitionCoreModule.cpp b/src/modules/partition/core/PartitionCoreModule.cpp index 6dd2b6faf..4b23c86e4 100644 --- a/src/modules/partition/core/PartitionCoreModule.cpp +++ b/src/modules/partition/core/PartitionCoreModule.cpp @@ -402,7 +402,7 @@ PartitionCoreModule::deletePartition( Device* device, Partition* partition ) deletePartition( device, childPartition ); } - QList< Calamares::job_ptr >& jobs = deviceInfo->jobs; + Calamares::JobList& jobs = deviceInfo->jobs; if ( partition->state() == KPM_PARTITION_STATE(New) ) { // First remove matching SetPartFlagsJobs @@ -496,10 +496,10 @@ PartitionCoreModule::setPartitionFlags( Device* device, PartitionInfo::setFlags( partition, flags ); } -QList< Calamares::job_ptr > +Calamares::JobList PartitionCoreModule::jobs() const { - QList< Calamares::job_ptr > lst; + Calamares::JobList lst; QList< Device* > devices; #ifdef DEBUG_PARTITION_UNSAFE @@ -947,12 +947,7 @@ PartitionCoreModule::revertDevice( Device* dev, bool individualRevert ) QList< Device* > devices; for ( DeviceInfo* const info : m_deviceInfos ) { - // device is a QScopedPointer - if ( !info || info->device.isNull() ) - continue; - if ( info->device->type() != Device::Type::Disk_Device ) - continue; - else + if ( info && !info->device.isNull() && info->device->type() == Device::Type::Disk_Device ) devices.append( info->device.data() ); } diff --git a/src/modules/partition/core/PartitionCoreModule.h b/src/modules/partition/core/PartitionCoreModule.h index 906119a74..7faf67863 100644 --- a/src/modules/partition/core/PartitionCoreModule.h +++ b/src/modules/partition/core/PartitionCoreModule.h @@ -247,7 +247,7 @@ private: QScopedPointer< Device > device; QScopedPointer< PartitionModel > partitionModel; const QScopedPointer< Device > immutableDevice; - QList< Calamares::job_ptr > jobs; + Calamares::JobList jobs; // To check if LVM VGs are deactivated bool isAvailable; diff --git a/src/modules/partition/gui/ChoicePage.cpp b/src/modules/partition/gui/ChoicePage.cpp index 04eec56ed..5e8260dec 100644 --- a/src/modules/partition/gui/ChoicePage.cpp +++ b/src/modules/partition/gui/ChoicePage.cpp @@ -960,19 +960,18 @@ ChoicePage::updateActionChoicePreview( ChoicePage::InstallChoice choice ) QLabel* sizeLabel = new QLabel( m_previewAfterFrame ); layout->addWidget( sizeLabel ); sizeLabel->setWordWrap( true ); - connect( m_afterPartitionSplitterWidget, &PartitionSplitterWidget::partitionResized, - this, [ this, sizeLabel ]( const QString& path, - qint64 size, - qint64 sizeNext ) - { - Q_UNUSED( path ) - sizeLabel->setText( tr( "%1 will be shrunk to %2MiB and a new " - "%3MiB partition will be created for %4." ) - .arg( m_beforePartitionBarsView->selectionModel()->currentIndex().data().toString() ) - .arg( CalamaresUtils::BytesToMiB( size ) ) - .arg( CalamaresUtils::BytesToMiB( sizeNext ) ) - .arg( *Calamares::Branding::ShortProductName ) ); - } ); + connect( m_afterPartitionSplitterWidget, &PartitionSplitterWidget::partitionResized, this, + [ this, sizeLabel ]( const QString& path, qint64 size, qint64 sizeNext ) + { + Q_UNUSED( path ) + sizeLabel->setText( tr( "%1 will be shrunk to %2MiB and a new " + "%3MiB partition will be created for %4." ) + .arg( m_beforePartitionBarsView->selectionModel()->currentIndex().data().toString() ) + .arg( CalamaresUtils::BytesToMiB( size ) ) + .arg( CalamaresUtils::BytesToMiB( sizeNext ) ) + .arg( *Calamares::Branding::ShortProductName ) ); + } + ); m_previewAfterFrame->show(); m_previewAfterLabel->show(); @@ -1025,18 +1024,25 @@ ChoicePage::updateActionChoicePreview( ChoicePage::InstallChoice choice ) eraseBootloaderLabel->setText( tr( "Boot loader location:" ) ); m_bootloaderComboBox = createBootloaderComboBox( eraseWidget ); - connect( m_core, &PartitionCoreModule::deviceReverted, - this, [ this ]( Device* dev ) - { - Q_UNUSED( dev ) - if ( !m_bootloaderComboBox.isNull() ) + connect( m_core->bootLoaderModel(), &QAbstractItemModel::modelReset, + [ this ]() { - if ( m_bootloaderComboBox->model() != m_core->bootLoaderModel() ) - m_bootloaderComboBox->setModel( m_core->bootLoaderModel() ); - - m_bootloaderComboBox->setCurrentIndex( m_lastSelectedDeviceIndex ); + if ( !m_bootloaderComboBox.isNull() ) + Calamares::restoreSelectedBootLoader( *m_bootloaderComboBox, m_core->bootLoaderInstallPath() ); } - }, Qt::QueuedConnection ); + ); + connect( m_core, &PartitionCoreModule::deviceReverted, this, + [ this ]( Device* dev ) + { + Q_UNUSED( dev ) + if ( !m_bootloaderComboBox.isNull() ) + { + if ( m_bootloaderComboBox->model() != m_core->bootLoaderModel() ) + m_bootloaderComboBox->setModel( m_core->bootLoaderModel() ); + + m_bootloaderComboBox->setCurrentIndex( m_lastSelectedDeviceIndex ); + } + }, Qt::QueuedConnection ); // ^ Must be Queued so it's sure to run when the widget is already visible. eraseLayout->addWidget( m_bootloaderComboBox ); diff --git a/src/modules/partition/gui/PartitionPage.cpp b/src/modules/partition/gui/PartitionPage.cpp index 647a69d5d..915f899b2 100644 --- a/src/modules/partition/gui/PartitionPage.cpp +++ b/src/modules/partition/gui/PartitionPage.cpp @@ -219,7 +219,7 @@ PartitionPage::onNewPartitionTableClicked() m_core->createPartitionTable( device, type ); } delete dlg; - // PartionModelReset isn't emmited after createPartitionTable, so we have to manually update + // PartionModelReset isn't emitted after createPartitionTable, so we have to manually update // the bootLoader index after the reset. updateBootLoaderIndex(); } @@ -511,45 +511,10 @@ PartitionPage::updateSelectedBootLoaderIndex() cDebug() << "Selected bootloader index" << m_lastSelectedBootLoaderIndex; } -int -findBootloader( const QAbstractItemModel* model, const QString& path ) -{ - for ( int i = 0; i < model->rowCount(); ++i) - { - const auto index = model->index( i, 0, QModelIndex() ); - if ( !index.isValid() ) - continue; - QVariant var = model->data( index, BootLoaderModel::BootLoaderPathRole ); - if ( var.isValid() && var.toString() == path ) - return i; - } - - return -1; -} - void PartitionPage::restoreSelectedBootLoader() { - const auto* model = m_ui->bootLoaderComboBox->model(); - if ( model->rowCount() < 1 ) - { - cDebug() << "No items in BootLoaderModel"; - return; - } - - int r = -1; - if ( m_core->bootLoaderInstallPath().isEmpty() ) - { - m_ui->bootLoaderComboBox->setCurrentIndex( 0 ); - } - else if ( (r = findBootloader( model, m_core->bootLoaderInstallPath() )) >= 0 ) - { - m_ui->bootLoaderComboBox->setCurrentIndex( r ); - } - else - { - m_ui->bootLoaderComboBox->setCurrentIndex( 0 ); - } + Calamares::restoreSelectedBootLoader( *(m_ui->bootLoaderComboBox), m_core->bootLoaderInstallPath() ); } diff --git a/src/modules/partition/gui/PartitionViewStep.cpp b/src/modules/partition/gui/PartitionViewStep.cpp index 2e186b3a8..58fa17674 100644 --- a/src/modules/partition/gui/PartitionViewStep.cpp +++ b/src/modules/partition/gui/PartitionViewStep.cpp @@ -619,7 +619,7 @@ PartitionViewStep::setConfigurationMap( const QVariantMap& configurationMap ) } -QList< Calamares::job_ptr > +Calamares::JobList PartitionViewStep::jobs() const { return m_core->jobs(); @@ -638,7 +638,11 @@ PartitionViewStep::checkRequirements() []{ return tr( "has at least one disk device available." ); }, []{ return tr( "There are no partitons to install on." ); }, m_core->deviceModel()->rowCount() > 0, // satisfied - true // required +#ifdef DEBUG_PARTITION_UNSAFE + false // optional +#else + true // required +#endif } ); return l; diff --git a/src/modules/partition/gui/PartitionViewStep.h b/src/modules/partition/gui/PartitionViewStep.h index 47f8fa127..e3d058e67 100644 --- a/src/modules/partition/gui/PartitionViewStep.h +++ b/src/modules/partition/gui/PartitionViewStep.h @@ -69,7 +69,7 @@ public: void setConfigurationMap( const QVariantMap& configurationMap ) override; - QList< Calamares::job_ptr > jobs() const override; + Calamares::JobList jobs() const override; Calamares::RequirementsList checkRequirements() override;