Merge branch 'qml-finished' into calamares

Improves the [finishedq] module &c to better support restart.
main
Adriaan de Groot 4 years ago
commit 08df3183dc

@ -82,10 +82,37 @@ Config::setRestartNowWanted( bool w )
}
}
void
Config::onInstallationFailed( const QString& message, const QString& details )
{
const bool msgChange = message != m_failureMessage;
const bool detChange = details != m_failureDetails;
m_failureMessage = message;
m_failureDetails = details;
if ( msgChange )
{
emit failureMessageChanged( message );
}
if ( detChange )
{
emit failureDetailsChanged( message );
}
if ( ( msgChange || detChange ) )
{
emit failureChanged( hasFailed() );
if ( hasFailed() )
{
setRestartNowMode( Config::RestartMode::Never );
}
}
}
void
Config::doRestart()
{
if ( restartNowMode() != RestartMode::Never && restartNowWanted() )
cDebug() << "Restart requested, mode=" << restartModes().find( restartNowMode() ) << " want?" << restartNowWanted();
if ( restartNowWanted() )
{
cDebug() << "Running restart command" << m_restartNowCommand;
QProcess::execute( "/bin/sh", { "-c", m_restartNowCommand } );

@ -24,6 +24,10 @@ class Config : public QObject
Q_PROPERTY( QString restartNowCommand READ restartNowCommand CONSTANT FINAL )
Q_PROPERTY( bool notifyOnFinished READ notifyOnFinished CONSTANT FINAL )
Q_PROPERTY( QString failureMessage READ failureMessage NOTIFY failureMessageChanged )
Q_PROPERTY( QString failureDetails READ failureDetails NOTIFY failureDetailsChanged )
Q_PROPERTY( bool failed READ hasFailed NOTIFY failureChanged )
public:
Config( QObject* parent = nullptr );
@ -36,23 +40,39 @@ public:
};
Q_ENUM( RestartMode )
void setConfigurationMap( const QVariantMap& configurationMap );
public Q_SLOTS:
RestartMode restartNowMode() const { return m_restartNowMode; }
bool restartNowWanted() const { return m_userWantsRestart; }
void setRestartNowMode( RestartMode m );
bool restartNowWanted() const
{
if ( restartNowMode() == RestartMode::Never )
{
return false;
}
return ( restartNowMode() == RestartMode::Always ) || m_userWantsRestart;
}
void setRestartNowWanted( bool w );
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 );
QString failureMessage() const { return m_failureMessage; }
QString failureDetails() const { return m_failureDetails; }
/// Failure is if any of the failure messages is non-empty
bool hasFailed() const { return !m_failureMessage.isEmpty() || !m_failureDetails.isEmpty(); }
/** @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.
*
* The "if desired" part is: only if the restart mode allows it,
* **and** the user has checked the box (or done whatever to
* turn on restartNowWanted()).
*/
void doRestart();
@ -63,17 +83,34 @@ public slots:
* 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 );
void doNotify( bool hasFailed );
void doNotify() { doNotify( hasFailed() ); }
/** @brief Tell the config the install failed
*
* This should be connected to the JobQueue and is called by
* the queue when the installation fails, with a suitable message.
*/
void onInstallationFailed( const QString& message, const QString& details );
signals:
void restartModeChanged( RestartMode m );
void restartNowWantedChanged( bool w );
void failureMessageChanged( const QString& );
void failureDetailsChanged( const QString& );
void failureChanged( bool );
private:
// Configuration parts
QString m_restartNowCommand;
RestartMode m_restartNowMode = RestartMode::Never;
bool m_userWantsRestart = false;
bool m_notifyOnFinished = false;
// Dynamic parts
bool m_hasFailed = false;
QString m_failureMessage;
QString m_failureDetails;
};
const NamedEnumTable< Config::RestartMode >& restartModes();

