[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)
This commit is contained in:
Adriaan de Groot 2020-07-29 13:59:06 +02:00
parent 43cd415d9a
commit f1c4caba48
2 changed files with 49 additions and 20 deletions

View File

@ -1442,46 +1442,74 @@ ChoicePage::currentChoice() const
return m_choice; return m_choice;
} }
bool
void ChoicePage::calculateNextEnabled() const
ChoicePage::updateNextEnabled()
{ {
bool enabled = false; bool enabled = false;
auto sm_p = m_beforePartitionBarsView ? m_beforePartitionBarsView->selectionModel() : nullptr; auto sm_p = m_beforePartitionBarsView ? m_beforePartitionBarsView->selectionModel() : nullptr;
switch ( m_choice ) switch ( m_choice )
{ {
case NoChoice: case NoChoice:
enabled = false; cDebug() << "No partitioning choice";
break; return false;
case Replace: case Replace:
case Alongside: case Alongside:
enabled = sm_p && sm_p->currentIndex().isValid(); if ( !( sm_p && sm_p->currentIndex().isValid() ) )
{
cDebug() << "No partition selected";
return false;
}
break; break;
case Erase: case Erase:
case Manual: case Manual:
enabled = true; enabled = true;
} }
if ( m_isEfi && if (!enabled)
( m_choice == Alongside ||
m_choice == Replace ) )
{ {
if ( m_core->efiSystemPartitions().count() == 0 ) cDebug() << "No valid choice made";
enabled = false; return false;
} }
if ( m_choice != Manual &&
m_encryptWidget->isVisible() &&
m_encryptWidget->state() == EncryptWidget::Encryption::Unconfirmed )
enabled = false;
if ( enabled == m_nextEnabled ) if ( m_isEfi && ( m_choice == Alongside || m_choice == Replace ) )
return; {
if ( m_core->efiSystemPartitions().count() == 0 )
{
cDebug() << "No EFI partition for alongside or replace";
return false;
}
}
m_nextEnabled = enabled; if ( m_choice != Manual && m_encryptWidget->isVisible() )
emit nextStatusChanged( enabled ); {
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 void

View File

@ -126,6 +126,7 @@ private slots:
void onEraseSwapChoiceChanged(); void onEraseSwapChoiceChanged();
private: private:
bool calculateNextEnabled() const;
void updateNextEnabled(); void updateNextEnabled();
void setupChoices(); void setupChoices();
QComboBox* createBootloaderComboBox( QWidget* parentButton ); QComboBox* createBootloaderComboBox( QWidget* parentButton );