diff --git a/src/calamares/CalamaresApplication.cpp b/src/calamares/CalamaresApplication.cpp index c7053a432..b17c9fb18 100644 --- a/src/calamares/CalamaresApplication.cpp +++ b/src/calamares/CalamaresApplication.cpp @@ -28,6 +28,8 @@ #include "utils/Logger.h" #include "JobQueue.h" #include "Settings.h" +#include "viewpages/ViewStep.h" +#include "ViewManager.h" CalamaresApplication::CalamaresApplication( int& argc, char *argv[] ) @@ -118,6 +120,13 @@ CalamaresApplication::mainWindow() } +void +CalamaresApplication::startPhase( Calamares::Phase phase ) +{ + m_moduleManager->loadModules( phase ); +} + + void CalamaresApplication::initSettings() { @@ -140,19 +149,9 @@ CalamaresApplication::initPlugins() connect( m_moduleManager, &Calamares::ModuleManager::initDone, this, &CalamaresApplication::onPluginsReady ); m_moduleManager->init(); -} - - -void -CalamaresApplication::onPluginsReady() -{ - initJobQueue(); - - m_mainwindow = new CalamaresWindow(); //also creates ViewManager - m_moduleManager->loadModules( Calamares::Prepare ); connect( m_moduleManager, &Calamares::ModuleManager::modulesLoaded, - [this]( Calamares::Phase phase ) + this, [this]( Calamares::Phase phase ) { if ( phase == Calamares::Prepare ) { @@ -161,10 +160,42 @@ CalamaresApplication::onPluginsReady() ProgressTreeModel* m = new ProgressTreeModel( this ); ProgressTreeView::instance()->setModel( m ); } + else if ( phase == Calamares::Install ) + { + Calamares::ViewManager* vm = Calamares::ViewManager::instance(); + Calamares::JobQueue* queue = Calamares::JobQueue::instance(); + + //FIXME: we should enqueue viewmodule jobs in the order from settings.conf, + // not in the order they show up in the UI + // Ideally, if a module is a viewmodule and isLoaded we should ask + // for jobs, else if it's a viewmodule and not isLoaded we bail with + // error, else if jobmodule and not isLoaded, just loadSelf. + for( Calamares::ViewStep* step : vm->prepareSteps() ) + { + queue->enqueue( step->jobs() ); + } + connect( queue, &Calamares::JobQueue::failed, + vm, &Calamares::ViewManager::onInstallationFailed ); + + queue->start(); + } }); } +void +CalamaresApplication::onPluginsReady() +{ + initJobQueue(); + + m_mainwindow = new CalamaresWindow(); //also creates ViewManager + connect( Calamares::ViewManager::instance(), &Calamares::ViewManager::phaseChangeRequested, + this, &CalamaresApplication::startPhase ); + + startPhase( Calamares::Prepare ); +} + + void CalamaresApplication::initJobQueue() { diff --git a/src/calamares/CalamaresApplication.h b/src/calamares/CalamaresApplication.h index 80add42be..e5273cedc 100644 --- a/src/calamares/CalamaresApplication.h +++ b/src/calamares/CalamaresApplication.h @@ -19,6 +19,8 @@ #ifndef CALAMARESAPPLICATION_H #define CALAMARESAPPLICATION_H +#include "Typedefs.h" + #include #define APP CalamaresApplication::instance() @@ -45,6 +47,8 @@ public: CalamaresWindow* mainWindow(); + void startPhase( Calamares::Phase phase ); + private slots: void onPluginsReady(); diff --git a/src/libcalamaresui/ViewManager.cpp b/src/libcalamaresui/ViewManager.cpp index 38ffd7494..8d02ff104 100644 --- a/src/libcalamaresui/ViewManager.cpp +++ b/src/libcalamaresui/ViewManager.cpp @@ -21,6 +21,7 @@ #include "viewpages/ViewStep.h" #include "InstallationViewStep.h" #include "JobQueue.h" +#include "modulesystem/ModuleManager.h" #include #include @@ -112,6 +113,31 @@ ViewManager::insertViewStep( int before, ViewStep* step) } +void +ViewManager::onInstallationFailed( const QString& message, const QString& details ) +{ + QString text = tr( + "

Installation Failed

" + "

%1

" + ).arg( message ); + + if ( !details.isEmpty() ) + { + text += tr( + "

%1

" + ).arg( details ); + } + + QMessageBox::critical( + QApplication::activeWindow(), + tr( "Error" ), + text, + QMessageBox::Close + ); + QApplication::quit(); +} + + QList< ViewStep* > ViewManager::prepareSteps() const { @@ -155,7 +181,7 @@ ViewManager::next() emit currentStepChanged(); if ( installing ) { - startInstallation(); + emit phaseChangeRequested( Calamares::Install ); } } else @@ -191,40 +217,4 @@ ViewManager::back() m_back->setEnabled( false ); } -void -ViewManager::startInstallation() -{ - JobQueue* queue = JobQueue::instance(); - for( ViewStep* step : m_prepareSteps ) - { - queue->enqueue( step->jobs() ); - } - connect( queue, &JobQueue::failed, this, &ViewManager::onInstallationFailed ); - queue->start(); -} - -void -ViewManager::onInstallationFailed( const QString& message, const QString& details ) -{ - QString text = tr( - "

Installation Failed

" - "

%1

" - ).arg( message ); - - if ( !details.isEmpty() ) - { - text += tr( - "

%1

" - ).arg( details ); - } - - QMessageBox::critical( - QApplication::activeWindow(), - tr( "Error" ), - text, - QMessageBox::Close - ); - QApplication::quit(); -} - } diff --git a/src/libcalamaresui/ViewManager.h b/src/libcalamaresui/ViewManager.h index fd1c85c5f..23535b0b8 100644 --- a/src/libcalamaresui/ViewManager.h +++ b/src/libcalamaresui/ViewManager.h @@ -20,6 +20,7 @@ #define VIEWMANAGER_H #include "UiDllMacro.h" +#include "Typedefs.h" #include #include @@ -54,10 +55,15 @@ public slots: void next(); void back(); + void onInstallationFailed( const QString& message, const QString& details ); + signals: void currentStepChanged(); + void phaseChangeRequested( Calamares::Phase ); private: + void insertViewStep( int before, ViewStep* step ); + static ViewManager* s_instance; QList< ViewStep* > m_steps; @@ -70,10 +76,6 @@ private: QPushButton* m_back; QPushButton* m_next; QPushButton* m_quit; - - void insertViewStep( int before, ViewStep* step ); - void startInstallation(); - void onInstallationFailed( const QString& message, const QString& details ); }; } diff --git a/src/libcalamaresui/modulesystem/ModuleManager.cpp b/src/libcalamaresui/modulesystem/ModuleManager.cpp index 616d070f9..30ee636cf 100644 --- a/src/libcalamaresui/modulesystem/ModuleManager.cpp +++ b/src/libcalamaresui/modulesystem/ModuleManager.cpp @@ -86,6 +86,12 @@ ModuleManager::loadModules( Phase phase ) << "\nCalamares will now quit."; qApp->quit(); } + if ( m_availableModules.value( moduleName )->isLoaded() ) + { + cDebug() << "Module" << moduleName << "already loaded."; + continue; + } + recursiveLoad( moduleName ); } emit modulesLoaded( phase );