diff --git a/src/ConversationList/ConversationItemModel.vala b/src/ConversationList/ConversationItemModel.vala index d299b9cfe..406a7dbf7 100644 --- a/src/ConversationList/ConversationItemModel.vala +++ b/src/ConversationList/ConversationItemModel.vala @@ -248,4 +248,10 @@ public class Mail.ConversationItemModel : GLib.Object { return has_flag; } + + public static int compare_func (Object a, Object b) { + var item1 = (ConversationItemModel) a; + var item2 = (ConversationItemModel) b; + return (int)(item2.timestamp - item1.timestamp); + } } diff --git a/src/ConversationList/ConversationList.vala b/src/ConversationList/ConversationList.vala index 3656d09c1..281c806a0 100644 --- a/src/ConversationList/ConversationList.vala +++ b/src/ConversationList/ConversationList.vala @@ -52,7 +52,6 @@ public class Mail.ConversationList : Gtk.Box { folder_info_flags = new Gee.HashMap (); threads = new Gee.HashMap (); list_store = new ConversationListStore (); - list_store.set_sort_func (thread_sort_function); list_store.set_filter_func (filter_function); list_box = new VirtualizingListBox () { @@ -414,7 +413,7 @@ public class Mail.ConversationList : Gtk.Box { private void add_conversation_item (Camel.FolderInfoFlags folder_info_flags, Camel.FolderThreadNode child, Camel.FolderThread thread, string service_uid) { var item = new ConversationItemModel (folder_info_flags, child, thread, service_uid); conversations[child.message.uid] = item; - list_store.add (item); + list_store.insert_sorted (item, ConversationItemModel.compare_func); } private static bool filter_function (GLib.Object obj) { @@ -426,10 +425,6 @@ public class Mail.ConversationList : Gtk.Box { } } - private static int thread_sort_function (ConversationItemModel item1, ConversationItemModel item2) { - return (int)(item2.timestamp - item1.timestamp); - } - public void mark_read_selected_messages () { var selected_rows = list_box.get_selected_rows (); foreach (var row in selected_rows) { diff --git a/src/ConversationList/ConversationListStore.vala b/src/ConversationList/ConversationListStore.vala index ccf31704c..0ee613cd9 100644 --- a/src/ConversationList/ConversationListStore.vala +++ b/src/ConversationList/ConversationListStore.vala @@ -27,10 +27,9 @@ public class Mail.ConversationListStore : ListModel, Object { private GLib.Sequence data = new GLib.Sequence (); private uint last_position = uint.MAX; private GLib.SequenceIter? last_iter; - private unowned GLib.CompareDataFunc compare_func; private unowned RowVisibilityFunc filter_func; - public GLib.Type get_item_type () { + private GLib.Type get_item_type () { return typeof (GLib.Object); } @@ -38,14 +37,10 @@ public class Mail.ConversationListStore : ListModel, Object { return data.get_length (); } - public GLib.Object? get_item (uint index) { + private GLib.Object? get_item (uint index) { return get_item_internal (index); } - public GLib.Object? get_item_unfiltered (uint index) { - return get_item_internal (index, true); - } - private GLib.Object? get_item_internal (uint index, bool unfiltered = false) { GLib.SequenceIter? iter = null; @@ -81,12 +76,8 @@ public class Mail.ConversationListStore : ListModel, Object { } } - public void add (ConversationItemModel data) { - if (compare_func != null) { - this.data.insert_sorted (data, compare_func); - } else { - this.data.append (data); - } + public void insert_sorted (ConversationItemModel item, CompareDataFunc compare_func) { + data.insert_sorted (item, compare_func); last_iter = null; last_position = uint.MAX; @@ -108,10 +99,6 @@ public class Mail.ConversationListStore : ListModel, Object { last_position = uint.MAX; } - public void set_sort_func (GLib.CompareDataFunc function) { - this.compare_func = function; - } - public void set_filter_func (RowVisibilityFunc? function) { filter_func = function; } @@ -175,14 +162,14 @@ public class Mail.ConversationListStore : ListModel, Object { return -1; } - public int get_index_of_unfiltered (GLib.Object? item) { + private int get_index_of_unfiltered (GLib.Object? item) { if (item == null) { return -1; } var length = get_n_items (); for (int i = 0; i < length; i++) { - if (item == get_item_unfiltered (i)) { + if (item == get_item_internal (i, true)) { return i; } }