From d78bc0c5c536117f0b2b36339c3752854013add2 Mon Sep 17 00:00:00 2001 From: Adriaan de Groot Date: Tue, 14 May 2019 13:04:24 +0200 Subject: [PATCH 1/8] [libcalamaresui] When disable-cancel is on, never confirm - This function is also reached by clicking the window-close decoration. --- src/libcalamaresui/ViewManager.cpp | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/src/libcalamaresui/ViewManager.cpp b/src/libcalamaresui/ViewManager.cpp index 9da71f85f..49ecfb9ad 100644 --- a/src/libcalamaresui/ViewManager.cpp +++ b/src/libcalamaresui/ViewManager.cpp @@ -364,14 +364,19 @@ ViewManager::back() bool ViewManager::confirmCancelInstallation() { + const auto* const settings = Calamares::Settings::instance(); + + if ( settings->disableCancel() ) + 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 = Calamares::Settings::instance()->isSetupMode() + QString title = settings->isSetupMode() ? tr( "Cancel setup?" ) : tr( "Cancel installation?" ); - QString question = Calamares::Settings::instance()->isSetupMode() + 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" From 58686571018da86108256ec4dc182ee70be00f40 Mon Sep 17 00:00:00 2001 From: Adriaan de Groot Date: Tue, 14 May 2019 13:06:54 +0200 Subject: [PATCH 2/8] [calamares] Hide the window-close decoration when disable-cancel is set --- src/calamares/CalamaresWindow.cpp | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/calamares/CalamaresWindow.cpp b/src/calamares/CalamaresWindow.cpp index 157941a90..6f851513c 100644 --- a/src/calamares/CalamaresWindow.cpp +++ b/src/calamares/CalamaresWindow.cpp @@ -56,6 +56,10 @@ CalamaresWindow::CalamaresWindow( QWidget* parent ) , m_debugWindow( nullptr ) , m_viewManager( nullptr ) { + // If we can never cancel, don't show the window-close button + if ( Calamares::Settings::instance()->disableCancel() ) + setWindowFlags( Qt::Window | Qt::WindowTitleHint | Qt::CustomizeWindowHint ); + CALAMARES_RETRANSLATE( setWindowTitle( Calamares::Settings::instance()->isSetupMode() ? tr( "%1 Setup Program" ).arg( *Calamares::Branding::ProductName ) From 25099ae854aa3047d650e296b043b46d90ace946 Mon Sep 17 00:00:00 2001 From: Adriaan de Groot Date: Tue, 14 May 2019 13:10:36 +0200 Subject: [PATCH 3/8] [libcalamaresui] Remove duplicate setEnabled - If executing is set to true, then later setEnabled( !executing && ... ) fill be false, so we don't need to call setEnabled( false ) here as well. --- src/libcalamaresui/ViewManager.cpp | 4 ---- 1 file changed, 4 deletions(-) diff --git a/src/libcalamaresui/ViewManager.cpp b/src/libcalamaresui/ViewManager.cpp index 49ecfb9ad..4a2f62154 100644 --- a/src/libcalamaresui/ViewManager.cpp +++ b/src/libcalamaresui/ViewManager.cpp @@ -281,12 +281,8 @@ ViewManager::next() executing = qobject_cast< ExecutionViewStep* >( m_steps.at( m_currentStep ) ) != nullptr; emit currentStepChanged(); if ( executing ) - { - m_back->setEnabled( false ); - m_next->setEnabled( false ); // 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() ); From ad4352b65c6ddde04b5ea995e1f23186fe40467e Mon Sep 17 00:00:00 2001 From: Adriaan de Groot Date: Tue, 14 May 2019 13:18:51 +0200 Subject: [PATCH 4/8] [libcalamaresui] Make stepIsExecute() more general - Checking if the **next** step is an execute-step is a little weird, so make the API more general (and add the +1 to indexes where it was using NextWillExecute before). --- src/libcalamaresui/ViewManager.cpp | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/src/libcalamaresui/ViewManager.cpp b/src/libcalamaresui/ViewManager.cpp index 4a2f62154..3777ff9c1 100644 --- a/src/libcalamaresui/ViewManager.cpp +++ b/src/libcalamaresui/ViewManager.cpp @@ -227,10 +227,18 @@ ViewManager::currentStepIndex() const return m_currentStep; } +/** @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 -stepNextWillExecute(const ViewStepList& steps, int index) +stepIsExecute( const ViewStepList& steps, int index ) { - return ( index + 1 < steps.count() ) && qobject_cast< ExecutionViewStep* >( steps.at( index + 1 ) ); + return + ( 0 <= index ) && + ( index < steps.count() ) && + ( qobject_cast< ExecutionViewStep* >( steps.at( index ) ) != nullptr ); } void @@ -245,7 +253,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 ( settings->showPromptBeforeExecution() && stepNextWillExecute( m_steps, m_currentStep ) ) + if ( settings->showPromptBeforeExecution() && stepIsExecute( m_steps, m_currentStep+1 ) ) { QString title = settings->isSetupMode() ? tr( "Continue with setup?" ) @@ -309,7 +317,8 @@ ViewManager::updateButtonLabels() ? tr( "Cancel setup without changing the system." ) : tr( "Cancel installation without changing the system." ); - if ( stepNextWillExecute( m_steps, m_currentStep ) ) + // If we're going into the execution step / install phase, other message + if ( stepIsExecute( m_steps, m_currentStep+1 ) ) m_next->setText( next ); else m_next->setText( tr( "&Next" ) ); From 088fa5004cc5219f9c0b98d28bc474021ab77cff Mon Sep 17 00:00:00 2001 From: Adriaan de Groot Date: Tue, 14 May 2019 13:21:05 +0200 Subject: [PATCH 5/8] [libcalamaresui] Disallow closing the window during execution - If the disable-cancel-during-exec setting is on, and the user clicks the window-close button, then disregard the close message. --- src/libcalamaresui/ViewManager.cpp | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/libcalamaresui/ViewManager.cpp b/src/libcalamaresui/ViewManager.cpp index 3777ff9c1..817ee346f 100644 --- a/src/libcalamaresui/ViewManager.cpp +++ b/src/libcalamaresui/ViewManager.cpp @@ -373,6 +373,8 @@ bool ViewManager::confirmCancelInstallation() if ( settings->disableCancel() ) return false; + if ( settings->dontCancel() && 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 && From d4f4a40fa5f9dda75cbb26281ce1c7aac39ed3eb Mon Sep 17 00:00:00 2001 From: Adriaan de Groot Date: Tue, 14 May 2019 13:34:14 +0200 Subject: [PATCH 6/8] [libcalamaresui] Refactor quit-enabling - Add signal for change-of-quit-enabledness - Minor tidying --- src/libcalamaresui/ViewManager.cpp | 33 ++++++++++++++++-------------- src/libcalamaresui/ViewManager.h | 4 +++- 2 files changed, 21 insertions(+), 16 deletions(-) diff --git a/src/libcalamaresui/ViewManager.cpp b/src/libcalamaresui/ViewManager.cpp index 817ee346f..450fa18a7 100644 --- a/src/libcalamaresui/ViewManager.cpp +++ b/src/libcalamaresui/ViewManager.cpp @@ -288,12 +288,7 @@ ViewManager::next() m_steps.at( m_currentStep )->onActivate(); executing = qobject_cast< ExecutionViewStep* >( m_steps.at( m_currentStep ) ) != nullptr; emit currentStepChanged(); - if ( executing ) - // 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() ); + updateCancelEnabled( !settings->disableCancel() && !(executing && settings->dontCancel() ) ); } else step->next(); @@ -307,13 +302,15 @@ ViewManager::next() void ViewManager::updateButtonLabels() { - QString next = Calamares::Settings::instance()->isSetupMode() + const auto* const settings = Calamares::Settings::instance(); + + QString next = settings->isSetupMode() ? tr( "&Set up" ) : tr( "&Install" ); - QString complete = Calamares::Settings::instance()->isSetupMode() + QString complete = settings->isSetupMode() ? tr( "Setup is complete. Close the setup program." ) : 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 installation without changing the system." ); @@ -328,15 +325,14 @@ ViewManager::updateButtonLabels() m_quit->setText( tr( "&Done" ) ); m_quit->setToolTip( complete ); m_quit->setVisible( true ); // At end, always visible and enabled. - m_quit->setEnabled( true ); + updateCancelEnabled( true ); } else { - if ( Calamares::Settings::instance()->disableCancel() ) - { - m_quit->setVisible( false ); - m_quit->setEnabled( false ); // Can't be triggered through DBUS - } + if ( settings->disableCancel() ) + m_quit->setVisible( false ); // In case we went back from final + updateCancelEnabled( !settings->disableCancel() && !( stepIsExecute( m_steps, m_currentStep ) && settings->dontCancel() ) ); + m_quit->setText( tr( "&Cancel" ) ); m_quit->setToolTip( quit ); } @@ -403,4 +399,11 @@ bool ViewManager::confirmCancelInstallation() return true; } +void +ViewManager::updateCancelEnabled( bool enabled ) +{ + m_quit->setEnabled( enabled ); + emit cancelEnabled( enabled ); +} + } // namespace diff --git a/src/libcalamaresui/ViewManager.h b/src/libcalamaresui/ViewManager.h index 65d787e44..50e8d1dc4 100644 --- a/src/libcalamaresui/ViewManager.h +++ b/src/libcalamaresui/ViewManager.h @@ -121,6 +121,7 @@ public slots: signals: void currentStepChanged(); void enlarge( QSize enlarge ) const; // See ViewStep::enlarge() + void cancelEnabled( bool enabled ) const; private: explicit ViewManager( QObject* parent = nullptr ); @@ -128,7 +129,8 @@ private: void insertViewStep( int before, ViewStep* step ); void updateButtonLabels(); - + void updateCancelEnabled( bool enabled ); + static ViewManager* s_instance; ViewStepList m_steps; From 2208ff95fe45fbdd7b510f97bbcfbaff95661e61 Mon Sep 17 00:00:00 2001 From: Adriaan de Groot Date: Tue, 14 May 2019 14:03:53 +0200 Subject: [PATCH 7/8] [calamares] Simplify disable-window-close-button code --- src/calamares/CalamaresWindow.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/calamares/CalamaresWindow.cpp b/src/calamares/CalamaresWindow.cpp index 6f851513c..b2e09d961 100644 --- a/src/calamares/CalamaresWindow.cpp +++ b/src/calamares/CalamaresWindow.cpp @@ -58,7 +58,7 @@ CalamaresWindow::CalamaresWindow( QWidget* parent ) { // If we can never cancel, don't show the window-close button if ( Calamares::Settings::instance()->disableCancel() ) - setWindowFlags( Qt::Window | Qt::WindowTitleHint | Qt::CustomizeWindowHint ); + setWindowFlag( Qt::WindowCloseButtonHint, false ); CALAMARES_RETRANSLATE( setWindowTitle( Calamares::Settings::instance()->isSetupMode() From a5cba02769bd826a665b796c0b59c639e1fe5824 Mon Sep 17 00:00:00 2001 From: Adriaan de Groot Date: Tue, 14 May 2019 14:07:33 +0200 Subject: [PATCH 8/8] [calamares] Leave a note about changing close-window hint --- src/calamares/CalamaresWindow.cpp | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/src/calamares/CalamaresWindow.cpp b/src/calamares/CalamaresWindow.cpp index b2e09d961..b570a9c86 100644 --- a/src/calamares/CalamaresWindow.cpp +++ b/src/calamares/CalamaresWindow.cpp @@ -165,7 +165,15 @@ CalamaresWindow::CalamaresWindow( QWidget* parent ) m_viewManager = Calamares::ViewManager::instance( this ); if ( branding->windowExpands() ) connect( m_viewManager, &Calamares::ViewManager::enlarge, this, &CalamaresWindow::enlarge ); - + // NOTE: Although the ViewManager has a signal cancelEnabled() that + // signals when the state of the cancel button changes (in + // particular, to disable cancel during the exec phase), + // we don't connect to it here. Changing the window flag + // for the close button causes uncomfortable window flashing + // and requires an extra show() (at least with KWin/X11) which + // is too annoying. Instead, leave it up to ignoring-the-quit- + // event, which is also the ViewManager's responsibility. + mainLayout->addWidget( m_viewManager->centralWidget() ); setStyleSheet( Calamares::Branding::instance()->stylesheet() ); }