[Xfce4-commits] <postler:master> Stop using a TreeModelSort for sorting

Christian Dywan noreply at xfce.org
Fri May 27 20:32:03 CEST 2011


Updating branch refs/heads/master
         to 4e508068eb054f8102664e27025bde21f87249b2 (commit)
       from b692fea99435518d8713298edf90a75b95c11638 (commit)

commit 4e508068eb054f8102664e27025bde21f87249b2
Author: Christian Dywan <christian at twotoasts.de>
Date:   Wed May 25 01:10:47 2011 +0200

    Stop using a TreeModelSort for sorting
    
    Sorting can happen in the query, this is faster and
    we don't need any message data in advance.

 postler/postler-messages.vala |  110 ++++++++++++++++++----------------------
 1 files changed, 50 insertions(+), 60 deletions(-)

diff --git a/postler/postler-messages.vala b/postler/postler-messages.vala
index e933e1b..e14eabc 100644
--- a/postler/postler-messages.vala
+++ b/postler/postler-messages.vala
@@ -12,7 +12,6 @@
 public class Postler.Messages : Gtk.TreeView {
     Accounts accounts;
     Gtk.TreeStore store;
-    Gtk.TreeModelSort sort;
     Gtk.TreePath defer_select;
     Dexter.Dexter dexter = new Dexter.Dexter ();
 
@@ -42,10 +41,10 @@ public class Postler.Messages : Gtk.TreeView {
     }
 
     void selection_changed () {
-        Gtk.TreeIter sort_iter;
-        if (get_selected_iter (out sort_iter)) {
+        Gtk.TreeIter iter;
+        if (get_selected_iter (out iter)) {
             string location;
-            sort.get (sort_iter, Columns.LOCATION, out location);
+            model.get (iter, Columns.LOCATION, out location);
             selected_location = location;
         } else
             selected_location = null;
@@ -160,24 +159,24 @@ public class Postler.Messages : Gtk.TreeView {
 
     void renderer_flag_toggled (Gtk.CellRendererToggle renderer,
                                 string                 path) {
-        Gtk.TreeIter sort_iter = Gtk.TreeIter ();
-        if (!sort.get_iter_from_string (out sort_iter, path))
+        Gtk.TreeIter iter = Gtk.TreeIter ();
+        if (!model.get_iter_from_string (out iter, path))
             return;
 
         string location;
-        sort.get (sort_iter, Columns.LOCATION, out location);
-        toggle_message_flag (sort_iter, ref location, 'F');
+        model.get (iter, Columns.LOCATION, out location);
+        toggle_message_flag (iter, ref location, 'F');
     }
 
     void renderer_status_toggled (Gtk.CellRendererToggle renderer,
                                   string                 path) {
-        Gtk.TreeIter sort_iter = Gtk.TreeIter ();
-        if (!sort.get_iter_from_string (out sort_iter, path))
+        Gtk.TreeIter iter = Gtk.TreeIter ();
+        if (!model.get_iter_from_string (out iter, path))
             return;
 
         string location;
-        sort.get (sort_iter, Columns.LOCATION, out location);
-        toggle_message_flag (sort_iter, ref location, 'S');
+        model.get (iter, Columns.LOCATION, out location);
+        toggle_message_flag (iter, ref location, 'S');
     }
 
     void on_drag_data_get (Gdk.DragContext context,
@@ -205,8 +204,6 @@ public class Postler.Messages : Gtk.TreeView {
 
         this.accounts = accounts;
         store = new Gtk.TreeStore (2, typeof (Message), typeof (string));
-        sort = new Gtk.TreeModelSort.with_model (store);
-        set_model (sort);
         set_search_equal_func (search_inline);
         get_selection ().set_mode (Gtk.SelectionMode.MULTIPLE);
         get_selection ().changed.connect (selection_changed);
@@ -272,11 +269,11 @@ public class Postler.Messages : Gtk.TreeView {
     public signal void content_display_window ();
     /* Vala fails to parse out parameters in virtual signals */
     void content_new_window () {
-        Gtk.TreeIter sort_iter;
-        if (get_selected_iter (out sort_iter)) {
+        Gtk.TreeIter iter;
+        if (get_selected_iter (out iter)) {
             string location;
-            sort.get (sort_iter, Columns.LOCATION, out location);
-            mark_message_read (sort_iter, ref location);
+            model.get (iter, Columns.LOCATION, out location);
+            mark_message_read (iter, ref location);
             Postler.App.spawn_module ("content", location);
         }
     }
@@ -458,9 +455,6 @@ public class Postler.Messages : Gtk.TreeView {
          && !FileUtils.test (location + "/cur", FileTest.EXISTS))
             return true;
 
-        /* FIXME no actual sorting occurs, we can stop using a sortable */
-        model = sort = new Gtk.TreeModelSort.with_model (store);
-
         var now = GLib.Date ();
         now.set_time_val (GLib.TimeVal ());
 
@@ -518,6 +512,7 @@ public class Postler.Messages : Gtk.TreeView {
                 get_selection().set_select_function( () => { return true; });
             }
 
+            model = store;
             hadjustment.value = vadjustment.value = 0;
 
         } catch (GLib.Error error) {
@@ -541,7 +536,6 @@ public class Postler.Messages : Gtk.TreeView {
         message.from_hash_table (message_data);
         store.insert_with_values (null, null, 0,
                                   Columns.MESSAGE, message);
-        model = sort = new Gtk.TreeModelSort.with_model (store);
     }
 
     internal static string toggle_flag (string location, char flag) {
@@ -570,7 +564,7 @@ public class Postler.Messages : Gtk.TreeView {
         return folder + "/" + Path.get_basename (bare_filename) + ":" + new_flags.str;
     }
 
-    void toggle_message_flag (Gtk.TreeIter sort_iter, ref string location, char flag) {
+    void toggle_message_flag (Gtk.TreeIter iter, ref string location, char flag) {
         return_if_fail (location != null);
         string new_location = toggle_flag (location, flag);
         /* TODO update message file */
@@ -580,20 +574,18 @@ public class Postler.Messages : Gtk.TreeView {
             string? flagged = null;
             string status = parse_flags (location, out flagged, out font_weight);
 
-            Gtk.TreeIter child_iter;
-            sort.convert_iter_to_child_iter (out child_iter, sort_iter);
-            store.set (child_iter,
+            store.set (iter,
                        Columns.LOCATION, new_location);
             if (location == selected_location)
                 selected_location = new_location;
         }
     }
 
-    bool get_selected_iter (out Gtk.TreeIter sort_iter) {
+    bool get_selected_iter (out Gtk.TreeIter iter) {
         GLib.List<Gtk.TreePath> paths = get_selection ().get_selected_rows (null);
-        sort_iter = Gtk.TreeIter ();
+        iter = Gtk.TreeIter ();
         var path = paths.nth_data (0);
-        if (path != null && sort.get_iter (out sort_iter, path))
+        if (path != null && model.get_iter (out iter, path))
             return true;
         return false;
     }
@@ -674,11 +666,11 @@ public class Postler.Messages : Gtk.TreeView {
         }
     }
 
-    void mark_message_read (Gtk.TreeIter sort_iter, ref string location) {
+    void mark_message_read (Gtk.TreeIter iter, ref string location) {
         return_if_fail (location != null);
         string bare_filename;
         if (!flags_from_filename (location, out bare_filename).contains ("S"))
-            toggle_message_flag (sort_iter, ref location, 'S');
+            toggle_message_flag (iter, ref location, 'S');
     }
 
     public void toggle_selected_flag (char flag) {
@@ -687,23 +679,23 @@ public class Postler.Messages : Gtk.TreeView {
 
         paths = get_selection ().get_selected_rows (null);
         foreach (var path in paths)
-            references.prepend (new Gtk.TreeRowReference (sort, path));
+            references.prepend (new Gtk.TreeRowReference (model, path));
 
         foreach (var reference in references) {
             var path = reference.get_path ();
-            Gtk.TreeIter sort_iter;
-            if (sort.get_iter (out sort_iter, path)) {
+            Gtk.TreeIter iter;
+            if (model.get_iter (out iter, path)) {
                 string location;
-                sort.get (sort_iter, Columns.LOCATION, out location);
-                toggle_message_flag (sort_iter, ref location, flag);
+                model.get (iter, Columns.LOCATION, out location);
+                toggle_message_flag (iter, ref location, flag);
             }
         }
     }
 
-    void display_message (Gtk.TreeIter sort_iter) {
+    void display_message (Gtk.TreeIter iter) {
         string location;
-        sort.get (sort_iter, Columns.LOCATION, out location);
-        mark_message_read (sort_iter, ref location);
+        model.get (iter, Columns.LOCATION, out location);
+        mark_message_read (iter, ref location);
         content.display (location, account_info);
     }
 
@@ -799,14 +791,14 @@ public class Postler.Messages : Gtk.TreeView {
         var references = new GLib.List<Gtk.TreeRowReference> ();
         paths = get_selection ().get_selected_rows (null);
         foreach (var path in paths)
-            references.prepend (new Gtk.TreeRowReference (sort, path));
+            references.prepend (new Gtk.TreeRowReference (model, path));
 
         foreach (var reference in references) {
             var path = reference.get_path ();
-            Gtk.TreeIter sort_iter;
-            if (sort.get_iter (out sort_iter, path)) {
+            Gtk.TreeIter iter;
+            if (model.get_iter (out iter, path)) {
                 string location;
-                sort.get (sort_iter, Columns.LOCATION, out location);
+                model.get (iter, Columns.LOCATION, out location);
                 var file = File.new_for_path (location);
                 try {
                     if (destination_path == null)
@@ -838,15 +830,13 @@ public class Postler.Messages : Gtk.TreeView {
                     }
 
                     /* Move to next, more recent message row */
-                    Gtk.TreeIter child_iter;
-                    sort.convert_iter_to_child_iter (out child_iter, sort_iter);
-                    Gtk.TreePath next_path = sort.get_path (sort_iter);
+                    Gtk.TreePath next_path = model.get_path (iter);
                     content.clear ();
-                    if (store.remove (child_iter)) {
+                    if (store.remove (iter)) {
                         next_path.prev ();
-                        if (sort.get_iter (out sort_iter, next_path)) {
-                            set_cursor (sort.get_path (sort_iter), null, false);
-                            display_message (sort_iter);
+                        if (model.get_iter (out iter, next_path)) {
+                            set_cursor (model.get_path (iter), null, false);
+                            display_message (iter);
                         }
                     }
                 } catch (GLib.Error error) {
@@ -867,11 +857,11 @@ public class Postler.Messages : Gtk.TreeView {
         get_dest_row_at_pos ((int)event.x, (int)event.y, out path, out pos);
 
         if (event.type == Gdk.EventType.2BUTTON_PRESS) {
-            Gtk.TreeIter sort_iter;
-            if (get_selected_iter (out sort_iter)) {
+            Gtk.TreeIter iter;
+            if (get_selected_iter (out iter)) {
                 string location;
-                sort.get (sort_iter, Columns.LOCATION, out location);
-                mark_message_read (sort_iter, ref location);
+                model.get (iter, Columns.LOCATION, out location);
+                mark_message_read (iter, ref location);
                 Postler.App.spawn_module ("content", location);
             }
         } else if (event.type == Gdk.EventType.BUTTON_PRESS
@@ -923,24 +913,24 @@ public class Postler.Messages : Gtk.TreeView {
         }
 
         GLib.List<Gtk.TreePath> paths = get_selection ().get_selected_rows (null);
-        Gtk.TreeIter sort_iter = Gtk.TreeIter ();
+        Gtk.TreeIter iter = Gtk.TreeIter ();
         var path = paths.nth_data (0);
-        if (path != null && sort.get_iter (out sort_iter, path)) {
+        if (path != null && model.get_iter (out iter, path)) {
             Gtk.TreeViewColumn column;
             get_path_at_pos ((int)event.x, (int)event.y, null,
                              out column, null, null);
             unowned string title = column.get_title ();
             /* Clickable icons should not display/ mark as read */
             if (title != _("Status") && title != _("Flagged"))
-                display_message (sort_iter);
+                display_message (iter);
         }
         return base.button_release_event (event);
     }
 
     public override void row_activated (Gtk.TreePath path, Gtk.TreeViewColumn column) {
-        Gtk.TreeIter sort_iter;
-        if (sort.get_iter (out sort_iter, path))
-            display_message (sort_iter);
+        Gtk.TreeIter iter;
+        if (model.get_iter (out iter, path))
+            display_message (iter);
     }
 }
 



More information about the Xfce4-commits mailing list