mirror of
https://github.com/subsurface/subsurface.git
synced 2025-01-19 14:25:27 +00:00
Add a PluginManager class
This class is currently very small but the reason of existence is to allow subsurface to be easily extendable via plugins. The current type of plugin that I'm making is Social Network, but another possibilities: - Dive Simulation Algorithm - Import/Export Filters - Profile Overlays Signed-off-by: Tomaz Canabrava <tomaz.canabrava@intel.com> Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
This commit is contained in:
parent
1d3bf5f407
commit
66d3e99ff2
3 changed files with 64 additions and 0 deletions
|
@ -72,6 +72,7 @@ set(SUBSURFACE_CORE_LIB_SRCS
|
|||
qtserialbluetooth.cpp
|
||||
metrics.cpp
|
||||
color.cpp
|
||||
pluginmanager.cpp
|
||||
${SERIAL_FTDI}
|
||||
${PLATFORM_SRC}
|
||||
${BT_CORE_SRC_FILES}
|
||||
|
|
44
subsurface-core/pluginmanager.cpp
Normal file
44
subsurface-core/pluginmanager.cpp
Normal file
|
@ -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;
|
||||
}
|
19
subsurface-core/pluginmanager.h
Normal file
19
subsurface-core/pluginmanager.h
Normal file
|
@ -0,0 +1,19 @@
|
|||
#ifndef PLUGINMANAGER_H
|
||||
#define PLUGINMANAGER_H
|
||||
|
||||
#include <QObject>
|
||||
|
||||
#include "isocialnetworkintegration.h"
|
||||
|
||||
class PluginManager {
|
||||
public:
|
||||
static PluginManager& instance();
|
||||
void loadPlugins();
|
||||
QList<ISocialNetworkIntegration*> socialNetworkIntegrationPlugins() const;
|
||||
private:
|
||||
PluginManager();
|
||||
PluginManager(const PluginManager&) = delete;
|
||||
PluginManager& operator=(const PluginManager&) = delete;
|
||||
};
|
||||
|
||||
#endif
|
Loading…
Add table
Reference in a new issue