[finished] Move the business logic to the Configt object

This commit is contained in:
Adriaan de Groot 2021-03-05 22:27:24 +01:00
parent 473576991d
commit 3ad3a9adfc
4 changed files with 61 additions and 21 deletions

View File

@ -82,6 +82,32 @@ 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 void
Config::doRestart() Config::doRestart()
{ {

View File

@ -24,6 +24,10 @@ class Config : public QObject
Q_PROPERTY( QString restartNowCommand READ restartNowCommand CONSTANT FINAL ) Q_PROPERTY( QString restartNowCommand READ restartNowCommand CONSTANT FINAL )
Q_PROPERTY( bool notifyOnFinished READ notifyOnFinished 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: public:
Config( QObject* parent = nullptr ); Config( QObject* parent = nullptr );
@ -36,17 +40,22 @@ public:
}; };
Q_ENUM( RestartMode ) Q_ENUM( RestartMode )
void setConfigurationMap( const QVariantMap& configurationMap );
public Q_SLOTS:
RestartMode restartNowMode() const { return m_restartNowMode; } RestartMode restartNowMode() const { return m_restartNowMode; }
void setRestartNowMode( RestartMode m );
bool restartNowWanted() const { return m_userWantsRestart; } bool restartNowWanted() const { return m_userWantsRestart; }
void setRestartNowWanted( bool w );
QString restartNowCommand() const { return m_restartNowCommand; } QString restartNowCommand() const { return m_restartNowCommand; }
bool notifyOnFinished() const { return m_notifyOnFinished; } bool notifyOnFinished() const { return m_notifyOnFinished; }
void setConfigurationMap( const QVariantMap& configurationMap ); QString failureMessage() const { return m_failureMessage; }
QString failureDetails() const { return m_failureDetails; }
public slots: /// Failure is if any of the failure messages is non-empty
void setRestartNowMode( RestartMode m ); bool hasFailed() const { return !m_failureMessage.isEmpty() || !m_failureDetails.isEmpty(); }
void setRestartNowWanted( bool w );
/** @brief Run the restart command, if desired. /** @brief Run the restart command, if desired.
* *
@ -63,17 +72,34 @@ public slots:
* At the end of installation (when the FinishedViewStep is activated), * At the end of installation (when the FinishedViewStep is activated),
* send a desktop notification via DBus that the install is done. * 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: signals:
void restartModeChanged( RestartMode m ); void restartModeChanged( RestartMode m );
void restartNowWantedChanged( bool w ); void restartNowWantedChanged( bool w );
void failureMessageChanged( const QString& );
void failureDetailsChanged( const QString& );
void failureChanged( bool );
private: private:
// Configuration parts
QString m_restartNowCommand; QString m_restartNowCommand;
RestartMode m_restartNowMode = RestartMode::Never; RestartMode m_restartNowMode = RestartMode::Never;
bool m_userWantsRestart = false; bool m_userWantsRestart = false;
bool m_notifyOnFinished = false; bool m_notifyOnFinished = false;
// Dynamic parts
bool m_hasFailed = false;
QString m_failureMessage;
QString m_failureDetails;
}; };
const NamedEnumTable< Config::RestartMode >& restartModes(); const NamedEnumTable< Config::RestartMode >& restartModes();

View File

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

View File

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