[Xfce4-commits] <postler:master> Interpret a month in search as "only in that month"

Christian Dywan noreply at xfce.org
Mon Jul 11 23:14:02 CEST 2011


Updating branch refs/heads/master
         to 54471f8f40a4674ce7b52c26659ecde2284312c0 (commit)
       from bb4be23780ed26841d2c1ed40f0d3a2ab43356e7 (commit)

commit 54471f8f40a4674ce7b52c26659ecde2284312c0
Author: Christian Dywan <christian at twotoasts.de>
Date:   Mon Jul 11 00:48:39 2011 +0200

    Interpret a month in search as "only in that month"
    
    Full month names in the locale are recognized.

 postler/postler-index.vala |   21 +++++++++++++++++++++
 1 files changed, 21 insertions(+), 0 deletions(-)

diff --git a/postler/postler-index.vala b/postler/postler-index.vala
index f33c480..b4da099 100644
--- a/postler/postler-index.vala
+++ b/postler/postler-index.vala
@@ -228,6 +228,7 @@ namespace Postler {
         }
 
         const string[] any_fields = { "subject", "sender", "excerpt" };
+        static GLib.HashTable<string,string>? dates = null;
 
         void search_statement (string folder, string sql,
             ref Sqlite.Statement statement) throws GLib.Error {
@@ -247,8 +248,28 @@ namespace Postler {
                     field = "excerpt";
                 /* We can use the prepared statement for uri search */
                 if (field != "uri") {
+                    if (dates == null) {
+                        /* Build a table of local month names */
+                        dates = new GLib.HashTable<string,string> (str_hash, str_equal);
+                        var timezone = new TimeZone.local ();
+                        var date = new DateTime.now (timezone);
+                        for (int month = 1; month < 12; month++) {
+                            var the_month = new DateTime (timezone,
+                                date.get_year (), month, 1, 0, 0, 0);
+                            string month_name = the_month.format ("%B");
+                            dates.insert (month_name, the_month.format ("%m"));
+                        }
+                    }
+
                     var cond = new StringBuilder ("(");
                     foreach (string word in parts[1].split (" ")) {
+                        /* Interpret a month as "only messages in that month" */
+                        string? month = dates.lookup (word.down ());
+                        if (month != null) {
+                            cond.append_printf (
+                                "strftime ('%%m', timestamp, 'unixepoch') = '%s' AND ", month);
+                            continue;
+                        }
                         /* * is a wildcard, ' must be escaped by doubling it */
                         string escaped = word.replace ("*", "%").replace ("\'", "\'\'");
                         /* any is an alias for subject, sender, attachment, excerpt */



More information about the Xfce4-commits mailing list