From 191554700489a78f07d0537acc8325f564ac212a Mon Sep 17 00:00:00 2001 From: Adriaan de Groot Date: Tue, 28 May 2019 13:05:40 +0200 Subject: [PATCH 1/4] [finished] Improve logging when restarting. --- src/modules/finished/FinishedPage.cpp | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/modules/finished/FinishedPage.cpp b/src/modules/finished/FinishedPage.cpp index c49bb9538..ade0b486b 100644 --- a/src/modules/finished/FinishedPage.cpp +++ b/src/modules/finished/FinishedPage.cpp @@ -99,7 +99,9 @@ FinishedPage::setRestartNowCommand( const QString& command ) void FinishedPage::setUpRestart() { - cDebug() << "FinishedPage::setUpRestart()"; + cDebug() << "FinishedPage::setUpRestart(), Quit button" + << "setup=" << m_restartSetUp + << "command=" << m_restartNowCommand; if ( !m_restartSetUp ) { connect( qApp, &QApplication::aboutToQuit, From 38c36e24393ace2249e92cd8ffc8c5471abef90b Mon Sep 17 00:00:00 2001 From: Adriaan de Groot Date: Tue, 28 May 2019 13:20:19 +0200 Subject: [PATCH 2/4] [finished] Use idiomatic Calamares::JobList --- src/modules/finished/FinishedViewStep.cpp | 4 ++-- src/modules/finished/FinishedViewStep.h | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/modules/finished/FinishedViewStep.cpp b/src/modules/finished/FinishedViewStep.cpp index d5c3c3f69..16b1de7eb 100644 --- a/src/modules/finished/FinishedViewStep.cpp +++ b/src/modules/finished/FinishedViewStep.cpp @@ -156,10 +156,10 @@ FinishedViewStep::onActivate() } -QList< Calamares::job_ptr > +Calamares::JobList FinishedViewStep::jobs() const { - return QList< Calamares::job_ptr >(); + return Calamares::JobList(); } void diff --git a/src/modules/finished/FinishedViewStep.h b/src/modules/finished/FinishedViewStep.h index 314f6acc6..02ba6ef83 100644 --- a/src/modules/finished/FinishedViewStep.h +++ b/src/modules/finished/FinishedViewStep.h @@ -57,7 +57,7 @@ public: void onActivate() override; - QList< Calamares::job_ptr > jobs() const override; + Calamares::JobList jobs() const override; void setConfigurationMap( const QVariantMap& configurationMap ) override; From 0c24a01eb9e41257c9a34e32df8e248d89624f53 Mon Sep 17 00:00:00 2001 From: Adriaan de Groot Date: Tue, 28 May 2019 13:27:21 +0200 Subject: [PATCH 3/4] [finished] Improve logging of restart mode - Don't use weirdly-named mode, store named mode in page, - Log the actual mode name when setting up the restart button. --- src/modules/finished/FinishedPage.cpp | 28 +++++++++++++---------- src/modules/finished/FinishedPage.h | 3 +-- src/modules/finished/FinishedViewStep.cpp | 7 ++++++ src/modules/finished/FinishedViewStep.h | 2 ++ 4 files changed, 26 insertions(+), 14 deletions(-) diff --git a/src/modules/finished/FinishedPage.cpp b/src/modules/finished/FinishedPage.cpp index ade0b486b..4bffa8221 100644 --- a/src/modules/finished/FinishedPage.cpp +++ b/src/modules/finished/FinishedPage.cpp @@ -39,7 +39,7 @@ FinishedPage::FinishedPage( QWidget* parent ) : QWidget( parent ) , ui( new Ui::FinishedPage ) - , m_restartSetUp( false ) + , m_mode( FinishedViewStep::RestartMode::UserUnchecked ) { ui->setupUi( this ); @@ -83,6 +83,8 @@ FinishedPage::setRestart( FinishedViewStep::RestartMode mode ) { using Mode = FinishedViewStep::RestartMode; + m_mode = mode; + ui->restartCheckBox->setVisible( mode != Mode::Never ); ui->restartCheckBox->setEnabled( mode != Mode::Always ); ui->restartCheckBox->setChecked( ( mode == Mode::Always ) || ( mode == Mode::UserChecked ) ); @@ -100,18 +102,20 @@ void FinishedPage::setUpRestart() { cDebug() << "FinishedPage::setUpRestart(), Quit button" - << "setup=" << m_restartSetUp + << "setup=" << FinishedViewStep::modeName( m_mode ) << "command=" << m_restartNowCommand; - if ( !m_restartSetUp ) - { - connect( qApp, &QApplication::aboutToQuit, - this, [this] - { - if ( ui->restartCheckBox->isVisible() && - ui->restartCheckBox->isChecked() ) - QProcess::execute( "/bin/sh", { "-c", m_restartNowCommand } ); - } ); - } + + connect( qApp, &QApplication::aboutToQuit, + [this]() + { + if ( ui->restartCheckBox->isVisible() && + ui->restartCheckBox->isChecked() ) + { + cDebug() << "Running restart command" << m_restartNowCommand; + QProcess::execute( "/bin/sh", { "-c", m_restartNowCommand } ); + } + } + ); } diff --git a/src/modules/finished/FinishedPage.h b/src/modules/finished/FinishedPage.h index 9954e6fa0..25b776ead 100644 --- a/src/modules/finished/FinishedPage.h +++ b/src/modules/finished/FinishedPage.h @@ -49,9 +49,8 @@ protected: private: Ui::FinishedPage* ui; + FinishedViewStep::RestartMode m_mode; QString m_restartNowCommand; - - bool m_restartSetUp; }; #endif // FINISHEDPAGE_H diff --git a/src/modules/finished/FinishedViewStep.cpp b/src/modules/finished/FinishedViewStep.cpp index 16b1de7eb..f5c0935c3 100644 --- a/src/modules/finished/FinishedViewStep.cpp +++ b/src/modules/finished/FinishedViewStep.cpp @@ -210,4 +210,11 @@ FinishedViewStep::setConfigurationMap( const QVariantMap& configurationMap ) 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(); ) diff --git a/src/modules/finished/FinishedViewStep.h b/src/modules/finished/FinishedViewStep.h index 02ba6ef83..7b3881099 100644 --- a/src/modules/finished/FinishedViewStep.h +++ b/src/modules/finished/FinishedViewStep.h @@ -41,6 +41,8 @@ public: UserChecked, ///< @brief Show button, starts 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 ); virtual ~FinishedViewStep() override; From 95009a5222bf5a689580948d20f0473e134ae308 Mon Sep 17 00:00:00 2001 From: Adriaan de Groot Date: Tue, 28 May 2019 13:38:28 +0200 Subject: [PATCH 4/4] [libcalamaresui] Fix disable-cancel behavior - d78bc0c5 added an early `return false` when cancel is disabled, before checking if we were at the last step; so last-step didn't get any special handling. - refactor so that last-step now gets special handling first, **then** disable-cancel handling, and then the usual case. --- src/libcalamaresui/ViewManager.cpp | 65 +++++++++++++++--------------- 1 file changed, 32 insertions(+), 33 deletions(-) diff --git a/src/libcalamaresui/ViewManager.cpp b/src/libcalamaresui/ViewManager.cpp index bc782c1c5..508581b4e 100644 --- a/src/libcalamaresui/ViewManager.cpp +++ b/src/libcalamaresui/ViewManager.cpp @@ -228,16 +228,16 @@ ViewManager::currentStepIndex() const } /** @brief Is the given step at @p index an execution step? - * + * * Returns true if the step is an execution step, false otherwise. * Also returns false if the @p index is out of range. */ static inline bool stepIsExecute( const ViewStepList& steps, int index ) { - return + return ( 0 <= index ) && - ( index < steps.count() ) && + ( index < steps.count() ) && ( qobject_cast< ExecutionViewStep* >( steps.at( index ) ) != nullptr ); } @@ -249,7 +249,7 @@ ViewManager::next() if ( step->isAtEnd() ) { const auto* const settings = Calamares::Settings::instance(); - + // 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. @@ -303,7 +303,7 @@ void ViewManager::updateButtonLabels() { const auto* const settings = Calamares::Settings::instance(); - + QString next = settings->isSetupMode() ? tr( "&Set up" ) : tr( "&Install" ); @@ -332,7 +332,7 @@ ViewManager::updateButtonLabels() if ( settings->disableCancel() ) m_quit->setVisible( false ); // In case we went back from final updateCancelEnabled( !settings->disableCancel() && !( stepIsExecute( m_steps, m_currentStep ) && settings->disableCancelDuringExec() ) ); - + m_quit->setText( tr( "&Cancel" ) ); m_quit->setToolTip( quit ); } @@ -366,37 +366,36 @@ ViewManager::back() bool ViewManager::confirmCancelInstallation() { 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() ) return false; if ( settings->disableCancelDuringExec() && stepIsExecute( m_steps, m_currentStep ) ) return false; - - // If it's NOT the last page of the last step, we ask for confirmation - if ( !( m_currentStep == m_steps.count() -1 && - m_steps.last()->isAtEnd() ) ) - { - QString title = settings->isSetupMode() - ? tr( "Cancel setup?" ) - : tr( "Cancel installation?" ); - QString question = settings->isSetupMode() - ? tr( "Do you really want to cancel the current setup process?\n" - "The setup program will quit and all changes will be lost." ) - : tr( "Do you really want to cancel the current install process?\n" - "The installer will quit and all changes will be lost." ); - QMessageBox mb( QMessageBox::Question, - title, - question, - QMessageBox::Yes | QMessageBox::No, - m_widget ); - mb.setDefaultButton( QMessageBox::No ); - mb.button( QMessageBox::Yes )->setText( tr( "&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; + + // Otherwise, confirm cancel/quit. + QString title = settings->isSetupMode() + ? tr( "Cancel setup?" ) + : tr( "Cancel installation?" ); + QString question = settings->isSetupMode() + ? tr( "Do you really want to cancel the current setup process?\n" + "The setup program will quit and all changes will be lost." ) + : tr( "Do you really want to cancel the current install process?\n" + "The installer will quit and all changes will be lost." ); + QMessageBox mb( QMessageBox::Question, + title, + question, + QMessageBox::Yes | QMessageBox::No, + m_widget ); + mb.setDefaultButton( QMessageBox::No ); + mb.button( QMessageBox::Yes )->setText( tr( "&Yes" ) ); + mb.button( QMessageBox::No )->setText( tr( "&No" ) ); + int response = mb.exec(); + return response == QMessageBox::Yes; } void