From 42b8d5096b2290a70a5f423edd4f43a124f355df Mon Sep 17 00:00:00 2001 From: Dominik Schmidt Date: Sat, 3 Aug 2013 20:52:17 +0200 Subject: [PATCH] Make it even easier to load plugins --- src/libtomahawk/utils/PluginLoader.cpp | 9 +++++++++ src/libtomahawk/utils/PluginLoader.h | 25 +++++++++++++++++++++++++ 2 files changed, 34 insertions(+) diff --git a/src/libtomahawk/utils/PluginLoader.cpp b/src/libtomahawk/utils/PluginLoader.cpp index f1a056f99..2d0863618 100644 --- a/src/libtomahawk/utils/PluginLoader.cpp +++ b/src/libtomahawk/utils/PluginLoader.cpp @@ -57,6 +57,15 @@ PluginLoader::~PluginLoader() } +const QString +PluginLoader::type() const +{ + Q_D( const PluginLoader ); + + return d->type; +} + + const QHash< QString, QObject* > PluginLoader::loadPlugins() const { tLog() << "Load plugins of type" << d_ptr->type; diff --git a/src/libtomahawk/utils/PluginLoader.h b/src/libtomahawk/utils/PluginLoader.h index 2cc495eb0..c9f7e8be5 100644 --- a/src/libtomahawk/utils/PluginLoader.h +++ b/src/libtomahawk/utils/PluginLoader.h @@ -19,6 +19,8 @@ #ifndef LIBTOMAHAWK_UTILS_PLUGINLOADER_H #define LIBTOMAHAWK_UTILS_PLUGINLOADER_H +#include "Logger.h" + #include #include "DllMacro.h" @@ -38,6 +40,29 @@ public: PluginLoader( const QString& type ); virtual ~PluginLoader(); + const QString type() const; + + template const QHash< QString, T* > loadPlugins() + { + const QHash< QString, QObject* > plugins = loadPlugins(); + + QHash< QString, T* > tPlugins; + foreach ( QObject* plugin, plugins.values() ) + { + T* tPlugin = qobject_cast< T* >( plugin ); + if ( tPlugin ) + { + tDebug() << "PluginLoader(" << type() << "): Loaded valid" << T::staticMetaObject.className() << "from" << plugins.key( plugin ); + tPlugins.insert( plugins.key( plugin ), tPlugin ); + } + else + { + tLog() << "PluginLoader(" << type() << "): Loaded invalid" << T::staticMetaObject.className() << "from" << plugins.key( plugin ); + } + } + + return tPlugins; + } const QHash< QString, QObject* > loadPlugins() const; private: