aboutsummaryrefslogtreecommitdiffstats
path: root/libempathy
diff options
context:
space:
mode:
authorXavier Claessens <xclaesse@src.gnome.org>2008-03-11 20:22:24 +0800
committerXavier Claessens <xclaesse@src.gnome.org>2008-03-11 20:22:24 +0800
commit584b98b1c352383f80d41713104d1a2fe5953e8b (patch)
tree153c372be1f056ff41ededf2e12c414fe9f1248d /libempathy
parentc68fcffc69b5c5941883965496f62f8b056868b0 (diff)
downloadgsoc2013-empathy-584b98b1c352383f80d41713104d1a2fe5953e8b.tar
gsoc2013-empathy-584b98b1c352383f80d41713104d1a2fe5953e8b.tar.gz
gsoc2013-empathy-584b98b1c352383f80d41713104d1a2fe5953e8b.tar.bz2
gsoc2013-empathy-584b98b1c352383f80d41713104d1a2fe5953e8b.tar.lz
gsoc2013-empathy-584b98b1c352383f80d41713104d1a2fe5953e8b.tar.xz
gsoc2013-empathy-584b98b1c352383f80d41713104d1a2fe5953e8b.tar.zst
gsoc2013-empathy-584b98b1c352383f80d41713104d1a2fe5953e8b.zip
Add empathy_contact_run_until_ready()
svn path=/trunk/; revision=749
Diffstat (limited to 'libempathy')
-rw-r--r--libempathy/empathy-contact.c78
-rw-r--r--libempathy/empathy-contact.h5
2 files changed, 81 insertions, 2 deletions
diff --git a/libempathy/empathy-contact.c b/libempathy/empathy-contact.c
index 7e3fa8f75..8f74119d6 100644
--- a/libempathy/empathy-contact.c
+++ b/libempathy/empathy-contact.c
@@ -313,6 +313,25 @@ contact_set_property (GObject *object,
};
}
+static void
+contact_set_ready_flag (EmpathyContact *contact,
+ EmpathyContactReady flag,
+ gboolean set)
+{
+ EmpathyContactPriv *priv = GET_PRIV (contact);
+ EmpathyContactReady ready_old = priv->ready;
+
+ if (set) {
+ priv->ready |= flag;
+ } else {
+ priv->ready &= ~flag;
+ }
+
+ if (priv->ready != ready_old) {
+ g_object_notify (G_OBJECT (contact), "ready");
+ }
+}
+
EmpathyContact *
empathy_contact_new (McAccount *account)
{
@@ -362,6 +381,8 @@ empathy_contact_set_id (EmpathyContact *contact,
g_free (priv->id);
priv->id = g_strdup (id);
+ contact_set_ready_flag (contact, EMPATHY_CONTACT_READY_ID,
+ !G_STR_EMPTY (id));
g_object_notify (G_OBJECT (contact), "id");
if (G_STR_EMPTY (priv->name)) {
@@ -401,6 +422,8 @@ empathy_contact_set_name (EmpathyContact *contact,
g_free (priv->name);
priv->name = g_strdup (name);
+ contact_set_ready_flag (contact, EMPATHY_CONTACT_READY_NAME,
+ !G_STR_EMPTY (name));
g_object_notify (G_OBJECT (contact), "name");
}
@@ -553,7 +576,7 @@ empathy_contact_get_handle (EmpathyContact *contact)
void
empathy_contact_set_handle (EmpathyContact *contact,
- guint handle)
+ guint handle)
{
EmpathyContactPriv *priv;
@@ -566,6 +589,8 @@ empathy_contact_set_handle (EmpathyContact *contact,
}
priv->handle = handle;
+ contact_set_ready_flag (contact, EMPATHY_CONTACT_READY_HANDLE,
+ handle != 0);
g_object_notify (G_OBJECT (contact), "handle");
}
@@ -722,3 +747,54 @@ empathy_contact_hash (gconstpointer key)
return priv->hash;
}
+typedef struct {
+ EmpathyContactReady ready;
+ GMainLoop *loop;
+} RunUntilReadyData;
+
+static void
+contact_ready_notify_cb (EmpathyContact *contact,
+ GParamSpec *param,
+ RunUntilReadyData *data)
+{
+ EmpathyContactPriv *priv = GET_PRIV (contact);
+
+ if ((priv->ready & data->ready) == data->ready) {
+ g_main_loop_quit (data->loop);
+ }
+}
+
+void
+empathy_contact_run_until_ready (EmpathyContact *contact,
+ EmpathyContactReady ready,
+ GMainLoop **loop)
+{
+ EmpathyContactPriv *priv = GET_PRIV (contact);
+ RunUntilReadyData data;
+ gulong signal_id;
+
+ g_return_if_fail (EMPATHY_IS_CONTACT (contact));
+
+ if ((priv->ready & ready) == ready) {
+ return;
+ }
+
+ data.loop = g_main_loop_new (NULL, FALSE);
+
+ signal_id = g_signal_connect (contact, "notify::ready",
+ G_CALLBACK (contact_ready_notify_cb),
+ &data);
+ if (loop != NULL) {
+ *loop = data.loop;
+ }
+
+ g_main_loop_run (data.loop);
+
+ if (loop != NULL) {
+ *loop = NULL;
+ }
+
+ g_signal_handler_disconnect (contact, signal_id);
+ g_main_loop_unref (data.loop);
+}
+
diff --git a/libempathy/empathy-contact.h b/libempathy/empathy-contact.h
index 343bf2f49..7d72b908f 100644
--- a/libempathy/empathy-contact.h
+++ b/libempathy/empathy-contact.h
@@ -64,7 +64,7 @@ typedef enum {
EMPATHY_CONTACT_READY_NONE = 0,
EMPATHY_CONTACT_READY_ID = 1 << 0,
EMPATHY_CONTACT_READY_HANDLE = 1 << 1,
- EMPATHY_CONTACT_READY_ALIAS = 1 << 2,
+ EMPATHY_CONTACT_READY_NAME = 1 << 2,
EMPATHY_CONTACT_READY_ALL = (1 << 3) - 1,
} EmpathyContactReady;
@@ -107,6 +107,9 @@ gboolean empathy_contact_can_voip (EmpathyContact *con
gboolean empathy_contact_equal (gconstpointer v1,
gconstpointer v2);
guint empathy_contact_hash (gconstpointer key);
+void empathy_contact_run_until_ready (EmpathyContact *contact,
+ EmpathyContactReady ready,
+ GMainLoop **loop);
G_END_DECLS