From a172327992d10b250f6534ea1817e5427f7baf4d Mon Sep 17 00:00:00 2001 From: nowrep Date: Fri, 24 May 2013 11:03:16 +0200 Subject: [PATCH] [Plugins] Added InitState to plugin's init() function --- src/lib/plugins/plugininterface.h | 7 +++---- src/lib/plugins/plugins.cpp | 8 ++++---- src/lib/plugins/plugins.h | 2 +- src/plugins/AccessKeysNavigation/akn_plugin.cpp | 4 +++- src/plugins/AccessKeysNavigation/akn_plugin.h | 2 +- src/plugins/GreaseMonkey/gm_plugin.cpp | 8 +++++--- src/plugins/GreaseMonkey/gm_plugin.h | 2 +- src/plugins/KWalletPasswords/kwalletplugin.cpp | 5 +++-- src/plugins/KWalletPasswords/kwalletplugin.h | 2 +- src/plugins/MouseGestures/mousegesturesplugin.cpp | 5 +++-- src/plugins/MouseGestures/mousegesturesplugin.h | 2 +- src/plugins/PIM/PIM_plugin.cpp | 6 ++++-- src/plugins/PIM/PIM_plugin.h | 2 +- src/plugins/TestPlugin/testplugin.cpp | 9 +++++++-- src/plugins/TestPlugin/testplugin.h | 2 +- 15 files changed, 39 insertions(+), 27 deletions(-) diff --git a/src/lib/plugins/plugininterface.h b/src/lib/plugins/plugininterface.h index cf80441cb..bb25c2604 100644 --- a/src/lib/plugins/plugininterface.h +++ b/src/lib/plugins/plugininterface.h @@ -59,13 +59,12 @@ class WebView; class PluginInterface { public: - //Plugin Necessary Init Functions - virtual PluginSpec pluginSpec() = 0; + enum InitState { StartupInitState, LateInitState }; - virtual void init(const QString &settingsPath) = 0; + virtual PluginSpec pluginSpec() = 0; + virtual void init(InitState state, const QString &settingsPath) = 0; virtual void unload() = 0; virtual bool testPlugin() = 0; - //End Plugin Necessary Init Functions virtual ~PluginInterface() { } virtual QTranslator* getTranslator(const QString &locale) { Q_UNUSED(locale) return 0; } diff --git a/src/lib/plugins/plugins.cpp b/src/lib/plugins/plugins.cpp index 9c836ee98..743044e86 100644 --- a/src/lib/plugins/plugins.cpp +++ b/src/lib/plugins/plugins.cpp @@ -54,7 +54,7 @@ bool Plugins::loadPlugin(Plugins::Plugin* plugin) } m_availablePlugins.removeOne(*plugin); - plugin->instance = initPlugin(iPlugin, plugin->pluginLoader); + plugin->instance = initPlugin(PluginInterface::LateInitState, iPlugin, plugin->pluginLoader); m_availablePlugins.prepend(*plugin); refreshLoadedPlugins(); @@ -140,7 +140,7 @@ void Plugins::loadPlugins() Plugin plugin; plugin.fullPath = fullPath; plugin.pluginLoader = loader; - plugin.instance = initPlugin(iPlugin, loader); + plugin.instance = initPlugin(PluginInterface::StartupInitState, iPlugin, loader); if (plugin.isLoaded()) { plugin.pluginSpec = iPlugin->pluginSpec(); @@ -211,13 +211,13 @@ void Plugins::loadAvailablePlugins() } } -PluginInterface* Plugins::initPlugin(PluginInterface* interface, QPluginLoader* loader) +PluginInterface* Plugins::initPlugin(PluginInterface::InitState state, PluginInterface* interface, QPluginLoader* loader) { if (!interface) { return 0; } - interface->init(mApp->currentProfilePath() + "extensions/"); + interface->init(state, mApp->currentProfilePath() + "extensions/"); if (!interface->testPlugin()) { interface->unload(); diff --git a/src/lib/plugins/plugins.h b/src/lib/plugins/plugins.h index ec5d681e6..9eb82c8cc 100644 --- a/src/lib/plugins/plugins.h +++ b/src/lib/plugins/plugins.h @@ -91,7 +91,7 @@ signals: private: bool alreadySpecInAvailable(const PluginSpec &spec); - PluginInterface* initPlugin(PluginInterface* interface, QPluginLoader* loader); + PluginInterface* initPlugin(PluginInterface::InitState state , PluginInterface* interface, QPluginLoader* loader); void refreshLoadedPlugins(); void loadAvailablePlugins(); diff --git a/src/plugins/AccessKeysNavigation/akn_plugin.cpp b/src/plugins/AccessKeysNavigation/akn_plugin.cpp index e672ea036..3d2304127 100644 --- a/src/plugins/AccessKeysNavigation/akn_plugin.cpp +++ b/src/plugins/AccessKeysNavigation/akn_plugin.cpp @@ -44,8 +44,10 @@ PluginSpec AKN_Plugin::pluginSpec() return spec; } -void AKN_Plugin::init(const QString &sPath) +void AKN_Plugin::init(InitState state, const QString &sPath) { + Q_UNUSED(state) + m_handler = new AKN_Handler(sPath, this); QZ_REGISTER_EVENT_HANDLER(PluginProxy::KeyPressHandler); diff --git a/src/plugins/AccessKeysNavigation/akn_plugin.h b/src/plugins/AccessKeysNavigation/akn_plugin.h index 59816f137..919280bdd 100644 --- a/src/plugins/AccessKeysNavigation/akn_plugin.h +++ b/src/plugins/AccessKeysNavigation/akn_plugin.h @@ -38,7 +38,7 @@ public: AKN_Plugin(); PluginSpec pluginSpec(); - void init(const QString &sPath); + void init(InitState state, const QString &settingsPath); void unload(); bool testPlugin(); diff --git a/src/plugins/GreaseMonkey/gm_plugin.cpp b/src/plugins/GreaseMonkey/gm_plugin.cpp index 1f992883a..7c1e34cdb 100644 --- a/src/plugins/GreaseMonkey/gm_plugin.cpp +++ b/src/plugins/GreaseMonkey/gm_plugin.cpp @@ -46,10 +46,12 @@ PluginSpec GM_Plugin::pluginSpec() return spec; } -void GM_Plugin::init(const QString &sPath) +void GM_Plugin::init(InitState state, const QString &settingsPath) { - m_manager = new GM_Manager(sPath, this); - m_settingsPath = sPath; + Q_UNUSED(state) + + m_manager = new GM_Manager(settingsPath, this); + m_settingsPath = settingsPath; connect(mApp->plugins(), SIGNAL(webPageCreated(WebPage*)), this, SLOT(webPageCreated(WebPage*))); } diff --git a/src/plugins/GreaseMonkey/gm_plugin.h b/src/plugins/GreaseMonkey/gm_plugin.h index 5542154de..6719ad1bd 100644 --- a/src/plugins/GreaseMonkey/gm_plugin.h +++ b/src/plugins/GreaseMonkey/gm_plugin.h @@ -36,7 +36,7 @@ public: explicit GM_Plugin(); PluginSpec pluginSpec(); - void init(const QString &sPath); + void init(InitState state, const QString &settingsPath); void unload(); bool testPlugin(); diff --git a/src/plugins/KWalletPasswords/kwalletplugin.cpp b/src/plugins/KWalletPasswords/kwalletplugin.cpp index 58bbb0c01..eced5ecae 100644 --- a/src/plugins/KWalletPasswords/kwalletplugin.cpp +++ b/src/plugins/KWalletPasswords/kwalletplugin.cpp @@ -42,9 +42,10 @@ PluginSpec KWalletPlugin::pluginSpec() return spec; } -void KWalletPlugin::init(const QString &sPath) +void KWalletPlugin::init(InitState state, const QString &settingsPath) { - Q_UNUSED(sPath); + Q_UNUSED(state); + Q_UNUSED(settingsPath); m_backend = new KWalletPasswordBackend; QZ_REGISTER_PASSWORD_BACKEND("KWallet", m_backend); diff --git a/src/plugins/KWalletPasswords/kwalletplugin.h b/src/plugins/KWalletPasswords/kwalletplugin.h index 7aa88fdb8..96e6950ee 100644 --- a/src/plugins/KWalletPasswords/kwalletplugin.h +++ b/src/plugins/KWalletPasswords/kwalletplugin.h @@ -35,7 +35,7 @@ public: explicit KWalletPlugin(); PluginSpec pluginSpec(); - void init(const QString &sPath); + void init(InitState state, const QString &settingsPath); void unload(); bool testPlugin(); diff --git a/src/plugins/MouseGestures/mousegesturesplugin.cpp b/src/plugins/MouseGestures/mousegesturesplugin.cpp index 8428e7b17..a87dce006 100644 --- a/src/plugins/MouseGestures/mousegesturesplugin.cpp +++ b/src/plugins/MouseGestures/mousegesturesplugin.cpp @@ -43,9 +43,10 @@ PluginSpec MouseGesturesPlugin::pluginSpec() return spec; } -void MouseGesturesPlugin::init(const QString &sPath) +void MouseGesturesPlugin::init(InitState state, const QString &settingsPath) { - Q_UNUSED(sPath) + Q_UNUSED(state) + Q_UNUSED(settingsPath) m_gestures = new MouseGestures(this); diff --git a/src/plugins/MouseGestures/mousegesturesplugin.h b/src/plugins/MouseGestures/mousegesturesplugin.h index abbf8a37b..fca7d415c 100644 --- a/src/plugins/MouseGestures/mousegesturesplugin.h +++ b/src/plugins/MouseGestures/mousegesturesplugin.h @@ -34,7 +34,7 @@ public: MouseGesturesPlugin(); PluginSpec pluginSpec(); - void init(const QString &sPath); + void init(InitState state, const QString &settingsPath); void unload(); bool testPlugin(); diff --git a/src/plugins/PIM/PIM_plugin.cpp b/src/plugins/PIM/PIM_plugin.cpp index 47b5417a0..4cc8fb726 100644 --- a/src/plugins/PIM/PIM_plugin.cpp +++ b/src/plugins/PIM/PIM_plugin.cpp @@ -46,9 +46,11 @@ PluginSpec PIM_Plugin::pluginSpec() return spec; } -void PIM_Plugin::init(const QString &sPath) +void PIM_Plugin::init(InitState state, const QString &settingsPath) { - m_handler = new PIM_Handler(sPath, this); + Q_UNUSED(state) + + m_handler = new PIM_Handler(settingsPath, this); QZ_REGISTER_EVENT_HANDLER(PluginProxy::KeyPressHandler); diff --git a/src/plugins/PIM/PIM_plugin.h b/src/plugins/PIM/PIM_plugin.h index aa06a2f75..7568348e6 100644 --- a/src/plugins/PIM/PIM_plugin.h +++ b/src/plugins/PIM/PIM_plugin.h @@ -38,7 +38,7 @@ public: PIM_Plugin(); PluginSpec pluginSpec(); - void init(const QString &sPath); + void init(InitState state, const QString &settingsPath); void unload(); bool testPlugin(); diff --git a/src/plugins/TestPlugin/testplugin.cpp b/src/plugins/TestPlugin/testplugin.cpp index 89cae0b35..715a0d046 100644 --- a/src/plugins/TestPlugin/testplugin.cpp +++ b/src/plugins/TestPlugin/testplugin.cpp @@ -51,7 +51,7 @@ PluginSpec TestPlugin::pluginSpec() return spec; } -void TestPlugin::init(const QString &sPath) +void TestPlugin::init(InitState state, const QString &settingsPath) { qDebug() << __FUNCTION__ << "called"; @@ -62,7 +62,12 @@ void TestPlugin::init(const QString &sPath) // Settings path is PROFILE/extensions/, in this directory // you can use global .ini file for QSettings named "extensions.ini" // or create new folder for your plugin and save in it anything you want - m_settingsPath = sPath; + m_settingsPath = settingsPath; + + // State can be either StartupInitState or LateInitState, and it + // indicates when the plugin have been loaded. + // Currently, it can be from preferences, or automatically at startup. + Q_UNUSED(state) // Registering this plugin as a MousePressHandler. // Otherwise mousePress() function will never be called diff --git a/src/plugins/TestPlugin/testplugin.h b/src/plugins/TestPlugin/testplugin.h index abb3e7f74..3e63b71f8 100644 --- a/src/plugins/TestPlugin/testplugin.h +++ b/src/plugins/TestPlugin/testplugin.h @@ -46,7 +46,7 @@ public: explicit TestPlugin(); PluginSpec pluginSpec(); - void init(const QString &sPath); + void init(InitState state, const QString &settingsPath); void unload(); bool testPlugin();