From f1c4caba483c5ddadadfd85b72bdebb2f1857a5d Mon Sep 17 00:00:00 2001 From: Adriaan de Groot Date: Wed, 29 Jul 2020 13:59:06 +0200 Subject: [PATCH] [partition] Refactor checking next-enabled - move the calculations to an own method (so it can use early-return and log things to explain why next is disabled) --- src/modules/partition/gui/ChoicePage.cpp | 68 +++++++++++++++++------- src/modules/partition/gui/ChoicePage.h | 1 + 2 files changed, 49 insertions(+), 20 deletions(-) diff --git a/src/modules/partition/gui/ChoicePage.cpp b/src/modules/partition/gui/ChoicePage.cpp index 9e48e69ac..9f654b1bf 100644 --- a/src/modules/partition/gui/ChoicePage.cpp +++ b/src/modules/partition/gui/ChoicePage.cpp @@ -1442,46 +1442,74 @@ ChoicePage::currentChoice() const return m_choice; } - -void -ChoicePage::updateNextEnabled() +bool +ChoicePage::calculateNextEnabled() const { bool enabled = false; - auto sm_p = m_beforePartitionBarsView ? m_beforePartitionBarsView->selectionModel() : nullptr; switch ( m_choice ) { case NoChoice: - enabled = false; - break; + cDebug() << "No partitioning choice"; + return false; case Replace: case Alongside: - enabled = sm_p && sm_p->currentIndex().isValid(); + if ( !( sm_p && sm_p->currentIndex().isValid() ) ) + { + cDebug() << "No partition selected"; + return false; + } break; case Erase: case Manual: enabled = true; } - if ( m_isEfi && - ( m_choice == Alongside || - m_choice == Replace ) ) + if (!enabled) { - if ( m_core->efiSystemPartitions().count() == 0 ) - enabled = false; + cDebug() << "No valid choice made"; + return false; } - if ( m_choice != Manual && - m_encryptWidget->isVisible() && - m_encryptWidget->state() == EncryptWidget::Encryption::Unconfirmed ) - enabled = false; - if ( enabled == m_nextEnabled ) - return; + if ( m_isEfi && ( m_choice == Alongside || m_choice == Replace ) ) + { + if ( m_core->efiSystemPartitions().count() == 0 ) + { + cDebug() << "No EFI partition for alongside or replace"; + return false; + } + } - m_nextEnabled = enabled; - emit nextStatusChanged( enabled ); + if ( m_choice != Manual && m_encryptWidget->isVisible() ) + { + switch ( m_encryptWidget->state() ) + { + case EncryptWidget::Encryption::Unconfirmed: + cDebug() << "No passphrase provided"; + return false; + case EncryptWidget::Encryption::Disabled: + case EncryptWidget::Encryption::Confirmed: + // Checkbox not checked, **or** passphrases match + break; + } + } + + return true; +} + + +void +ChoicePage::updateNextEnabled() +{ + bool enabled = calculateNextEnabled(); + + if ( enabled != m_nextEnabled ) + { + m_nextEnabled = enabled; + emit nextStatusChanged( enabled ); + } } void diff --git a/src/modules/partition/gui/ChoicePage.h b/src/modules/partition/gui/ChoicePage.h index 1ff8f0d40..a28892011 100644 --- a/src/modules/partition/gui/ChoicePage.h +++ b/src/modules/partition/gui/ChoicePage.h @@ -126,6 +126,7 @@ private slots: void onEraseSwapChoiceChanged(); private: + bool calculateNextEnabled() const; void updateNextEnabled(); void setupChoices(); QComboBox* createBootloaderComboBox( QWidget* parentButton );