[finished] Heavy refactor
- move most of the business logic to Config - make retranslate of the page more robust (e.g. changing language after failure would restore the un-failed message) There's still some bits left.
This commit is contained in:
parent
288fe5b274
commit
9d6d8ecaea
@ -33,11 +33,55 @@ Config::Config( 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
|
void
|
||||||
Config::setConfigurationMap( const QVariantMap& configurationMap )
|
Config::setConfigurationMap( const QVariantMap& configurationMap )
|
||||||
{
|
{
|
||||||
RestartMode mode = RestartMode::Never;
|
RestartMode mode = RestartMode::Never;
|
||||||
|
|
||||||
|
//TODO:3.3 remove deprecated restart settings
|
||||||
QString restartMode = CalamaresUtils::getString( configurationMap, "restartNowMode" );
|
QString restartMode = CalamaresUtils::getString( configurationMap, "restartNowMode" );
|
||||||
if ( restartMode.isEmpty() )
|
if ( restartMode.isEmpty() )
|
||||||
{
|
{
|
||||||
@ -69,6 +113,9 @@ Config::setConfigurationMap( const QVariantMap& configurationMap )
|
|||||||
}
|
}
|
||||||
|
|
||||||
m_restartNowMode = mode;
|
m_restartNowMode = mode;
|
||||||
|
m_userWantsRestart = ( mode == RestartMode::Always || mode == RestartMode::UserDefaultChecked );
|
||||||
|
emit restartModeChanged( m_restartNowMode );
|
||||||
|
emit restartNowWantedChanged( m_userWantsRestart );
|
||||||
|
|
||||||
if ( mode != RestartMode::Never )
|
if ( mode != RestartMode::Never )
|
||||||
{
|
{
|
||||||
|
@ -20,8 +20,10 @@ class Config : public QObject
|
|||||||
{
|
{
|
||||||
Q_OBJECT
|
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( QString restartNowCommand READ restartNowCommand CONSTANT FINAL )
|
||||||
Q_PROPERTY( RestartMode restartNowMode READ restartNowMode CONSTANT FINAL )
|
|
||||||
Q_PROPERTY( bool notifyOnFinished READ notifyOnFinished CONSTANT FINAL )
|
Q_PROPERTY( bool notifyOnFinished READ notifyOnFinished CONSTANT FINAL )
|
||||||
|
|
||||||
public:
|
public:
|
||||||
@ -36,15 +38,26 @@ public:
|
|||||||
};
|
};
|
||||||
Q_ENUM( RestartMode )
|
Q_ENUM( RestartMode )
|
||||||
|
|
||||||
QString restartNowCommand() const { return m_restartNowCommand; }
|
|
||||||
RestartMode restartNowMode() const { return m_restartNowMode; }
|
RestartMode restartNowMode() const { return m_restartNowMode; }
|
||||||
|
bool restartNowWanted() const { return m_userWantsRestart; }
|
||||||
|
|
||||||
|
QString restartNowCommand() const { return m_restartNowCommand; }
|
||||||
bool notifyOnFinished() const { return m_notifyOnFinished; }
|
bool notifyOnFinished() const { return m_notifyOnFinished; }
|
||||||
|
|
||||||
void setConfigurationMap( const QVariantMap& configurationMap );
|
void setConfigurationMap( const QVariantMap& configurationMap );
|
||||||
|
|
||||||
|
public slots:
|
||||||
|
void setRestartNowMode( RestartMode m );
|
||||||
|
void setRestartNowWanted( bool w );
|
||||||
|
|
||||||
|
signals:
|
||||||
|
void restartModeChanged( RestartMode m );
|
||||||
|
void restartNowWantedChanged( bool w );
|
||||||
|
|
||||||
private:
|
private:
|
||||||
QString m_restartNowCommand;
|
QString m_restartNowCommand;
|
||||||
RestartMode m_restartNowMode = RestartMode::Never;
|
RestartMode m_restartNowMode = RestartMode::Never;
|
||||||
|
bool m_userWantsRestart = false;
|
||||||
bool m_notifyOnFinished = false;
|
bool m_notifyOnFinished = false;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -27,10 +27,9 @@
|
|||||||
#include <QProcess>
|
#include <QProcess>
|
||||||
|
|
||||||
|
|
||||||
FinishedPage::FinishedPage( QWidget* parent )
|
FinishedPage::FinishedPage( Config* config, QWidget* parent )
|
||||||
: QWidget( parent )
|
: QWidget( parent )
|
||||||
, ui( new Ui::FinishedPage )
|
, ui( new Ui::FinishedPage )
|
||||||
, m_mode( Config::RestartMode::UserDefaultUnchecked )
|
|
||||||
{
|
{
|
||||||
ui->setupUi( this );
|
ui->setupUi( this );
|
||||||
|
|
||||||
@ -38,68 +37,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>" ) );
|
|
||||||
} )
|
|
||||||
}
|
|
||||||
|
|
||||||
|
ui->restartCheckBox->setVisible( mode != Mode::Never );
|
||||||
void
|
ui->restartCheckBox->setEnabled( mode != Mode::Always );
|
||||||
FinishedPage::setRestart( Config::RestartMode mode )
|
} );
|
||||||
{
|
connect( config, &Config::restartNowWantedChanged, ui->restartCheckBox, &QCheckBox::setChecked );
|
||||||
using Mode = Config::RestartMode;
|
connect( ui->restartCheckBox, &QCheckBox::stateChanged, [config]( int state ) {
|
||||||
|
config->setRestartNowWanted( state != 0 );
|
||||||
m_mode = mode;
|
|
||||||
|
|
||||||
ui->restartCheckBox->setVisible( mode != Mode::Never );
|
|
||||||
ui->restartCheckBox->setEnabled( mode != Mode::Always );
|
|
||||||
ui->restartCheckBox->setChecked( ( mode == Mode::Always ) || ( mode == Mode::UserDefaultChecked ) );
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
void
|
|
||||||
FinishedPage::setRestartNowCommand( const QString& command )
|
|
||||||
{
|
|
||||||
m_restartNowCommand = command;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
void
|
|
||||||
FinishedPage::setUpRestart()
|
|
||||||
{
|
|
||||||
cDebug() << "FinishedPage::setUpRestart(), Quit button"
|
|
||||||
<< "setup=" << restartModes().find( 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 } );
|
|
||||||
}
|
|
||||||
} );
|
} );
|
||||||
}
|
|
||||||
|
|
||||||
|
CALAMARES_RETRANSLATE_SLOT( &FinishedPage::retranslate );
|
||||||
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
FinishedPage::focusInEvent( QFocusEvent* e )
|
FinishedPage::focusInEvent( QFocusEvent* e )
|
||||||
@ -110,19 +60,64 @@ FinishedPage::focusInEvent( QFocusEvent* e )
|
|||||||
void
|
void
|
||||||
FinishedPage::onInstallationFailed( const QString& message, const QString& details )
|
FinishedPage::onInstallationFailed( const QString& message, const QString& details )
|
||||||
{
|
{
|
||||||
const auto* branding = Calamares::Branding::instance();
|
m_failure = !message.isEmpty() ? message : details;
|
||||||
Q_UNUSED( details )
|
retranslate();
|
||||||
if ( Calamares::Settings::instance()->isSetupMode() )
|
}
|
||||||
ui->mainText->setText( tr( "<h1>Setup Failed</h1><br/>"
|
|
||||||
"%1 has not been set up on your computer.<br/>"
|
void
|
||||||
"The error message was: %2." )
|
FinishedPage::retranslate()
|
||||||
.arg( branding->versionedName() )
|
{
|
||||||
.arg( message ) );
|
|
||||||
else
|
const auto* branding = Calamares::Branding::instance();
|
||||||
ui->mainText->setText( tr( "<h1>Installation Failed</h1><br/>"
|
|
||||||
"%1 has not been installed on your computer.<br/>"
|
ui->retranslateUi( this );
|
||||||
"The error message was: %2." )
|
if ( !m_failure.has_value() )
|
||||||
.arg( branding->versionedName() )
|
{
|
||||||
.arg( message ) );
|
if ( Calamares::Settings::instance()->isSetupMode() )
|
||||||
setRestart( Config::RestartMode::Never );
|
{
|
||||||
|
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/>"
|
||||||
|
"%1 has not been set up on your computer.<br/>"
|
||||||
|
"The error message was: %2." )
|
||||||
|
.arg( branding->versionedName() )
|
||||||
|
.arg( message ) );
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
ui->mainText->setText( tr( "<h1>Installation Failed</h1><br/>"
|
||||||
|
"%1 has not been installed on your computer.<br/>"
|
||||||
|
"The error message was: %2." )
|
||||||
|
.arg( branding->versionedName() )
|
||||||
|
.arg( message ) );
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -16,6 +16,8 @@
|
|||||||
|
|
||||||
#include <QWidget>
|
#include <QWidget>
|
||||||
|
|
||||||
|
#include <optional>
|
||||||
|
|
||||||
namespace Ui
|
namespace Ui
|
||||||
{
|
{
|
||||||
class FinishedPage;
|
class FinishedPage;
|
||||||
@ -25,24 +27,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( Config::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;
|
||||||
Config::RestartMode m_mode;
|
|
||||||
QString m_restartNowCommand;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // FINISHEDPAGE_H
|
#endif // FINISHEDPAGE_H
|
||||||
|
@ -28,7 +28,7 @@
|
|||||||
FinishedViewStep::FinishedViewStep( QObject* parent )
|
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_widget( new FinishedPage( m_config ) )
|
||||||
, m_installFailed( false )
|
, m_installFailed( false )
|
||||||
{
|
{
|
||||||
auto jq = Calamares::JobQueue::instance();
|
auto jq = Calamares::JobQueue::instance();
|
||||||
@ -128,10 +128,29 @@ FinishedViewStep::sendNotification()
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
#if 0
|
||||||
|
void
|
||||||
|
FinishedPage::setUpRestart()
|
||||||
|
{
|
||||||
|
cDebug() << "FinishedPage::setUpRestart(), Quit button"
|
||||||
|
<< "setup=" << restartModes().find( 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 } );
|
||||||
|
}
|
||||||
|
} );
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
|
||||||
void
|
void
|
||||||
FinishedViewStep::onActivate()
|
FinishedViewStep::onActivate()
|
||||||
{
|
{
|
||||||
m_widget->setUpRestart();
|
// m_widget->setUpRestart();
|
||||||
|
|
||||||
if ( m_config->notifyOnFinished() )
|
if ( m_config->notifyOnFinished() )
|
||||||
{
|
{
|
||||||
@ -158,12 +177,6 @@ void
|
|||||||
FinishedViewStep::setConfigurationMap( const QVariantMap& configurationMap )
|
FinishedViewStep::setConfigurationMap( const QVariantMap& configurationMap )
|
||||||
{
|
{
|
||||||
m_config->setConfigurationMap( configurationMap );
|
m_config->setConfigurationMap( configurationMap );
|
||||||
m_widget->setRestart( m_config->restartNowMode() );
|
|
||||||
|
|
||||||
if ( m_config->restartNowMode() != Config::RestartMode::Never )
|
|
||||||
{
|
|
||||||
m_widget->setRestartNowCommand( m_config->restartNowCommand() );
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
CALAMARES_PLUGIN_FACTORY_DEFINITION( FinishedViewStepFactory, registerPlugin< FinishedViewStep >(); )
|
CALAMARES_PLUGIN_FACTORY_DEFINITION( FinishedViewStepFactory, registerPlugin< FinishedViewStep >(); )
|
||||||
|
Loading…
Reference in New Issue
Block a user