mirror of
https://github.com/tomahawk-player/tomahawk.git
synced 2025-08-07 14:46:33 +02:00
Make it even easier to load plugins
This commit is contained in:
@@ -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
|
const QHash< QString, QObject* > PluginLoader::loadPlugins() const
|
||||||
{
|
{
|
||||||
tLog() << "Load plugins of type" << d_ptr->type;
|
tLog() << "Load plugins of type" << d_ptr->type;
|
||||||
|
@@ -19,6 +19,8 @@
|
|||||||
#ifndef LIBTOMAHAWK_UTILS_PLUGINLOADER_H
|
#ifndef LIBTOMAHAWK_UTILS_PLUGINLOADER_H
|
||||||
#define LIBTOMAHAWK_UTILS_PLUGINLOADER_H
|
#define LIBTOMAHAWK_UTILS_PLUGINLOADER_H
|
||||||
|
|
||||||
|
#include "Logger.h"
|
||||||
|
|
||||||
#include <QStringList>
|
#include <QStringList>
|
||||||
|
|
||||||
#include "DllMacro.h"
|
#include "DllMacro.h"
|
||||||
@@ -38,6 +40,29 @@ public:
|
|||||||
PluginLoader( const QString& type );
|
PluginLoader( const QString& type );
|
||||||
virtual ~PluginLoader();
|
virtual ~PluginLoader();
|
||||||
|
|
||||||
|
const QString type() const;
|
||||||
|
|
||||||
|
template<typename T> 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;
|
const QHash< QString, QObject* > loadPlugins() const;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
Reference in New Issue
Block a user