diff --git a/src/modules/partition/gui/PartitionPage.cpp b/src/modules/partition/gui/PartitionPage.cpp index 43db4aa3d..5f16e9dc1 100644 --- a/src/modules/partition/gui/PartitionPage.cpp +++ b/src/modules/partition/gui/PartitionPage.cpp @@ -506,9 +506,44 @@ 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() ); + cDebug() << i << model->itemData( index ); + 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 ); + } }