From 2081f6c62d3c149be5cb0b9ca04f3325098e3af2 Mon Sep 17 00:00:00 2001 From: Matthias Schiffer Date: Tue, 17 Aug 2010 01:03:25 +0200 Subject: Sort roster entries and groups correctly --- src/gui/Roster.vala | 28 ++++++++++++++++++++++++++-- 1 file changed, 26 insertions(+), 2 deletions(-) (limited to 'src/gui') diff --git a/src/gui/Roster.vala b/src/gui/Roster.vala index 32bdb6d..75e6631 100644 --- a/src/gui/Roster.vala +++ b/src/gui/Roster.vala @@ -11,7 +11,7 @@ public class Roster { contactList = new ContactListModel(this); model = new RosterModel(contactList); - rosterView.set_model(new RosterFilter(this, model)); + rosterView.set_model(new RosterFilter(this, new RosterSorter(model))); rosterView.query_tooltip.connect((x, y, keyboard_tip, tooltip) => { Gtk.TreeModel model; @@ -57,7 +57,7 @@ public class Roster { }); rosterView.model.row_inserted.connect((path, iter) => { - rosterView.expand_to_path(path); + Idle.add(() => {rosterView.expand_to_path(path); return false;}); }); Gtk.TreeViewColumn contactColumn = new Gtk.TreeViewColumn.with_attributes(null, new CellRendererContact(), "data", 0, null); @@ -698,4 +698,28 @@ public class Roster { }); } } + + private class RosterSorter : Gtk.TreeModelSort { + public RosterSorter(Gtk.TreeModel childModel) { + Object(model: childModel); + + set_sort_column_id(0, Gtk.SortType.ASCENDING); + set_sort_func(0, (model, itera, iterb) => { + Value value; + model.get_value(itera, 0, out value); + Object a = value.get_object(); + model.get_value(iterb, 0, out value); + Object b = value.get_object(); + + if(a is String && b is String) { + return (a as String).data.collate((b as String).data); + } + else if(a is Contact && b is Contact) { + return (a as Contact).display_string.collate((b as Contact).display_string); + } + + assert_not_reached(); + }); + } + } } -- cgit v1.2.3