aboutsummaryrefslogtreecommitdiffstats
path: root/libempathy/empathy-contact.c
diff options
context:
space:
mode:
authorSjoerd Simons <sjoerd.simons@collabora.co.uk>2009-01-10 00:11:48 +0800
committerXavier Claessens <xclaesse@src.gnome.org>2009-01-10 00:11:48 +0800
commit19dc1bdbd665f4ce79ec186294618218f65be49f (patch)
treee5c62c5a8cf7b46d4b5f469e6297482b0018f818 /libempathy/empathy-contact.c
parent56524fbc916e872c70465dec7c1cf5b59e066fb5 (diff)
downloadgsoc2013-empathy-19dc1bdbd665f4ce79ec186294618218f65be49f.tar
gsoc2013-empathy-19dc1bdbd665f4ce79ec186294618218f65be49f.tar.gz
gsoc2013-empathy-19dc1bdbd665f4ce79ec186294618218f65be49f.tar.bz2
gsoc2013-empathy-19dc1bdbd665f4ce79ec186294618218f65be49f.tar.lz
gsoc2013-empathy-19dc1bdbd665f4ce79ec186294618218f65be49f.tar.xz
gsoc2013-empathy-19dc1bdbd665f4ce79ec186294618218f65be49f.tar.zst
gsoc2013-empathy-19dc1bdbd665f4ce79ec186294618218f65be49f.zip
Add empathy_contact_call_when_ready
Signed-off-by: Sjoerd Simons <sjoerd.simons@collabora.co.uk> svn path=/trunk/; revision=2126
Diffstat (limited to 'libempathy/empathy-contact.c')
-rw-r--r--libempathy/empathy-contact.c74
1 files changed, 63 insertions, 11 deletions
diff --git a/libempathy/empathy-contact.c b/libempathy/empathy-contact.c
index 541858673..a8a617c29 100644
--- a/libempathy/empathy-contact.c
+++ b/libempathy/empathy-contact.c
@@ -53,8 +53,15 @@ typedef struct {
gboolean is_user;
guint hash;
EmpathyContactReady ready;
+ GList *ready_callbacks;
} EmpathyContactPriv;
+typedef struct {
+ EmpathyContactReady ready;
+ EmpathyContactReadyCb *callback;
+ gpointer user_data;
+} ReadyCbData;
+
static void contact_finalize (GObject *object);
static void contact_get_property (GObject *object, guint param_id,
GValue *value, GParamSpec *pspec);
@@ -330,6 +337,21 @@ contact_set_property (GObject *object,
};
}
+static gboolean
+contact_is_ready (EmpathyContact *contact, EmpathyContactReady ready)
+{
+ EmpathyContactPriv *priv = GET_PRIV (contact);
+
+ /* When the name is NULL, empathy_contact_get_name() fallback to the id.
+ * When the caller want to wait the name to be ready, it also want to wait
+ * the id to be ready in case of fallback. */
+ if ((ready & EMPATHY_CONTACT_READY_NAME) && G_STR_EMPTY (priv->name))
+ ready |= EMPATHY_CONTACT_READY_ID;
+
+ return (priv->ready & ready) == ready;
+}
+
+
static void
contact_set_ready_flag (EmpathyContact *contact,
EmpathyContactReady flag)
@@ -338,8 +360,24 @@ contact_set_ready_flag (EmpathyContact *contact,
if (!(priv->ready & flag))
{
+ GList *l, *ln;
+
priv->ready |= flag;
g_object_notify (G_OBJECT (contact), "ready");
+
+ for (l = priv->ready_callbacks ; l != NULL ; l = ln )
+ {
+ ReadyCbData *d = (ReadyCbData *)l->data;
+ ln = g_list_next (l);
+
+ if (contact_is_ready (contact, d->ready))
+ {
+ d->callback (contact, d->user_data);
+
+ priv->ready_callbacks = g_list_delete_link
+ (priv->ready_callbacks, l);
+ }
+ }
}
}
@@ -768,22 +806,36 @@ empathy_contact_hash (gconstpointer key)
return priv->hash;
}
-static gboolean
-contact_is_ready_func (GObject *contact,
- gpointer user_data)
+void empathy_contact_call_when_ready (EmpathyContact *contact,
+ EmpathyContactReady ready, EmpathyContactReadyCb *callback, gpointer
+ user_data)
{
EmpathyContactPriv *priv = GET_PRIV (contact);
- EmpathyContactReady ready;
- ready = GPOINTER_TO_UINT (user_data);
+ g_return_if_fail (contact != NULL);
+ g_return_if_fail (callback != NULL);
- /* When the name is NULL, empathy_contact_get_name() fallback to the id.
- * When the caller want to wait the name to be ready, it also want to wait
- * the id to be ready in case of fallback. */
- if ((ready & EMPATHY_CONTACT_READY_NAME) && G_STR_EMPTY (priv->name))
- ready |= EMPATHY_CONTACT_READY_ID;
+ if (contact_is_ready (contact, ready))
+ {
+ callback (contact, user_data);
+ }
+ else
+ {
+ ReadyCbData *d = g_slice_new0 (ReadyCbData);
+ d->ready = ready;
+ d->callback = callback;
+ d->user_data = user_data;
+ priv->ready_callbacks = g_list_prepend (priv->ready_callbacks,
+ d);
+ }
+}
- return (priv->ready & ready) == ready;
+static gboolean
+contact_is_ready_func (GObject *contact,
+ gpointer user_data)
+{
+ return contact_is_ready (EMPATHY_CONTACT (contact),
+ GPOINTER_TO_UINT (user_data));
}
void