diff --git a/src/modules/finished/FinishedPage.cpp b/src/modules/finished/FinishedPage.cpp index 4bffa8221..e2ad4a24f 100644 --- a/src/modules/finished/FinishedPage.cpp +++ b/src/modules/finished/FinishedPage.cpp @@ -20,12 +20,12 @@ #include "FinishedPage.h" -#include "ui_FinishedPage.h" #include "CalamaresVersion.h" -#include "utils/Logger.h" +#include "ViewManager.h" +#include "ui_FinishedPage.h" #include "utils/CalamaresUtilsGui.h" +#include "utils/Logger.h" #include "utils/Retranslator.h" -#include "ViewManager.h" #include #include @@ -48,33 +48,29 @@ FinishedPage::FinishedPage( QWidget* parent ) ui->mainText->setOpenExternalLinks( true ); CALAMARES_RETRANSLATE( - ui->retranslateUi( this ); - if ( Calamares::Settings::instance()->isSetupMode() ) - { + const auto* branding = Calamares::Branding::instance(); ui->retranslateUi( this ); + if ( Calamares::Settings::instance()->isSetupMode() ) { ui->mainText->setText( tr( "

All done.


" "%1 has been set up on your computer.
" "You may now start using your new system." ) - .arg( *Calamares::Branding::VersionedName ) ); - ui->restartCheckBox->setToolTip( tr ( "" - "

When this box is checked, your system will " - "restart immediately when you click on " - "Done " - "or close the setup program.

" ) ); - } - else - { + .arg( branding->versionedName() ) ); + ui->restartCheckBox->setToolTip( tr( "" + "

When this box is checked, your system will " + "restart immediately when you click on " + "Done " + "or close the setup program.

" ) ); + } else { ui->mainText->setText( tr( "

All done.


" "%1 has been installed on your computer.
" "You may now restart into your new system, or continue " "using the %2 Live environment." ) - .arg( *Calamares::Branding::VersionedName, *Calamares::Branding::ProductName ) ); - ui->restartCheckBox->setToolTip( tr ( "" - "

When this box is checked, your system will " - "restart immediately when you click on " - "Done " - "or close the installer.

" ) ); - } - ) + .arg( branding->versionedName(), branding->productName() ) ); + ui->restartCheckBox->setToolTip( tr( "" + "

When this box is checked, your system will " + "restart immediately when you click on " + "Done " + "or close the installer.

" ) ); + } ) } @@ -102,20 +98,15 @@ void FinishedPage::setUpRestart() { cDebug() << "FinishedPage::setUpRestart(), Quit button" - << "setup=" << FinishedViewStep::modeName( m_mode ) - << "command=" << 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 } ); - } - } - ); + << "setup=" << FinishedViewStep::modeName( m_mode ) << "command=" << 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 } ); + } + } ); } @@ -128,18 +119,19 @@ FinishedPage::focusInEvent( QFocusEvent* e ) void FinishedPage::onInstallationFailed( const QString& message, const QString& details ) { + const auto* branding = Calamares::Branding::instance(); Q_UNUSED( details ) if ( Calamares::Settings::instance()->isSetupMode() ) ui->mainText->setText( tr( "

Setup Failed


" "%1 has not been set up on your computer.
" "The error message was: %2." ) - .arg( *Calamares::Branding::VersionedName ) - .arg( message ) ); + .arg( branding->versionedName() ) + .arg( message ) ); else ui->mainText->setText( tr( "

Installation Failed


