aboutsummaryrefslogtreecommitdiffstats
path: root/subsurface-core
diff options
context:
space:
mode:
authorGravatar Tomaz Canabrava <tomaz.canabrava@intel.com>2015-10-09 19:18:45 -0300
committerGravatar Dirk Hohndel <dirk@hohndel.org>2015-10-30 10:36:51 -0700
commit66d3e99ff2bea172d991ad59db19586ce7bcbed6 (patch)
treeaac0745460bd072a3e9954b20c8e50020c95a8e7 /subsurface-core
parent1d3bf5f407ab39987b2274c28493220fb363e13f (diff)
downloadsubsurface-66d3e99ff2bea172d991ad59db19586ce7bcbed6.tar.gz
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>
Diffstat (limited to 'subsurface-core')
-rw-r--r--subsurface-core/CMakeLists.txt1
-rw-r--r--subsurface-core/pluginmanager.cpp44
-rw-r--r--subsurface-core/pluginmanager.h19
3 files changed, 64 insertions, 0 deletions
diff --git a/subsurface-core/CMakeLists.txt b/subsurface-core/CMakeLists.txt
index 60efb7d92..e56f8bb34 100644
--- a/subsurface-core/CMakeLists.txt
+++ b/subsurface-core/CMakeLists.txt
@@ -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}
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
diff --git a/subsurface-core/pluginmanager.h b/subsurface-core/pluginmanager.h
new file mode 100644
index 000000000..c4943895c
--- /dev/null
+++ b/subsurface-core/pluginmanager.h
@@ -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 \ No newline at end of file