diff options
Diffstat (limited to 'subsurface-core/pluginmanager.cpp')
-rw-r--r-- | subsurface-core/pluginmanager.cpp | 44 |
1 files changed, 44 insertions, 0 deletions
diff --git a/subsurface-core/pluginmanager.cpp b/subsurface-core/pluginmanager.cpp new file mode 100644 index 000000000..41d226f61 --- /dev/null +++ b/subsurface-core/pluginmanager.cpp @@ -0,0 +1,44 @@ +#include "pluginmanager.h" + +#include <QApplication> +#include <QDir> +#include <QPluginLoader> + +static QList<ISocialNetworkIntegration*> _socialNetworks; + +PluginManager& PluginManager::instance() { + static PluginManager self; + return self; +} + +void PluginManager::loadPlugins() { + 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"); + + foreach (const QString& fileName, pluginsDir.entryList(QDir::Files)) { + QPluginLoader loader(pluginsDir.absoluteFilePath(fileName)); + QObject *plugin = loader.instance(); + if(!plugin) { + continue; + } + + if (ISocialNetworkIntegration *social = qobject_cast<ISocialNetworkIntegration*>(plugin)){ + _socialNetworks.push_back(social); + } + } +} + +QList<ISocialNetworkIntegration*> PluginManager::socialNetworkIntegrationPlugins() const { + return _socialNetworks; +}
\ No newline at end of file |