Skip to content

Commit

Permalink
[loading] Refactor a little bit the loading code to split different u…
Browse files Browse the repository at this point in the history
…se cases
  • Loading branch information
jcelerier committed Aug 23, 2024
1 parent 3709f8f commit 8eec21c
Show file tree
Hide file tree
Showing 7 changed files with 47 additions and 36 deletions.
55 changes: 31 additions & 24 deletions src/app/Application.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -426,26 +426,48 @@ void Application::init()
{
m_view->sizeChanged(m_view->size());
m_view->ready();

auto sqa = safe_cast<SafeQApplication*>(m_app);
connect(sqa, &SafeQApplication::fileOpened, this, [&](const QString& file) {
auto& ctx = m_presenter->applicationContext();
m_presenter->documentManager().loadFile(ctx, file);
});
}

QTimer::singleShot(10, [&] { initDocuments(); });
QTimer::singleShot(10, [&] {
initDocuments();

#if defined(QT_FEATURE_thread)
#if QT_FEATURE_thread == 1
QThreadPool::globalInstance()->setMaxThreadCount(2);
#endif
#endif

auto& ctx = m_presenter->applicationContext();
// The plug-ins have the ability to override the boot process.
for(auto plug : ctx.guiApplicationPlugins())
{
plug->afterStartup();
}
});
}

void Application::initDocuments()
{
auto& ctx = m_presenter->applicationContext();
if(!appSettings.loadList.empty())
// The plug-ins have the ability to override the boot process.
for(auto plug : ctx.guiApplicationPlugins())
{
for(const auto& doc : appSettings.loadList)
m_presenter->documentManager().loadFile(ctx, doc);
if(plug->handleLoading())
{
return;
}
}

if(appSettings.gui)
if(!appSettings.loadList.empty())
{
auto sqa = safe_cast<SafeQApplication*>(m_app);
connect(sqa, &SafeQApplication::fileOpened, this, [&](const QString& file) {
m_presenter->documentManager().loadFile(ctx, file);
});
for(const auto& doc : appSettings.loadList)
m_presenter->documentManager().loadFile(ctx, doc);
}

// Try to reload if there was a crash
Expand Down Expand Up @@ -479,21 +501,6 @@ void Application::initDocuments()
#if !defined(SCORE_SPLASH_SCREEN)
openNewDocument();
#endif

#if defined(QT_FEATURE_thread)
#if QT_FEATURE_thread == 1
QThreadPool::globalInstance()->setMaxThreadCount(2);
#endif
#endif

// The plug-ins have the ability to override the boot process.
for(auto plug : ctx.guiApplicationPlugins())
{
if(plug->handleStartup())
{
return;
}
}
}

void Application::openNewDocument()
Expand Down
4 changes: 3 additions & 1 deletion src/lib/score/plugins/application/GUIApplicationPlugin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -46,11 +46,13 @@ Document* GUIApplicationPlugin::currentDocument() const
return context.documents.currentDocument();
}

bool GUIApplicationPlugin::handleStartup()
bool GUIApplicationPlugin::handleLoading()
{
return false;
}

void GUIApplicationPlugin::afterStartup() { }

void GUIApplicationPlugin::prepareNewDocument() { }

void GUIApplicationPlugin::on_documentChanged(
Expand Down
10 changes: 8 additions & 2 deletions src/lib/score/plugins/application/GUIApplicationPlugin.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -123,10 +123,16 @@ class SCORE_LIB_BASE_EXPORT GUIApplicationPlugin
Document* currentDocument() const;

/**
* @brief handleStartup
* @brief afterStartup
* Returns true if the start-up was handled by this plug-in.
*/
virtual bool handleStartup();
virtual bool handleLoading();

/**
* @brief afterStartup
* Called after all the documents have been created / loaded
*/
virtual void afterStartup();

/**
* @brief on_initDocument
Expand Down
5 changes: 1 addition & 4 deletions src/plugins/score-plugin-engine/Engine/ApplicationPlugin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ ApplicationPlugin::~ApplicationPlugin()
// aboutToClose.
}

bool ApplicationPlugin::handleStartup()
void ApplicationPlugin::afterStartup()
{
if(!context.documents.documents().empty())
{
Expand All @@ -65,11 +65,8 @@ bool ApplicationPlugin::handleStartup()
QTimer::singleShot(
(1 + context.applicationSettings.waitAfterLoad) * 1000, &m_execution,
[this] { m_execution.request_play_local(true); });
return true;
}
}

return false;
}

void ApplicationPlugin::initialize()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ class SCORE_PLUGIN_ENGINE_EXPORT ApplicationPlugin final

void initialize() override;

bool handleStartup() override;
void afterStartup() override;
score::GUIElements makeGUIElements() override;

void prepareNewDocument() override;
Expand Down
5 changes: 2 additions & 3 deletions src/plugins/score-plugin-js/JS/ApplicationPlugin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ ApplicationPlugin::ApplicationPlugin(const score::GUIApplicationContext& ctx)

ApplicationPlugin::~ApplicationPlugin() { }

bool ApplicationPlugin::handleStartup()
void ApplicationPlugin::afterStartup()
{
#if __has_include(<QQuickWindow>)
if(QFileInfo f{context.applicationSettings.ui}; f.isFile())
Expand All @@ -38,7 +38,7 @@ bool ApplicationPlugin::handleStartup()
m_window->setHeight(480);
item->setParentItem(m_window->contentItem());
m_window->show();
return true;
return;
}
}
else
Expand All @@ -49,6 +49,5 @@ bool ApplicationPlugin::handleStartup()
delete m_comp;
}
#endif
return false;
}
}
2 changes: 1 addition & 1 deletion src/plugins/score-plugin-js/JS/ApplicationPlugin.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ class ApplicationPlugin final
explicit ApplicationPlugin(const score::GUIApplicationContext& ctx);

~ApplicationPlugin() override;
bool handleStartup() override;
void afterStartup() override;

QQmlEngine m_engine;
QQmlComponent* m_comp{};
Expand Down

0 comments on commit 8eec21c

Please sign in to comment.