]> git.0d.be Git - empathy.git/blobdiff - libempathy-gtk/empathy-contact-list-store.c
Merge branch 'people-nearby-fake-group-613558'
[empathy.git] / libempathy-gtk / empathy-contact-list-store.c
index 25a2e7ad2fcb8b8c3be5a6840205153025a83d0d..6b35b082440ab1835f2f35578828a1eb4bec67b7 100644 (file)
@@ -833,8 +833,9 @@ contact_list_store_setup (EmpathyContactListStore *store)
                GDK_TYPE_PIXBUF,      /* Avatar pixbuf */
                G_TYPE_BOOLEAN,       /* Avatar pixbuf visible */
                G_TYPE_STRING,        /* Name */
+               G_TYPE_UINT,          /* Presence type */
                G_TYPE_STRING,        /* Status string */
-               G_TYPE_BOOLEAN,       /* Show status */
+               G_TYPE_BOOLEAN,       /* Compact view */
                EMPATHY_TYPE_CONTACT, /* Contact type */
                G_TYPE_BOOLEAN,       /* Is group */
                G_TYPE_BOOLEAN,       /* Is active */
@@ -1291,8 +1292,11 @@ contact_list_store_contact_update (EmpathyContactListStore *store,
                                    EMPATHY_CONTACT_LIST_STORE_COL_PIXBUF_AVATAR, pixbuf_avatar,
                                    EMPATHY_CONTACT_LIST_STORE_COL_PIXBUF_AVATAR_VISIBLE, show_avatar,
                                    EMPATHY_CONTACT_LIST_STORE_COL_NAME, empathy_contact_get_name (contact),
-                                   EMPATHY_CONTACT_LIST_STORE_COL_STATUS, empathy_contact_get_status (contact),
-                                   EMPATHY_CONTACT_LIST_STORE_COL_STATUS_VISIBLE, !priv->is_compact,
+                                   EMPATHY_CONTACT_LIST_STORE_COL_PRESENCE_TYPE,
+                                     empathy_contact_get_presence (contact),
+                                   EMPATHY_CONTACT_LIST_STORE_COL_STATUS,
+                                     empathy_contact_get_presence_message (contact),
+                                   EMPATHY_CONTACT_LIST_STORE_COL_COMPACT, priv->is_compact,
                                    EMPATHY_CONTACT_LIST_STORE_COL_IS_GROUP, FALSE,
                                    EMPATHY_CONTACT_LIST_STORE_COL_IS_ONLINE, now_online,
                                    EMPATHY_CONTACT_LIST_STORE_COL_IS_SEPARATOR, FALSE,
@@ -1540,6 +1544,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,
@@ -1550,6 +1568,18 @@ 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,
+               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 +1595,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 */
@@ -1765,7 +1811,7 @@ contact_list_store_update_list_mode_foreach (GtkTreeModel           *model,
        gtk_tree_store_set (GTK_TREE_STORE (store), iter,
                            EMPATHY_CONTACT_LIST_STORE_COL_ICON_STATUS, pixbuf_status,
                            EMPATHY_CONTACT_LIST_STORE_COL_PIXBUF_AVATAR_VISIBLE, show_avatar,
-                           EMPATHY_CONTACT_LIST_STORE_COL_STATUS_VISIBLE, !priv->is_compact,
+                           EMPATHY_CONTACT_LIST_STORE_COL_COMPACT, priv->is_compact,
                            -1);
 
        return FALSE;