[libcalamaresui] Switch text on 'next' button

- If the next step will be an install-step (e.g. hit the optional
   confirmation step) then change the text on the 'next' button to
   'install'.
 - Do a little refactoring to make that more pleasant.

FIXES #905
This commit is contained in:
Adriaan de Groot 2018-02-13 08:11:11 -05:00
parent e9d9efce20
commit 958aee1d41
2 changed files with 25 additions and 12 deletions

View File

@ -192,6 +192,11 @@ ViewManager::currentStepIndex() const
return m_currentStep;
}
static inline bool
stepNextWillExecute(const ViewStepList& steps, int index)
{
return ( index + 1 < steps.count() ) && qobject_cast< ExecutionViewStep* >( steps.at( index + 1 ) );
}
void
ViewManager::next()
@ -203,9 +208,7 @@ ViewManager::next()
// Special case when the user clicks next on the very last page in a view phase
// and right before switching to an execution phase.
// Depending on Calamares::Settings, we show an "are you sure" prompt or not.
if ( Calamares::Settings::instance()->showPromptBeforeExecution() &&
m_currentStep + 1 < m_steps.count() &&
qobject_cast< ExecutionViewStep* >( m_steps.at( m_currentStep + 1 ) ) )
if ( Calamares::Settings::instance()->showPromptBeforeExecution() && stepNextWillExecute( m_steps, m_currentStep ) )
{
int reply =
QMessageBox::question( m_widget,
@ -242,15 +245,29 @@ ViewManager::next()
m_next->setEnabled( !executing && m_steps.at( m_currentStep )->isNextEnabled() );
m_back->setEnabled( !executing && m_steps.at( m_currentStep )->isBackEnabled() );
if ( m_currentStep == m_steps.count() -1 &&
m_steps.last()->isAtEnd() )
updateButtonLabels();
}
void
ViewManager::updateButtonLabels()
{
if ( stepNextWillExecute( m_steps, m_currentStep ) )
m_next->setText( tr( "&Install" ) );
else
m_next->setText( tr( "&Next" ) );
if ( m_currentStep == m_steps.count() -1 && m_steps.last()->isAtEnd() )
{
m_quit->setText( tr( "&Done" ) );
m_quit->setToolTip( tr( "The installation is complete. Close the installer." ) );
}
else
{
m_quit->setText( tr( "&Cancel" ) );
m_quit->setToolTip( tr( "Cancel installation without changing the system." ) );
}
}
void
ViewManager::back()
{
@ -273,12 +290,7 @@ ViewManager::back()
if ( m_currentStep == 0 && m_steps.first()->isAtBeginning() )
m_back->setEnabled( false );
if ( !( m_currentStep == m_steps.count() -1 &&
m_steps.last()->isAtEnd() ) )
{
m_quit->setText( tr( "&Cancel" ) );
m_quit->setToolTip( tr( "Cancel installation without changing the system." ) );
}
updateButtonLabels();
}
bool ViewManager::confirmCancelInstallation()

View File

@ -126,6 +126,7 @@ private:
virtual ~ViewManager() override;
void insertViewStep( int before, ViewStep* step );
void updateButtonLabels();
static ViewManager* s_instance;