@ -22,10 +22,10 @@ FinishedViewStep::FinishedViewStep( QObject* parent )
: Calamares::ViewStep( parent )
, m_config( new Config( this ) )
, m_widget( new FinishedPage( m_config ) )
, m_installFailed( false )
{
auto jq = Calamares::JobQueue::instance();
connect( jq, &Calamares::JobQueue::failed, this, &FinishedViewStep::onInstallationFailed );
connect( jq, &Calamares::JobQueue::failed, m_config, &Config::onInstallationFailed );
connect( jq, &Calamares::JobQueue::failed, m_widget, &FinishedPage::onInstallationFailed );
emit nextStatusChanged( true );
}
@ -85,7 +85,7 @@ FinishedViewStep::isAtEnd() const
void
FinishedViewStep::onActivate()
{
m_config->doNotify( m_installFailed );
m_config->doNotify();
connect( qApp, &QApplication::aboutToQuit, m_config, &Config::doRestart );
}
@ -96,14 +96,6 @@ FinishedViewStep::jobs() const
return Calamares::JobList();
}
void
FinishedViewStep::onInstallationFailed( const QString& message, const QString& details )
{
m_installFailed = true;
m_config->setRestartNowMode( Config::RestartMode::Never );
m_widget->onInstallationFailed( message, details );
}
void
FinishedViewStep::setConfigurationMap( const QVariantMap& configurationMap )
{

@ -42,13 +42,9 @@ public:
void setConfigurationMap( const QVariantMap& configurationMap ) override;
public slots:
void onInstallationFailed( const QString& message, const QString& details );
private:
Config* m_config;
FinishedPage* m_widget;
bool m_installFailed; // Track if onInstallationFailed() was called
};
CALAMARES_PLUGIN_FACTORY_DECLARATION( FinishedViewStepFactory )

@ -22,10 +22,9 @@ CALAMARES_PLUGIN_FACTORY_DEFINITION( FinishedQmlViewStepFactory, registerPlugin<
FinishedQmlViewStep::FinishedQmlViewStep( QObject* parent )
: Calamares::QmlViewStep( parent )
, m_config( new Config( this ) )
, m_installFailed( false )
{
auto jq = Calamares::JobQueue::instance();
connect( jq, &Calamares::JobQueue::failed, this, &FinishedQmlViewStep::onInstallationFailed );
connect( jq, &Calamares::JobQueue::failed, m_config, &Config::onInstallationFailed );
emit nextStatusChanged( true );
}
@ -67,8 +66,7 @@ FinishedQmlViewStep::isAtEnd() const
void
FinishedQmlViewStep::onActivate()
{
m_config->doNotify( m_installFailed );
//connect( qApp, &QApplication::aboutToQuit, m_config, &Config::doRestart );
m_config->doNotify();
QmlViewStep::onActivate();
}
@ -85,13 +83,6 @@ FinishedQmlViewStep::getConfig()
return m_config;
}
void
FinishedQmlViewStep::onInstallationFailed( const QString& message, const QString& details )
{
m_installFailed = true;
m_config->setRestartNowMode( Config::RestartMode::Never );
}
void
FinishedQmlViewStep::setConfigurationMap( const QVariantMap& configurationMap )
{

@ -46,9 +46,6 @@ public:
void setConfigurationMap( const QVariantMap& configurationMap ) override;
QObject* getConfig() override;
public slots:
void onInstallationFailed( const QString& message, const QString& details );
private:
Config* m_config;

@ -18,8 +18,6 @@ import org.kde.kirigami 2.7 as Kirigami
import QtGraphicalEffects 1.0
import QtQuick.Window 2.3
import org.kde.plasma.core 2.0 as PlasmaCore
Page {
id: finished
@ -62,27 +60,17 @@ Page {
anchors.centerIn: parent
spacing: 6
PlasmaCore.DataSource {
id: executer
engine: "executable"
onNewData: {executer.disconnectSource(sourceName);}
}
Button {
id: button
text: qsTr("Close Installer")
icon.name: "application-exit"
onClicked: { ViewManager.quit(); }
//onClicked: console.log("close calamares");
}
Button {
text: qsTr("Restart System")
icon.name: "system-reboot"
//onClicked: { config.doRestart(); }
onClicked: {
executer.connectSource("systemctl -i reboot");
}
onClicked: { config.doRestart(); }
}
}
@ -103,4 +91,16 @@ Page {
}
}
function onActivate()
{
// This QML page has a **button** for restarting,
// so just pretend the setting is clicked; this is a
// poor solution, recommended is to set restartNowMode to Always
// in the config.
config.setRestartNowWanted(true);
}
function onLeave()
{
}
}

Loading…
Cancel
Save