diff --git a/ChangeLog b/ChangeLog index bf6b867d3..f2c338621 100644 --- a/ChangeLog +++ b/ChangeLog @@ -5,6 +5,8 @@ To be released * Fixes Github #133: Subscribe into TheOldReader categories * Improves Google Reader API error handling * Now using HTTPS only when accessing TheOldReader + * Added LifereaNodeSourceActivatable interface to allow plugins + implementing new node source types. 2015-01-06 Lars Windolf diff --git a/src/Makefile.am b/src/Makefile.am index 3ed7c5c53..8d6ee22c6 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -100,8 +100,9 @@ Liferea_3_0_gir_FILES = \ ui/liferea_shell.c ui/liferea_shell.h \ ui/liferea_shell_activatable.c ui/liferea_shell_activatable.h \ ui/media_player.c ui/media_player.h \ - ui/media_player_activatable.c ui/media_player_activatable.h -Liferea_3_0_gir_INCLUDES = Gtk-3.0 + ui/media_player_activatable.c ui/media_player_activatable.h \ + fl_sources/node_source.c fl_sources/node_source.h +Liferea_3_0_gir_INCLUDES = Gtk-3.0 libxml2-2.0 girdir = $(datadir)/liferea/gir-1.0 gir_DATA = $(INTROSPECTION_GIRS) diff --git a/src/fl_sources/Makefile.am b/src/fl_sources/Makefile.am index 4ac547548..5b58671cc 100644 --- a/src/fl_sources/Makefile.am +++ b/src/fl_sources/Makefile.am @@ -9,6 +9,7 @@ AM_CPPFLAGS = \ noinst_LIBRARIES = libliflsources.a libliflsources_a_SOURCES = node_source.c node_source.h \ + node_source_activatable.c node_source_activatable.h \ aol_source.c aol_source.h \ aol_source_feed.c \ aol_source_opml.c aol_source_opml.h \ diff --git a/src/fl_sources/node_source.c b/src/fl_sources/node_source.c index 509385b40..aa377d753 100644 --- a/src/fl_sources/node_source.c +++ b/src/fl_sources/node_source.c @@ -1,7 +1,7 @@ /** * @file node_source.c generic node source provider implementation * - * Copyright (C) 2005-2014 Lars Windolf + * Copyright (C) 2005-2015 Lars Windolf * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -33,6 +33,7 @@ #include "item_state.h" #include "node.h" #include "node_type.h" +#include "plugins_engine.h" #include "ui/icons.h" #include "ui/liferea_dialog.h" #include "ui/ui_common.h" @@ -46,8 +47,10 @@ #include "fl_sources/reedah_source.h" #include "fl_sources/theoldreader_source.h" #include "fl_sources/ttrss_source.h" +#include "fl_sources/node_source_activatable.h" -static GSList *nodeSourceTypes = NULL; +static GSList *nodeSourceTypes = NULL; +static PeasExtensionSet *extensions = NULL; nodePtr node_source_root_from_node (nodePtr node) @@ -75,7 +78,7 @@ node_source_type_find (const gchar *typeStr, guint capabilities) return NULL; } -static gboolean +gboolean node_source_type_register (nodeSourceTypePtr type) { debug1 (DEBUG_PARSING, "Registering node source type %s", type->name); @@ -124,6 +127,9 @@ node_source_setup_root (void) node_source_type_register (ttrss_source_get_type ()); node_source_type_register (theoldreader_source_get_type ()); + extensions = peas_extension_set_new (PEAS_ENGINE (liferea_plugins_engine_get_default ()), + LIFEREA_NODE_SOURCE_ACTIVATABLE_TYPE, NULL); + type = node_source_type_find (NULL, NODE_SOURCE_CAPABILITY_IS_ROOT); if (!type) g_error ("No root capable node source found!"); diff --git a/src/fl_sources/node_source.h b/src/fl_sources/node_source.h index 8a754c108..43fa4d09c 100644 --- a/src/fl_sources/node_source.h +++ b/src/fl_sources/node_source.h @@ -366,6 +366,15 @@ void node_source_item_set_flag (nodePtr node, itemPtr item, gboolean newState); */ void node_source_convert_to_local (nodePtr node); +/** + * Registers a new node source type. Needs to be called before feed list import! + * To be used only via NodeSourceTypeActivatable + * + * @param type the type to register + */ +gboolean node_source_type_register (nodeSourceTypePtr type); + + /* implementation of the node type interface */ #define IS_NODE_SOURCE(node) (node->type == node_source_get_node_type ()) diff --git a/src/fl_sources/node_source_activatable.c b/src/fl_sources/node_source_activatable.c new file mode 100644 index 000000000..f96fc110b --- /dev/null +++ b/src/fl_sources/node_source_activatable.c @@ -0,0 +1,61 @@ +/* + * @file node_type_activatable.c Node Source Plugin Type + * + * Copyright (C) 2015 Lars Windolf + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ + +#include "node_source_activatable.h" + +/** + * SECTION:node_source_activatable + * @short_description: Interface for activatable extensions providing a new node source type + * @see_also: #PeasExtensionSet + * + * #LifereaNodeSourceActivatable is an interface which should be implemented by + * extensions that want to a new node source type (usually online news aggregators) + **/ +G_DEFINE_INTERFACE (LifereaNodeSourceActivatable, liferea_node_source_activatable, G_TYPE_OBJECT) + +void +liferea_node_source_activatable_default_init (LifereaNodeSourceActivatableInterface *iface) +{ + /* No properties yet */ +} + +void +liferea_node_source_activatable_activate (LifereaNodeSourceActivatable * activatable) +{ + LifereaNodeSourceActivatableInterface *iface; + + g_return_if_fail (IS_LIFEREA_NODE_SOURCE_ACTIVATABLE (activatable)); + + iface = LIFEREA_NODE_SOURCE_ACTIVATABLE_GET_IFACE (activatable); + if (iface->activate) + iface->activate (activatable); +} + +void +liferea_node_source_activatable_deactivate (LifereaNodeSourceActivatable * activatable) +{ + LifereaNodeSourceActivatableInterface *iface; + + g_return_if_fail (IS_LIFEREA_NODE_SOURCE_ACTIVATABLE (activatable)); + + iface = LIFEREA_NODE_SOURCE_ACTIVATABLE_GET_IFACE (activatable); + if (iface->deactivate) + iface->deactivate (activatable); +} diff --git a/src/fl_sources/node_source_activatable.h b/src/fl_sources/node_source_activatable.h new file mode 100644 index 000000000..2ba7da58f --- /dev/null +++ b/src/fl_sources/node_source_activatable.h @@ -0,0 +1,54 @@ +/* + * @file node_source_activatable.h Node Source Plugin Type + * + * Copyright (C) 2015 Lars Windolf + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ + +#ifndef _LIFEREA_NODE_SOURCE_ACTIVATABLE_H__ +#define _LIFEREA_NODE_SOURCE_ACTIVATABLE_H__ + +#include +#include + +G_BEGIN_DECLS + +#define LIFEREA_NODE_SOURCE_ACTIVATABLE_TYPE (liferea_node_source_activatable_get_type ()) +#define LIFEREA_NODE_SOURCE_ACTIVATABLE(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), LIFEREA_NODE_SOURCE_ACTIVATABLE_TYPE, LifereaNodeSourceActivatable)) +#define LIFEREA_NODE_SOURCE_ACTIVATABLE_IFACE(obj) (G_TYPE_CHECK_CLASS_CAST ((obj), LIFEREA_NODE_SOURCE_ACTIVATABLE_TYPE, LifereaNodeSourceActivatableInterface)) +#define IS_LIFEREA_NODE_SOURCE_ACTIVATABLE(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), LIFEREA_NODE_SOURCE_ACTIVATABLE_TYPE)) +#define LIFEREA_NODE_SOURCE_ACTIVATABLE_GET_IFACE(obj) (G_TYPE_INSTANCE_GET_INTERFACE ((obj), LIFEREA_NODE_SOURCE_ACTIVATABLE_TYPE, LifereaNodeSourceActivatableInterface)) + +typedef struct _LifereaNodeSourceActivatable LifereaNodeSourceActivatable; +typedef struct _LifereaNodeSourceActivatableInterface LifereaNodeSourceActivatableInterface; + +struct _LifereaNodeSourceActivatableInterface +{ + GTypeInterface g_iface; + + void (*activate) (LifereaNodeSourceActivatable * activatable); + void (*deactivate) (LifereaNodeSourceActivatable * activatable); +}; + +GType liferea_node_source_activatable_get_type (void) G_GNUC_CONST; + +void liferea_node_source_activatable_activate (LifereaNodeSourceActivatable *activatable); + +void liferea_node_source_activatable_deactivate (LifereaNodeSourceActivatable *activatable); + +G_END_DECLS + +#endif /* __LIFEREA_NODE_SOURCE_ACTIVATABLE_H__ */ diff --git a/src/plugins_engine.c b/src/plugins_engine.c index 662f92e24..13e0dfc3e 100644 --- a/src/plugins_engine.c +++ b/src/plugins_engine.c @@ -4,7 +4,7 @@ * * Copyright (C) 2002-2005 Paolo Maggi * Copyright (C) 2010 Steve Frécinaux - * Copyright (C) 2012 Lars Windolf + * Copyright (C) 2012-2015 Lars Windolf * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -102,6 +102,36 @@ liferea_plugins_engine_init (LifereaPluginsEngine * engine) engine, "loaded-plugins", G_SETTINGS_BIND_DEFAULT); } +/* Provide default signal handlers */ + +static void +on_extension_added (PeasExtensionSet *extensions, + PeasPluginInfo *info, + PeasExtension *exten, + gpointer user_data) +{ + peas_extension_call (exten, "activate"); +} + +static void +on_extension_removed (PeasExtensionSet *extensions, + PeasPluginInfo *info, + PeasExtension *exten, + gpointer user_data) +{ + peas_extension_call (exten, "deactivate"); +} + +void +liferea_plugins_engine_set_default_signals (PeasExtensionSet *extensions, + gpointer user_data) +{ + g_signal_connect (extensions, "extension-added", G_CALLBACK (on_extension_added), user_data); + g_signal_connect (extensions, "extension-removed", G_CALLBACK (on_extension_removed), user_data); + + peas_extension_set_call (extensions, "activate"); +} + static void liferea_plugins_engine_dispose (GObject * object) { diff --git a/src/plugins_engine.h b/src/plugins_engine.h index 8ba61ae58..a7808d30e 100644 --- a/src/plugins_engine.h +++ b/src/plugins_engine.h @@ -1,7 +1,7 @@ /* * plugins_engine.h: Liferea Plugins using libpeas * - * Copyright (C) 2012 Lars Windolf + * Copyright (C) 2012-2015 Lars Windolf * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -22,8 +22,8 @@ #ifndef _PLUGINS_ENGINE #define _PLUGINS_ENGINE -#include #include +#include G_BEGIN_DECLS @@ -51,6 +51,16 @@ GType liferea_plugins_engine_get_type (void) G_GNUC_CONST; LifereaPluginsEngine *liferea_plugins_engine_get_default (void); +/** + * liferea_plugins_set_default_signals: + * + * Set up default "activate" and "deactivate" signals. + * + * @extensions: the extensions set + * @user_data: some user data (or NULL) + */ +void liferea_plugins_set_default_signals (PeasExtensionSet *extensions, gpointer user_data); + G_END_DECLS #endif diff --git a/src/ui/liferea_shell.c b/src/ui/liferea_shell.c index e0e68a451..c0bba5aef 100644 --- a/src/ui/liferea_shell.c +++ b/src/ui/liferea_shell.c @@ -818,24 +818,6 @@ on_menu_export (gpointer callback_data, guint callback_action, GtkWidget *widget export_OPML_file (); } -static void -on_extension_added (PeasExtensionSet *extensions, - PeasPluginInfo *info, - PeasExtension *exten, - LifereaShell *shell) -{ - peas_extension_call (exten, "activate"); -} - -static void -on_extension_removed (PeasExtensionSet *extensions, - PeasPluginInfo *info, - PeasExtension *exten, - LifereaShell *shell) -{ - peas_extension_call (exten, "deactivate"); -} - /* methods to receive URLs which were dropped anywhere in the main window */ static void liferea_shell_URL_received (GtkWidget *widget, GdkDragContext *context, gint x, gint y, GtkSelectionData *data, guint info, guint time_received) @@ -1353,10 +1335,7 @@ liferea_shell_create (GtkApplication *app, const gchar *overrideWindowState) shell->priv->extensions = peas_extension_set_new (PEAS_ENGINE (liferea_plugins_engine_get_default ()), LIFEREA_TYPE_SHELL_ACTIVATABLE, "shell", shell, NULL); - g_signal_connect (shell->priv->extensions, "extension-added", G_CALLBACK (on_extension_added), shell); - g_signal_connect (shell->priv->extensions, "extension-removed", G_CALLBACK (on_extension_removed), shell); - - peas_extension_set_call (shell->priv->extensions, "activate"); + liferea_plugins_engine_set_default_signals (shell->priv->extensions, shell); /* 14. Rebuild search folders if needed */ if (searchFolderRebuild) diff --git a/src/ui/media_player.c b/src/ui/media_player.c index 155182959..a3057ad9d 100644 --- a/src/ui/media_player.c +++ b/src/ui/media_player.c @@ -1,7 +1,7 @@ /* * @file liferea_media_player.c media player helpers * - * Copyright (C) 2012 Lars Windolf + * Copyright (C) 2012-2015 Lars Windolf * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -23,31 +23,9 @@ #include "plugins_engine.h" #include -#include // FIXME: This should be a member of some object! -static PeasExtensionSet *extensions = NULL; /**< Plugin management */ -static gint count = 0; /**< Number of active auth plugins */ - -static void -on_extension_added (PeasExtensionSet *extensions, - PeasPluginInfo *info, - PeasExtension *exten, - gpointer user_data) -{ - peas_extension_call (exten, "activate"); - count++; -} - -static void -on_extension_removed (PeasExtensionSet *extensions, - PeasPluginInfo *info, - PeasExtension *exten, - gpointer user_data) -{ - peas_extension_call (exten, "deactivate"); - count--; -} +static PeasExtensionSet *extensions = NULL; static PeasExtensionSet * liferea_media_player_get_extension_set (void) @@ -56,10 +34,7 @@ liferea_media_player_get_extension_set (void) extensions = peas_extension_set_new (PEAS_ENGINE (liferea_plugins_engine_get_default ()), LIFEREA_MEDIA_PLAYER_ACTIVATABLE_TYPE, NULL); - g_signal_connect (extensions, "extension-added", G_CALLBACK (on_extension_added), NULL); - g_signal_connect (extensions, "extension-removed", G_CALLBACK (on_extension_removed), NULL); - - peas_extension_set_foreach (extensions, on_extension_added, NULL); + liferea_plugins_engine_set_default_signals (extensions, NULL); } return extensions;