From f0a312a6e5653dfb9206998e32273ba8a4f193e2 Mon Sep 17 00:00:00 2001 From: dfighter1985 Date: Sat, 7 Jun 2014 17:23:06 +0200 Subject: [PATCH] Progress bar will now actually show progress. --HG-- branch : gsoc2014-dfighter --- .../src/extension_system/iplugin_manager.h | 6 +++ .../src/extension_system/plugin_manager.cpp | 7 ++++ code/studio/src/pm_watcher.cpp | 42 +++++++++++++++++++ code/studio/src/pm_watcher.h | 9 ++++ code/studio/src/splash_screen.cpp | 7 ++++ code/studio/src/splash_screen.h | 1 + 6 files changed, 72 insertions(+) diff --git a/code/studio/src/extension_system/iplugin_manager.h b/code/studio/src/extension_system/iplugin_manager.h index 1c8eea5d4..15fa4a336 100644 --- a/code/studio/src/extension_system/iplugin_manager.h +++ b/code/studio/src/extension_system/iplugin_manager.h @@ -134,9 +134,15 @@ Q_SIGNALS: /// Signal that the list of available plugins has changed. void pluginsChanged(); + void pluginCount( int count ); + void pluginLoading( const char *plugin ); void pluginInitializing( const char *plugin ); void pluginStarting( const char *plugin ); + + void pluginsLoaded(); + void pluginsInitialized(); + void pluginsStarted(); }; }; // namespace ExtensionSystem diff --git a/code/studio/src/extension_system/plugin_manager.cpp b/code/studio/src/extension_system/plugin_manager.cpp index 4dcb40d31..265268896 100644 --- a/code/studio/src/extension_system/plugin_manager.cpp +++ b/code/studio/src/extension_system/plugin_manager.cpp @@ -92,17 +92,24 @@ void PluginManager::loadPlugins() setPluginState(spec, State::Resolved); QList queue = loadQueue(); + Q_EMIT pluginCount( queue.count() ); Q_FOREACH (PluginSpec *spec, queue) setPluginState(spec, State::Loaded); + + Q_EMIT pluginsLoaded(); Q_FOREACH (PluginSpec *spec, queue) setPluginState(spec, State::Initialized); + + Q_EMIT pluginsInitialized(); QListIterator it(queue); it.toBack(); while (it.hasPrevious()) setPluginState(it.previous(), State::Running); + + Q_EMIT pluginsStarted(); Q_EMIT pluginsChanged(); } diff --git a/code/studio/src/pm_watcher.cpp b/code/studio/src/pm_watcher.cpp index 1a029a1a3..85c6d267b 100644 --- a/code/studio/src/pm_watcher.cpp +++ b/code/studio/src/pm_watcher.cpp @@ -19,11 +19,25 @@ #include "extension_system\iplugin_manager.h" #include "splash_screen.h" +namespace +{ + enum Progress + { + PLUGINS_LOADED = 10, + PLUGINS_INITIALIZED = 90, + PLUGINS_STARTED = 100 + }; +} + void PluginManagerWatcher::connect() { QObject::connect( pm, SIGNAL( pluginLoading( const char * ) ), this, SLOT( onPluginLoading( const char * ) ) ); QObject::connect( pm, SIGNAL( pluginInitializing( const char * ) ), this, SLOT( onPluginInitializing( const char * ) ) ); QObject::connect( pm, SIGNAL( pluginStarting( const char * ) ), this, SLOT( onPluginStarting( const char * ) ) ); + QObject::connect( pm, SIGNAL( pluginsLoaded() ), this, SLOT( onPluginsLoaded() ) ); + QObject::connect( pm, SIGNAL( pluginsInitialized() ), this, SLOT( onPluginsInitialized() ) ); + QObject::connect( pm, SIGNAL( pluginsStarted() ), this, SLOT( onPluginsStarted() ) ); + QObject::connect( pm, SIGNAL( pluginCount( int ) ), this, SLOT( onPluginCount( int ) ) ); } void PluginManagerWatcher::disconnect() @@ -31,6 +45,10 @@ void PluginManagerWatcher::disconnect() QObject::disconnect( pm, SIGNAL( pluginLoading( const char * ) ), this, SLOT( onPluginLoading( const char * ) ) ); QObject::disconnect( pm, SIGNAL( pluginInitializing( const char * ) ), this, SLOT( onPluginInitializing( const char * ) ) ); QObject::disconnect( pm, SIGNAL( pluginStarting( const char * ) ), this, SLOT( onPluginStarting( const char * ) ) ); + QObject::disconnect( pm, SIGNAL( pluginsLoaded() ), this, SLOT( onPluginsLoaded() ) ); + QObject::disconnect( pm, SIGNAL( pluginsInitialized() ), this, SLOT( onPluginsInitialized() ) ); + QObject::disconnect( pm, SIGNAL( pluginsStarted() ), this, SLOT( onPluginsStarted() ) ); + QObject::disconnect( pm, SIGNAL( pluginCount( int ) ), this, SLOT( onPluginCount( int ) ) ); } void PluginManagerWatcher::onPluginLoading( const char *plugin ) @@ -39,6 +57,8 @@ void PluginManagerWatcher::onPluginLoading( const char *plugin ) s += plugin; s += "..."; sp->setText( s ); + + sp->advanceProgress( PLUGINS_LOADED / pluginCount ); } void PluginManagerWatcher::onPluginInitializing( const char *plugin ) @@ -47,6 +67,8 @@ void PluginManagerWatcher::onPluginInitializing( const char *plugin ) s += plugin; s += "..."; sp->setText( s ); + + sp->advanceProgress( ( PLUGINS_INITIALIZED - PLUGINS_LOADED ) / pluginCount ); } void PluginManagerWatcher::onPluginStarting( const char *plugin ) @@ -55,7 +77,27 @@ void PluginManagerWatcher::onPluginStarting( const char *plugin ) s += plugin; s += "..."; sp->setText( s ); + + sp->advanceProgress( ( PLUGINS_STARTED - PLUGINS_INITIALIZED ) / pluginCount ); } +void PluginManagerWatcher::onPluginsLoaded() +{ + sp->setProgress( PLUGINS_LOADED ); +} +void PluginManagerWatcher::onPluginsInitialized() +{ + sp->setProgress( PLUGINS_INITIALIZED ); +} + +void PluginManagerWatcher::onPluginsStarted() +{ + sp->setProgress( PLUGINS_STARTED ); +} + +void PluginManagerWatcher::onPluginCount( int count ) +{ + pluginCount = count; +} \ No newline at end of file diff --git a/code/studio/src/pm_watcher.h b/code/studio/src/pm_watcher.h index a36bae57b..e37e81401 100644 --- a/code/studio/src/pm_watcher.h +++ b/code/studio/src/pm_watcher.h @@ -32,9 +32,11 @@ class PluginManagerWatcher : public QObject { Q_OBJECT public: + PluginManagerWatcher(){ sp = NULL; pm = NULL; + pluginCount = 0; } ~PluginManagerWatcher(){ @@ -53,9 +55,16 @@ private Q_SLOTS: void onPluginInitializing( const char *plugin ); void onPluginStarting( const char *plugin ); + void onPluginsLoaded(); + void onPluginsInitialized(); + void onPluginsStarted(); + + void onPluginCount( int count ); + private: SplashScreen *sp; ExtensionSystem::IPluginManager *pm; + int pluginCount; }; diff --git a/code/studio/src/splash_screen.cpp b/code/studio/src/splash_screen.cpp index 984c8d62c..2bd67c11c 100644 --- a/code/studio/src/splash_screen.cpp +++ b/code/studio/src/splash_screen.cpp @@ -71,6 +71,13 @@ void SplashScreen::setProgress( int percent ) QCoreApplication::instance()->processEvents(); } +void SplashScreen::advanceProgress( int percent ) +{ + progress += percent; + repaint(); + QCoreApplication::instance()->processEvents(); +} + void SplashScreen::drawContents( QPainter *painter ) { QSplashScreen::drawContents( painter ); diff --git a/code/studio/src/splash_screen.h b/code/studio/src/splash_screen.h index 3fa2458cb..ec6cd3da8 100644 --- a/code/studio/src/splash_screen.h +++ b/code/studio/src/splash_screen.h @@ -34,6 +34,7 @@ public: void clearText(); void setTextXY( int x, int y ){ textX = x; textY = y; } void setProgress( int percent ); + void advanceProgress( int percent ); void setProgressBarEnabled( bool b ){ progressBarEnabled = b; } void setProgressBarRect( int left, int top, int width, int height ){}