[empathy] roster-view: sort top contacts alphabetically



commit bed1c1b27c5ccb6d35be8ef2b2bb6b4fa8f24f24
Author: Guillaume Desmottes <guillaume desmottes collabora co uk>
Date:   Thu Jun 14 15:42:53 2012 +0200

    roster-view: sort top contacts alphabetically
    
    We just want them to be on top but they should be sorted alphabetically
    together, not by popularity. This makes the 'top' contacts more stable.
    
    https://bugzilla.gnome.org/show_bug.cgi?id=678091

 libempathy-gtk/empathy-roster-view.c |   44 ++++++++++++++-------------------
 1 files changed, 19 insertions(+), 25 deletions(-)
---
diff --git a/libempathy-gtk/empathy-roster-view.c b/libempathy-gtk/empathy-roster-view.c
index 97125c7..a035c89 100644
--- a/libempathy-gtk/empathy-roster-view.c
+++ b/libempathy-gtk/empathy-roster-view.c
@@ -512,33 +512,21 @@ compare_roster_contacts_by_alias (EmpathyRosterContact *a,
   return g_ascii_strcasecmp (alias_a, alias_b);
 }
 
-static gint
-compare_individual_top_position (EmpathyRosterView *self,
-    EmpathyRosterContact *a,
-    EmpathyRosterContact *b)
+static gboolean
+contact_in_top (EmpathyRosterView *self,
+    EmpathyRosterContact *contact)
 {
-  FolksIndividual *ind_a, *ind_b;
+  FolksIndividual *individual;
   GList *tops;
-  gint index_a, index_b;
 
-  ind_a = empathy_roster_contact_get_individual (a);
-  ind_b = empathy_roster_contact_get_individual (b);
+  individual = empathy_roster_contact_get_individual (contact);
 
   tops = empathy_individual_manager_get_top_individuals (self->priv->manager);
 
-  index_a = g_list_index (tops, ind_a);
-  index_b = g_list_index (tops, ind_b);
+  if (g_list_index (tops, individual) != -1)
+    return TRUE;
 
-  if (index_a == index_b)
-    return 0;
-
-  if (index_a == -1)
-    return 1;
-
-  if (index_b == -1)
-    return -1;
-
-  return index_a - index_b;
+  return FALSE;
 }
 
 static gint
@@ -546,13 +534,19 @@ compare_roster_contacts_no_group (EmpathyRosterView *self,
     EmpathyRosterContact *a,
     EmpathyRosterContact *b)
 {
-  gint top;
+  gboolean top_a, top_b;
 
-  top = compare_individual_top_position (self, a, b);
-  if (top != 0)
-    return top;
+  top_a = contact_in_top (self, a);
+  top_b = contact_in_top (self, b);
 
-  return compare_roster_contacts_by_alias (a, b);
+  if (top_a == top_b)
+    /* Both contacts are in the top of the roster (or not). Sort them
+     * alphabetically */
+    return compare_roster_contacts_by_alias (a, b);
+  else if (top_a)
+    return -1;
+  else
+    return 1;
 }
 
 static gint



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]