diff --git a/CHANGES b/CHANGES index f70fb5a44..00184df4d 100644 --- a/CHANGES +++ b/CHANGES @@ -31,8 +31,10 @@ This release contains contributions from (alphabetically by first name): display-managers. * *Partition* module: it is now possible to build without libparted. Since KPMCore may not need this library anymore, it is a dependency that will - be dropped as soon as it is feasible. Add `-DCMAKE_DISABLE_FIND_PACKAGE_LIBPARTED=ON` - to the CMake flags to do so. + be dropped as soon as it is feasible. Add this to the CMake flags: + `-DCMAKE_DISABLE_FIND_PACKAGE_LIBPARTED=ON` + * *Partition* module: the location that is selected for the bootloader, + no longer changes when a new partition is created. #1098 * Python modules: several modules have had translations added. This is usually only visible when the module runs as part of the *exec* step, when the module's *pretty name* is displayed. In addition, some error diff --git a/src/modules/partition/core/BootLoaderModel.cpp b/src/modules/partition/core/BootLoaderModel.cpp index e10a7c930..f0661d8b0 100644 --- a/src/modules/partition/core/BootLoaderModel.cpp +++ b/src/modules/partition/core/BootLoaderModel.cpp @@ -67,6 +67,8 @@ BootLoaderModel::createMbrItems() void BootLoaderModel::update() { + beginResetModel(); + blockSignals( true ); clear(); createMbrItems(); @@ -111,6 +113,8 @@ BootLoaderModel::update() createBootLoaderItem( tr( "Do not install a boot loader" ), QString(), false ) ); } + blockSignals( false ); + endResetModel(); } @@ -119,12 +123,12 @@ BootLoaderModel::data( const QModelIndex& index, int role ) const { if ( role == Qt::DisplayRole ) { - if ( QStandardItemModel::data( index, BootLoaderModel::BootLoaderPathRole ).toString().isEmpty() ) - return QStandardItemModel::data( index, Qt::DisplayRole ).toString(); + QString displayRole = QStandardItemModel::data( index, Qt::DisplayRole ).toString(); + QString pathRole = QStandardItemModel::data( index, BootLoaderModel::BootLoaderPathRole ).toString(); + if ( pathRole.isEmpty() ) + return displayRole; - return tr( "%1 (%2)" ) - .arg( QStandardItemModel::data( index, Qt::DisplayRole ).toString() ) - .arg( QStandardItemModel::data( index, BootLoaderModel::BootLoaderPathRole ).toString() ); + return tr( "%1 (%2)" ).arg( displayRole, pathRole ); } return QStandardItemModel::data( index, role ); } diff --git a/src/modules/partition/gui/PartitionPage.cpp b/src/modules/partition/gui/PartitionPage.cpp index ba6845020..5f16e9dc1 100644 --- a/src/modules/partition/gui/PartitionPage.cpp +++ b/src/modules/partition/gui/PartitionPage.cpp @@ -79,6 +79,7 @@ PartitionPage::PartitionPage( PartitionCoreModule* core, QWidget* parent ) value( "alwaysShowPartitionLabels" ).toBool() ); m_ui->deviceComboBox->setModel( m_core->deviceModel() ); m_ui->bootLoaderComboBox->setModel( m_core->bootLoaderModel() ); + connect( m_core->bootLoaderModel(), &QAbstractItemModel::modelReset, this, &PartitionPage::restoreSelectedBootLoader ); PartitionBarsView::NestedPartitionsMode mode = Calamares::JobQueue::instance()->globalStorage()-> value( "drawNestedPartitions" ).toBool() ? PartitionBarsView::DrawNestedPartitions : @@ -505,6 +506,47 @@ 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 ); + } +} + + void PartitionPage::updateFromCurrentDevice() { diff --git a/src/modules/partition/gui/PartitionPage.h b/src/modules/partition/gui/PartitionPage.h index 75d39c9dc..9999c334d 100644 --- a/src/modules/partition/gui/PartitionPage.h +++ b/src/modules/partition/gui/PartitionPage.h @@ -57,6 +57,8 @@ private slots: void updateBootLoaderInstallPath(); /// @brief Explicitly selected boot loader path void updateSelectedBootLoaderIndex(); + /// @brief After boot loader model changes, try to preserve previously set value + void restoreSelectedBootLoader(); private: QScopedPointer< Ui_PartitionPage > m_ui;