2015-10-09 19:18:45 -03:00
|
|
|
#include "pluginmanager.h"
|
|
|
|
|
|
|
|
#include <QApplication>
|
|
|
|
#include <QDir>
|
|
|
|
#include <QPluginLoader>
|
2015-10-29 21:47:08 -02:00
|
|
|
#include <QDebug>
|
2015-10-09 19:18:45 -03:00
|
|
|
|
|
|
|
static QList<ISocialNetworkIntegration*> _socialNetworks;
|
|
|
|
|
2015-10-29 21:47:08 -02:00
|
|
|
PluginManager& PluginManager::instance()
|
|
|
|
{
|
2015-10-09 19:18:45 -03:00
|
|
|
static PluginManager self;
|
|
|
|
return self;
|
|
|
|
}
|
|
|
|
|
2015-10-29 21:47:08 -02:00
|
|
|
PluginManager::PluginManager()
|
|
|
|
{
|
2015-10-09 19:26:05 -03:00
|
|
|
}
|
|
|
|
|
2015-10-29 21:47:08 -02:00
|
|
|
void PluginManager::loadPlugins()
|
|
|
|
{
|
2015-10-09 19:18:45 -03: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 21:47:08 -02:00
|
|
|
qDebug() << "Plugins Directory: " << pluginsDir;
|
2015-10-09 19:18:45 -03:00
|
|
|
foreach (const QString& fileName, pluginsDir.entryList(QDir::Files)) {
|
|
|
|
QPluginLoader loader(pluginsDir.absoluteFilePath(fileName));
|
|
|
|
QObject *plugin = loader.instance();
|
2015-10-29 21:47:08 -02:00
|
|
|
if(!plugin)
|
2015-10-09 19:18:45 -03:00
|
|
|
continue;
|
|
|
|
|
2015-11-08 10:51:50 -02:00
|
|
|
if (ISocialNetworkIntegration *social = qobject_cast<ISocialNetworkIntegration*>(plugin)) {
|
|
|
|
qDebug() << "Adding the plugin: " << social->socialNetworkName();
|
2015-10-09 19:18:45 -03:00
|
|
|
_socialNetworks.push_back(social);
|
2015-11-08 10:51:50 -02:00
|
|
|
}
|
2015-10-29 21:47:08 -02:00
|
|
|
}
|
2015-10-09 19:18:45 -03:00
|
|
|
}
|
|
|
|
|
2015-10-29 21:47:08 -02:00
|
|
|
QList<ISocialNetworkIntegration*> PluginManager::socialNetworkIntegrationPlugins() const
|
|
|
|
{
|
2015-10-09 19:18:45 -03:00
|
|
|
return _socialNetworks;
|
2015-10-29 21:47:08 -02:00
|
|
|
}
|