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

View File

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