[empathy] Add functions on the dispatcher to add/remove extra handlers
- From: Sjoerd Simons <sjoerds src gnome org>
- To: svn-commits-list gnome org
- Cc:
- Subject: [empathy] Add functions on the dispatcher to add/remove extra handlers
- Date: Sun, 30 Aug 2009 16:29:00 +0000 (UTC)
commit 40f2188129d8fc2d8d718adea0bb3c417013465d
Author: Sjoerd Simons <sjoerd simons collabora co uk>
Date: Sat Aug 29 17:10:04 2009 +0100
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(+), 0 deletions(-)
---
diff --git a/libempathy/empathy-dispatcher.c b/libempathy/empathy-dispatcher.c
index dfd041d..67b7527 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;
@@ -891,6 +898,30 @@ dispatcher_constructor (GType type,
}
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)
{
EmpathyDispatcherPriv *priv = GET_PRIV (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 c4daa60..6176ea0 100644
--- a/libempathy/empathy-dispatcher.h
+++ b/libempathy/empathy-dispatcher.h
@@ -28,6 +28,7 @@
#include <telepathy-glib/channel.h>
#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);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]