]> git.0d.be Git - empathy.git/commitdiff
Sort profiles to have free protocols first. Fixes bug #460605.
authorXavier Claessens <xclaesse@gmail.com>
Fri, 27 Jul 2007 16:18:43 +0000 (16:18 +0000)
committerXavier Claessens <xclaesse@src.gnome.org>
Fri, 27 Jul 2007 16:18:43 +0000 (16:18 +0000)
2007-07-27 Xavier Claessens  <xclaesse@gmail.com>

* libempathy-gtk/empathy-profile-chooser.c: Sort profiles to have
free protocols first. Fixes bug #460605.

svn path=/trunk/; revision=206

ChangeLog
libempathy-gtk/empathy-profile-chooser.c

index 00df367bdd4eb1ff584ab38256e4302ac24587b3..a7a112da5f9c1085ea9f6c5d2e7e9e836594b507 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,8 @@
+2007-07-27 Xavier Claessens  <xclaesse@gmail.com>
+
+       * libempathy-gtk/empathy-profile-chooser.c: Sort profiles to have
+       free protocols first. Fixes bug #460605.
+
 2007-07-27 Xavier Claessens  <xclaesse@gmail.com>
 
        * libempathy/empathy-message.c:
index 1885c2fb2a1e3031e60836722872773ae134deb2..a3cc9a32d6b552e41172f741f9b71212c59ba390 100644 (file)
@@ -25,9 +25,8 @@
 #include <gtk/gtk.h>
 #include <libmissioncontrol/mc-profile.h>
 
-#include <libempathy-gtk/empathy-ui-utils.h>
-
 #include "empathy-profile-chooser.h"
+#include "empathy-ui-utils.h"
 
 enum {
        COL_ICON,
@@ -53,6 +52,53 @@ empathy_profile_chooser_get_selected (GtkWidget *widget)
        return profile;
 }
 
+static gint
+profile_chooser_sort_protocol_value (const gchar *protocol_name)
+{
+       if (strcmp (protocol_name, "jabber") == 0) {
+               return 0;
+       }
+       else if (strcmp (protocol_name, "salut") == 0) {
+               return 1;
+       }
+
+       return 2;
+}
+
+static gint
+profile_chooser_sort_func (GtkTreeModel *model,
+                          GtkTreeIter  *iter_a,
+                          GtkTreeIter  *iter_b,
+                          gpointer      user_data)
+{
+       McProfile   *profile_a;
+       McProfile   *profile_b;
+       const gchar *proto_a;
+       const gchar *proto_b;
+       gint         cmp;
+
+       gtk_tree_model_get (model, iter_a,
+                           COL_PROFILE, &profile_a,
+                           -1);
+       gtk_tree_model_get (model, iter_b,
+                           COL_PROFILE, &profile_b,
+                           -1);
+
+       proto_a = mc_profile_get_protocol_name (profile_a);
+       proto_b = mc_profile_get_protocol_name (profile_b);
+       cmp = profile_chooser_sort_protocol_value (proto_a);
+       cmp -= profile_chooser_sort_protocol_value (proto_b);
+       if (cmp == 0) {
+               cmp = strcmp (mc_profile_get_display_name (profile_a),
+                             mc_profile_get_display_name (profile_b));
+       }
+
+       g_object_unref (profile_a);
+       g_object_unref (profile_b);
+
+       return cmp;
+}
+
 GtkWidget *
 empathy_profile_chooser_new (void)
 {
@@ -83,6 +129,15 @@ empathy_profile_chooser_new (void)
                                        "text", COL_LABEL,
                                        NULL);
 
+       /* Set the profile sort function */
+       gtk_tree_sortable_set_sort_column_id (GTK_TREE_SORTABLE (store),
+                                             COL_PROFILE,
+                                             GTK_SORT_ASCENDING);
+       gtk_tree_sortable_set_sort_func (GTK_TREE_SORTABLE (store),
+                                        COL_PROFILE,
+                                        profile_chooser_sort_func,
+                                        NULL, NULL);
+
        profiles = mc_profiles_list ();
        for (l = profiles; l; l = l->next) {
                McProfile *profile;
@@ -95,9 +150,10 @@ empathy_profile_chooser_new (void)
                                    COL_LABEL, mc_profile_get_display_name (profile),
                                    COL_PROFILE, profile,
                                    -1);
-               gtk_combo_box_set_active_iter (GTK_COMBO_BOX (combo_box), &iter);
        }
 
+       gtk_combo_box_set_active_iter (GTK_COMBO_BOX (combo_box), &iter);
+
        mc_profiles_free_list (profiles);
        g_object_unref (store);