" "%1 has not been installed on your computer.
" "The error message was: %2." ) - .arg( *Calamares::Branding::VersionedName ) - .arg( message ) ); + .arg( branding->versionedName() ) + .arg( message ) ); setRestart( FinishedViewStep::RestartMode::Never ); } diff --git a/src/modules/finished/FinishedPage.h b/src/modules/finished/FinishedPage.h index 25b776ead..40f437e07 100644 --- a/src/modules/finished/FinishedPage.h +++ b/src/modules/finished/FinishedPage.h @@ -44,7 +44,7 @@ public slots: void onInstallationFailed( const QString& message, const QString& details ); protected: - void focusInEvent( QFocusEvent* e ) override; //choose the child widget to focus + void focusInEvent( QFocusEvent* e ) override; //choose the child widget to focus private: Ui::FinishedPage* ui; @@ -53,4 +53,4 @@ private: QString m_restartNowCommand; }; -#endif // FINISHEDPAGE_H +#endif // FINISHEDPAGE_H diff --git a/src/modules/finished/FinishedViewStep.cpp b/src/modules/finished/FinishedViewStep.cpp index f5c0935c3..7e4cf1c6b 100644 --- a/src/modules/finished/FinishedViewStep.cpp +++ b/src/modules/finished/FinishedViewStep.cpp @@ -29,22 +29,20 @@ #include "utils/NamedEnum.h" #include "utils/Variant.h" +#include #include #include #include -#include static const NamedEnumTable< FinishedViewStep::RestartMode >& modeNames() { using Mode = FinishedViewStep::RestartMode; - static const NamedEnumTable< Mode > names{ - { QStringLiteral( "never" ), Mode::Never }, - { QStringLiteral( "user-unchecked" ), Mode::UserUnchecked }, - { QStringLiteral( "user-checked" ), Mode::UserChecked }, - { QStringLiteral( "always" ), Mode::Always } - } ; + static const NamedEnumTable< Mode > names { { QStringLiteral( "never" ), Mode::Never }, + { QStringLiteral( "user-unchecked" ), Mode::UserUnchecked }, + { QStringLiteral( "user-checked" ), Mode::UserChecked }, + { QStringLiteral( "always" ), Mode::Always } }; return names; } @@ -56,10 +54,8 @@ FinishedViewStep::FinishedViewStep( QObject* parent ) , m_notifyOnFinished( false ) { auto jq = Calamares::JobQueue::instance(); - connect( jq, &Calamares::JobQueue::failed, - m_widget, &FinishedPage::onInstallationFailed ); - connect( jq, &Calamares::JobQueue::failed, - this, &FinishedViewStep::onInstallationFailed ); + connect( jq, &Calamares::JobQueue::failed, m_widget, &FinishedPage::onInstallationFailed ); + connect( jq, &Calamares::JobQueue::failed, this, &FinishedViewStep::onInstallationFailed ); emit nextStatusChanged( true ); } @@ -68,7 +64,9 @@ FinishedViewStep::FinishedViewStep( QObject* parent ) FinishedViewStep::~FinishedViewStep() { if ( m_widget && m_widget->parent() == nullptr ) + { m_widget->deleteLater(); + } } @@ -119,30 +117,36 @@ FinishedViewStep::sendNotification() // If the installation failed, don't send notification popup; // there's a (modal) dialog popped up with the failure notice. if ( installFailed ) + { return; + } - QDBusInterface notify( "org.freedesktop.Notifications", "/org/freedesktop/Notifications", "org.freedesktop.Notifications" ); + QDBusInterface notify( + "org.freedesktop.Notifications", "/org/freedesktop/Notifications", "org.freedesktop.Notifications" ); if ( notify.isValid() ) { - QDBusReply r = notify.call( "Notify", - QString( "Calamares" ), - QVariant( 0U ), - QString( "calamares" ), - Calamares::Settings::instance()->isSetupMode() - ? tr( "Setup Complete" ) - : tr( "Installation Complete" ), - Calamares::Settings::instance()->isSetupMode() - ? tr( "The setup of %1 is complete." ).arg( *Calamares::Branding::VersionedName ) - : tr( "The installation of %1 is complete." ).arg( *Calamares::Branding::VersionedName ), - QStringList(), - QVariantMap(), - QVariant( 0 ) - ); + const auto* branding = Calamares::Branding::instance(); + QDBusReply< uint > r = notify.call( + "Notify", + QString( "Calamares" ), + QVariant( 0U ), + QString( "calamares" ), + Calamares::Settings::instance()->isSetupMode() ? tr( "Setup Complete" ) : tr( "Installation Complete" ), + Calamares::Settings::instance()->isSetupMode() + ? tr( "The setup of %1 is complete." ).arg( branding->versionedName() ) + : tr( "The installation of %1 is complete." ).arg( branding->versionedName() ), + QStringList(), + QVariantMap(), + QVariant( 0 ) ); if ( !r.isValid() ) + { cWarning() << "Could not call org.freedesktop.Notifications.Notify at end of installation." << r.error(); + } } else + { cWarning() << "Could not get dbus interface for notifications at end of installation." << notify.lastError(); + } } @@ -152,7 +156,9 @@ FinishedViewStep::onActivate() m_widget->setUpRestart(); if ( m_notifyOnFinished ) + { sendNotification(); + } } @@ -179,22 +185,30 @@ FinishedViewStep::setConfigurationMap( const QVariantMap& configurationMap ) if ( restartMode.isEmpty() ) { if ( configurationMap.contains( "restartNowEnabled" ) ) + { cWarning() << "Configuring the finished module with deprecated restartNowEnabled settings"; + } bool restartNowEnabled = CalamaresUtils::getBool( configurationMap, "restartNowEnabled", false ); bool restartNowChecked = CalamaresUtils::getBool( configurationMap, "restartNowChecked", false ); if ( !restartNowEnabled ) + { mode = RestartMode::Never; + } else + { mode = restartNowChecked ? RestartMode::UserChecked : RestartMode::UserUnchecked; + } } else { bool ok = false; mode = modeNames().find( restartMode, ok ); if ( !ok ) + { cWarning() << "Configuring the finished module with bad restartNowMode" << restartMode; + } } m_widget->setRestart( mode ); @@ -203,18 +217,21 @@ FinishedViewStep::setConfigurationMap( const QVariantMap& configurationMap ) { QString restartNowCommand = CalamaresUtils::getString( configurationMap, "restartNowCommand" ); if ( restartNowCommand.isEmpty() ) + { restartNowCommand = QStringLiteral( "shutdown -r now" ); + } m_widget->setRestartNowCommand( restartNowCommand ); } m_notifyOnFinished = CalamaresUtils::getBool( configurationMap, "notifyOnFinished", false ); } -QString FinishedViewStep::modeName(FinishedViewStep::RestartMode m) +QString +FinishedViewStep::modeName( FinishedViewStep::RestartMode m ) { bool ok = false; return modeNames().find( m, ok ); // May be QString() } -CALAMARES_PLUGIN_FACTORY_DEFINITION( FinishedViewStepFactory, registerPlugin(); ) +CALAMARES_PLUGIN_FACTORY_DEFINITION( FinishedViewStepFactory, registerPlugin< FinishedViewStep >(); ) diff --git a/src/modules/finished/FinishedViewStep.h b/src/modules/finished/FinishedViewStep.h index 2df37e9b6..8f57d0210 100644 --- a/src/modules/finished/FinishedViewStep.h +++ b/src/modules/finished/FinishedViewStep.h @@ -36,10 +36,10 @@ class PLUGINDLLEXPORT FinishedViewStep : public Calamares::ViewStep public: enum class RestartMode { - Never=0, ///< @brief Don't show button, just exit - UserUnchecked, ///< @brief Show button, starts unchecked - UserChecked, ///< @brief Show button, starts checked - Always ///< @brief Show button, can't change, checked + Never = 0, ///< @brief Don't show button, just exit + UserUnchecked, ///< @brief Show button, starts unchecked + 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 );