diff options
author | Jussi Kukkonen <jku@linux.intel.com> | 2011-09-06 16:50:35 +0800 |
---|---|---|
committer | Emilio Pozuelo Monfort <emilio.pozuelo@collabora.co.uk> | 2011-09-08 19:49:34 +0800 |
commit | 777e9d330ae950e5cc89f757317fde4e96762363 (patch) | |
tree | f59e134dc6e3465a15cf0f9d3b80f54e407c9946 /libempathy-gtk | |
parent | 180787f1addccd923d50b45858ba24a0487e98bc (diff) | |
download | gsoc2013-empathy-777e9d330ae950e5cc89f757317fde4e96762363.tar gsoc2013-empathy-777e9d330ae950e5cc89f757317fde4e96762363.tar.gz gsoc2013-empathy-777e9d330ae950e5cc89f757317fde4e96762363.tar.bz2 gsoc2013-empathy-777e9d330ae950e5cc89f757317fde4e96762363.tar.lz gsoc2013-empathy-777e9d330ae950e5cc89f757317fde4e96762363.tar.xz gsoc2013-empathy-777e9d330ae950e5cc89f757317fde4e96762363.tar.zst gsoc2013-empathy-777e9d330ae950e5cc89f757317fde4e96762363.zip |
log-window: sort "Who" list store alphabetically
Currently "Who"-list is sorted with "g_strcmp0 (name)" which
is not what we want (e.g. "Chris" becomes before "bob" because of
the initial capital letter).
Start sorting using g_utf8_collate_key().
https://bugzilla.gnome.org/show_bug.cgi?id=658336
Diffstat (limited to 'libempathy-gtk')
-rw-r--r-- | libempathy-gtk/empathy-log-window.c | 38 |
1 files changed, 27 insertions, 11 deletions
diff --git a/libempathy-gtk/empathy-log-window.c b/libempathy-gtk/empathy-log-window.c index 7b016735e..896462e88 100644 --- a/libempathy-gtk/empathy-log-window.c +++ b/libempathy-gtk/empathy-log-window.c @@ -182,6 +182,7 @@ enum COL_WHO_TYPE, COL_WHO_ICON, COL_WHO_NAME, + COL_WHO_NAME_SORT_KEY, COL_WHO_ID, COL_WHO_ACCOUNT, COL_WHO_TARGET, @@ -1864,22 +1865,29 @@ populate_entities_from_search_hits (void) { TplEntityType type = tpl_entity_get_entity_type (hit->target); EmpathyContact *contact; + const gchar *name; + gchar *sort_key; gboolean room = type == TPL_ENTITY_ROOM; contact = empathy_contact_from_tpl_contact (hit->account, hit->target); + name = empathy_contact_get_alias (contact); + sort_key = g_utf8_collate_key (name, -1); + gtk_list_store_append (store, &iter); gtk_list_store_set (store, &iter, COL_WHO_TYPE, COL_TYPE_NORMAL, COL_WHO_ICON, room ? EMPATHY_IMAGE_GROUP_MESSAGE : EMPATHY_IMAGE_AVATAR_DEFAULT, - COL_WHO_NAME, empathy_contact_get_alias (contact), + COL_WHO_NAME, name, + COL_WHO_NAME_SORT_KEY, sort_key, COL_WHO_ID, tpl_entity_get_identifier (hit->target), COL_WHO_ACCOUNT, hit->account, COL_WHO_TARGET, hit->target, -1); + g_free (sort_key); g_object_unref (contact); } } @@ -2282,21 +2290,28 @@ log_manager_got_entities_cb (GObject *manager, TplEntity *entity = TPL_ENTITY (l->data); TplEntityType type = tpl_entity_get_entity_type (entity); EmpathyContact *contact; + const gchar *name; + gchar *sort_key; gboolean room = type == TPL_ENTITY_ROOM; contact = empathy_contact_from_tpl_contact (ctx->account, entity); + name = empathy_contact_get_alias (contact); + sort_key = g_utf8_collate_key (name, -1); + gtk_list_store_append (store, &iter); gtk_list_store_set (store, &iter, COL_WHO_TYPE, COL_TYPE_NORMAL, COL_WHO_ICON, room ? EMPATHY_IMAGE_GROUP_MESSAGE : EMPATHY_IMAGE_AVATAR_DEFAULT, - COL_WHO_NAME, empathy_contact_get_alias (contact), + COL_WHO_NAME, name, + COL_WHO_NAME_SORT_KEY, sort_key, COL_WHO_ID, tpl_entity_get_identifier (entity), COL_WHO_ACCOUNT, ctx->account, COL_WHO_TARGET, entity, -1); + g_free (sort_key); g_object_unref (contact); if (ctx->self->priv->selected_account != NULL && @@ -2448,23 +2463,23 @@ log_window_who_populate (EmpathyLogWindow *self) } static gint -sort_by_name (GtkTreeModel *model, +sort_by_name_key (GtkTreeModel *model, GtkTreeIter *a, GtkTreeIter *b, gpointer user_data) { - gchar *name1, *name2; + gchar *key1, *key2; gint type1, type2; gint ret; gtk_tree_model_get (model, a, COL_WHO_TYPE, &type1, - COL_WHO_NAME, &name1, + COL_WHO_NAME_SORT_KEY, &key1, -1); gtk_tree_model_get (model, b, COL_WHO_TYPE, &type2, - COL_WHO_NAME, &name2, + COL_WHO_NAME_SORT_KEY, &key2, -1); if (type1 == COL_TYPE_ANY) @@ -2476,10 +2491,10 @@ sort_by_name (GtkTreeModel *model, else if (type2 == COL_TYPE_SEPARATOR) ret = 1; else - ret = g_strcmp0 (name1, name2); + ret = g_strcmp0 (key1, key2); - g_free (name1); - g_free (name2); + g_free (key1); + g_free (key2); return ret; } @@ -2626,6 +2641,7 @@ log_window_who_setup (EmpathyLogWindow *self) G_TYPE_INT, /* type */ G_TYPE_STRING, /* icon */ G_TYPE_STRING, /* name */ + G_TYPE_STRING, /* name sort key */ G_TYPE_STRING, /* id */ TP_TYPE_ACCOUNT, /* account */ TPL_TYPE_ENTITY); /* target */ @@ -2660,10 +2676,10 @@ log_window_who_setup (EmpathyLogWindow *self) NULL, NULL); gtk_tree_sortable_set_sort_column_id (sortable, - COL_WHO_NAME, + COL_WHO_NAME_SORT_KEY, GTK_SORT_ASCENDING); gtk_tree_sortable_set_sort_func (sortable, - COL_WHO_NAME, sort_by_name, + COL_WHO_NAME_SORT_KEY, sort_by_name_key, NULL, NULL); gtk_tree_view_set_search_column (view, COL_WHO_NAME); |