]> git.0d.be Git - empathy.git/blobdiff - libempathy-gtk/empathy-persona-store.c
individual_view_drag_end: remove the auto scroll
[empathy.git] / libempathy-gtk / empathy-persona-store.c
index b77e34d4b76f7770360dd04e3bfdc18bc1d325ec..a48fa121e59ddd1a2808937c7b74686fadfa9c63 100644 (file)
@@ -142,7 +142,7 @@ persona_active_new (EmpathyPersonaStore *self,
   ShowActiveData *data;
 
   DEBUG ("Contact:'%s' now active, and %s be removed",
-      folks_aliasable_get_alias (FOLKS_ALIASABLE (persona)),
+      folks_alias_details_get_alias (FOLKS_ALIAS_DETAILS (persona)),
       remove_ ? "WILL" : "WILL NOT");
 
   data = g_slice_new0 (ShowActiveData);
@@ -186,12 +186,9 @@ persona_set_active (EmpathyPersonaStore *self,
     gboolean active,
     gboolean set_changed)
 {
-  EmpathyPersonaStorePriv *priv;
   GtkTreePath *path;
   GtkTreeIter iter;
 
-  priv = GET_PRIV (self);
-
   path = find_persona (self, persona);
   if (path == NULL)
     return;
@@ -213,7 +210,7 @@ static gboolean
 persona_active_cb (ShowActiveData *data)
 {
   const gchar *alias =
-      folks_aliasable_get_alias (FOLKS_ALIASABLE (data->persona));
+      folks_alias_details_get_alias (FOLKS_ALIAS_DETAILS (data->persona));
 
   if (data->remove)
     {
@@ -235,7 +232,7 @@ persona_updated_cb (FolksPersona *persona,
     EmpathyPersonaStore *self)
 {
   DEBUG ("Contact:'%s' updated, checking roster is in sync...",
-      folks_aliasable_get_alias (FOLKS_ALIASABLE (persona)));
+      folks_alias_details_get_alias (FOLKS_ALIAS_DETAILS (persona)));
 
   update_persona (self, persona);
 }
@@ -281,6 +278,7 @@ add_persona (EmpathyPersonaStore *self,
   GtkTreeIter iter;
   GtkTreePath *path;
   FolksPersonaStore *store;
+  TpContact *tp_contact;
   EmpathyContact *contact;
   const gchar *alias;
 
@@ -289,12 +287,15 @@ add_persona (EmpathyPersonaStore *self,
 
   priv = GET_PRIV (self);
 
-  alias = folks_aliasable_get_alias (FOLKS_ALIASABLE (persona));
+  alias = folks_alias_details_get_alias (FOLKS_ALIAS_DETAILS (persona));
   if (EMP_STR_EMPTY (alias))
     return;
 
-  contact = empathy_contact_dup_from_tp_contact (tpf_persona_get_contact (
-      TPF_PERSONA (persona)));
+  tp_contact = tpf_persona_get_contact (TPF_PERSONA (persona));
+  if (tp_contact == NULL)
+    return;
+
+  contact = empathy_contact_dup_from_tp_contact (tp_contact);
   store = folks_persona_get_store (persona);
 
   gtk_list_store_insert_with_values (GTK_LIST_STORE (self), &iter, 0,
@@ -351,14 +352,18 @@ get_persona_status_icon (EmpathyPersonaStore *self,
     FolksPersona *persona)
 {
   EmpathyPersonaStorePriv *priv = GET_PRIV (self);
+  TpContact *tp_contact;
   EmpathyContact *contact;
   const gchar *protocol_name = NULL;
   gchar *icon_name = NULL;
   GdkPixbuf *pixbuf_status = NULL;
   const gchar *status_icon_name = NULL;
 
-  contact = empathy_contact_dup_from_tp_contact (tpf_persona_get_contact (
-      TPF_PERSONA (persona)));
+  tp_contact = tpf_persona_get_contact (TPF_PERSONA (persona));
+  if (tp_contact == NULL)
+    return NULL;
+
+  contact = empathy_contact_dup_from_tp_contact (tp_contact);
 
   status_icon_name = empathy_icon_name_for_contact (contact);
   if (status_icon_name == NULL)
@@ -408,7 +413,7 @@ update_persona (EmpathyPersonaStore *self,
   const gchar *alias;
 
   path = find_persona (self, persona);
-  alias = folks_aliasable_get_alias (FOLKS_ALIASABLE (persona));
+  alias = folks_alias_details_get_alias (FOLKS_ALIAS_DETAILS (persona));
 
   if (path == NULL)
     {
@@ -425,9 +430,10 @@ update_persona (EmpathyPersonaStore *self,
   else
     {
       FolksPersonaStore *store;
+      TpContact *tp_contact;
       EmpathyContact *contact;
       GtkTreeIter iter;
-      GdkPixbuf *pixbuf_avatar;
+      GdkPixbuf *pixbuf_avatar = NULL;
       GdkPixbuf *pixbuf_status;
       gboolean now_online = FALSE;
       gboolean was_online = TRUE;
@@ -438,7 +444,8 @@ update_persona (EmpathyPersonaStore *self,
       gtk_tree_path_free (path);
 
       /* Get online state now. */
-      now_online = folks_has_presence_is_online (FOLKS_HAS_PRESENCE (persona));
+      now_online = folks_presence_details_is_online (
+          FOLKS_PRESENCE_DETAILS (persona));
 
       /* Get online state before. */
       gtk_tree_model_get (GTK_TREE_MODEL (self), &iter,
@@ -466,39 +473,43 @@ update_persona (EmpathyPersonaStore *self,
         }
 
       /* We still need to use EmpathyContact for the capabilities stuff */
-      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);
-      pixbuf_status = get_persona_status_icon (self, persona);
-
-      gtk_list_store_set (GTK_LIST_STORE (self), &iter,
-          EMPATHY_PERSONA_STORE_COL_ICON_STATUS, pixbuf_status,
-          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,
-              folks_has_presence_get_presence_type (
-                  FOLKS_HAS_PRESENCE (persona)),
-          EMPATHY_PERSONA_STORE_COL_STATUS,
-              folks_has_presence_get_presence_message (
-                  FOLKS_HAS_PRESENCE (persona)),
-          EMPATHY_PERSONA_STORE_COL_IS_ONLINE, now_online,
-          EMPATHY_PERSONA_STORE_COL_CAN_AUDIO_CALL,
-              empathy_contact_get_capabilities (contact) &
-                EMPATHY_CAPABILITIES_AUDIO,
-          EMPATHY_PERSONA_STORE_COL_CAN_VIDEO_CALL,
-              empathy_contact_get_capabilities (contact) &
-                EMPATHY_CAPABILITIES_VIDEO,
-          -1);
-
-      g_object_unref (contact);
+      tp_contact = tpf_persona_get_contact (TPF_PERSONA (persona));
+      if (tp_contact != NULL)
+        {
+          contact = empathy_contact_dup_from_tp_contact (tp_contact);
+          store = folks_persona_get_store (persona);
+
+          pixbuf_avatar = empathy_pixbuf_avatar_from_contact_scaled (contact,
+              32, 32);
+          pixbuf_status = get_persona_status_icon (self, persona);
+
+          gtk_list_store_set (GTK_LIST_STORE (self), &iter,
+              EMPATHY_PERSONA_STORE_COL_ICON_STATUS, pixbuf_status,
+              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,
+                  folks_presence_details_get_presence_type (
+                      FOLKS_PRESENCE_DETAILS (persona)),
+              EMPATHY_PERSONA_STORE_COL_STATUS,
+                  folks_presence_details_get_presence_message (
+                      FOLKS_PRESENCE_DETAILS (persona)),
+              EMPATHY_PERSONA_STORE_COL_IS_ONLINE, now_online,
+              EMPATHY_PERSONA_STORE_COL_CAN_AUDIO_CALL,
+                  empathy_contact_get_capabilities (contact) &
+                    EMPATHY_CAPABILITIES_AUDIO,
+              EMPATHY_PERSONA_STORE_COL_CAN_VIDEO_CALL,
+                  empathy_contact_get_capabilities (contact) &
+                    EMPATHY_CAPABILITIES_VIDEO,
+              -1);
+
+          g_object_unref (contact);
+        }
 
       if (pixbuf_avatar)
         g_object_unref (pixbuf_avatar);
@@ -528,11 +539,11 @@ update_persona (EmpathyPersonaStore *self,
 
 static void
 individual_personas_changed_cb (GObject *object,
-    GList *added,
-    GList *removed,
+    GeeSet *added,
+    GeeSet *removed,
     EmpathyPersonaStore *self)
 {
-  GList *l;
+  GeeIterator *iter;
 
   /* One of the personas' row references might hold the last reference to the
    * PersonaStore, so we need to keep a reference ourselves so we don't get
@@ -540,12 +551,24 @@ individual_personas_changed_cb (GObject *object,
   g_object_ref (self);
 
   /* Remove the old personas. */
-  for (l = removed; l != NULL; l = l->next)
-    remove_persona_and_disconnect (self, FOLKS_PERSONA (l->data));
+  iter = gee_iterable_iterator (GEE_ITERABLE (removed));
+  while (gee_iterator_next (iter))
+    {
+      FolksPersona *persona = gee_iterator_get (iter);
+      remove_persona_and_disconnect (self, persona);
+      g_clear_object (&persona);
+    }
+  g_clear_object (&iter);
 
   /* Add each of the new personas to the tree model */
-  for (l = added; l != NULL; l = l->next)
-    add_persona_and_connect (self, FOLKS_PERSONA (l->data));
+  iter = gee_iterable_iterator (GEE_ITERABLE (added));
+  while (gee_iterator_next (iter))
+    {
+      FolksPersona *persona = gee_iterator_get (iter);
+      add_persona_and_connect (self, persona);
+      g_clear_object (&persona);
+    }
+  g_clear_object (&iter);
 
   g_object_unref (self);
 }
@@ -556,14 +579,15 @@ sort_personas (FolksPersona *persona_a,
 {
   EmpathyContact *contact;
   TpAccount *account_a, *account_b;
+  TpContact *tp_contact_a, *tp_contact_b;
   gint ret_val;
 
   g_return_val_if_fail (persona_a != NULL || persona_b != NULL, 0);
 
   /* alias */
   ret_val = g_utf8_collate (
-      folks_aliasable_get_alias (FOLKS_ALIASABLE (persona_a)),
-      folks_aliasable_get_alias (FOLKS_ALIASABLE (persona_b)));
+      folks_alias_details_get_alias (FOLKS_ALIAS_DETAILS (persona_a)),
+      folks_alias_details_get_alias (FOLKS_ALIAS_DETAILS (persona_b)));
 
   if (ret_val != 0)
     goto out;
@@ -575,26 +599,34 @@ sort_personas (FolksPersona *persona_a,
   if (ret_val != 0)
     goto out;
 
-  contact = empathy_contact_dup_from_tp_contact (tpf_persona_get_contact (
-      TPF_PERSONA (persona_a)));
+  tp_contact_a = tpf_persona_get_contact (TPF_PERSONA (persona_a));
+  tp_contact_b = tpf_persona_get_contact (TPF_PERSONA (persona_b));
+
+  /* handle the case that one or more of these personas are from the cache */
+  if (tp_contact_a == NULL || tp_contact_b == NULL)
+    {
+      ret_val = (tp_contact_a != NULL ? 1 : -1);
+      goto out;
+    }
+
+  contact = empathy_contact_dup_from_tp_contact (tp_contact_a);
   account_a = empathy_contact_get_account (contact);
   g_object_unref (contact);
 
-  contact = empathy_contact_dup_from_tp_contact (tpf_persona_get_contact (
-      TPF_PERSONA (persona_b)));
+  contact = empathy_contact_dup_from_tp_contact (tp_contact_b);
   account_b = empathy_contact_get_account (contact);
   g_object_unref (contact);
 
   /* protocol */
   ret_val = strcmp (tp_account_get_protocol (account_a),
-        tp_account_get_protocol (account_a));
+        tp_account_get_protocol (account_b));
 
   if (ret_val != 0)
     goto out;
 
   /* account ID */
   ret_val = strcmp (tp_proxy_get_object_path (account_a),
-        tp_proxy_get_object_path (account_a));
+        tp_proxy_get_object_path (account_b));
 
 out:
   return ret_val;
@@ -628,8 +660,10 @@ state_sort_func (GtkTreeModel *model,
    * the presences.
    */
   ret_val = -tp_connection_presence_type_cmp_availability (
-      folks_has_presence_get_presence_type (FOLKS_HAS_PRESENCE (persona_a)),
-      folks_has_presence_get_presence_type (FOLKS_HAS_PRESENCE (persona_b)));
+      folks_presence_details_get_presence_type (
+          FOLKS_PRESENCE_DETAILS (persona_a)),
+      folks_presence_details_get_presence_type (
+          FOLKS_PRESENCE_DETAILS (persona_b)));
 
   if (ret_val == 0) {
     /* Fallback: compare by name et al. */
@@ -864,8 +898,8 @@ finalize (GObject *object)
 {
   EmpathyPersonaStorePriv *priv = GET_PRIV (object);
 
-  g_hash_table_destroy (priv->status_icons);
-  g_hash_table_destroy (priv->personas);
+  g_hash_table_unref (priv->status_icons);
+  g_hash_table_unref (priv->personas);
 
   G_OBJECT_CLASS (empathy_persona_store_parent_class)->finalize (object);
 }
@@ -995,15 +1029,22 @@ empathy_persona_store_set_individual (EmpathyPersonaStore *self,
   /* Remove the old individual */
   if (priv->individual != NULL)
     {
-      GList *personas, *l;
+      GeeSet *personas;
+      GeeIterator *iter;
 
       g_signal_handlers_disconnect_by_func (priv->individual,
           (GCallback) individual_personas_changed_cb, self);
 
       /* Disconnect from and remove all personas belonging to this individual */
       personas = folks_individual_get_personas (priv->individual);
-      for (l = personas; l != NULL; l = l->next)
-        remove_persona_and_disconnect (self, FOLKS_PERSONA (l->data));
+      iter = gee_iterable_iterator (GEE_ITERABLE (personas));
+      while (gee_iterator_next (iter))
+        {
+          FolksPersona *persona = gee_iterator_get (iter);
+          remove_persona_and_disconnect (self, persona);
+          g_clear_object (&persona);
+        }
+      g_clear_object (&iter);
 
       g_object_unref (priv->individual);
     }
@@ -1013,7 +1054,8 @@ empathy_persona_store_set_individual (EmpathyPersonaStore *self,
   /* Add the new individual */
   if (individual != NULL)
     {
-      GList *personas, *l;
+      GeeSet *personas;
+      GeeIterator *iter;
 
       g_object_ref (individual);
 
@@ -1021,9 +1063,16 @@ empathy_persona_store_set_individual (EmpathyPersonaStore *self,
           (GCallback) individual_personas_changed_cb, self);
 
       /* Add pre-existing Personas */
+
       personas = folks_individual_get_personas (individual);
-      for (l = personas; l != NULL; l = l->next)
-        add_persona_and_connect (self, FOLKS_PERSONA (l->data));
+      iter = gee_iterable_iterator (GEE_ITERABLE (personas));
+      while (gee_iterator_next (iter))
+        {
+          FolksPersona *persona = gee_iterator_get (iter);
+          add_persona_and_connect (self, persona);
+          g_clear_object (&persona);
+        }
+      g_clear_object (&iter);
     }
 
   g_object_notify (G_OBJECT (self), "individual");