[Xfce4-commits] <postler:master> Rework filtering and filter newly added messages

Christian Dywan noreply at xfce.org
Wed Jan 19 02:58:01 CET 2011


Updating branch refs/heads/master
         to 448534cf541be3fee22d7b8918ad7eb11cc4a880 (commit)
       from 15ebca0210e139640b40de8672eae8f61a169c97 (commit)

commit 448534cf541be3fee22d7b8918ad7eb11cc4a880
Author: Christian Dywan <christian at twotoasts.de>
Date:   Mon Jan 17 23:16:04 2011 +0100

    Rework filtering and filter newly added messages
    
    This also solves problems with Hide Read.

 postler/postler-bureau.vala   |    1 -
 postler/postler-messages.vala |   73 ++++++++++++++++++++++------------------
 2 files changed, 40 insertions(+), 34 deletions(-)

diff --git a/postler/postler-bureau.vala b/postler/postler-bureau.vala
index 7144c40..5d107eb 100644
--- a/postler/postler-bureau.vala
+++ b/postler/postler-bureau.vala
@@ -357,7 +357,6 @@ public class Postler.Bureau : Gtk.Window {
 
     void action_hide_read () {
         messages.hide_read = !messages.hide_read;
-        messages.populate (messages.selected_location, messages.account_info);
     }
 
     /* TODO: Send outstanding outgoing mail */
diff --git a/postler/postler-messages.vala b/postler/postler-messages.vala
index 238af65..720f010 100644
--- a/postler/postler-messages.vala
+++ b/postler/postler-messages.vala
@@ -20,14 +20,15 @@ public class Postler.Messages : Gtk.TreeView {
     public bool rich_rows { get; set; default = true; }
     public bool show_attachments { get; set; default = false; }
     public bool newest_at_the_bottom { get; set; default = false; }
-    
+
     public string? location { get; private set; }
     public AccountInfo account_info { get; private set; }
     public string? selected_location { get; private set; }
 
     string to_or_from;
-    string last_filter = "";
-    string last_header = "";
+    string[] headers = {};
+    string[] filters = {};
+    string[] folders = {};
     FileMonitor[] folder_monitors = {};
 
     enum Columns {
@@ -297,6 +298,10 @@ public class Postler.Messages : Gtk.TreeView {
         Gtk.BindingEntry.add_signal (binding_set,
             Gdk.keyval_from_name ("Delete"), 0, "delete", 0);
         content_display_window.connect (content_new_window);
+
+        notify["hide-read"].connect (() => {
+            search (filters[0] ?? "", headers[0] ?? "");
+        });
     }
 
     [Signal (action=true)]
@@ -526,8 +531,8 @@ public class Postler.Messages : Gtk.TreeView {
     }
 
     public void search (string filter, string header="subject") {
-        last_filter = filter;
-        last_header = header;
+        headers = {};
+        filters = {};
         populate (location, account_info, filter.down (), header);
     }
 
@@ -549,8 +554,7 @@ public class Postler.Messages : Gtk.TreeView {
         string attachment;
     }
 
-    private Message? read_message (File contents, bool folder_new,
-        string[] headers, string[] filters) {
+    private Message? read_message (File contents, bool folder_new) {
 
         string filename = contents.get_basename ();
         if (filename[0] == '.')
@@ -653,7 +657,7 @@ public class Postler.Messages : Gtk.TreeView {
     }
 
     public bool populate (string? location, AccountInfo account_info,
-        string filter="", string header="") {
+        string? filter=null, string? header=null) {
         clear ();
         if (location == null)
             return true;
@@ -663,10 +667,6 @@ public class Postler.Messages : Gtk.TreeView {
 
         model = sort = null;
 
-        if (filter != "")
-            last_filter = filter;
-        if (header != "")
-            last_header = header;
         var now = GLib.Date ();
         now.set_time_val (GLib.TimeVal ());
 
@@ -679,26 +679,34 @@ public class Postler.Messages : Gtk.TreeView {
             to_or_from = "from";
 
         try {
-            string[] headers = {};
-            string[] filters = {};
-            string[] folders = {};
-
-            if (location.has_prefix ("search:")) {
-                string query = location.substring (7);
-                string[] parts = query.split ("/", 2);
-                return_val_if_fail (parts[0] != null && parts[1] != null, false);
-                headers += parts[0];
-                filters += parts[1].down ();
-                foreach (var folder in accounts.get_folders ()) {
-                    folders += folder + "/INBOX/new";
-                    folders += folder + "/INBOX/cur";
+            if (location != this.location) {
+                folders = {};
+                headers = {};
+                filters = {};
+                if (location.has_prefix ("search:")) {
+                    foreach (var folder in accounts.get_folders ()) {
+                        folders += folder + "/INBOX/new";
+                        folders += folder + "/INBOX/cur";
+                    }
+                }
+                else {
+                    folders += location + "/cur";
+                    folders += location + "/new";
+                }
+            }
+
+            if (filters[0] == null) {
+                headers = { filter != null && filter != "" ? header : null };
+                filters = { filter != "" ? filter : null };
+
+                if (location.has_prefix ("search:")) {
+                    string query = location.substring (7);
+                    string[] parts = query.split ("/", 2);
+                    return_val_if_fail (parts[0] != null && parts[1] != null, false);
+                    headers += parts[0];
+                    filters += parts[1].down ();
                 }
-            } else {
-                folders += location + "/cur";
-                folders += location + "/new";
             }
-            headers += last_header != "" ? last_header : null;
-            filters += last_filter != "" ? last_filter : null;
 
             foreach (var folder in folders) {
                 var folder_dir = File.new_for_path (folder);
@@ -728,8 +736,7 @@ public class Postler.Messages : Gtk.TreeView {
                     unowned string name = info.get_name ();
 
                     var message_path = folder_dir.resolve_relative_path (name);
-                    var message = read_message (message_path, folder_new,
-                        headers, filters);
+                    var message = read_message (message_path, folder_new);
                     if (message == null)
                         continue;
                     message.size = info.get_size ();
@@ -870,7 +877,7 @@ public class Postler.Messages : Gtk.TreeView {
             if (get_message_iter (file.get_path (), null))
                 break;
             bool folder_new = file.get_path ().has_suffix ("/new");
-            var message = read_message (file, folder_new, {}, {});
+            var message = read_message (file, folder_new);
             if (message == null)
                 break;
             message.size = 0; /* FIXME: get file size */



More information about the Xfce4-commits mailing list