Refactor view module workflow in ViewManager.

This commit is contained in:
Teo Mrnjavac 2015-09-09 19:05:20 +02:00
parent 2a0eb9e481
commit 5e87e01374
2 changed files with 32 additions and 78 deletions

View File

@ -20,9 +20,8 @@
#include "utils/Logger.h" #include "utils/Logger.h"
#include "viewpages/ViewStep.h" #include "viewpages/ViewStep.h"
#include "InstallationViewStep.h" #include "ExecutionViewStep.h"
#include "JobQueue.h" #include "JobQueue.h"
#include "modulesystem/ModuleManager.h"
#include "utils/Retranslator.h" #include "utils/Retranslator.h"
#include "Branding.h" #include "Branding.h"
#include "Settings.h" #include "Settings.h"
@ -30,6 +29,7 @@
#include <QApplication> #include <QApplication>
#include <QBoxLayout> #include <QBoxLayout>
#include <QMessageBox> #include <QMessageBox>
#include <QMetaObject>
namespace Calamares namespace Calamares
{ {
@ -46,11 +46,10 @@ ViewManager::ViewManager( QObject* parent )
: QObject( parent ) : QObject( parent )
, m_widget( new QWidget() ) , m_widget( new QWidget() )
, m_currentStep( 0 ) , m_currentStep( 0 )
, m_installationViewStep( nullptr )
, m_phase( Prepare )
, m_finishedStep( nullptr )
{ {
Q_ASSERT( !s_instance );
s_instance = this; s_instance = this;
QBoxLayout* mainLayout = new QVBoxLayout; QBoxLayout* mainLayout = new QVBoxLayout;
m_widget->setLayout( mainLayout ); m_widget->setLayout( mainLayout );
@ -80,13 +79,11 @@ ViewManager::ViewManager( QObject* parent )
connect( m_back, &QPushButton::clicked, this, &ViewManager::back ); connect( m_back, &QPushButton::clicked, this, &ViewManager::back );
m_back->setEnabled( false ); m_back->setEnabled( false );
m_installationViewStep = new InstallationViewStep( this );
connect( m_quit, &QPushButton::clicked, connect( m_quit, &QPushButton::clicked,
this, [this]() this, [this]()
{ {
if ( m_steps.at( m_currentStep ) == m_installationViewStep || // If it's NOT the last page of the last step, we ask for confirmation
!( m_currentStep == m_steps.count() -1 && if ( !( m_currentStep == m_steps.count() -1 &&
m_steps.last()->isAtEnd() ) ) m_steps.last()->isAtEnd() ) )
{ {
int response = QMessageBox::question( m_widget, int response = QMessageBox::question( m_widget,
@ -98,11 +95,16 @@ ViewManager::ViewManager( QObject* parent )
if ( response == QMessageBox::Yes ) if ( response == QMessageBox::Yes )
qApp->quit(); qApp->quit();
} }
else //we're at the end else // Means we're at the end, no need to confirm.
{ {
qApp->quit(); qApp->quit();
} }
} ); } );
connect( JobQueue::instance(), &JobQueue::failed,
this, &ViewManager::onInstallationFailed );
connect( JobQueue::instance(), &JobQueue::finished,
this, &ViewManager::next );
} }
@ -123,30 +125,9 @@ void
ViewManager::addViewStep( ViewStep* step ) ViewManager::addViewStep( ViewStep* step )
{ {
insertViewStep( m_steps.size(), step ); insertViewStep( m_steps.size(), step );
// If this is the first inserted view step, update status of "Next" button
if ( m_phase == Prepare ) if ( m_steps.count() == 1 )
{ m_next->setEnabled( step->isNextEnabled() );
m_prepareSteps.append( step );
// If this is the first inserted view step, update status of "Next" button
if ( m_prepareSteps.count() == 1 )
m_next->setEnabled( step->isNextEnabled() );
}
else if ( m_phase == PostInstall )
{
//FIXME: allow multiple postinstall pages
if ( !m_finishedStep )
m_finishedStep = step;
}
}
void
ViewManager::setUpInstallationStep()
{
if ( m_installationViewStep && !m_steps.contains( m_installationViewStep ) )
{
insertViewStep( m_steps.count(), m_installationViewStep );
}
} }
@ -198,21 +179,15 @@ ViewManager::onInstallationFailed( const QString& message, const QString& detail
msgBox.setInformativeText( text ); msgBox.setInformativeText( text );
msgBox.exec(); msgBox.exec();
QApplication::quit(); cLog() << "Calamares will now quit.";
qApp->quit();
} }
QList< ViewStep* > ViewStepList
ViewManager::prepareSteps() const ViewManager::viewSteps() const
{ {
return m_prepareSteps; return m_steps;
}
ViewStep*
ViewManager::installationStep() const
{
return m_installationViewStep;
} }
@ -223,13 +198,6 @@ ViewManager::currentStep() const
} }
ViewStep*
ViewManager::finishedStep() const
{
return m_finishedStep;
}
int int
ViewManager::currentStepIndex() const ViewManager::currentStepIndex() const
{ {
@ -241,15 +209,15 @@ void
ViewManager::next() ViewManager::next()
{ {
ViewStep* step = m_steps.at( m_currentStep ); ViewStep* step = m_steps.at( m_currentStep );
bool installing = false; bool executing = false;
if ( step->isAtEnd() ) if ( step->isAtEnd() )
{ {
// Special case when the user clicks next on the very last page in the Prepare phase // Special case when the user clicks next on the very last page in a view phase
// and right before switching to the Install phase. // and right before switching to an execution phase.
// Depending on Calamares::Settings, we show an "are you sure" prompt or not. // Depending on Calamares::Settings, we show an "are you sure" prompt or not.
if ( Calamares::Settings::instance()->showPromptBeforeInstall() && if ( Calamares::Settings::instance()->showPromptBeforeExecution() &&
m_currentStep + 1 < m_steps.count() && m_currentStep + 1 < m_steps.count() &&
m_steps.at( m_currentStep + 1 ) == m_installationViewStep ) qobject_cast< ExecutionViewStep* >( m_steps.at( m_currentStep + 1 ) ) )
{ {
int reply = int reply =
QMessageBox::question( m_widget, QMessageBox::question( m_widget,
@ -274,19 +242,15 @@ ViewManager::next()
m_stack->setCurrentIndex( m_currentStep ); m_stack->setCurrentIndex( m_currentStep );
step->onLeave(); step->onLeave();
m_steps.at( m_currentStep )->onActivate(); m_steps.at( m_currentStep )->onActivate();
installing = m_steps.at( m_currentStep ) == m_installationViewStep; executing = qobject_cast< ExecutionViewStep* >( m_steps.at( m_currentStep ) ) != nullptr;
emit currentStepChanged(); emit currentStepChanged();
if ( installing ) if ( executing )
{ {
emit phaseChangeRequested( Calamares::Install );
m_phase = Install;
m_back->setEnabled( false ); m_back->setEnabled( false );
m_next->setEnabled( false ); m_next->setEnabled( false );
connect( Calamares::JobQueue::instance(), &Calamares::JobQueue::finished, connect( Calamares::JobQueue::instance(), &Calamares::JobQueue::finished,
this, [this] this, [this]
{ {
emit phaseChangeRequested( Calamares::PostInstall );
m_phase = PostInstall;
m_next->setEnabled( true ); m_next->setEnabled( true );
} ); } );
} }
@ -296,8 +260,8 @@ ViewManager::next()
step->next(); step->next();
} }
m_next->setEnabled( !installing && m_steps.at( m_currentStep )->isNextEnabled() ); m_next->setEnabled( !executing && m_steps.at( m_currentStep )->isNextEnabled() );
m_back->setEnabled( !installing && m_steps.at( m_currentStep )->isBackEnabled() ); m_back->setEnabled( !executing && m_steps.at( m_currentStep )->isBackEnabled() );
if ( m_currentStep == m_steps.count() -1 && if ( m_currentStep == m_steps.count() -1 &&
m_steps.last()->isAtEnd() ) m_steps.last()->isAtEnd() )

View File

@ -31,7 +31,7 @@ namespace Calamares
{ {
class ViewStep; class ViewStep;
class InstallationViewStep; class ExecutionViewStep;
class UIDLLEXPORT ViewManager : public QObject class UIDLLEXPORT ViewManager : public QObject
{ {
@ -46,12 +46,8 @@ public:
void addViewStep( ViewStep* step ); void addViewStep( ViewStep* step );
void setUpInstallationStep(); ViewStepList viewSteps() const;
QList< ViewStep* > prepareSteps() const;
ViewStep* installationStep() const;
ViewStep* currentStep() const; ViewStep* currentStep() const;
ViewStep* finishedStep() const;
int currentStepIndex() const; int currentStepIndex() const;
@ -63,17 +59,13 @@ public slots:
signals: signals:
void currentStepChanged(); void currentStepChanged();
void phaseChangeRequested( Calamares::Phase );
private: private:
void insertViewStep( int before, ViewStep* step ); void insertViewStep( int before, ViewStep* step );
static ViewManager* s_instance; static ViewManager* s_instance;
QList< ViewStep* > m_steps; ViewStepList m_steps;
QList< ViewStep* > m_prepareSteps;
InstallationViewStep* m_installationViewStep;
ViewStep* m_finishedStep;
int m_currentStep; int m_currentStep;
QWidget* m_widget; QWidget* m_widget;
@ -81,8 +73,6 @@ private:
QPushButton* m_back; QPushButton* m_back;
QPushButton* m_next; QPushButton* m_next;
QPushButton* m_quit; QPushButton* m_quit;
Calamares::Phase m_phase;
}; };
} }