Merge branch 'qml-finished' into calamares
This commit is contained in:
commit
d3acc39d2d
@ -11,6 +11,7 @@ calamares_add_plugin( finished
|
|||||||
TYPE viewmodule
|
TYPE viewmodule
|
||||||
EXPORT_MACRO PLUGINDLLEXPORT_PRO
|
EXPORT_MACRO PLUGINDLLEXPORT_PRO
|
||||||
SOURCES
|
SOURCES
|
||||||
|
Config.cpp
|
||||||
FinishedViewStep.cpp
|
FinishedViewStep.cpp
|
||||||
FinishedPage.cpp
|
FinishedPage.cpp
|
||||||
UI
|
UI
|
||||||
|
201
src/modules/finished/Config.cpp
Normal file
201
src/modules/finished/Config.cpp
Normal file
@ -0,0 +1,201 @@
|
|||||||
|
/* === This file is part of Calamares - <https://calamares.io> ===
|
||||||
|
*
|
||||||
|
* SPDX-FileCopyrightText: 2021 Adriaan de Groot <groot@kde.org>
|
||||||
|
* SPDX-License-Identifier: GPL-3.0-or-later
|
||||||
|
*
|
||||||
|
* Calamares is Free Software: see the License-Identifier above.
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include "Config.h"
|
||||||
|
|
||||||
|
#include "Branding.h"
|
||||||
|
#include "Settings.h"
|
||||||
|
#include "utils/Logger.h"
|
||||||
|
#include "utils/Variant.h"
|
||||||
|
|
||||||
|
#include <QProcess>
|
||||||
|
#include <QtDBus/QDBusConnection>
|
||||||
|
#include <QtDBus/QDBusInterface>
|
||||||
|
#include <QtDBus/QDBusReply>
|
||||||
|
|
||||||
|
const NamedEnumTable< Config::RestartMode >&
|
||||||
|
restartModes()
|
||||||
|
{
|
||||||
|
using M = Config::RestartMode;
|
||||||
|
static const NamedEnumTable< M > table { { "never", M::Never },
|
||||||
|
{ "user-unchecked", M::UserDefaultUnchecked },
|
||||||
|
{ "unchecked", M::UserDefaultUnchecked },
|
||||||
|
{ "user-checked", M::UserDefaultChecked },
|
||||||
|
{ "checked", M::UserDefaultChecked },
|
||||||
|
{ "always", M::Always }
|
||||||
|
|
||||||
|
};
|
||||||
|
return table;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
Config::Config( QObject* parent )
|
||||||
|
: QObject( parent )
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
Config::setRestartNowMode( Config::RestartMode m )
|
||||||
|
{
|
||||||
|
// Can only go "down" in state (Always > UserDefaultChecked > .. > Never)
|
||||||
|
if ( m > m_restartNowMode )
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
// If changing to an unconditional mode, also set other flag
|
||||||
|
if ( m == RestartMode::Always || m == RestartMode::Never )
|
||||||
|
{
|
||||||
|
setRestartNowWanted( m == RestartMode::Always );
|
||||||
|
}
|
||||||
|
|
||||||
|
if ( m != m_restartNowMode )
|
||||||
|
{
|
||||||
|
m_restartNowMode = m;
|
||||||
|
emit restartModeChanged( m );
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
Config::setRestartNowWanted( bool w )
|
||||||
|
{
|
||||||
|
// Follow the mode which may affect @p w
|
||||||
|
if ( m_restartNowMode == RestartMode::Always )
|
||||||
|
{
|
||||||
|
w = true;
|
||||||
|
}
|
||||||
|
if ( m_restartNowMode == RestartMode::Never )
|
||||||
|
{
|
||||||
|
w = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
if ( w != m_userWantsRestart )
|
||||||
|
{
|
||||||
|
m_userWantsRestart = w;
|
||||||
|
emit restartNowWantedChanged( w );
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
Config::doRestart()
|
||||||
|
{
|
||||||
|
if ( restartNowMode() != RestartMode::Never && restartNowWanted() )
|
||||||
|
{
|
||||||
|
cDebug() << "Running restart command" << m_restartNowCommand;
|
||||||
|
QProcess::execute( "/bin/sh", { "-c", m_restartNowCommand } );
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void
|
||||||
|
Config::doNotify( bool hasFailed )
|
||||||
|
{
|
||||||
|
if ( !notifyOnFinished() )
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
QDBusInterface notify(
|
||||||
|
"org.freedesktop.Notifications", "/org/freedesktop/Notifications", "org.freedesktop.Notifications" );
|
||||||
|
if ( notify.isValid() )
|
||||||
|
{
|
||||||
|
cDebug() << "Sending notification of completion. Failed?" << hasFailed;
|
||||||
|
|
||||||
|
QString title;
|
||||||
|
QString message;
|
||||||
|
if ( hasFailed )
|
||||||
|
{
|
||||||
|
title = Calamares::Settings::instance()->isSetupMode() ? tr( "Setup Failed" ) : tr( "Installation Failed" );
|
||||||
|
message = Calamares::Settings::instance()->isSetupMode()
|
||||||
|
? tr( "The setup of %1 did not complete successfully." )
|
||||||
|
: tr( "The installation of %1 did not complete successfully." );
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
title = Calamares::Settings::instance()->isSetupMode() ? tr( "Setup Complete" )
|
||||||
|
: tr( "Installation Complete" );
|
||||||
|
message = Calamares::Settings::instance()->isSetupMode() ? tr( "The setup of %1 is complete." )
|
||||||
|
: tr( "The installation of %1 is complete." );
|
||||||
|
}
|
||||||
|
|
||||||
|
const auto* branding = Calamares::Branding::instance();
|
||||||
|
QDBusReply< uint > r = notify.call( "Notify",
|
||||||
|
QString( "Calamares" ),
|
||||||
|
QVariant( 0U ),
|
||||||
|
QString( "calamares" ),
|
||||||
|
title,
|
||||||
|
message.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();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void
|
||||||
|
Config::setConfigurationMap( const QVariantMap& configurationMap )
|
||||||
|
{
|
||||||
|
RestartMode mode = RestartMode::Never;
|
||||||
|
|
||||||
|
//TODO:3.3 remove deprecated restart settings
|
||||||
|
QString restartMode = CalamaresUtils::getString( configurationMap, "restartNowMode" );
|
||||||
|
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::UserDefaultChecked : RestartMode::UserDefaultUnchecked;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
bool ok = false;
|
||||||
|
mode = restartModes().find( restartMode, ok );
|
||||||
|
if ( !ok )
|
||||||
|
{
|
||||||
|
cWarning() << "Configuring the finished module with bad restartNowMode" << restartMode;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
m_restartNowMode = mode;
|
||||||
|
m_userWantsRestart = ( mode == RestartMode::Always || mode == RestartMode::UserDefaultChecked );
|
||||||
|
emit restartModeChanged( m_restartNowMode );
|
||||||
|
emit restartNowWantedChanged( m_userWantsRestart );
|
||||||
|
|
||||||
|
if ( mode != RestartMode::Never )
|
||||||
|
{
|
||||||
|
QString restartNowCommand = CalamaresUtils::getString( configurationMap, "restartNowCommand" );
|
||||||
|
if ( restartNowCommand.isEmpty() )
|
||||||
|
{
|
||||||
|
restartNowCommand = QStringLiteral( "shutdown -r now" );
|
||||||
|
}
|
||||||
|
m_restartNowCommand = restartNowCommand;
|
||||||
|
}
|
||||||
|
|
||||||
|
m_notifyOnFinished = CalamaresUtils::getBool( configurationMap, "notifyOnFinished", false );
|
||||||
|
}
|
81
src/modules/finished/Config.h
Normal file
81
src/modules/finished/Config.h
Normal file
@ -0,0 +1,81 @@
|
|||||||
|
/* === This file is part of Calamares - <https://calamares.io> ===
|
||||||
|
*
|
||||||
|
* SPDX-FileCopyrightText: 2021 Adriaan de Groot <groot@kde.org>
|
||||||
|
* SPDX-License-Identifier: GPL-3.0-or-later
|
||||||
|
*
|
||||||
|
* Calamares is Free Software: see the License-Identifier above.
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifndef FINISHED_CONFIG_H
|
||||||
|
#define FINISHED_CONFIG_H
|
||||||
|
|
||||||
|
#include "utils/NamedEnum.h"
|
||||||
|
|
||||||
|
#include <QObject>
|
||||||
|
|
||||||
|
class Config : public QObject
|
||||||
|
{
|
||||||
|
Q_OBJECT
|
||||||
|
|
||||||
|
Q_PROPERTY( RestartMode restartNowMode READ restartNowMode WRITE setRestartNowMode NOTIFY restartModeChanged )
|
||||||
|
Q_PROPERTY( bool restartNowWanted READ restartNowWanted WRITE setRestartNowWanted NOTIFY restartNowWantedChanged )
|
||||||
|
|
||||||
|
Q_PROPERTY( QString restartNowCommand READ restartNowCommand CONSTANT FINAL )
|
||||||
|
Q_PROPERTY( bool notifyOnFinished READ notifyOnFinished CONSTANT FINAL )
|
||||||
|
|
||||||
|
public:
|
||||||
|
Config( QObject* parent = nullptr );
|
||||||
|
|
||||||
|
enum class RestartMode
|
||||||
|
{
|
||||||
|
Never,
|
||||||
|
UserDefaultUnchecked,
|
||||||
|
UserDefaultChecked,
|
||||||
|
Always
|
||||||
|
};
|
||||||
|
Q_ENUM( RestartMode )
|
||||||
|
|
||||||
|
RestartMode restartNowMode() const { return m_restartNowMode; }
|
||||||
|
bool restartNowWanted() const { return m_userWantsRestart; }
|
||||||
|
|
||||||
|
QString restartNowCommand() const { return m_restartNowCommand; }
|
||||||
|
bool notifyOnFinished() const { return m_notifyOnFinished; }
|
||||||
|
|
||||||
|
void setConfigurationMap( const QVariantMap& configurationMap );
|
||||||
|
|
||||||
|
public slots:
|
||||||
|
void setRestartNowMode( RestartMode m );
|
||||||
|
void setRestartNowWanted( bool w );
|
||||||
|
|
||||||
|
/** @brief Run the restart command, if desired.
|
||||||
|
*
|
||||||
|
* This should generally not be called somewhere during the
|
||||||
|
* application's execution, but only in response to QApplication::quit()
|
||||||
|
* or something like that when the user expects the system to restart.
|
||||||
|
*/
|
||||||
|
void doRestart();
|
||||||
|
|
||||||
|
/** @brief Send DBus notification, if desired.
|
||||||
|
*
|
||||||
|
* This takes notifyOnFinished() into account.
|
||||||
|
*
|
||||||
|
* At the end of installation (when the FinishedViewStep is activated),
|
||||||
|
* send a desktop notification via DBus that the install is done.
|
||||||
|
*/
|
||||||
|
void doNotify( bool hasFailed = false );
|
||||||
|
|
||||||
|
signals:
|
||||||
|
void restartModeChanged( RestartMode m );
|
||||||
|
void restartNowWantedChanged( bool w );
|
||||||
|
|
||||||
|
private:
|
||||||
|
QString m_restartNowCommand;
|
||||||
|
RestartMode m_restartNowMode = RestartMode::Never;
|
||||||
|
bool m_userWantsRestart = false;
|
||||||
|
bool m_notifyOnFinished = false;
|
||||||
|
};
|
||||||
|
|
||||||
|
const NamedEnumTable< Config::RestartMode >& restartModes();
|
||||||
|
|
||||||
|
#endif
|
@ -11,26 +11,19 @@
|
|||||||
|
|
||||||
#include "FinishedPage.h"
|
#include "FinishedPage.h"
|
||||||
|
|
||||||
#include "CalamaresVersion.h"
|
#include "Config.h"
|
||||||
#include "ViewManager.h"
|
|
||||||
#include "ui_FinishedPage.h"
|
#include "ui_FinishedPage.h"
|
||||||
#include "utils/CalamaresUtilsGui.h"
|
|
||||||
#include "utils/Logger.h"
|
|
||||||
#include "utils/Retranslator.h"
|
|
||||||
|
|
||||||
#include <QApplication>
|
|
||||||
#include <QBoxLayout>
|
|
||||||
#include <QFocusEvent>
|
|
||||||
#include <QLabel>
|
|
||||||
#include <QProcess>
|
|
||||||
|
|
||||||
#include "Branding.h"
|
#include "Branding.h"
|
||||||
#include "Settings.h"
|
#include "Settings.h"
|
||||||
|
#include "utils/Retranslator.h"
|
||||||
|
|
||||||
FinishedPage::FinishedPage( QWidget* parent )
|
#include <QFocusEvent>
|
||||||
|
|
||||||
|
|
||||||
|
FinishedPage::FinishedPage( Config* config, QWidget* parent )
|
||||||
: QWidget( parent )
|
: QWidget( parent )
|
||||||
, ui( new Ui::FinishedPage )
|
, ui( new Ui::FinishedPage )
|
||||||
, m_mode( FinishedViewStep::RestartMode::UserUnchecked )
|
|
||||||
{
|
{
|
||||||
ui->setupUi( this );
|
ui->setupUi( this );
|
||||||
|
|
||||||
@ -38,68 +31,19 @@ FinishedPage::FinishedPage( QWidget* parent )
|
|||||||
ui->mainText->setWordWrap( true );
|
ui->mainText->setWordWrap( true );
|
||||||
ui->mainText->setOpenExternalLinks( true );
|
ui->mainText->setOpenExternalLinks( true );
|
||||||
|
|
||||||
CALAMARES_RETRANSLATE(
|
connect( config, &Config::restartModeChanged, [this]( Config::RestartMode mode ) {
|
||||||
const auto* branding = Calamares::Branding::instance(); ui->retranslateUi( this );
|
using Mode = Config::RestartMode;
|
||||||
if ( Calamares::Settings::instance()->isSetupMode() ) {
|
|
||||||
ui->mainText->setText( tr( "<h1>All done.</h1><br/>"
|
|
||||||
"%1 has been set up on your computer.<br/>"
|
|
||||||
"You may now start using your new system." )
|
|
||||||
.arg( branding->versionedName() ) );
|
|
||||||
ui->restartCheckBox->setToolTip( tr( "<html><head/><body>"
|
|
||||||
"<p>When this box is checked, your system will "
|
|
||||||
"restart immediately when you click on "
|
|
||||||
"<span style=\"font-style:italic;\">Done</span> "
|
|
||||||
"or close the setup program.</p></body></html>" ) );
|
|
||||||
} else {
|
|
||||||
ui->mainText->setText( tr( "<h1>All done.</h1><br/>"
|
|
||||||
"%1 has been installed on your computer.<br/>"
|
|
||||||
"You may now restart into your new system, or continue "
|
|
||||||
"using the %2 Live environment." )
|
|
||||||
.arg( branding->versionedName(), branding->productName() ) );
|
|
||||||
ui->restartCheckBox->setToolTip( tr( "<html><head/><body>"
|
|
||||||
"<p>When this box is checked, your system will "
|
|
||||||
"restart immediately when you click on "
|
|
||||||
"<span style=\"font-style:italic;\">Done</span> "
|
|
||||||
"or close the installer.</p></body></html>" ) );
|
|
||||||
} )
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
void
|
|
||||||
FinishedPage::setRestart( FinishedViewStep::RestartMode mode )
|
|
||||||
{
|
|
||||||
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 ) );
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
void
|
|
||||||
FinishedPage::setRestartNowCommand( const QString& command )
|
|
||||||
{
|
|
||||||
m_restartNowCommand = command;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
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 } );
|
|
||||||
}
|
|
||||||
} );
|
} );
|
||||||
}
|
connect( config, &Config::restartNowWantedChanged, ui->restartCheckBox, &QCheckBox::setChecked );
|
||||||
|
connect( ui->restartCheckBox, &QCheckBox::stateChanged, [config]( int state ) {
|
||||||
|
config->setRestartNowWanted( state != 0 );
|
||||||
|
} );
|
||||||
|
|
||||||
|
CALAMARES_RETRANSLATE_SLOT( &FinishedPage::retranslate );
|
||||||
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
FinishedPage::focusInEvent( QFocusEvent* e )
|
FinishedPage::focusInEvent( QFocusEvent* e )
|
||||||
@ -110,19 +54,64 @@ FinishedPage::focusInEvent( QFocusEvent* e )
|
|||||||
void
|
void
|
||||||
FinishedPage::onInstallationFailed( const QString& message, const QString& details )
|
FinishedPage::onInstallationFailed( const QString& message, const QString& details )
|
||||||
{
|
{
|
||||||
|
m_failure = !message.isEmpty() ? message : details;
|
||||||
|
retranslate();
|
||||||
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
FinishedPage::retranslate()
|
||||||
|
{
|
||||||
|
|
||||||
const auto* branding = Calamares::Branding::instance();
|
const auto* branding = Calamares::Branding::instance();
|
||||||
Q_UNUSED( details )
|
|
||||||
|
ui->retranslateUi( this );
|
||||||
|
if ( !m_failure.has_value() )
|
||||||
|
{
|
||||||
if ( Calamares::Settings::instance()->isSetupMode() )
|
if ( Calamares::Settings::instance()->isSetupMode() )
|
||||||
|
{
|
||||||
|
ui->mainText->setText( tr( "<h1>All done.</h1><br/>"
|
||||||
|
"%1 has been set up on your computer.<br/>"
|
||||||
|
"You may now start using your new system." )
|
||||||
|
.arg( branding->versionedName() ) );
|
||||||
|
ui->restartCheckBox->setToolTip( tr( "<html><head/><body>"
|
||||||
|
"<p>When this box is checked, your system will "
|
||||||
|
"restart immediately when you click on "
|
||||||
|
"<span style=\"font-style:italic;\">Done</span> "
|
||||||
|
"or close the setup program.</p></body></html>" ) );
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
ui->mainText->setText( tr( "<h1>All done.</h1><br/>"
|
||||||
|
"%1 has been installed on your computer.<br/>"
|
||||||
|
"You may now restart into your new system, or continue "
|
||||||
|
"using the %2 Live environment." )
|
||||||
|
.arg( branding->versionedName(), branding->productName() ) );
|
||||||
|
ui->restartCheckBox->setToolTip( tr( "<html><head/><body>"
|
||||||
|
"<p>When this box is checked, your system will "
|
||||||
|
"restart immediately when you click on "
|
||||||
|
"<span style=\"font-style:italic;\">Done</span> "
|
||||||
|
"or close the installer.</p></body></html>" ) );
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
const QString message = m_failure.value();
|
||||||
|
|
||||||
|
if ( Calamares::Settings::instance()->isSetupMode() )
|
||||||
|
{
|
||||||
ui->mainText->setText( tr( "<h1>Setup Failed</h1><br/>"
|
ui->mainText->setText( tr( "<h1>Setup Failed</h1><br/>"
|
||||||
"%1 has not been set up on your computer.<br/>"
|
"%1 has not been set up on your computer.<br/>"
|
||||||
"The error message was: %2." )
|
"The error message was: %2." )
|
||||||
.arg( branding->versionedName() )
|
.arg( branding->versionedName() )
|
||||||
.arg( message ) );
|
.arg( message ) );
|
||||||
|
}
|
||||||
else
|
else
|
||||||
|
{
|
||||||
ui->mainText->setText( tr( "<h1>Installation Failed</h1><br/>"
|
ui->mainText->setText( tr( "<h1>Installation Failed</h1><br/>"
|
||||||
"%1 has not been installed on your computer.<br/>"
|
"%1 has not been installed on your computer.<br/>"
|
||||||
"The error message was: %2." )
|
"The error message was: %2." )
|
||||||
.arg( branding->versionedName() )
|
.arg( branding->versionedName() )
|
||||||
.arg( message ) );
|
.arg( message ) );
|
||||||
setRestart( FinishedViewStep::RestartMode::Never );
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -11,10 +11,12 @@
|
|||||||
#ifndef FINISHEDPAGE_H
|
#ifndef FINISHEDPAGE_H
|
||||||
#define FINISHEDPAGE_H
|
#define FINISHEDPAGE_H
|
||||||
|
|
||||||
|
|
||||||
#include <QWidget>
|
#include <QWidget>
|
||||||
|
|
||||||
#include "FinishedViewStep.h"
|
#include <optional>
|
||||||
|
|
||||||
|
class Config;
|
||||||
namespace Ui
|
namespace Ui
|
||||||
{
|
{
|
||||||
class FinishedPage;
|
class FinishedPage;
|
||||||
@ -24,24 +26,19 @@ class FinishedPage : public QWidget
|
|||||||
{
|
{
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
public:
|
public:
|
||||||
explicit FinishedPage( QWidget* parent = nullptr );
|
explicit FinishedPage( Config* config, QWidget* parent = nullptr );
|
||||||
|
|
||||||
void setRestart( FinishedViewStep::RestartMode mode );
|
|
||||||
void setRestartNowCommand( const QString& command );
|
|
||||||
|
|
||||||
void setUpRestart();
|
|
||||||
|
|
||||||
public slots:
|
public slots:
|
||||||
void onInstallationFailed( const QString& message, const QString& details );
|
void onInstallationFailed( const QString& message, const QString& details );
|
||||||
|
void retranslate();
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
void focusInEvent( QFocusEvent* e ) override; //choose the child widget to focus
|
void focusInEvent( QFocusEvent* e ) override; //choose the child widget to focus
|
||||||
|
|
||||||
private:
|
private:
|
||||||
Ui::FinishedPage* ui;
|
Ui::FinishedPage* ui;
|
||||||
|
std::optional< QString > m_failure;
|
||||||
FinishedViewStep::RestartMode m_mode;
|
|
||||||
QString m_restartNowCommand;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // FINISHEDPAGE_H
|
#endif // FINISHEDPAGE_H
|
||||||
|
@ -10,42 +10,21 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
#include "FinishedViewStep.h"
|
#include "FinishedViewStep.h"
|
||||||
|
|
||||||
|
#include "Config.h"
|
||||||
#include "FinishedPage.h"
|
#include "FinishedPage.h"
|
||||||
|
|
||||||
#include "Branding.h"
|
|
||||||
#include "JobQueue.h"
|
#include "JobQueue.h"
|
||||||
#include "Settings.h"
|
|
||||||
|
|
||||||
#include "utils/Logger.h"
|
#include <QApplication>
|
||||||
#include "utils/NamedEnum.h"
|
|
||||||
#include "utils/Variant.h"
|
|
||||||
|
|
||||||
#include <QVariantMap>
|
|
||||||
#include <QtDBus/QDBusConnection>
|
|
||||||
#include <QtDBus/QDBusInterface>
|
|
||||||
#include <QtDBus/QDBusReply>
|
|
||||||
|
|
||||||
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 } };
|
|
||||||
|
|
||||||
return names;
|
|
||||||
}
|
|
||||||
|
|
||||||
FinishedViewStep::FinishedViewStep( QObject* parent )
|
FinishedViewStep::FinishedViewStep( QObject* parent )
|
||||||
: Calamares::ViewStep( parent )
|
: Calamares::ViewStep( parent )
|
||||||
, m_widget( new FinishedPage() )
|
, m_config( new Config( this ) )
|
||||||
, installFailed( false )
|
, m_widget( new FinishedPage( m_config ) )
|
||||||
, m_notifyOnFinished( false )
|
, m_installFailed( false )
|
||||||
{
|
{
|
||||||
auto jq = Calamares::JobQueue::instance();
|
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, this, &FinishedViewStep::onInstallationFailed );
|
||||||
|
|
||||||
emit nextStatusChanged( true );
|
emit nextStatusChanged( true );
|
||||||
@ -102,54 +81,12 @@ FinishedViewStep::isAtEnd() const
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
|
||||||
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" );
|
|
||||||
if ( notify.isValid() )
|
|
||||||
{
|
|
||||||
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();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
void
|
void
|
||||||
FinishedViewStep::onActivate()
|
FinishedViewStep::onActivate()
|
||||||
{
|
{
|
||||||
m_widget->setUpRestart();
|
m_config->doNotify( m_installFailed );
|
||||||
|
connect( qApp, &QApplication::aboutToQuit, m_config, &Config::doRestart );
|
||||||
if ( m_notifyOnFinished )
|
|
||||||
{
|
|
||||||
sendNotification();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -162,67 +99,15 @@ FinishedViewStep::jobs() const
|
|||||||
void
|
void
|
||||||
FinishedViewStep::onInstallationFailed( const QString& message, const QString& details )
|
FinishedViewStep::onInstallationFailed( const QString& message, const QString& details )
|
||||||
{
|
{
|
||||||
Q_UNUSED( message )
|
m_installFailed = true;
|
||||||
Q_UNUSED( details )
|
m_config->setRestartNowMode( Config::RestartMode::Never );
|
||||||
installFailed = true;
|
m_widget->onInstallationFailed( message, details );
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
FinishedViewStep::setConfigurationMap( const QVariantMap& configurationMap )
|
FinishedViewStep::setConfigurationMap( const QVariantMap& configurationMap )
|
||||||
{
|
{
|
||||||
RestartMode mode = RestartMode::Never;
|
m_config->setConfigurationMap( configurationMap );
|
||||||
|
|
||||||
QString restartMode = CalamaresUtils::getString( configurationMap, "restartNowMode" );
|
|
||||||
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 );
|
|
||||||
|
|
||||||
if ( mode != RestartMode::Never )
|
|
||||||
{
|
|
||||||
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 )
|
|
||||||
{
|
|
||||||
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 >(); )
|
||||||
|
@ -11,13 +11,11 @@
|
|||||||
#ifndef FINISHEDVIEWSTEP_H
|
#ifndef FINISHEDVIEWSTEP_H
|
||||||
#define FINISHEDVIEWSTEP_H
|
#define FINISHEDVIEWSTEP_H
|
||||||
|
|
||||||
#include <QObject>
|
#include "DllMacro.h"
|
||||||
|
|
||||||
#include "utils/PluginFactory.h"
|
#include "utils/PluginFactory.h"
|
||||||
#include "viewpages/ViewStep.h"
|
#include "viewpages/ViewStep.h"
|
||||||
|
|
||||||
#include "DllMacro.h"
|
class Config;
|
||||||
|
|
||||||
class FinishedPage;
|
class FinishedPage;
|
||||||
|
|
||||||
class PLUGINDLLEXPORT FinishedViewStep : public Calamares::ViewStep
|
class PLUGINDLLEXPORT FinishedViewStep : public Calamares::ViewStep
|
||||||
@ -25,16 +23,6 @@ class PLUGINDLLEXPORT FinishedViewStep : public Calamares::ViewStep
|
|||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
|
|
||||||
public:
|
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
|
|
||||||
};
|
|
||||||
/// @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 );
|
||||||
~FinishedViewStep() override;
|
~FinishedViewStep() override;
|
||||||
|
|
||||||
@ -58,16 +46,9 @@ public slots:
|
|||||||
void onInstallationFailed( const QString& message, const QString& details );
|
void onInstallationFailed( const QString& message, const QString& details );
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
Config* m_config;
|
||||||
FinishedPage* m_widget;
|
FinishedPage* m_widget;
|
||||||
|
bool m_installFailed; // Track if onInstallationFailed() was called
|
||||||
/**
|
|
||||||
* @brief At the end of installation (when this step is activated),
|
|
||||||
* send a desktop notification via DBus that the install is done.
|
|
||||||
*/
|
|
||||||
void sendNotification();
|
|
||||||
|
|
||||||
bool installFailed;
|
|
||||||
bool m_notifyOnFinished;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
CALAMARES_PLUGIN_FACTORY_DECLARATION( FinishedViewStepFactory )
|
CALAMARES_PLUGIN_FACTORY_DECLARATION( FinishedViewStepFactory )
|
||||||
|
Loading…
Reference in New Issue
Block a user