aboutsummaryrefslogtreecommitdiffstats
path: root/libempathy-gtk
diff options
context:
space:
mode:
authorDanielle Madeley <danielle.madeley@collabora.co.uk>2010-03-22 14:02:21 +0800
committerDanielle Madeley <danielle.madeley@collabora.co.uk>2010-03-24 16:42:04 +0800
commit1a665bc714aa3c9789c3f0c46307f3e93679f15e (patch)
tree33ee0b0878928883f78477998a8fe150a04725cb /libempathy-gtk
parent9cd08545e92314b01ca95b5432ef612720e24afb (diff)
downloadgsoc2013-empathy-1a665bc714aa3c9789c3f0c46307f3e93679f15e.tar
gsoc2013-empathy-1a665bc714aa3c9789c3f0c46307f3e93679f15e.tar.gz
gsoc2013-empathy-1a665bc714aa3c9789c3f0c46307f3e93679f15e.tar.bz2
gsoc2013-empathy-1a665bc714aa3c9789c3f0c46307f3e93679f15e.tar.lz
gsoc2013-empathy-1a665bc714aa3c9789c3f0c46307f3e93679f15e.tar.xz
gsoc2013-empathy-1a665bc714aa3c9789c3f0c46307f3e93679f15e.tar.zst
gsoc2013-empathy-1a665bc714aa3c9789c3f0c46307f3e93679f15e.zip
Clean up sorting function to take top/bottom lists of fake groups
Even if we choose not to sort People Nearby, this patch is useful because it makes how the sorting of groups is done much clearer and allows us to add other fake groups in the future.
Diffstat (limited to 'libempathy-gtk')
-rw-r--r--libempathy-gtk/empathy-contact-list-store.c61
1 files changed, 52 insertions, 9 deletions
diff --git a/libempathy-gtk/empathy-contact-list-store.c b/libempathy-gtk/empathy-contact-list-store.c
index 25a2e7ad2..55cddd4cc 100644
--- a/libempathy-gtk/empathy-contact-list-store.c
+++ b/libempathy-gtk/empathy-contact-list-store.c
@@ -1541,6 +1541,20 @@ contact_list_store_get_group (EmpathyContactListStore *store,
}
static gint
+get_position (const char **strv,
+ const char *str)
+{
+ int i;
+
+ for (i = 0; strv[i] != NULL; i++) {
+ if (!tp_strdiff (strv[i], str))
+ return i;
+ }
+
+ return -1;
+}
+
+static gint
compare_separator_and_groups (gboolean is_separator_a,
gboolean is_separator_b,
const gchar *name_a,
@@ -1550,6 +1564,19 @@ compare_separator_and_groups (gboolean is_separator_a,
gboolean fake_group_a,
gboolean fake_group_b)
{
+ /* these two lists are the sorted list of fake groups to include at the
+ * top and bottom of the roster */
+ const char *top_groups[] = {
+ EMPATHY_CONTACT_LIST_STORE_FAVORITE,
+ EMPATHY_CONTACT_LIST_STORE_PEOPLE_NEARBY,
+ NULL
+ };
+
+ const char *bottom_groups[] = {
+ EMPATHY_CONTACT_LIST_STORE_UNGROUPED,
+ NULL
+ };
+
if (is_separator_a || is_separator_b) {
/* We have at least one separator */
if (is_separator_a) {
@@ -1565,18 +1592,34 @@ compare_separator_and_groups (gboolean is_separator_a,
} else if (contact_a && !contact_b) {
return -1;
} else if (!contact_a && !contact_b) {
- /* Two groups. The 'Ungrouped' fake group is display at the bottom of the
- * contact list and the 'Favorites' at the top. */
- if (fake_group_a && !tp_strdiff (name_a, EMPATHY_CONTACT_LIST_STORE_UNGROUPED))
- return 1;
- else if (fake_group_b && !tp_strdiff (name_b, EMPATHY_CONTACT_LIST_STORE_UNGROUPED))
+ gboolean a_in_top, b_in_top, a_in_bottom, b_in_bottom;
+
+ a_in_top = fake_group_a &&
+ tp_strv_contains (top_groups, name_a);
+ b_in_top = fake_group_b &&
+ tp_strv_contains (top_groups, name_b);
+ a_in_bottom = fake_group_b &&
+ tp_strv_contains (bottom_groups, name_a);
+ b_in_bottom = fake_group_b &&
+ tp_strv_contains (bottom_groups, name_b);
+
+ if (a_in_top && b_in_top) {
+ /* compare positions */
+ return CLAMP (get_position (top_groups, name_a) -
+ get_position (top_groups, name_b),
+ -1, 1);
+ } else if (a_in_bottom && b_in_bottom) {
+ /* compare positions */
+ return CLAMP (get_position (bottom_groups, name_a) -
+ get_position (bottom_groups, name_b),
+ -1, 1);
+ } else if (a_in_top || b_in_bottom) {
return -1;
- else if (fake_group_a && !tp_strdiff (name_a, EMPATHY_CONTACT_LIST_STORE_FAVORITE))
- return -1;
- else if (fake_group_b && !tp_strdiff (name_b, EMPATHY_CONTACT_LIST_STORE_FAVORITE))
+ } else if (b_in_top || a_in_bottom) {
return 1;
- else
+ } else {
return g_utf8_collate (name_a, name_b);
+ }
}
/* Two contacts, ordering depends of the sorting policy */