2017-04-27 18:24:53 +00:00
|
|
|
// SPDX-License-Identifier: GPL-2.0
|
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;
|
|
|
|
|
2017-04-22 19:29:46 +00:00
|
|
|
// no point in including dive.h for this
|
|
|
|
extern int verbose;
|
|
|
|
|
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");
|
|
|
|
|
2017-04-22 19:29:46 +00:00
|
|
|
if (verbose)
|
|
|
|
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-11-08 12:51:50 +00:00
|
|
|
if (ISocialNetworkIntegration *social = qobject_cast<ISocialNetworkIntegration*>(plugin)) {
|
|
|
|
qDebug() << "Adding the plugin: " << social->socialNetworkName();
|
2015-10-09 22:18:45 +00:00
|
|
|
_socialNetworks.push_back(social);
|
2015-11-08 12:51:50 +00:00
|
|
|
}
|
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
|
|
|
}
|