[Xfce4-commits] <postler:master> Recognise search:field/value in the service

Christian Dywan noreply at xfce.org
Sat Jul 2 17:08:08 CEST 2011


Updating branch refs/heads/master
         to b84041125ee01d95d6437419226c5ab55d5b75b1 (commit)
       from e471a1171aee5d269fbf254b1d389d10d1dfae61 (commit)

commit b84041125ee01d95d6437419226c5ab55d5b75b1
Author: Christian Dywan <christian at twotoasts.de>
Date:   Fri Jul 1 01:04:13 2011 +0200

    Recognise search:field/value in the service

 postler/postler-index.vala    |   43 +++++++++++++++++++++++++++++++---------
 postler/postler-messages.vala |    2 +-
 2 files changed, 34 insertions(+), 11 deletions(-)

diff --git a/postler/postler-index.vala b/postler/postler-index.vala
index 1dd0557..1d77f38 100644
--- a/postler/postler-index.vala
+++ b/postler/postler-index.vala
@@ -273,20 +273,43 @@ namespace Postler {
         }
 
         public string[] get_messages (string folder) throws GLib.Error {
+            unowned string sql = """
+                SELECT threads AS thread_id FROM messages
+                WHERE $FIELD LIKE ?2 GROUP BY threads
+                HAVING (SELECT COUNT (*) FROM messages WHERE id = thread_id)
+                ORDER BY date ASC
+                """;
+
             if (statement_list == null) {
-                if (database.prepare_v2 ("""
-                    SELECT threads AS thread_id FROM messages
-                    WHERE uri LIKE ?1 GROUP BY threads
-                    HAVING (SELECT COUNT (*) FROM messages WHERE id = thread_id)
-                    ORDER BY date ASC
-                    """,
-                    -1, out statement_list) != Sqlite.OK)
+                if (database.prepare_v2 (sql.replace ("$FIELD", "uri"),
+                                         -1, out statement_list) != Sqlite.OK)
+                    throw new GLib.FileError.FAILED (_("Failed to list messages: %s"), database.errmsg ());
+            }
+
+            /* file:// or search:field/value */
+            bool success;
+            if (folder.has_prefix ("search:")) {
+                string[] parts = folder.slice (7, -1).split ("/", 2);
+                if (parts[0] == null || parts[1] == null)
+                    throw new GLib.FileError.FAILED (_("Failed to list messages: %s"),
+                                                     "parts[0] == null || parts[1] == null");
+                string field = parts[0];
+                if (field == "from")
+                    field = "sender";
+                else if (field == "to")
+                    field = "recipients";
+                Sqlite.Statement statement;
+                if (database.prepare_v2 (sql.replace ("$FIELD", field),
+                                         -1, out statement) != Sqlite.OK)
                     throw new GLib.FileError.FAILED (_("Failed to list messages: %s"), database.errmsg ());
+                string search_value = "%%%s%%".printf (parts[1]);
+                success = statement_list.bind_text (2, search_value, -1) == Sqlite.OK;
             }
+            else
+                success = statement_list.bind_text (2, folder, -1) == Sqlite.OK;
+
             int result = Sqlite.ERROR;
-            bool success =
-                statement_list.bind_text (1, folder, -1) == Sqlite.OK
-             && row_or_done (((result = statement_list.step ())));
+            success = success && row_or_done (((result = statement_list.step ())));
             if (!success) {
                 statement_list.reset ();
                 throw new GLib.FileError.FAILED (_("Failed to list messages: %s"), database.errmsg ());
diff --git a/postler/postler-messages.vala b/postler/postler-messages.vala
index 8530a69..512cfdb 100644
--- a/postler/postler-messages.vala
+++ b/postler/postler-messages.vala
@@ -412,7 +412,7 @@ public class Postler.Messages : Gtk.TreeView {
                 /* FIXME: The client emits, the callback isn't called */
                 client.got_message.connect (got_message);
                 if (location.has_prefix ("search:"))
-                    messages = yield client.get_messages ("%/INBOX/%");
+                    messages = yield client.get_messages (location);
                 else
                     messages = yield client.get_messages ("file://" + location + "%");
             }



More information about the Xfce4-commits mailing list