From 7a89b535387b551d2469483ee6f7d1bd57106eb6 Mon Sep 17 00:00:00 2001 From: Teo Mrnjavac Date: Fri, 19 Feb 2016 16:33:19 +0100 Subject: [PATCH] Refactor leave event of ChoicePage, add ESP mount point support. PVS now calls ChoicePage::onLeave, which in turn runs ChoicePage:: doAlongsideApply and/or sets up the ESP mount point based on the UI state if it's running in EFI mode and the action is Alongside or Replace. If setting up under BIOS, Alongside and Replace always install the bootloader in the MBR of the current device. --- src/modules/partition/gui/ChoicePage.cpp | 114 ++++++++++++++---- src/modules/partition/gui/ChoicePage.h | 5 +- .../partition/gui/PartitionViewStep.cpp | 5 +- 3 files changed, 98 insertions(+), 26 deletions(-) diff --git a/src/modules/partition/gui/ChoicePage.cpp b/src/modules/partition/gui/ChoicePage.cpp index f8ac0bde9..b863d2431 100644 --- a/src/modules/partition/gui/ChoicePage.cpp +++ b/src/modules/partition/gui/ChoicePage.cpp @@ -466,6 +466,45 @@ ChoicePage::doAlongsideSetupSplitter( const QModelIndex& current, } +void +ChoicePage::onLeave() +{ + if ( m_choice == Alongside ) + doAlongsideApply(); + + if ( m_isEfi && ( m_choice == Alongside || m_choice == Replace ) ) + { + QList< Partition* > efiSystemPartitions = m_core->efiSystemPartitions(); + if ( efiSystemPartitions.count() == 1 ) + { + PartitionInfo::setMountPoint( + efiSystemPartitions.first(), + Calamares::JobQueue::instance()-> + globalStorage()-> + value( "efiSystemPartition" ).toString() ); + } + else if ( efiSystemPartitions.count() > 1 && m_efiComboBox ) + { + PartitionInfo::setMountPoint( + efiSystemPartitions.at( m_efiComboBox->currentIndex() ), + Calamares::JobQueue::instance()-> + globalStorage()-> + value( "efiSystemPartition" ).toString() ); + } + else + { + cDebug() << "ERROR: cannot set up EFI system partition.\nESP count:" + << efiSystemPartitions.count() << "\nm_efiComboBox:" + << m_efiComboBox; + } + } + else // installPath is then passed to the bootloader module for MBR setup + { + m_core->setBootLoaderInstallPath( selectedDevice()->deviceNode() ); + } +} + + void ChoicePage::doAlongsideApply() { @@ -504,28 +543,6 @@ ChoicePage::doAlongsideApply() // have to push it one sector further, therefore + 2 instead of + 1. m_core->createPartition( dev, newPartition ); - m_core->setBootLoaderInstallPath( dev->deviceNode() ); - - /*if ( m_isEfi ) - { - QList< Partition* > efiSystemPartitions = m_core->efiSystemPartitions(); - if ( efiSystemPartitions.count() == 1 ) - { - PartitionInfo::setMountPoint( - efiSystemPartitions.first(), - Calamares::JobQueue::instance()-> - globalStorage()-> - value( "efiSystemPartition" ).toString() ); - } - else if ( efiSystemPartitions.count() > 1 ) - { - PartitionInfo::setMountPoint( - efiSystemPartitions.at( m_efiComboBox->currentIndex() ), - Calamares::JobQueue::instance()-> - globalStorage()-> - value( "efiSystemPartition" ).toString() ); - } - }*/ m_core->dumpQueue(); @@ -792,6 +809,59 @@ ChoicePage::updateActionChoicePreview( ChoicePage::Choice choice ) break; } + if ( m_isEfi && ( m_choice == Alongside || m_choice == Replace ) ) + { + QHBoxLayout* efiLayout = new QHBoxLayout; + layout->addLayout( efiLayout ); + m_efiLabel = new QLabel( m_previewAfterFrame ); + efiLayout->addWidget( m_efiLabel ); + m_efiComboBox = new QComboBox( m_previewAfterFrame ); + efiLayout->addWidget( m_efiComboBox ); + m_efiLabel->setBuddy( m_efiComboBox ); + m_efiComboBox->hide(); + efiLayout->addStretch(); + + // Only the already existing ones: + QList< Partition* > efiSystemPartitions = m_core->efiSystemPartitions(); + + if ( efiSystemPartitions.count() == 0 ) //should never happen + { + m_efiLabel->setText( + tr( "An EFI system partition cannot be found anywhere " + "on this system. Please go back and use manual " + "partitioning to set up %1." ) + .arg( Calamares::Branding::instance()-> + string( Calamares::Branding::ShortProductName ) ) ); + setNextEnabled( false ); + } + else if ( efiSystemPartitions.count() == 1 ) //probably most usual situation + { + m_efiLabel->setText( + tr( "The EFI system partition at %1 will be used for " + "starting %2." ) + .arg( efiSystemPartitions.first()->partitionPath() ) + .arg( Calamares::Branding::instance()-> + string( Calamares::Branding::ShortProductName ) ) ); + setNextEnabled( true ); + } + else + { + m_efiComboBox->show(); + m_efiLabel->setText( tr( "EFI system partition:" ) ); + for ( int i = 0; i < efiSystemPartitions.count(); ++i ) + { + Partition* efiPartition = efiSystemPartitions.at( i ); + m_efiComboBox->addItem( efiPartition->partitionPath(), i ); + + // We pick an ESP on the currently selected device, if possible + if ( efiPartition->devicePath() == selectedDevice()->deviceNode() && + efiPartition->number() == 1 ) + m_efiComboBox->setCurrentIndex( i ); + } + setNextEnabled( true ); + } + } + // Also handle selection behavior on beforeFrame. QAbstractItemView::SelectionMode previewSelectionMode; switch ( m_choice ) diff --git a/src/modules/partition/gui/ChoicePage.h b/src/modules/partition/gui/ChoicePage.h index deff203c3..bf6660e64 100644 --- a/src/modules/partition/gui/ChoicePage.h +++ b/src/modules/partition/gui/ChoicePage.h @@ -64,7 +64,7 @@ public: Choice currentChoice() const; - void doAlongsideApply(); + void onLeave(); signals: void nextStatusChanged( bool ); @@ -87,6 +87,7 @@ private: void updateActionChoicePreview( ChoicePage::Choice choice ); void setupActions(); OsproberEntryList getOsproberEntriesForDevice( Device* device ) const; + void doAlongsideApply(); bool m_nextEnabled; PartitionCoreModule* m_core; @@ -112,6 +113,8 @@ private: QPointer< PartitionLabelsView > m_afterPartitionLabelsView; QPointer< PartitionSplitterWidget > m_afterPartitionSplitterWidget; QPointer< QComboBox > m_bootloaderComboBox; + QPointer< QLabel > m_efiLabel; + QPointer< QComboBox > m_efiComboBox; int m_lastSelectedDeviceIndex; diff --git a/src/modules/partition/gui/PartitionViewStep.cpp b/src/modules/partition/gui/PartitionViewStep.cpp index 86e5923f8..607c87839 100644 --- a/src/modules/partition/gui/PartitionViewStep.cpp +++ b/src/modules/partition/gui/PartitionViewStep.cpp @@ -363,9 +363,8 @@ PartitionViewStep::onActivate() void PartitionViewStep::onLeave() { - if ( m_widget->currentWidget() == m_choicePage && - m_choicePage->currentChoice() == ChoicePage::Alongside ) - m_choicePage->doAlongsideApply(); + if ( m_widget->currentWidget() == m_choicePage ) + m_choicePage->onLeave(); }