From 40f2188129d8fc2d8d718adea0bb3c417013465d Mon Sep 17 00:00:00 2001 From: Sjoerd Simons Date: Sat, 29 Aug 2009 17:10:04 +0100 Subject: Add functions on the dispatcher to add/remove extra handlers --- libempathy/empathy-dispatcher.c | 70 +++++++++++++++++++++++++++++++++++++++++ libempathy/empathy-dispatcher.h | 11 +++++++ 2 files changed, 81 insertions(+) diff --git a/libempathy/empathy-dispatcher.c b/libempathy/empathy-dispatcher.c index dfd041d6b..67b75278d 100644 --- a/libempathy/empathy-dispatcher.c +++ b/libempathy/empathy-dispatcher.c @@ -56,6 +56,8 @@ #define GET_PRIV(obj) EMPATHY_GET_PRIV (obj, EmpathyDispatcher) typedef struct { + gboolean dispose_has_run; + EmpathyAccountManager *account_manager; /* connection to connection data mapping */ GHashTable *connections; @@ -66,8 +68,13 @@ typedef struct /* channels which the dispatcher is listening "invalidated" */ GList *channels; GPtrArray *array; + + /* main handler */ EmpathyHandler *handler; + /* extra handlers */ + GList *handlers; + GHashTable *request_channel_class_async_ids; } EmpathyDispatcherPriv; @@ -890,6 +897,30 @@ dispatcher_constructor (GType type, return retval; } +static void +dispatcher_dispose (GObject *object) +{ + EmpathyDispatcherPriv *priv = GET_PRIV (object); + GList *l; + + if (priv->dispose_has_run) + return; + + priv->dispose_has_run = TRUE; + + for (l = priv->handlers ; l != NULL; l = g_list_next (l)) + g_object_unref (G_OBJECT (l->data)); + + g_list_free (priv->handlers); + priv->handlers = NULL; + + if (priv->handler != NULL) + g_object_unref (priv->handler); + priv->handler = NULL; + + G_OBJECT_CLASS (empathy_dispatcher_parent_class)->dispose (object); +} + static void dispatcher_finalize (GObject *object) { @@ -983,6 +1014,7 @@ empathy_dispatcher_class_init (EmpathyDispatcherClass *klass) GObjectClass *object_class = G_OBJECT_CLASS (klass); GParamSpec *param_spec; + object_class->dispose = dispatcher_dispose; object_class->finalize = dispatcher_finalize; object_class->constructor = dispatcher_constructor; @@ -1827,3 +1859,41 @@ empathy_dispatcher_handle_channels (EmpathyHandler *handler, return TRUE; } + + +EmpathyHandler * +empathy_dispatcher_add_handler (EmpathyDispatcher *dispatcher, + const gchar *name, + GPtrArray *filters, + GStrv capabilities) +{ + EmpathyDispatcherPriv *priv = GET_PRIV (dispatcher); + EmpathyHandler *handler; + + handler = empathy_handler_new (name, filters, capabilities); + priv->handlers = g_list_prepend (priv->handlers, handler); + + /* Only set the handle_channels function, the Channel property on the main + * handler will always report all dispatched channels even if they came from + * a different Handler */ + empathy_handler_set_handle_channels_func (handler, + empathy_dispatcher_handle_channels, + dispatcher); + + return handler; +} + +void +empathy_dispatcher_remove_handler (EmpathyDispatcher *dispatcher, + EmpathyHandler *handler) +{ + EmpathyDispatcherPriv *priv = GET_PRIV (dispatcher); + GList *h; + + h = g_list_find (priv->handlers, handler); + g_return_if_fail (h != NULL); + + priv->handlers = g_list_delete_link (priv->handlers, h); + + g_object_unref (handler); +} diff --git a/libempathy/empathy-dispatcher.h b/libempathy/empathy-dispatcher.h index c4daa60fd..6176ea088 100644 --- a/libempathy/empathy-dispatcher.h +++ b/libempathy/empathy-dispatcher.h @@ -28,6 +28,7 @@ #include #include "empathy-contact.h" +#include "empathy-handler.h" #include "empathy-dispatch-operation.h" G_BEGIN_DECLS @@ -101,6 +102,16 @@ EmpathyDispatcher * empathy_dispatcher_new (const gchar *name, GPtrArray *filters, GStrv capabilities); +EmpathyHandler * +empathy_dispatcher_add_handler (EmpathyDispatcher *dispatcher, + const gchar *name, + GPtrArray *filters, + GStrv capabilities); + +void +empathy_dispatcher_remove_handler (EmpathyDispatcher *dispatcher, + EmpathyHandler *handler); + /* Get the dispatcher singleton */ EmpathyDispatcher * empathy_dispatcher_dup_singleton (void); -- cgit v1.2.3