[prev in list] [next in list] [prev in thread] [next in thread]
List: kde-commits
Subject: playground/sysadmin/shaman
From: Dario Freddi <drf () kde ! org>
Date: 2010-02-16 18:55:49
Message-ID: 1266346549.094151.12139.nullmailer () svn ! kde ! org
[Download RAW message or body]
SVN commit 1091130 by dafre:
Revise the plugin system to make it modular, so that libshamangui will be able to \
hook into it the gui plugins. And also remove some useless methods from Base while \
we're at it
Signed-off-by: Dario Freddi <drf@kde.org>
M +6 -1 libshaman/CMakeLists.txt
D libshaman/PluginLoader.cpp
D libshaman/PluginLoader_p.h
A libshaman/pluginsystem (directory)
A libshaman/pluginsystem/CorePluginLoader.cpp [License: GPL (v3+)]
A libshaman/pluginsystem/CorePluginLoader_p.h [License: GPL (v3+)]
A libshaman/pluginsystem/PluginLoader.cpp \
libshaman/PluginLoader.cpp#1091129 [License: GPL (v2+)] A \
libshaman/pluginsystem/PluginLoader_p.h libshaman/PluginLoader_p.h#1091129 \
[License: GPL (v2+)] A libshaman/pluginsystem/ProviderPluginLoader.cpp \
[License: GPL (v3+)] A libshaman/pluginsystem/ProviderPluginLoader_p.h \
[License: GPL (v3+)] A libshaman/shamanabstractpluginloader.cpp \
[License: GPL (v2+)] A libshaman/shamanabstractpluginloader.h \
[License: GPL (v2+)] M +1 -1 libshaman/shamanbackend.cpp
M +19 -26 libshaman/shamanbase.cpp
M +4 -33 libshaman/shamanbase.h
M +1 -3 libshaman/shamanbase_p.h
M +1 -1 libshaman/shamanpluginconfig.cpp
M +14 -121 shaman/libshamangui/PluginLoader.cpp
M +1 -1 shaman/libshamangui/shamanguiplugin_p.h
--- trunk/playground/sysadmin/shaman/libshaman/CMakeLists.txt #1091129:1091130
@@ -18,6 +18,7 @@
set(shamancore_SRCS
shamanabstractpackage.cpp
shamanabstractplugin.cpp
+ shamanabstractpluginloader.cpp
shamanbackend.cpp
shamanbackendinterface.cpp
shamanbackendpackage.cpp
@@ -33,7 +34,6 @@
shamanpluginconfig.cpp
shamanpackagewatcher.cpp
shamanglobalpackagewatcher.cpp
- PluginLoader.cpp
shamantransactioninterface.cpp
shamantransactionquestion.cpp
shamanprovider.cpp
@@ -42,6 +42,11 @@
HooksEventLoop.cpp
shamanwidgetfactory.cpp
shamanquery.cpp
+
+ # Plugin system
+ pluginsystem/PluginLoader.cpp
+ pluginsystem/CorePluginLoader.cpp
+ pluginsystem/ProviderPluginLoader.cpp
)
if (USE_SCRIPTED_BACKEND)
--- trunk/playground/sysadmin/shaman/libshaman/shamanbackend.cpp #1091129:1091130
@@ -19,7 +19,7 @@
#include "shamanbase_p.h"
#include "shamantransactioninterface_p.h"
#include "HooksEventLoop_p.h"
-#include "PluginLoader_p.h"
+#include "pluginsystem/PluginLoader_p.h"
#include "shamancoreplugin.h"
#include "shamanbackendinterface.h"
#include <KIcon>
--- trunk/playground/sysadmin/shaman/libshaman/shamanbase.cpp #1091129:1091130
@@ -8,14 +8,16 @@
License as published by the Free Software Foundation; either
version 2 of the License, or (at your option) any later version.
*/
-#include "shamanbase.h"
#include "shamanbase_p.h"
#include "shamancoreinterface.h"
-#include "PluginLoader_p.h"
#include "shamanbackend.h"
#include "shamanproviderplugin.h"
+#include "pluginsystem/PluginLoader_p.h"
+#include "pluginsystem/CorePluginLoader_p.h"
+#include "pluginsystem/ProviderPluginLoader_p.h"
+
#include <QThread>
#include <KDebug>
@@ -51,6 +53,9 @@
Q_D(Base);
d->q_ptr = this;
KGlobal::locale()->insertCatalog("libshaman");
+
+ //Initialize PluginLoader
+ d->pluginLoader = new PluginLoader(d->config, this);
}
Base::~Base()
@@ -65,23 +70,25 @@
d->coreInterface = new CoreInterface(this);
d->mode = mode;
- //Initialize PluginLoader
- d->pluginLoader = new PluginLoader(d->config, this);
+ // Set up pluginLoader connections
connect(d->pluginLoader, SIGNAL(backendPluginCreated(Shaman::Backend*)), \
SLOT(__k__slotBackendCreated(Shaman::Backend*)));
- connect(d->pluginLoader, SIGNAL(providerCreated(Shaman::Provider*)), \
SLOT(__k__slotProviderCreated(Shaman::Provider*)));
connect(d->pluginLoader, SIGNAL(pluginsLoaded()), \
SLOT(__k__slotSetProviderPlugins()));
connect(d->pluginLoader, SIGNAL(pluginsLoaded()), this, \
SLOT(__k__initCompleted()));
+ // Register the basic loaders
+ registerPluginLoader(new CorePluginLoader);
+ registerPluginLoader(new ProviderPluginLoader);
+
// Load 'em up
- if (d->plugins.isEmpty() && d->pluginTypes == All) {
- d->pluginLoader->loadAllPlugins();
- } else if (!d->plugins.isEmpty()) {
- d->pluginLoader->loadPluginsByName(d->plugins);
- } else {
- d->pluginLoader->loadPluginsByType(d->pluginTypes);
- }
+ d->pluginLoader->loadPlugins();
}
+void Base::registerPluginLoader(AbstractPluginLoader* loader)
+{
+ Q_D(Base);
+ d->pluginLoader->registerPluginLoader(loader);
+}
+
KSharedConfig::Ptr Base::configurationFile()
{
Q_D(Base);
@@ -94,20 +101,6 @@
d->config = cfg;
}
-void Base::setPlugins(Base::PluginTypes types)
-{
- Q_D(Base);
- d->plugins.clear();
- d->pluginTypes = types;
-}
-
-void Base::setPlugins(const QStringList& plugins)
-{
- Q_D(Base);
- d->pluginTypes = All;
- d->plugins = plugins;
-}
-
CoreInterface * Base::core()
{
Q_D(Base);
--- trunk/playground/sysadmin/shaman/libshaman/shamanbase.h #1091129:1091130
@@ -22,6 +22,8 @@
namespace Shaman {
+class AbstractPluginLoader;
+
class GuiInterface;
class CoreInterface;
class StatusBarInterface;
@@ -65,20 +67,6 @@
Q_PRIVATE_SLOT(d_func(), void __k__slotSetProviderPlugins())
Q_PRIVATE_SLOT(d_func(), void __k__initCompleted())
public:
- enum PluginType {
- None = 0,
- Core = 1,
- Provider = 2,
- /* =4 */
- /* =8 */
- /* =16 */
- /* =32 */
- /* =64 */
- /* =128 */
- All = 256
- };
- Q_DECLARE_FLAGS(PluginTypes, PluginType)
-
/**
* \enum OperationMode
* This enum describe the operation modes of the backend
@@ -113,27 +101,12 @@
void setConfigurationFile(KSharedConfig::Ptr cfg);
/**
- * Sets the plugin types that will be loaded when libshaman will be \
initialized.
- * By default, all plugins are loaded.
- *
- * \note calling this function after init() will have no effect
- *
- * \param types The plugin types
- */
- void setPlugins(PluginTypes types);
- /**
- * Sets the plugins to be loaded to a list of plugin names. Generally you \
would
- * prefer to use the other overload.
- *
- * \param plugins the plugins to be loaded
- */
- void setPlugins(const QStringList &plugins);
-
- /**
* Informs all plugins that the configuration got changed.
*/
void setConfigurationChanged();
+ void registerPluginLoader(AbstractPluginLoader *loader);
+
public Q_SLOTS:
/**
* Initializes LibShaman. Calling this function will load all plugins \
specified with @@ -152,6 +125,4 @@
};
}
-Q_DECLARE_OPERATORS_FOR_FLAGS(Shaman::Base::PluginTypes)
-
#endif
--- trunk/playground/sysadmin/shaman/libshaman/shamanbase_p.h #1091129:1091130
@@ -27,8 +27,7 @@
BasePrivate()
: pluginLoader(0),
coreInterface(0),
- config(KGlobal::config()),
- pluginTypes(Base::All)
+ config(KGlobal::config())
{}
~BasePrivate()
{}
@@ -39,7 +38,6 @@
PluginLoader * pluginLoader;
CoreInterface * coreInterface;
KSharedConfig::Ptr config;
- Base::PluginTypes pluginTypes;
QStringList plugins;
Base::OperationMode mode;
--- trunk/playground/sysadmin/shaman/libshaman/shamanpluginconfig.cpp \
#1091129:1091130 @@ -10,7 +10,7 @@
#include "shamanpluginconfig.h"
#include "shamanbase_p.h"
-#include "PluginLoader_p.h"
+#include "pluginsystem/PluginLoader_p.h"
namespace Shaman {
--- trunk/playground/sysadmin/shaman/shaman/libshamangui/PluginLoader.cpp \
#1091129:1091130 @@ -13,8 +13,6 @@
#include <config-shaman.h>
#include "shamanabstractplugin_p.h"
-#include "shamancoreplugin_p.h"
-#include "shamanbackend_p.h"
#include "shamanbackendinterface_p.h"
#include "shamanproviderplugin_p.h"
#include <backend-config_p.h>
@@ -56,8 +54,7 @@
void cacheServiceList();
KSharedConfig::Ptr config;
- QList<CorePlugin*> corePlugins;
- QList<Provider*> providerPlugins;
+ QList<GuiPlugin*> guiPlugins;
QHash<QString, KConfigGroup> configInterfaces;
KService::List offers;
@@ -81,7 +78,7 @@
offers = KServiceTypeTrader::self()->query("Shaman/Plugin");
}
-void PluginLoader::Private::loadAllPluginsOfType(Base::PluginType type)
+void PluginLoader::Private::loadGuiPlugins()
{
Q_Q(PluginLoader);
@@ -101,34 +98,20 @@
continue;
}
- //try to load the specified library
- KPluginFactory *factory = KPluginLoader(offer->library()).factory();
-
- if (!factory)
- {
- kError(5001) << "KPluginFactory could not load the plugin:" << \
offer->library();
- continue;
- }
-
// Switch here: we need to know what to do with each plugin.
QString ptype = offer->property("X-KDE-Shaman-plugin-type").toString();
- if (ptype == "Core" && type == Base::Core) {
- CorePlugin * plugin = factory->create< CorePlugin >(q->parent());
+ if (ptype == "Gui") {
+ //try to load the specified library
+ KPluginFactory *factory = KPluginLoader(offer->library()).factory();
- if ( !plugin ) {
- // Troubles...
- kWarning() << "failed to load" << offer->desktopEntryName();
+ if (!factory)
+ {
+ kError(5001) << "KPluginFactory could not load the plugin:" << \
offer->library(); continue;
}
- corePlugins.append(plugin);
- plugin->init();
- plugin->d_func()->setPluginName(offer->name());
- emit q->corePluginCreated(plugin);
- continue;
- } else if (ptype == "Provider" && type == Base::Provider) {
- ProviderPlugin * plugin = factory->create< ProviderPlugin \
>(q->parent()); + GuiPlugin * plugin = factory->create< GuiPlugin \
> >(q->parent());
if ( !plugin ) {
// Troubles...
@@ -136,27 +119,10 @@
continue;
}
- /*if (offer->property("X-KDE-Shaman-plugin-script").isValid()) {
- // FIXME: force cast
- ScriptGuiPlugin * scriptPlugin = (ScriptGuiPlugin*)plugin;
- QString scriptname = INSTALL_PREFIX;
- scriptname.append("/share/shaman/plugins/");
- scriptname.append(offer->property("X-KDE-Shaman-plugin-script").toString());
- scriptPlugin->loadScript(scriptname);
- kDebug(5001) << "Gui-Plugin script" << scriptname;
- }*/
-
- // Create a provider out of it BEFORE initializing it
- Provider *provider = new Provider(plugin, q->parent());
-
- // Now initialize
- plugin->d_func()->setPluginName(offer->name());
+ guiPlugins.append(plugin);
plugin->init();
-
- providerPlugins.append(provider);
-
- emit q->providerCreated(provider);
- continue;
+ plugin->d_func()->setPluginName(offer->name());
+ emit q->guiPluginCreated(plugin);
}
}
@@ -164,15 +130,10 @@
<< "provider";
}
-void PluginLoader::loadAllPlugins()
+void PluginLoader::loadGuiPlugins()
{
- // Load backend first
- d->initBackend();
+ d->loadGuiPlugins();
- // Then all the rest
- d->loadAllPluginsOfType(Base::Core);
- d->loadAllPluginsOfType(Base::Provider);
-
// Done
emit pluginsLoaded();
}
@@ -197,74 +158,6 @@
emit pluginsLoaded();
}
-void PluginLoader::Private::initBackend()
-{
- Q_Q(PluginLoader);
-
- BackendInterface *backend = 0;
-
-#ifndef USE_SCRIPTED_BACKEND
- QObjectList l = QPluginLoader::staticInstances();
- foreach(QObject *o, l) {
- backend = qobject_cast<BackendInterface *>(o);
- if (backend) {
- kDebug() << "BackendInterface successfully Initialized";
- break;
- }
- }
-#else
- ScriptBackend * scriptPlugin = new ScriptBackend(q->parent(), QVariantList());
- scriptPlugin->loadScript(QString(BACKEND_PATH));
- kDebug(5001) << "Backend-Plugin script" << BACKEND_PATH;
- backend = scriptPlugin;
-#endif
-
- if (!backend) {
- // We would end up crashing stuff. Display a meaningful messagebox and flee
- KMessageBox::error(0, i18n("The package management backend could not be \
loaded. Please check your installation"));
- QCoreApplication::instance()->quit();
- return;
- }
-
- // Create the backend and inject into it the interface
- Backend *b = new Backend(backend, q);
- // Now trigger initialization
- QEventLoop e;
- backend->setState(Shaman::Backend::Initializing);
- connect(b, SIGNAL(stateChanged(Shaman::Backend::State)), &e, SLOT(quit()));
-
- QMetaObject::invokeMethod(backend, "init", Qt::QueuedConnection);
- kDebug() << "Backend init routine started";
- // Wait for the backend to change state
- while (b->state() != Shaman::Backend::Idling) {
- e.exec();
- }
-
- kDebug() << "Backend init routine ended";
- emit q->backendPluginCreated(b);
-}
-
-QList< CorePlugin* > PluginLoader::corePlugins()
-{
- return d->corePlugins;
-}
-
-QList<Provider*> PluginLoader::providers()
-{
- return d->providerPlugins;
-}
-
-QHash< CorePlugin*, const char* > PluginLoader::hooksFor(CorePlugin::Hook hook)
-{
- QHash< CorePlugin*, const char* > rethash;
- foreach (CorePlugin *plugin, d->corePlugins) {
- if (plugin->d_func()->memberForHook(hook)) {
- rethash.insert(plugin, plugin->d_func()->memberForHook(hook));
- }
- }
-
- return rethash;
-}
KConfigGroup PluginLoader::configGroupFor(const QString &interface) const
{
kDebug() << "Checking interface " << interface << ", I have " << \
d->configInterfaces.keys();
--- trunk/playground/sysadmin/shaman/shaman/libshamangui/shamanguiplugin_p.h \
#1091129:1091130 @@ -15,7 +15,7 @@
#include "shamancoreplugin_p.h"
namespace Shaman {
-
+
class GuiPluginPrivate : public CorePluginPrivate
{
public:
[prev in list] [next in list] [prev in thread] [next in thread]
Configure |
About |
News |
Add a list |
Sponsored by KoreLogic