From 6930c689b7b5449a98f91430cbd96627050d8e2e Mon Sep 17 00:00:00 2001 From: Tomaz Canabrava Date: Fri, 9 Oct 2015 18:16:34 -0300 Subject: Add an interface for Social Network Interfaces The Social Network plugins need an interface file to describe the expected behavior of it, this little header file will serve for that. Signed-off-by: Tomaz Canabrava Signed-off-by: Dirk Hohndel --- subsurface-core/isocialnetworkintegration.h | 67 +++++++++++++++++++++++++++++ 1 file changed, 67 insertions(+) create mode 100644 subsurface-core/isocialnetworkintegration.h (limited to 'subsurface-core/isocialnetworkintegration.h') diff --git a/subsurface-core/isocialnetworkintegration.h b/subsurface-core/isocialnetworkintegration.h new file mode 100644 index 000000000..e20ab646f --- /dev/null +++ b/subsurface-core/isocialnetworkintegration.h @@ -0,0 +1,67 @@ +#ifndef ISOCIALNETWORKINTEGRATION_H +#define ISOCIALNETWORKINTEGRATION_H + +/* This Interface represents a Plugin for Social Network integration, + * with it you may be able to create plugins for facebook, instagram, + * twitpic, google plus and any other thing you may imagine. + * + * We bundle facebook integration as an example. + */ + +class ISocialNetworkIntegration { + /*! + * @name socialNetworkName + * @brief The name of this social network + * @return The name of this social network + * + * The name of this social network will be used to populate the Menu to toggle states + * between connected/disconnected, and also submit stuff to it. + */ + QString socialNetworkName() const = 0; + + /*! + * @name socialNetworkIcon + * @brief The icon of this social network + * @return The icon of this social network + * + * The icon of this social network will be used to populate the menu, and can also be + * used on a toolbar if requested. + */ + QIcon socialNetworkIcon() const = 0; + + /*! + * @name isConnected + * @brief returns true if connected to this social network, false otherwise + * @return true if connected to this social network, false otherwise + */ + bool isConnected() = 0; + + /*! + * @name requestLogin + * @brief try to login on this social network. + * + * Try to login on this social network. All widget implementation that + * manages login should be done inside this function. + */ + void requestLogin() = 0; + + /*! + * @name requestLogoff + * @brief tries to logoff from this social network + * + * Try to logoff from this social network. + */ + void requestLogoff() = 0; + + /*! + * @name uploadCurrentDive + * @brief send the current dive info to the Social Network + * + * Should format all the options and pixmaps from the current dive + * to update to the social network. All widget stuff related to sendint + * dive information should be executed inside this function. + */ + void uploadCurrentDive() = 0; +}; + +#endif \ No newline at end of file -- cgit v1.2.3-70-g09d2 From 1d3bf5f407ab39987b2274c28493220fb363e13f Mon Sep 17 00:00:00 2001 From: Tomaz Canabrava Date: Fri, 9 Oct 2015 19:17:58 -0300 Subject: Fix the ISocialNetworkIntegration interface I missed a few virtuals there. :) Signed-off-by: Tomaz Canabrava Signed-off-by: Dirk Hohndel --- subsurface-core/isocialnetworkintegration.h | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) (limited to 'subsurface-core/isocialnetworkintegration.h') diff --git a/subsurface-core/isocialnetworkintegration.h b/subsurface-core/isocialnetworkintegration.h index e20ab646f..9e54c87ab 100644 --- a/subsurface-core/isocialnetworkintegration.h +++ b/subsurface-core/isocialnetworkintegration.h @@ -1,6 +1,8 @@ #ifndef ISOCIALNETWORKINTEGRATION_H #define ISOCIALNETWORKINTEGRATION_H +#include + /* This Interface represents a Plugin for Social Network integration, * with it you may be able to create plugins for facebook, instagram, * twitpic, google plus and any other thing you may imagine. @@ -17,7 +19,7 @@ class ISocialNetworkIntegration { * The name of this social network will be used to populate the Menu to toggle states * between connected/disconnected, and also submit stuff to it. */ - QString socialNetworkName() const = 0; + virtual QString socialNetworkName() const = 0; /*! * @name socialNetworkIcon @@ -27,14 +29,14 @@ class ISocialNetworkIntegration { * The icon of this social network will be used to populate the menu, and can also be * used on a toolbar if requested. */ - QIcon socialNetworkIcon() const = 0; + virtual QString socialNetworkIcon() const = 0; /*! * @name isConnected * @brief returns true if connected to this social network, false otherwise * @return true if connected to this social network, false otherwise */ - bool isConnected() = 0; + virtual bool isConnected() = 0; /*! * @name requestLogin @@ -43,7 +45,7 @@ class ISocialNetworkIntegration { * Try to login on this social network. All widget implementation that * manages login should be done inside this function. */ - void requestLogin() = 0; + virtual void requestLogin() = 0; /*! * @name requestLogoff @@ -51,7 +53,7 @@ class ISocialNetworkIntegration { * * Try to logoff from this social network. */ - void requestLogoff() = 0; + virtual void requestLogoff() = 0; /*! * @name uploadCurrentDive @@ -61,7 +63,9 @@ class ISocialNetworkIntegration { * to update to the social network. All widget stuff related to sendint * dive information should be executed inside this function. */ - void uploadCurrentDive() = 0; + virtual void uploadCurrentDive() = 0; }; +Q_DECLARE_INTERFACE(ISocialNetworkIntegration, "org.subsurface.ISocialNetworkIntegration.v1") + #endif \ No newline at end of file -- cgit v1.2.3-70-g09d2 From d3a8288ad5a25db502cb0c782b72c3242f3f30e9 Mon Sep 17 00:00:00 2001 From: Tomaz Canabrava Date: Fri, 9 Oct 2015 20:15:26 -0300 Subject: Populate the MainMenu with social network actions The magic happens here: We are iterating over the plugins and populating the main menu with all actions provided by them. Currently we can't test this as we don't have a single plugin. Next patch series of commits will be adding the Facebook plugin. Signed-off-by: Tomaz Canabrava Signed-off-by: Dirk Hohndel --- desktop-widgets/mainwindow.cpp | 21 +++++++++++++++++++++ subsurface-core/isocialnetworkintegration.h | 1 + 2 files changed, 22 insertions(+) (limited to 'subsurface-core/isocialnetworkintegration.h') diff --git a/desktop-widgets/mainwindow.cpp b/desktop-widgets/mainwindow.cpp index 2afc8f979..0150a7c6f 100644 --- a/desktop-widgets/mainwindow.cpp +++ b/desktop-widgets/mainwindow.cpp @@ -11,6 +11,7 @@ #include #include #include + #include "version.h" #include "divelistview.h" #include "downloadfromdivecomputer.h" @@ -52,6 +53,8 @@ #include #include #include "subsurface-core/color.h" +#include "subsurface-core/isocialnetworkintegration.h" +#include "subsurface-core/pluginmanager.h" #if defined(FBSUPPORT) #include "socialnetworks.h" @@ -252,6 +255,24 @@ MainWindow::MainWindow() : QMainWindow(), ui.actionFacebook->setEnabled(false); #endif + if(PluginManager::instance().socialNetworkIntegrationPlugins().count()) { + QMenu *connections = new QMenu(); + for(ISocialNetworkIntegration *plugin : PluginManager::instance().socialNetworkIntegrationPlugins()){ + QAction *toggle_connection = new QAction(this); + toggle_connection->setText(plugin->socialNetworkName()); + toggle_connection->setIcon(QIcon(plugin->socialNetworkIcon())); + + QAction *share_on = new QAction(this); + share_on->setText(plugin->socialNetworkName()); + share_on->setIcon(QIcon(plugin->socialNetworkIcon())); + ui.menuShare_on->addAction(share_on); + connections->addAction(toggle_connection); + } + ui.menuShare_on->addSeparator(); + ui.menuShare_on->addMenu(connections); + } else { + ui.menubar->removeAction(ui.menuShare_on->menuAction()); + } ui.menubar->show(); set_git_update_cb(&updateProgress); diff --git a/subsurface-core/isocialnetworkintegration.h b/subsurface-core/isocialnetworkintegration.h index 9e54c87ab..97ff91dc2 100644 --- a/subsurface-core/isocialnetworkintegration.h +++ b/subsurface-core/isocialnetworkintegration.h @@ -11,6 +11,7 @@ */ class ISocialNetworkIntegration { +public: /*! * @name socialNetworkName * @brief The name of this social network -- cgit v1.2.3-70-g09d2 From 8dad3457ef1f412517c4d81f08ebd14680788ec3 Mon Sep 17 00:00:00 2001 From: Tomaz Canabrava Date: Thu, 29 Oct 2015 21:47:08 -0200 Subject: Make the skeleton Facebook plugin and make sure it is loaded Currently we need to copy manually the plugin dynamic library to the /plugins folder. Signed-off-by: Tomaz Canabrava Signed-off-by: Dirk Hohndel --- desktop-widgets/mainwindow.cpp | 4 ++- desktop-widgets/plugins/facebook/CMakeLists.txt | 5 +-- .../plugins/facebook/facebook_integration.cpp | 36 ++++++++++++++++++++++ .../plugins/facebook/facebook_integration.h | 21 +++++++++++++ subsurface-core/isocialnetworkintegration.h | 2 +- subsurface-core/pluginmanager.cpp | 24 +++++++++------ 6 files changed, 78 insertions(+), 14 deletions(-) (limited to 'subsurface-core/isocialnetworkintegration.h') diff --git a/desktop-widgets/mainwindow.cpp b/desktop-widgets/mainwindow.cpp index 0150a7c6f..23b4fb9b0 100644 --- a/desktop-widgets/mainwindow.cpp +++ b/desktop-widgets/mainwindow.cpp @@ -256,15 +256,17 @@ MainWindow::MainWindow() : QMainWindow(), #endif if(PluginManager::instance().socialNetworkIntegrationPlugins().count()) { - QMenu *connections = new QMenu(); + QMenu *connections = new QMenu(tr("Connect to")); for(ISocialNetworkIntegration *plugin : PluginManager::instance().socialNetworkIntegrationPlugins()){ QAction *toggle_connection = new QAction(this); toggle_connection->setText(plugin->socialNetworkName()); toggle_connection->setIcon(QIcon(plugin->socialNetworkIcon())); + toggle_connection->setData(QVariant::fromValue(plugin)); QAction *share_on = new QAction(this); share_on->setText(plugin->socialNetworkName()); share_on->setIcon(QIcon(plugin->socialNetworkIcon())); + share_on->setData(QVariant::fromValue(plugin)); ui.menuShare_on->addAction(share_on); connections->addAction(toggle_connection); } diff --git a/desktop-widgets/plugins/facebook/CMakeLists.txt b/desktop-widgets/plugins/facebook/CMakeLists.txt index cccfec1f5..8628bd070 100644 --- a/desktop-widgets/plugins/facebook/CMakeLists.txt +++ b/desktop-widgets/plugins/facebook/CMakeLists.txt @@ -1,5 +1,6 @@ set(FACEBOOK_PLUGIN_SRCS facebook_integration.cpp) -add_library(facebook_integration ${FACEBOOK_PLUGIN_SRCS}) +add_library(facebook_integration SHARED ${FACEBOOK_PLUGIN_SRCS}) -target_link_libraries(facebook_integration subsurface_core ${QT_LIBRARIES}) +target_link_libraries(facebook_integration subsurface_corelib ${QT_LIBRARIES}) +add_dependencies(facebook_integration subsurface_corelib) \ No newline at end of file diff --git a/desktop-widgets/plugins/facebook/facebook_integration.cpp b/desktop-widgets/plugins/facebook/facebook_integration.cpp index e69de29bb..e9b2297a0 100644 --- a/desktop-widgets/plugins/facebook/facebook_integration.cpp +++ b/desktop-widgets/plugins/facebook/facebook_integration.cpp @@ -0,0 +1,36 @@ +#include "facebook_integration.h" + +FacebookPlugin::FacebookPlugin(QObject* parent): QObject(parent) +{ + +} + +bool FacebookPlugin::isConnected() +{ + +} + +void FacebookPlugin::requestLogin() +{ + +} + +void FacebookPlugin::requestLogoff() +{ + +} + +QString FacebookPlugin::socialNetworkIcon() const +{ + return QString(); +} + +QString FacebookPlugin::socialNetworkName() const +{ + return tr("Facebook"); +} + +void FacebookPlugin::uploadCurrentDive() +{ + +} diff --git a/desktop-widgets/plugins/facebook/facebook_integration.h b/desktop-widgets/plugins/facebook/facebook_integration.h index e69de29bb..a9d212e7e 100644 --- a/desktop-widgets/plugins/facebook/facebook_integration.h +++ b/desktop-widgets/plugins/facebook/facebook_integration.h @@ -0,0 +1,21 @@ +#ifndef FACEBOOK_INTEGRATION_H +#define FACEBOOK_INTEGRATION_H + +#include "subsurface-core/isocialnetworkintegration.h" +#include + +class FacebookPlugin : public QObject, public ISocialNetworkIntegration { + Q_OBJECT + Q_PLUGIN_METADATA(IID "org.subsurface.plugins.ISocialNetworkIntegration") + Q_INTERFACES(ISocialNetworkIntegration) +public: + explicit FacebookPlugin(QObject* parent = 0); + virtual bool isConnected(); + virtual void requestLogin(); + virtual void requestLogoff(); + virtual QString socialNetworkIcon() const; + virtual QString socialNetworkName() const; + virtual void uploadCurrentDive(); +}; + +#endif \ No newline at end of file diff --git a/subsurface-core/isocialnetworkintegration.h b/subsurface-core/isocialnetworkintegration.h index 97ff91dc2..778a171b3 100644 --- a/subsurface-core/isocialnetworkintegration.h +++ b/subsurface-core/isocialnetworkintegration.h @@ -68,5 +68,5 @@ public: }; Q_DECLARE_INTERFACE(ISocialNetworkIntegration, "org.subsurface.ISocialNetworkIntegration.v1") - +Q_DECLARE_METATYPE(ISocialNetworkIntegration*); #endif \ No newline at end of file diff --git a/subsurface-core/pluginmanager.cpp b/subsurface-core/pluginmanager.cpp index 290f43df0..5c0f22525 100644 --- a/subsurface-core/pluginmanager.cpp +++ b/subsurface-core/pluginmanager.cpp @@ -3,18 +3,22 @@ #include #include #include +#include static QList _socialNetworks; -PluginManager& PluginManager::instance() { +PluginManager& PluginManager::instance() +{ static PluginManager self; return self; } -PluginManager::PluginManager() { +PluginManager::PluginManager() +{ } -void PluginManager::loadPlugins() { +void PluginManager::loadPlugins() +{ QDir pluginsDir(qApp->applicationDirPath()); #if defined(Q_OS_WIN) @@ -29,19 +33,19 @@ void PluginManager::loadPlugins() { #endif pluginsDir.cd("plugins"); + qDebug() << "Plugins Directory: " << pluginsDir; foreach (const QString& fileName, pluginsDir.entryList(QDir::Files)) { QPluginLoader loader(pluginsDir.absoluteFilePath(fileName)); QObject *plugin = loader.instance(); - if(!plugin) { + if(!plugin) continue; - } - if (ISocialNetworkIntegration *social = qobject_cast(plugin)){ + if (ISocialNetworkIntegration *social = qobject_cast(plugin)) _socialNetworks.push_back(social); - } - } + } } -QList PluginManager::socialNetworkIntegrationPlugins() const { +QList PluginManager::socialNetworkIntegrationPlugins() const +{ return _socialNetworks; -} \ No newline at end of file +} -- cgit v1.2.3-70-g09d2