Merge branch 'issue-1151'

FIXES #1151
This commit is contained in:
Adriaan de Groot 2019-05-28 13:40:49 +02:00
commit 447a39d71d
5 changed files with 63 additions and 50 deletions

View File

@ -228,16 +228,16 @@ ViewManager::currentStepIndex() const
} }
/** @brief Is the given step at @p index an execution step? /** @brief Is the given step at @p index an execution step?
* *
* Returns true if the step is an execution step, false otherwise. * Returns true if the step is an execution step, false otherwise.
* Also returns false if the @p index is out of range. * Also returns false if the @p index is out of range.
*/ */
static inline bool static inline bool
stepIsExecute( const ViewStepList& steps, int index ) stepIsExecute( const ViewStepList& steps, int index )
{ {
return return
( 0 <= index ) && ( 0 <= index ) &&
( index < steps.count() ) && ( index < steps.count() ) &&
( qobject_cast< ExecutionViewStep* >( steps.at( index ) ) != nullptr ); ( qobject_cast< ExecutionViewStep* >( steps.at( index ) ) != nullptr );
} }
@ -249,7 +249,7 @@ ViewManager::next()
if ( step->isAtEnd() ) if ( step->isAtEnd() )
{ {
const auto* const settings = Calamares::Settings::instance(); const auto* const settings = Calamares::Settings::instance();
// 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.
@ -303,7 +303,7 @@ void
ViewManager::updateButtonLabels() ViewManager::updateButtonLabels()
{ {
const auto* const settings = Calamares::Settings::instance(); const auto* const settings = Calamares::Settings::instance();
QString next = settings->isSetupMode() QString next = settings->isSetupMode()
? tr( "&Set up" ) ? tr( "&Set up" )
: tr( "&Install" ); : tr( "&Install" );
@ -332,7 +332,7 @@ ViewManager::updateButtonLabels()
if ( settings->disableCancel() ) if ( settings->disableCancel() )
m_quit->setVisible( false ); // In case we went back from final m_quit->setVisible( false ); // In case we went back from final
updateCancelEnabled( !settings->disableCancel() && !( stepIsExecute( m_steps, m_currentStep ) && settings->disableCancelDuringExec() ) ); updateCancelEnabled( !settings->disableCancel() && !( stepIsExecute( m_steps, m_currentStep ) && settings->disableCancelDuringExec() ) );
m_quit->setText( tr( "&Cancel" ) ); m_quit->setText( tr( "&Cancel" ) );
m_quit->setToolTip( quit ); m_quit->setToolTip( quit );
} }
@ -366,37 +366,36 @@ ViewManager::back()
bool ViewManager::confirmCancelInstallation() bool ViewManager::confirmCancelInstallation()
{ {
const auto* const settings = Calamares::Settings::instance(); const auto* const settings = Calamares::Settings::instance();
// When we're at the very end, then it's always OK to exit.
if ( m_currentStep == m_steps.count() -1 && m_steps.last()->isAtEnd() )
return true;
// Not at the very end, cancel/quit might be disabled
if ( settings->disableCancel() ) if ( settings->disableCancel() )
return false; return false;
if ( settings->disableCancelDuringExec() && stepIsExecute( m_steps, m_currentStep ) ) if ( settings->disableCancelDuringExec() && stepIsExecute( m_steps, m_currentStep ) )
return false; return false;
// If it's NOT the last page of the last step, we ask for confirmation // Otherwise, confirm cancel/quit.
if ( !( m_currentStep == m_steps.count() -1 && QString title = settings->isSetupMode()
m_steps.last()->isAtEnd() ) ) ? tr( "Cancel setup?" )
{ : tr( "Cancel installation?" );
QString title = settings->isSetupMode() QString question = settings->isSetupMode()
? tr( "Cancel setup?" ) ? tr( "Do you really want to cancel the current setup process?\n"
: tr( "Cancel installation?" ); "The setup program will quit and all changes will be lost." )
QString question = settings->isSetupMode() : tr( "Do you really want to cancel the current install process?\n"
? tr( "Do you really want to cancel the current setup process?\n" "The installer will quit and all changes will be lost." );
"The setup program will quit and all changes will be lost." ) QMessageBox mb( QMessageBox::Question,
: tr( "Do you really want to cancel the current install process?\n" title,
"The installer will quit and all changes will be lost." ); question,
QMessageBox mb( QMessageBox::Question, QMessageBox::Yes | QMessageBox::No,
title, m_widget );
question, mb.setDefaultButton( QMessageBox::No );
QMessageBox::Yes | QMessageBox::No, mb.button( QMessageBox::Yes )->setText( tr( "&Yes" ) );
m_widget ); mb.button( QMessageBox::No )->setText( tr( "&No" ) );
mb.setDefaultButton( QMessageBox::No ); int response = mb.exec();
mb.button( QMessageBox::Yes )->setText( tr( "&Yes" ) ); return response == QMessageBox::Yes;
mb.button( QMessageBox::No )->setText( tr( "&No" ) );
int response = mb.exec();
return response == QMessageBox::Yes;
}
else // Means we're at the end, no need to confirm.
return true;
} }
void void

View File

@ -39,7 +39,7 @@
FinishedPage::FinishedPage( QWidget* parent ) FinishedPage::FinishedPage( QWidget* parent )
: QWidget( parent ) : QWidget( parent )
, ui( new Ui::FinishedPage ) , ui( new Ui::FinishedPage )
, m_restartSetUp( false ) , m_mode( FinishedViewStep::RestartMode::UserUnchecked )
{ {
ui->setupUi( this ); ui->setupUi( this );
@ -83,6 +83,8 @@ FinishedPage::setRestart( FinishedViewStep::RestartMode mode )
{ {
using Mode = FinishedViewStep::RestartMode; using Mode = FinishedViewStep::RestartMode;
m_mode = mode;
ui->restartCheckBox->setVisible( mode != Mode::Never ); ui->restartCheckBox->setVisible( mode != Mode::Never );
ui->restartCheckBox->setEnabled( mode != Mode::Always ); ui->restartCheckBox->setEnabled( mode != Mode::Always );
ui->restartCheckBox->setChecked( ( mode == Mode::Always ) || ( mode == Mode::UserChecked ) ); ui->restartCheckBox->setChecked( ( mode == Mode::Always ) || ( mode == Mode::UserChecked ) );
@ -99,17 +101,21 @@ FinishedPage::setRestartNowCommand( const QString& command )
void void
FinishedPage::setUpRestart() FinishedPage::setUpRestart()
{ {
cDebug() << "FinishedPage::setUpRestart()"; cDebug() << "FinishedPage::setUpRestart(), Quit button"
if ( !m_restartSetUp ) << "setup=" << FinishedViewStep::modeName( m_mode )
{ << "command=" << m_restartNowCommand;
connect( qApp, &QApplication::aboutToQuit,
this, [this] connect( qApp, &QApplication::aboutToQuit,
{ [this]()
if ( ui->restartCheckBox->isVisible() && {
ui->restartCheckBox->isChecked() ) if ( ui->restartCheckBox->isVisible() &&
QProcess::execute( "/bin/sh", { "-c", m_restartNowCommand } ); ui->restartCheckBox->isChecked() )
} ); {
} cDebug() << "Running restart command" << m_restartNowCommand;
QProcess::execute( "/bin/sh", { "-c", m_restartNowCommand } );
}
}
);
} }

View File

@ -49,9 +49,8 @@ protected:
private: private:
Ui::FinishedPage* ui; Ui::FinishedPage* ui;
FinishedViewStep::RestartMode m_mode;
QString m_restartNowCommand; QString m_restartNowCommand;
bool m_restartSetUp;
}; };
#endif // FINISHEDPAGE_H #endif // FINISHEDPAGE_H

View File

@ -156,10 +156,10 @@ FinishedViewStep::onActivate()
} }
QList< Calamares::job_ptr > Calamares::JobList
FinishedViewStep::jobs() const FinishedViewStep::jobs() const
{ {
return QList< Calamares::job_ptr >(); return Calamares::JobList();
} }
void void
@ -210,4 +210,11 @@ FinishedViewStep::setConfigurationMap( const QVariantMap& configurationMap )
m_notifyOnFinished = CalamaresUtils::getBool( configurationMap, "notifyOnFinished", false ); m_notifyOnFinished = CalamaresUtils::getBool( configurationMap, "notifyOnFinished", false );
} }
QString FinishedViewStep::modeName(FinishedViewStep::RestartMode m)
{
bool ok = false;
return modeNames().find( m, ok ); // May be QString()
}
CALAMARES_PLUGIN_FACTORY_DEFINITION( FinishedViewStepFactory, registerPlugin<FinishedViewStep>(); ) CALAMARES_PLUGIN_FACTORY_DEFINITION( FinishedViewStepFactory, registerPlugin<FinishedViewStep>(); )

View File

@ -41,6 +41,8 @@ public:
UserChecked, ///< @brief Show button, starts checked UserChecked, ///< @brief Show button, starts checked
Always ///< @brief Show button, can't change, checked Always ///< @brief Show button, can't change, checked
}; };
/// @brief Returns the config-name of the given restart-mode @p m
static QString modeName( RestartMode m );
explicit FinishedViewStep( QObject* parent = nullptr ); explicit FinishedViewStep( QObject* parent = nullptr );
virtual ~FinishedViewStep() override; virtual ~FinishedViewStep() override;
@ -57,7 +59,7 @@ public:
void onActivate() override; void onActivate() override;
QList< Calamares::job_ptr > jobs() const override; Calamares::JobList jobs() const override;
void setConfigurationMap( const QVariantMap& configurationMap ) override; void setConfigurationMap( const QVariantMap& configurationMap ) override;