Skip to content

Commit

Permalink
Added LifereaNodeSourceActivatable interface to allow plugins impleme…
Browse files Browse the repository at this point in the history
…nting new node source types. (for Github #18)
  • Loading branch information
lwindolf committed Jan 13, 2015
1 parent d4c2354 commit 4c302a5
Show file tree
Hide file tree
Showing 11 changed files with 186 additions and 58 deletions.
2 changes: 2 additions & 0 deletions ChangeLog
Original file line number Diff line number Diff line change
Expand Up @@ -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 <[email protected]>
Expand Down
5 changes: 3 additions & 2 deletions src/Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
1 change: 1 addition & 0 deletions src/fl_sources/Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -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 \
Expand Down
12 changes: 9 additions & 3 deletions src/fl_sources/node_source.c
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/**
* @file node_source.c generic node source provider implementation
*
* Copyright (C) 2005-2014 Lars Windolf <[email protected]>
* Copyright (C) 2005-2015 Lars Windolf <[email protected]>
*
* 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
Expand Down Expand Up @@ -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"
Expand All @@ -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)
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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!");
Expand Down
9 changes: 9 additions & 0 deletions src/fl_sources/node_source.h
Original file line number Diff line number Diff line change
Expand Up @@ -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 ())
Expand Down
61 changes: 61 additions & 0 deletions src/fl_sources/node_source_activatable.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
/*
* @file node_type_activatable.c Node Source Plugin Type
*
* Copyright (C) 2015 Lars Windolf <[email protected]>
*
* 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);
}
54 changes: 54 additions & 0 deletions src/fl_sources/node_source_activatable.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
/*
* @file node_source_activatable.h Node Source Plugin Type
*
* Copyright (C) 2015 Lars Windolf <[email protected]>
*
* 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 <glib-object.h>
#include <gtk/gtk.h>

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__ */
32 changes: 31 additions & 1 deletion src/plugins_engine.c
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
*
* Copyright (C) 2002-2005 Paolo Maggi
* Copyright (C) 2010 Steve Frécinaux
* Copyright (C) 2012 Lars Windolf <[email protected]>
* Copyright (C) 2012-2015 Lars Windolf <[email protected]>
*
* 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
Expand Down Expand Up @@ -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)
{
Expand Down
14 changes: 12 additions & 2 deletions src/plugins_engine.h
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/*
* plugins_engine.h: Liferea Plugins using libpeas
*
* Copyright (C) 2012 Lars Windolf <[email protected]>
* Copyright (C) 2012-2015 Lars Windolf <[email protected]>
*
* 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
Expand All @@ -22,8 +22,8 @@
#ifndef _PLUGINS_ENGINE
#define _PLUGINS_ENGINE

#include <glib.h>
#include <libpeas/peas-engine.h>
#include <libpeas/peas-extension-set.h>

G_BEGIN_DECLS

Expand Down Expand Up @@ -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
23 changes: 1 addition & 22 deletions src/ui/liferea_shell.c
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand Down
31 changes: 3 additions & 28 deletions src/ui/media_player.c
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/*
* @file liferea_media_player.c media player helpers
*
* Copyright (C) 2012 Lars Windolf <[email protected]>
* Copyright (C) 2012-2015 Lars Windolf <[email protected]>
*
* 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
Expand All @@ -23,31 +23,9 @@
#include "plugins_engine.h"

#include <libpeas/peas-activatable.h>
#include <libpeas/peas-extension-set.h>

// 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)
Expand All @@ -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;
Expand Down

0 comments on commit 4c302a5

Please sign in to comment.