aboutsummaryrefslogtreecommitdiffstats
path: root/libempathy/empathy-utils.c
diff options
context:
space:
mode:
authorXavier Claessens <xclaesse@src.gnome.org>2008-04-11 21:10:32 +0800
committerXavier Claessens <xclaesse@src.gnome.org>2008-04-11 21:10:32 +0800
commit3346d34f028b478093817ab18d8c8591e7319dad (patch)
tree4f1b98a34e7cda55194a22315c8aa07e868be804 /libempathy/empathy-utils.c
parent0a9b1b97332e50e1b86d29ae836f9e81f2d6ed7d (diff)
downloadgsoc2013-empathy-3346d34f028b478093817ab18d8c8591e7319dad.tar
gsoc2013-empathy-3346d34f028b478093817ab18d8c8591e7319dad.tar.gz
gsoc2013-empathy-3346d34f028b478093817ab18d8c8591e7319dad.tar.bz2
gsoc2013-empathy-3346d34f028b478093817ab18d8c8591e7319dad.tar.lz
gsoc2013-empathy-3346d34f028b478093817ab18d8c8591e7319dad.tar.xz
gsoc2013-empathy-3346d34f028b478093817ab18d8c8591e7319dad.tar.zst
gsoc2013-empathy-3346d34f028b478093817ab18d8c8591e7319dad.zip
Add empathy_run_until_read[_full] functions
svn path=/trunk/; revision=892
Diffstat (limited to 'libempathy/empathy-utils.c')
-rw-r--r--libempathy/empathy-utils.c76
1 files changed, 76 insertions, 0 deletions
diff --git a/libempathy/empathy-utils.c b/libempathy/empathy-utils.c
index 07cd6802e..3b6b1bbd2 100644
--- a/libempathy/empathy-utils.c
+++ b/libempathy/empathy-utils.c
@@ -605,4 +605,80 @@ empathy_file_lookup (const gchar *filename, const gchar *subdir)
return path;
}
+typedef struct {
+ EmpathyRunUntilReadyFunc func;
+ gpointer user_data;
+ GObject *object;
+ GMainLoop *loop;
+} RunUntilReadyData;
+
+static void
+run_until_ready_cb (RunUntilReadyData *data)
+{
+ if (!data->func || data->func (data->object, data->user_data)) {
+ empathy_debug (DEBUG_DOMAIN, "Object %p is ready", data->object);
+ g_main_loop_quit (data->loop);
+ }
+}
+
+static gboolean
+object_is_ready (GObject *object,
+ gpointer user_data)
+{
+ gboolean ready;
+
+ g_object_get (object, "ready", &ready, NULL);
+
+ return ready;
+}
+
+void
+empathy_run_until_ready_full (gpointer object,
+ const gchar *signal,
+ EmpathyRunUntilReadyFunc func,
+ gpointer user_data,
+ GMainLoop **loop)
+{
+ RunUntilReadyData data;
+ gulong signal_id;
+
+ g_return_if_fail (G_IS_OBJECT (object));
+ g_return_if_fail (signal != NULL);
+
+ if (func && func (object, user_data)) {
+ return;
+ }
+
+ empathy_debug (DEBUG_DOMAIN, "Starting run until ready for object %p",
+ object);
+
+ data.func = func;
+ data.user_data = user_data;
+ data.object = object;
+ data.loop = g_main_loop_new (NULL, FALSE);
+
+ signal_id = g_signal_connect_swapped (object, signal,
+ G_CALLBACK (run_until_ready_cb),
+ &data);
+ if (loop != NULL) {
+ *loop = data.loop;
+ }
+
+ g_main_loop_run (data.loop);
+
+ if (loop != NULL) {
+ *loop = NULL;
+ }
+
+ g_signal_handler_disconnect (object, signal_id);
+ g_main_loop_unref (data.loop);
+}
+
+void
+empathy_run_until_ready (gpointer object)
+{
+ empathy_run_until_ready_full (object, "notify::ready", object_is_ready,
+ NULL, NULL);
+}
+