]> git.0d.be Git - empathy.git/blobdiff - libempathy-gtk/empathy-persona-store.c
Merge branch 'sasl'
[empathy.git] / libempathy-gtk / empathy-persona-store.c
index 52a03d6e4b102b8f8d09d175b7fc8e064375df54..fbeeb6991ae5c1a2a7fd8536eddf254646588f41 100644 (file)
@@ -142,7 +142,7 @@ persona_active_new (EmpathyPersonaStore *self,
   ShowActiveData *data;
 
   DEBUG ("Contact:'%s' now active, and %s be removed",
-      folks_alias_get_alias (FOLKS_ALIAS (persona)),
+      folks_aliasable_get_alias (FOLKS_ALIASABLE (persona)),
       remove_ ? "WILL" : "WILL NOT");
 
   data = g_slice_new0 (ShowActiveData);
@@ -212,7 +212,8 @@ persona_set_active (EmpathyPersonaStore *self,
 static gboolean
 persona_active_cb (ShowActiveData *data)
 {
-  const gchar *alias = folks_alias_get_alias (FOLKS_ALIAS (data->persona));
+  const gchar *alias =
+      folks_aliasable_get_alias (FOLKS_ALIASABLE (data->persona));
 
   if (data->remove)
     {
@@ -234,7 +235,7 @@ persona_updated_cb (FolksPersona *persona,
     EmpathyPersonaStore *self)
 {
   DEBUG ("Contact:'%s' updated, checking roster is in sync...",
-      folks_alias_get_alias (FOLKS_ALIAS (persona)));
+      folks_aliasable_get_alias (FOLKS_ALIASABLE (persona)));
 
   update_persona (self, persona);
 }
@@ -279,6 +280,7 @@ add_persona (EmpathyPersonaStore *self,
   EmpathyPersonaStorePriv *priv;
   GtkTreeIter iter;
   GtkTreePath *path;
+  FolksPersonaStore *store;
   EmpathyContact *contact;
   const gchar *alias;
 
@@ -287,15 +289,18 @@ add_persona (EmpathyPersonaStore *self,
 
   priv = GET_PRIV (self);
 
-  alias = folks_alias_get_alias (FOLKS_ALIAS (persona));
+  alias = folks_aliasable_get_alias (FOLKS_ALIASABLE (persona));
   if (EMP_STR_EMPTY (alias))
     return;
 
-  contact = empathy_contact_new (tpf_persona_get_contact (
+  contact = empathy_contact_dup_from_tp_contact (tpf_persona_get_contact (
       TPF_PERSONA (persona)));
+  store = folks_persona_get_store (persona);
 
   gtk_list_store_insert_with_values (GTK_LIST_STORE (self), &iter, 0,
       EMPATHY_PERSONA_STORE_COL_NAME, alias,
+      EMPATHY_PERSONA_STORE_COL_ACCOUNT_NAME,
+          folks_persona_store_get_display_name (store),
       EMPATHY_PERSONA_STORE_COL_DISPLAY_ID,
           folks_persona_get_display_id (persona),
       EMPATHY_PERSONA_STORE_COL_PERSONA, persona,
@@ -352,7 +357,7 @@ get_persona_status_icon (EmpathyPersonaStore *self,
   GdkPixbuf *pixbuf_status = NULL;
   const gchar *status_icon_name = NULL;
 
-  contact = empathy_contact_new (tpf_persona_get_contact (
+  contact = empathy_contact_dup_from_tp_contact (tpf_persona_get_contact (
       TPF_PERSONA (persona)));
 
   status_icon_name = empathy_icon_name_for_contact (contact);
@@ -403,7 +408,7 @@ update_persona (EmpathyPersonaStore *self,
   const gchar *alias;
 
   path = find_persona (self, persona);
-  alias = folks_alias_get_alias (FOLKS_ALIAS (persona));
+  alias = folks_aliasable_get_alias (FOLKS_ALIASABLE (persona));
 
   if (path == NULL)
     {
@@ -419,6 +424,7 @@ update_persona (EmpathyPersonaStore *self,
     }
   else
     {
+      FolksPersonaStore *store;
       EmpathyContact *contact;
       GtkTreeIter iter;
       GdkPixbuf *pixbuf_avatar;
@@ -460,8 +466,9 @@ update_persona (EmpathyPersonaStore *self,
         }
 
       /* We still need to use EmpathyContact for the capabilities stuff */
-      contact = empathy_contact_new (tpf_persona_get_contact (
+      contact = empathy_contact_dup_from_tp_contact (tpf_persona_get_contact (
           TPF_PERSONA (persona)));
+      store = folks_persona_get_store (persona);
 
       pixbuf_avatar = empathy_pixbuf_avatar_from_contact_scaled (contact,
           32, 32);
@@ -472,6 +479,8 @@ update_persona (EmpathyPersonaStore *self,
           EMPATHY_PERSONA_STORE_COL_PIXBUF_AVATAR, pixbuf_avatar,
           EMPATHY_PERSONA_STORE_COL_PIXBUF_AVATAR_VISIBLE, priv->show_avatars,
           EMPATHY_PERSONA_STORE_COL_NAME, alias,
+          EMPATHY_PERSONA_STORE_COL_ACCOUNT_NAME,
+              folks_persona_store_get_display_name (store),
           EMPATHY_PERSONA_STORE_COL_DISPLAY_ID,
               folks_persona_get_display_id (persona),
           EMPATHY_PERSONA_STORE_COL_PRESENCE_TYPE,
@@ -516,42 +525,20 @@ update_persona (EmpathyPersonaStore *self,
 }
 
 static void
-individual_notify_personas_cb (GObject *object,
-    GParamSpec *pspec,
+individual_personas_changed_cb (GObject *object,
+    GList *added,
+    GList *removed,
     EmpathyPersonaStore *self)
 {
-  EmpathyPersonaStorePriv *priv = GET_PRIV (self);
-  GList *old_personas, *new_personas, *removed_personas, *l;
-
-  /* Remove old personas which are no longer in the individual.
-   * Build a list of such personas to remove from our hash table.
-   * This is slow. */
-  old_personas = g_hash_table_get_keys (priv->personas);
-  new_personas = folks_individual_get_personas (FOLKS_INDIVIDUAL (object));
-  removed_personas = NULL;
+  GList *l;
 
-  for (l = old_personas; l != NULL; l = l->next)
-    {
-      GList *i = g_list_find (new_personas, l->data);
-      if (i == NULL)
-        removed_personas = g_list_prepend (removed_personas, l->data);
-    }
-  g_list_free (old_personas);
-
-  /* Remove the removed personas. We can't do this from inside the above loop,
-   * as old_personas is only valid until the hash table is modified. */
-  for (l = removed_personas; l != NULL; l = l->next)
+  /* Remove the old personas. */
+  for (l = removed; l != NULL; l = l->next)
     remove_persona_and_disconnect (self, FOLKS_PERSONA (l->data));
-  g_list_free (removed_personas);
 
   /* Add each of the new personas to the tree model */
-  for (l = new_personas; l != NULL; l = l->next)
-    {
-      FolksPersona *persona = FOLKS_PERSONA (l->data);
-
-      if (g_hash_table_lookup (priv->personas, persona) == NULL)
-        add_persona_and_connect (self, persona);
-    }
+  for (l = added; l != NULL; l = l->next)
+    add_persona_and_connect (self, FOLKS_PERSONA (l->data));
 }
 
 static gint
@@ -565,8 +552,9 @@ sort_personas (FolksPersona *persona_a,
   g_return_val_if_fail (persona_a != NULL || persona_b != NULL, 0);
 
   /* alias */
-  ret_val = g_utf8_collate (folks_alias_get_alias (FOLKS_ALIAS (persona_a)),
-          folks_alias_get_alias (FOLKS_ALIAS (persona_b)));
+  ret_val = g_utf8_collate (
+      folks_aliasable_get_alias (FOLKS_ALIASABLE (persona_a)),
+      folks_aliasable_get_alias (FOLKS_ALIASABLE (persona_b)));
 
   if (ret_val != 0)
     goto out;
@@ -578,12 +566,12 @@ sort_personas (FolksPersona *persona_a,
   if (ret_val != 0)
     goto out;
 
-  contact = empathy_contact_new (tpf_persona_get_contact (
+  contact = empathy_contact_dup_from_tp_contact (tpf_persona_get_contact (
       TPF_PERSONA (persona_a)));
   account_a = empathy_contact_get_account (contact);
   g_object_unref (contact);
 
-  contact = empathy_contact_new (tpf_persona_get_contact (
+  contact = empathy_contact_dup_from_tp_contact (tpf_persona_get_contact (
       TPF_PERSONA (persona_b)));
   account_b = empathy_contact_get_account (contact);
   g_object_unref (contact);
@@ -734,6 +722,7 @@ set_up (EmpathyPersonaStore *self)
     GDK_TYPE_PIXBUF,      /* Avatar pixbuf */
     G_TYPE_BOOLEAN,       /* Avatar pixbuf visible */
     G_TYPE_STRING,        /* Name */
+    G_TYPE_STRING,        /* Account name */
     G_TYPE_STRING,        /* Display ID */
     G_TYPE_UINT,          /* Presence type */
     G_TYPE_STRING,        /* Status string */
@@ -1000,7 +989,7 @@ empathy_persona_store_set_individual (EmpathyPersonaStore *self,
       GList *personas, *l;
 
       g_signal_handlers_disconnect_by_func (priv->individual,
-          (GCallback) individual_notify_personas_cb, self);
+          (GCallback) individual_personas_changed_cb, self);
 
       /* Disconnect from and remove all personas belonging to this individual */
       personas = folks_individual_get_personas (priv->individual);
@@ -1019,8 +1008,8 @@ empathy_persona_store_set_individual (EmpathyPersonaStore *self,
 
       g_object_ref (individual);
 
-      g_signal_connect (individual, "notify::personas",
-          (GCallback) individual_notify_personas_cb, self);
+      g_signal_connect (individual, "personas-changed",
+          (GCallback) individual_personas_changed_cb, self);
 
       /* Add pre-existing Personas */
       personas = folks_individual_get_personas (individual);