Sort folders in sidebar (case-insensitive): #3692

This is the first half of #3692, sorting the folders in the sidebar.  Also, this patch ensures that messages are listed in chronologically descending order.  (No option to change either sorts at this time.)
This commit is contained in:
Jim Nelson 2011-06-24 16:28:05 -07:00
parent d179cb9bdd
commit f94018474b
4 changed files with 48 additions and 4 deletions

View file

@ -4,6 +4,13 @@
* (version 2.1 or later). See the COPYING file in this distribution.
*/
// These are defined here due to this bug:
// https://bugzilla.gnome.org/show_bug.cgi?id=653379
public enum TreeSortable {
DEFAULT_SORT_COLUMN_ID = -1,
UNSORTED_SORT_COLUMN_ID = -2
}
public class FolderListStore : Gtk.TreeStore {
public enum Column {
NAME,
@ -40,6 +47,8 @@ public class FolderListStore : Gtk.TreeStore {
public FolderListStore() {
set_column_types(Column.get_types());
set_default_sort_func(sort_by_name);
set_sort_column_id(TreeSortable.DEFAULT_SORT_COLUMN_ID, Gtk.SortType.ASCENDING);
}
public void add_folder(Geary.Folder folder) {
@ -67,5 +76,15 @@ public class FolderListStore : Gtk.TreeStore {
return folder;
}
private int sort_by_name(Gtk.TreeModel model, Gtk.TreeIter aiter, Gtk.TreeIter biter) {
string aname;
model.get(aiter, Column.NAME, out aname);
string bname;
model.get(biter, Column.NAME, out bname);
return strcmp(aname.down(), bname.down());
}
}

View file

@ -31,7 +31,7 @@ public class MainWindow : Gtk.Window {
public MainWindow() {
title = GearyApplication.NAME;
set_default_size(800, 600);
set_default_size(862, 684);
try {
ui.add_ui_from_string(MAIN_MENU_XML, -1);

View file

@ -52,12 +52,14 @@ public class MessageListStore : Gtk.TreeStore {
public MessageListStore() {
set_column_types(Column.get_types());
set_default_sort_func(sort_by_date);
set_sort_column_id(TreeSortable.DEFAULT_SORT_COLUMN_ID, Gtk.SortType.DESCENDING);
}
// The Email should've been fetched with Geary.Email.Field.ENVELOPE, at least.
//
// TODO: Need to insert email's in their proper position, not merely append.
public void append_envelope(Geary.Email envelope) {
assert(envelope.fields.fulfills(Geary.Email.Field.ENVELOPE));
Gtk.TreeIter iter;
append(out iter, null);
@ -79,5 +81,20 @@ public class MessageListStore : Gtk.TreeStore {
return email;
}
private int sort_by_date(Gtk.TreeModel model, Gtk.TreeIter aiter, Gtk.TreeIter biter) {
Geary.Email aenvelope;
get(aiter, Column.MESSAGE_OBJECT, out aenvelope);
Geary.Email benvelope;
get(biter, Column.MESSAGE_OBJECT, out benvelope);
int diff = aenvelope.date.value.compare(benvelope.date.value);
if (diff != 0)
return diff;
// stabilize sort by using the mail's position, which is always unique in a folder
return aenvelope.location.position - benvelope.location.position;
}
}

View file

@ -32,10 +32,14 @@ public class Geary.Email : Object {
};
}
public inline bool is_set(Field required_fields) {
public inline bool is_all_set(Field required_fields) {
return (this & required_fields) == required_fields;
}
public inline bool is_set(Field required_fields) {
return (this & required_fields) != 0;
}
public inline Field set(Field field) {
return (this | field);
}
@ -43,6 +47,10 @@ public class Geary.Email : Object {
public inline Field clear(Field field) {
return (this & ~(field));
}
public inline bool fulfills(Field required_fields) {
return is_all_set(required_fields);
}
}
public Geary.EmailLocation location { get; private set; }