};
}
+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)
{
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)) {
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");
}
void
empathy_contact_set_handle (EmpathyContact *contact,
- guint handle)
+ guint handle)
{
EmpathyContactPriv *priv;
}
priv->handle = handle;
+ contact_set_ready_flag (contact, EMPATHY_CONTACT_READY_HANDLE,
+ handle != 0);
g_object_notify (G_OBJECT (contact), "handle");
}
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);
+}
+
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;
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