aboutsummaryrefslogtreecommitdiffstats
path: root/libempathy-gtk
diff options
context:
space:
mode:
authorGuillaume Desmottes <guillaume.desmottes@collabora.co.uk>2009-12-09 19:59:33 +0800
committerGuillaume Desmottes <guillaume.desmottes@collabora.co.uk>2009-12-09 19:59:33 +0800
commit7190ca926a151a3fa1fec7ec9faf6a490a378b8e (patch)
tree588eeb91ad629c565f0ad6bb2f702d0928e52278 /libempathy-gtk
parentd7a4689a729cbd5da40d34d532f4b61f2e3aeadb (diff)
downloadgsoc2013-empathy-7190ca926a151a3fa1fec7ec9faf6a490a378b8e.tar
gsoc2013-empathy-7190ca926a151a3fa1fec7ec9faf6a490a378b8e.tar.gz
gsoc2013-empathy-7190ca926a151a3fa1fec7ec9faf6a490a378b8e.tar.bz2
gsoc2013-empathy-7190ca926a151a3fa1fec7ec9faf6a490a378b8e.tar.lz
gsoc2013-empathy-7190ca926a151a3fa1fec7ec9faf6a490a378b8e.tar.xz
gsoc2013-empathy-7190ca926a151a3fa1fec7ec9faf6a490a378b8e.tar.zst
gsoc2013-empathy-7190ca926a151a3fa1fec7ec9faf6a490a378b8e.zip
account-chooser: display enabled accounts first (#604166)
Diffstat (limited to 'libempathy-gtk')
-rw-r--r--libempathy-gtk/empathy-account-chooser.c40
1 files changed, 40 insertions, 0 deletions
diff --git a/libempathy-gtk/empathy-account-chooser.c b/libempathy-gtk/empathy-account-chooser.c
index 61d63b32c..bd46efc16 100644
--- a/libempathy-gtk/empathy-account-chooser.c
+++ b/libempathy-gtk/empathy-account-chooser.c
@@ -503,6 +503,41 @@ account_manager_prepared_cb (GObject *source_object,
g_signal_emit (chooser, signals[READY], 0);
}
+static gint
+account_cmp (GtkTreeModel *model,
+ GtkTreeIter *a,
+ GtkTreeIter *b,
+ gpointer user_data)
+{
+ gboolean a_enabled, b_enabled;
+ gchar *a_text, *b_text;
+ gint result;
+
+ gtk_tree_model_get (model, a, COL_ACCOUNT_ENABLED, &a_enabled, -1);
+ gtk_tree_model_get (model, b, COL_ACCOUNT_ENABLED, &b_enabled, -1);
+
+ /* Enabled accounts are displayed first */
+ if (a_enabled != b_enabled)
+ return a_enabled ? -1: 1;
+
+ gtk_tree_model_get (model, a, COL_ACCOUNT_TEXT, &a_text, -1);
+ gtk_tree_model_get (model, b, COL_ACCOUNT_TEXT, &b_text, -1);
+
+ if (a_text == b_text)
+ result = 0;
+ else if (a_text == NULL)
+ result = 1;
+ else if (b_text == NULL)
+ result = -1;
+ else
+ result = g_ascii_strcasecmp (a_text, b_text);
+
+ g_free (a_text);
+ g_free (b_text);
+
+ return result;
+}
+
static void
account_chooser_setup (EmpathyAccountChooser *chooser)
{
@@ -524,6 +559,11 @@ account_chooser_setup (EmpathyAccountChooser *chooser)
G_TYPE_BOOLEAN, /* Enabled */
TP_TYPE_ACCOUNT);
+ gtk_tree_sortable_set_default_sort_func (GTK_TREE_SORTABLE (store),
+ account_cmp, chooser, NULL);
+ gtk_tree_sortable_set_sort_column_id (GTK_TREE_SORTABLE (store),
+ GTK_TREE_SORTABLE_DEFAULT_SORT_COLUMN_ID, GTK_SORT_ASCENDING);
+
gtk_combo_box_set_model (combobox, GTK_TREE_MODEL (store));
renderer = gtk_cell_renderer_pixbuf_new ();