[libcalamaresui] Refactor quit-enabling

- Add signal for change-of-quit-enabledness
 - Minor tidying
This commit is contained in:
Adriaan de Groot 2019-05-14 13:34:14 +02:00
parent 088fa5004c
commit d4f4a40fa5
2 changed files with 21 additions and 16 deletions

View File

@ -288,12 +288,7 @@ ViewManager::next()
m_steps.at( m_currentStep )->onActivate(); m_steps.at( m_currentStep )->onActivate();
executing = qobject_cast< ExecutionViewStep* >( m_steps.at( m_currentStep ) ) != nullptr; executing = qobject_cast< ExecutionViewStep* >( m_steps.at( m_currentStep ) ) != nullptr;
emit currentStepChanged(); emit currentStepChanged();
if ( executing ) updateCancelEnabled( !settings->disableCancel() && !(executing && settings->dontCancel() ) );
// Enabled if there's nothing blocking it during exec
m_quit->setEnabled( !( settings->dontCancel() || settings->disableCancel() ) );
else
// Enabled unless it's also hidden
m_quit->setEnabled( !settings->disableCancel() );
} }
else else
step->next(); step->next();
@ -307,13 +302,15 @@ ViewManager::next()
void void
ViewManager::updateButtonLabels() ViewManager::updateButtonLabels()
{ {
QString next = Calamares::Settings::instance()->isSetupMode() const auto* const settings = Calamares::Settings::instance();
QString next = settings->isSetupMode()
? tr( "&Set up" ) ? tr( "&Set up" )
: tr( "&Install" ); : tr( "&Install" );
QString complete = Calamares::Settings::instance()->isSetupMode() QString complete = settings->isSetupMode()
? tr( "Setup is complete. Close the setup program." ) ? tr( "Setup is complete. Close the setup program." )
: tr( "The installation is complete. Close the installer." ); : tr( "The installation is complete. Close the installer." );
QString quit = Calamares::Settings::instance()->isSetupMode() QString quit = settings->isSetupMode()
? tr( "Cancel setup without changing the system." ) ? tr( "Cancel setup without changing the system." )
: tr( "Cancel installation without changing the system." ); : tr( "Cancel installation without changing the system." );
@ -328,15 +325,14 @@ ViewManager::updateButtonLabels()
m_quit->setText( tr( "&Done" ) ); m_quit->setText( tr( "&Done" ) );
m_quit->setToolTip( complete ); m_quit->setToolTip( complete );
m_quit->setVisible( true ); // At end, always visible and enabled. m_quit->setVisible( true ); // At end, always visible and enabled.
m_quit->setEnabled( true ); updateCancelEnabled( true );
} }
else else
{ {
if ( Calamares::Settings::instance()->disableCancel() ) if ( settings->disableCancel() )
{ m_quit->setVisible( false ); // In case we went back from final
m_quit->setVisible( false ); updateCancelEnabled( !settings->disableCancel() && !( stepIsExecute( m_steps, m_currentStep ) && settings->dontCancel() ) );
m_quit->setEnabled( false ); // Can't be triggered through DBUS
}
m_quit->setText( tr( "&Cancel" ) ); m_quit->setText( tr( "&Cancel" ) );
m_quit->setToolTip( quit ); m_quit->setToolTip( quit );
} }
@ -403,4 +399,11 @@ bool ViewManager::confirmCancelInstallation()
return true; return true;
} }
void
ViewManager::updateCancelEnabled( bool enabled )
{
m_quit->setEnabled( enabled );
emit cancelEnabled( enabled );
}
} // namespace } // namespace

View File

@ -121,6 +121,7 @@ public slots:
signals: signals:
void currentStepChanged(); void currentStepChanged();
void enlarge( QSize enlarge ) const; // See ViewStep::enlarge() void enlarge( QSize enlarge ) const; // See ViewStep::enlarge()
void cancelEnabled( bool enabled ) const;
private: private:
explicit ViewManager( QObject* parent = nullptr ); explicit ViewManager( QObject* parent = nullptr );
@ -128,6 +129,7 @@ private:
void insertViewStep( int before, ViewStep* step ); void insertViewStep( int before, ViewStep* step );
void updateButtonLabels(); void updateButtonLabels();
void updateCancelEnabled( bool enabled );
static ViewManager* s_instance; static ViewManager* s_instance;