2015-10-09 22:18:45 +00:00
|
|
|
#include "pluginmanager.h"
|
|
|
|
|
|
|
|
#include <QApplication>
|
|
|
|
#include <QDir>
|
|
|
|
#include <QPluginLoader>
|
2015-10-29 23:47:08 +00:00
|
|
|
#include <QDebug>
|
2015-10-09 22:18:45 +00:00
|
|
|
|
|
|
|
static QList<ISocialNetworkIntegration*> _socialNetworks;
|
|
|
|
|
2015-10-29 23:47:08 +00:00
|
|
|
PluginManager& PluginManager::instance()
|
|
|
|
{
|
2015-10-09 22:18:45 +00:00
|
|
|
static PluginManager self;
|
|
|
|
return self;
|
|
|
|
}
|
|
|
|
|
2015-10-29 23:47:08 +00:00
|
|
|
PluginManager::PluginManager()
|
|
|
|
{
|
2015-10-09 22:26:05 +00:00
|
|
|
}
|
|
|
|
|
2015-10-29 23:47:08 +00:00
|
|
|
void PluginManager::loadPlugins()
|
|
|
|
{
|
2015-10-09 22:18:45 +00:00
|
|
|
QDir pluginsDir(qApp->applicationDirPath());
|
|
|
|
|
|
|
|
#if defined(Q_OS_WIN)
|
|
|
|
if (pluginsDir.dirName().toLower() == "debug" || pluginsDir.dirName().toLower() == "release")
|
|
|
|
pluginsDir.cdUp();
|
|
|
|
#elif defined(Q_OS_MAC)
|
|
|
|
if (pluginsDir.dirName() == "MacOS") {
|
|
|
|
pluginsDir.cdUp();
|
|
|
|
pluginsDir.cdUp();
|
|
|
|
pluginsDir.cdUp();
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
pluginsDir.cd("plugins");
|
|
|
|
|
2015-10-29 23:47:08 +00:00
|
|
|
qDebug() << "Plugins Directory: " << pluginsDir;
|
2015-10-09 22:18:45 +00:00
|
|
|
foreach (const QString& fileName, pluginsDir.entryList(QDir::Files)) {
|
|
|
|
QPluginLoader loader(pluginsDir.absoluteFilePath(fileName));
|
|
|
|
QObject *plugin = loader.instance();
|
2015-10-29 23:47:08 +00:00
|
|
|
if(!plugin)
|
2015-10-09 22:18:45 +00:00
|
|
|
continue;
|
|
|
|
|
2015-10-29 23:47:08 +00:00
|
|
|
if (ISocialNetworkIntegration *social = qobject_cast<ISocialNetworkIntegration*>(plugin))
|
2015-10-09 22:18:45 +00:00
|
|
|
_socialNetworks.push_back(social);
|
2015-10-29 23:47:08 +00:00
|
|
|
}
|
2015-10-09 22:18:45 +00:00
|
|
|
}
|
|
|
|
|
2015-10-29 23:47:08 +00:00
|
|
|
QList<ISocialNetworkIntegration*> PluginManager::socialNetworkIntegrationPlugins() const
|
|
|
|
{
|
2015-10-09 22:18:45 +00:00
|
|
|
return _socialNetworks;
|
2015-10-29 23:47:08 +00:00
|
|
|
}
|