aboutsummaryrefslogtreecommitdiffstats
path: root/libempathy/empathy-connection-managers.c
diff options
context:
space:
mode:
authorGuillaume Desmottes <guillaume.desmottes@collabora.co.uk>2010-01-21 19:57:18 +0800
committerGuillaume Desmottes <guillaume.desmottes@collabora.co.uk>2010-01-22 19:58:40 +0800
commitf6d60f33a0ab2af025e7d13a8dea9a93c6eab3f9 (patch)
treeb4094634ca8a0f1757344d1fab9cdc375f9dd0fc /libempathy/empathy-connection-managers.c
parentec21e853954665c0f3ad8f7d16001a77e535715d (diff)
downloadgsoc2013-empathy-f6d60f33a0ab2af025e7d13a8dea9a93c6eab3f9.tar
gsoc2013-empathy-f6d60f33a0ab2af025e7d13a8dea9a93c6eab3f9.tar.gz
gsoc2013-empathy-f6d60f33a0ab2af025e7d13a8dea9a93c6eab3f9.tar.bz2
gsoc2013-empathy-f6d60f33a0ab2af025e7d13a8dea9a93c6eab3f9.tar.lz
gsoc2013-empathy-f6d60f33a0ab2af025e7d13a8dea9a93c6eab3f9.tar.xz
gsoc2013-empathy-f6d60f33a0ab2af025e7d13a8dea9a93c6eab3f9.tar.zst
gsoc2013-empathy-f6d60f33a0ab2af025e7d13a8dea9a93c6eab3f9.zip
add empathy_connection_managers_call_when_ready
That's easier to use than checking if ready and connecting a callback.
Diffstat (limited to 'libempathy/empathy-connection-managers.c')
-rw-r--r--libempathy/empathy-connection-managers.c63
1 files changed, 63 insertions, 0 deletions
diff --git a/libempathy/empathy-connection-managers.c b/libempathy/empathy-connection-managers.c
index 5d381075e..7085b507b 100644
--- a/libempathy/empathy-connection-managers.c
+++ b/libempathy/empathy-connection-managers.c
@@ -291,3 +291,66 @@ empathy_connection_managers_get_cms_num (EmpathyConnectionManagers *self)
return g_list_length (priv->cms);
}
+
+typedef struct
+{
+ EmpathyConnectionManagers *self;
+ EmpathyConnectionManagersWhenReadyCb callback;
+ gpointer user_data;
+ guint ready_id;
+} CallWhenReadyContext;
+
+static void
+call_when_ready_ctx_free (CallWhenReadyContext *ctx)
+{
+ g_signal_handler_disconnect (ctx->self, ctx->ready_id);
+ g_object_unref (ctx->self);
+ g_slice_free (CallWhenReadyContext, ctx);
+}
+
+static void
+cwr_ready (EmpathyConnectionManagers *self,
+ GParamSpec *spec,
+ CallWhenReadyContext *ctx)
+{
+ g_assert (ctx->callback != NULL);
+
+ ctx->callback (self, NULL, ctx->user_data);
+
+ call_when_ready_ctx_free (ctx);
+}
+
+static CallWhenReadyContext *
+call_when_ready_ctx_new (EmpathyConnectionManagers *self,
+ EmpathyConnectionManagersWhenReadyCb callback,
+ gpointer user_data)
+{
+ CallWhenReadyContext *ctx = g_slice_new (CallWhenReadyContext);
+
+ ctx->self = g_object_ref (self);
+ ctx->callback = callback;
+ ctx->user_data = user_data;
+
+ ctx->ready_id = g_signal_connect (self, "notify::ready",
+ G_CALLBACK (cwr_ready), ctx);
+
+ return ctx;
+}
+
+void
+empathy_connection_managers_call_when_ready (
+ EmpathyConnectionManagers *self,
+ EmpathyConnectionManagersWhenReadyCb callback,
+ gpointer user_data)
+{
+ EmpathyConnectionManagersPriv *priv = GET_PRIV (self);
+
+ if (priv->ready)
+ {
+ callback (self, NULL, user_data);
+ }
+ else
+ {
+ call_when_ready_ctx_new (self, callback, user_data);
+ }
+}