]> git.0d.be Git - empathy.git/blobdiff - libempathy-gtk/empathy-individual-store.c
Merge branch 'gnome-3-8'
[empathy.git] / libempathy-gtk / empathy-individual-store.c
index aa3f6334d77f033115ab5ba3a9ae4691367fae13..3ebe35a6b03552f61bb1e4166270263d8a7596f0 100644 (file)
  */
 
 #include "config.h"
+#include "empathy-individual-store.h"
 
-#include <string.h>
-
-#include <glib.h>
 #include <glib/gi18n-lib.h>
-#include <gtk/gtk.h>
-
-#include <folks/folks.h>
-#include <folks/folks-telepathy.h>
-#include <telepathy-glib/util.h>
 
-#include <libempathy/empathy-utils.h>
-#include <libempathy/empathy-enum-types.h>
-
-#include "empathy-individual-store.h"
-#include "empathy-ui-utils.h"
 #include "empathy-gtk-enum-types.h"
+#include "empathy-ui-utils.h"
+#include "empathy-utils.h"
 
 #define DEBUG_FLAG EMPATHY_DEBUG_CONTACT
-#include <libempathy/empathy-debug.h>
+#include "empathy-debug.h"
 
 /* Active users are those which have recently changed state
  * (e.g. online, offline or from normal to a busy state).
@@ -100,48 +90,6 @@ static void individual_store_contact_update (EmpathyIndividualStore *self,
 G_DEFINE_TYPE (EmpathyIndividualStore, empathy_individual_store,
     GTK_TYPE_TREE_STORE);
 
-static const gchar * const *
-individual_get_client_types (FolksIndividual *individual)
-{
-  GeeSet *personas;
-  GeeIterator *iter;
-  const gchar * const *types = NULL;
-  FolksPresenceType presence_type = FOLKS_PRESENCE_TYPE_UNSET;
-
-  personas = folks_individual_get_personas (individual);
-  iter = gee_iterable_iterator (GEE_ITERABLE (personas));
-  while (gee_iterator_next (iter))
-    {
-      FolksPresenceDetails *presence;
-      FolksPersona *persona = gee_iterator_get (iter);
-
-      /* We only want personas which have presence and a TpContact */
-      if (!empathy_folks_persona_is_interesting (persona))
-        goto while_finish;
-
-      presence = FOLKS_PRESENCE_DETAILS (persona);
-
-      if (folks_presence_details_typecmp (
-              folks_presence_details_get_presence_type (presence),
-              presence_type) > 0)
-        {
-          TpContact *tp_contact;
-
-          presence_type = folks_presence_details_get_presence_type (presence);
-
-          tp_contact = tpf_persona_get_contact (TPF_PERSONA (persona));
-          if (tp_contact != NULL)
-            types = tp_contact_get_client_types (tp_contact);
-        }
-
-while_finish:
-      g_clear_object (&persona);
-    }
-  g_clear_object (&iter);
-
-  return types;
-}
-
 static void
 add_individual_to_store (GtkTreeStore *store,
     GtkTreeIter *iter,
@@ -156,7 +104,7 @@ add_individual_to_store (GtkTreeStore *store,
   empathy_individual_can_audio_video_call (individual, &can_audio_call,
       &can_video_call, NULL);
 
-  types = individual_get_client_types (individual);
+  types = empathy_individual_get_client_types (individual);
 
   gtk_tree_store_insert_with_values (store, iter, parent, 0,
       EMPATHY_INDIVIDUAL_STORE_COL_NAME,
@@ -330,94 +278,100 @@ void
 empathy_individual_store_add_individual (EmpathyIndividualStore *self,
     FolksIndividual *individual)
 {
-  GtkTreeIter iter;
-  GeeIterator *group_iter = NULL;
+  GtkTreeIter iter, iter_group;
+  GeeSet *group_set = NULL;
+  gboolean grouped = FALSE;
 
   if (EMP_STR_EMPTY (folks_alias_details_get_alias (
           FOLKS_ALIAS_DETAILS (individual))))
     return;
 
-  if (self->priv->show_groups)
+  if (!self->priv->show_groups)
     {
-      GeeSet *group_set = NULL;
-
-      group_set = folks_group_details_get_groups (
-          FOLKS_GROUP_DETAILS (individual));
+      /* add our individual to the toplevel of the store */
+      add_individual_to_store (GTK_TREE_STORE (self), &iter, NULL,
+          individual);
 
-      if (gee_collection_get_size (GEE_COLLECTION (group_set)) > 0)
-        group_iter = gee_iterable_iterator (GEE_ITERABLE (group_set));
+      goto finally;
     }
 
-  /* fall-back groups, in case there are no named groups */
-  if (group_iter == NULL)
+  group_set = folks_group_details_get_groups (
+      FOLKS_GROUP_DETAILS (individual));
+
+  if (gee_collection_get_size (GEE_COLLECTION (group_set)) > 0)
     {
-      GtkTreeIter iter_group, *parent;
+      /* add the contact to its groups */
+      GeeIterator *group_iter =
+        gee_iterable_iterator (GEE_ITERABLE (group_set));
+
+      while (group_iter != NULL && gee_iterator_next (group_iter))
+        {
+          gchar *group_name = gee_iterator_get (group_iter);
+
+          individual_store_get_group (self, group_name, &iter_group,
+              NULL, NULL, FALSE);
+
+          add_individual_to_store (GTK_TREE_STORE (self), &iter, &iter_group,
+              individual);
+          grouped = TRUE;
+
+          g_free (group_name);
+        }
+
+      g_clear_object (&group_iter);
+    }
+  else
+    {
+      /* fall-back groups, in case there are no named groups */
       EmpathyContact *contact;
       TpConnection *connection;
-      gchar *protocol_name = NULL;
-
-      parent = &iter_group;
+      const gchar *protocol_name = NULL;
 
       contact = empathy_contact_dup_from_folks_individual (individual);
       if (contact != NULL)
         {
           connection = empathy_contact_get_connection (contact);
-          tp_connection_parse_object_path (connection, &protocol_name, NULL);
+          protocol_name = tp_connection_get_protocol_name (connection);
         }
 
-      if (!self->priv->show_groups)
-        parent = NULL;
-      else if (!tp_strdiff (protocol_name, "local-xmpp"))
+      if (!tp_strdiff (protocol_name, "local-xmpp"))
         {
           /* these are People Nearby */
           individual_store_get_group (self,
               EMPATHY_INDIVIDUAL_STORE_PEOPLE_NEARBY, &iter_group, NULL, NULL,
               TRUE);
-        }
-      else
-        {
-          individual_store_get_group (self,
-              EMPATHY_INDIVIDUAL_STORE_UNGROUPED,
-              &iter_group, NULL, NULL, TRUE);
+          add_individual_to_store (GTK_TREE_STORE (self), &iter, &iter_group,
+              individual);
+          grouped = TRUE;
         }
 
-      add_individual_to_store (GTK_TREE_STORE (self), &iter, parent,
-          individual);
-
-      g_free (protocol_name);
       g_clear_object (&contact);
     }
 
-  /* Else add to each group. */
-  while (group_iter != NULL && gee_iterator_next (group_iter))
+  if (folks_favourite_details_get_is_favourite (
+        FOLKS_FAVOURITE_DETAILS (individual)))
     {
-      gchar *group_name = gee_iterator_get (group_iter);
-      GtkTreeIter iter_group;
-
-      individual_store_get_group (self, group_name, &iter_group, NULL, NULL,
-          FALSE);
+      /* Add contact to the fake 'Favorites' group */
+      individual_store_get_group (self, EMPATHY_INDIVIDUAL_STORE_FAVORITE,
+          &iter_group, NULL, NULL, TRUE);
 
       add_individual_to_store (GTK_TREE_STORE (self), &iter, &iter_group,
           individual);
-
-      g_free (group_name);
+      grouped = TRUE;
     }
-  g_clear_object (&group_iter);
 
-  if (self->priv->show_groups &&
-      folks_favourite_details_get_is_favourite (
-          FOLKS_FAVOURITE_DETAILS (individual)))
+  if (!grouped)
     {
-      /* Add contact to the fake 'Favorites' group */
-      GtkTreeIter iter_group;
-
-      individual_store_get_group (self, EMPATHY_INDIVIDUAL_STORE_FAVORITE,
+      /* Else add the contact to 'Ungrouped' */
+      individual_store_get_group (self,
+          EMPATHY_INDIVIDUAL_STORE_UNGROUPED,
           &iter_group, NULL, NULL, TRUE);
-
       add_individual_to_store (GTK_TREE_STORE (self), &iter, &iter_group,
           individual);
     }
 
+
+finally:
   individual_store_contact_update (self, individual);
 }
 
@@ -441,8 +395,6 @@ individual_store_contact_set_active (EmpathyIndividualStore *self,
           EMPATHY_INDIVIDUAL_STORE_COL_IS_ACTIVE, active,
           -1);
 
-      DEBUG ("Set item %s", active ? "active" : "inactive");
-
       if (set_changed)
         {
           path = gtk_tree_model_get_path (model, l->data);
@@ -481,10 +433,6 @@ individual_store_contact_active_new (EmpathyIndividualStore *self,
 {
   ShowActiveData *data;
 
-  DEBUG ("Individual'%s' now active, and %s be removed",
-      folks_alias_details_get_alias (FOLKS_ALIAS_DETAILS (individual)),
-      remove_ ? "WILL" : "WILL NOT");
-
   data = g_slice_new0 (ShowActiveData);
 
   /* We don't actually want to force either the IndividualStore or the
@@ -532,9 +480,6 @@ individual_store_contact_active_cb (ShowActiveData *data)
       empathy_individual_store_remove_individual (data->self, data->individual);
     }
 
-  DEBUG ("Individual'%s' no longer active",
-      folks_alias_details_get_alias (FOLKS_ALIAS_DETAILS (data->individual)));
-
   individual_store_contact_set_active (data->self,
       data->individual, FALSE, TRUE);
 
@@ -561,9 +506,15 @@ individual_avatar_pixbuf_received_cb (FolksIndividual *individual,
 
   if (error != NULL)
     {
-      DEBUG ("failed to retrieve pixbuf for individual %s: %s",
-          folks_alias_details_get_alias (FOLKS_ALIAS_DETAILS (individual)),
-          error->message);
+      /* No need to display an error if the individal just doesn't have an
+       * avatar */
+      if (!g_error_matches (error, G_IO_ERROR, G_IO_ERROR_NOT_FOUND))
+        {
+          DEBUG ("failed to retrieve pixbuf for individual %s: %s",
+              folks_alias_details_get_alias (FOLKS_ALIAS_DETAILS (individual)),
+              error->message);
+        }
+
       g_clear_error (&error);
     }
   else if (data->store != NULL)
@@ -639,15 +590,10 @@ individual_store_contact_update (EmpathyIndividualStore *self,
       if (self->priv->show_active)
         {
           do_set_active = TRUE;
-
-          DEBUG ("Set active (individual added)");
         }
     }
   else
     {
-      DEBUG ("Individual'%s' in list:YES, should be:YES",
-          folks_alias_details_get_alias (FOLKS_ALIAS_DETAILS (individual)));
-
       /* Get online state before. */
       if (iters && g_list_length (iters) > 0)
         {
@@ -662,17 +608,12 @@ individual_store_contact_update (EmpathyIndividualStore *self,
             {
               do_set_active = TRUE;
               do_set_refresh = TRUE;
-
-              DEBUG ("Set active (individual updated %s)",
-                  was_online ? "online  -> offline" : "offline -> online");
             }
           else
             {
               /* Was TRUE for presence updates. */
               /* do_set_active = FALSE;  */
               do_set_refresh = TRUE;
-
-              DEBUG ("Set active (individual updated)");
             }
         }
 
@@ -710,7 +651,7 @@ individual_store_contact_update (EmpathyIndividualStore *self,
       empathy_individual_can_audio_video_call (individual, &can_audio_call,
           &can_video_call, NULL);
 
-      types = individual_get_client_types (individual);
+      types = empathy_individual_get_client_types (individual);
 
       gtk_tree_store_set (GTK_TREE_STORE (self), l->data,
           EMPATHY_INDIVIDUAL_STORE_COL_ICON_STATUS, pixbuf_status,
@@ -761,9 +702,6 @@ individual_store_individual_updated_cb (FolksIndividual *individual,
     GParamSpec *param,
     EmpathyIndividualStore *self)
 {
-  DEBUG ("Individual'%s' updated, checking roster is in sync...",
-      folks_alias_details_get_alias (FOLKS_ALIAS_DETAILS (individual)));
-
   individual_store_contact_update (self, individual);
 }
 
@@ -774,9 +712,6 @@ individual_store_contact_updated_cb (EmpathyContact *contact,
 {
   FolksIndividual *individual;
 
-  DEBUG ("Contact '%s' updated, checking roster is in sync...",
-      empathy_contact_get_alias (contact));
-
   individual = g_object_get_data (G_OBJECT (contact), "individual");
   if (individual == NULL)
     return;
@@ -792,9 +727,6 @@ individual_personas_changed_cb (FolksIndividual *individual,
 {
   GeeIterator *iter;
 
-  DEBUG ("Individual '%s' personas-changed.",
-      folks_individual_get_id (individual));
-
   iter = gee_iterable_iterator (GEE_ITERABLE (removed));
   /* FIXME: libfolks hasn't grown capabilities support yet, so we have to go
    * through the EmpathyContacts for them. */
@@ -1190,8 +1122,8 @@ individual_store_contact_sort (FolksIndividual *individual_a,
       g_assert (account_b != NULL);
 
       /* protocol */
-      ret_val = g_strcmp0 (tp_account_get_protocol (account_a),
-          tp_account_get_protocol (account_b));
+      ret_val = g_strcmp0 (tp_account_get_protocol_name (account_a),
+          tp_account_get_protocol_name (account_b));
 
       if (ret_val != 0)
         goto out;