2007-06-25 Murray Cumming <murrayc@murrayc.com>
authorMurray Cumming <murrayc@murrayc.com>
Mon, 25 Jun 2007 08:37:19 +0000 (08:37 +0000)
committerMurray Cumming <murrayc@murrayc.com>
Mon, 25 Jun 2007 08:37:19 +0000 (08:37 +0000)
* src/dbus_api/modest-dbus-callbacks.c: (on_dbus_method_search):
* src/modest-search.c: (modest_search_folder),
(modest_search_all_accounts): Actually search only in the specified folder,
doing a simple match on the folder ID.
* src/modest-search.h: Added a folder field to the ModestSearch struct,
and added some documentation.

pmo-trunk-r2389

ChangeLog2
src/dbus_api/modest-dbus-callbacks.c
src/modest-search.c
src/modest-search.h

index 4d2468b..3da9f84 100644 (file)
@@ -1,3 +1,12 @@
+2007-06-25  Murray Cumming  <murrayc@murrayc.com>
+
+       * src/dbus_api/modest-dbus-callbacks.c: (on_dbus_method_search):
+       * src/modest-search.c: (modest_search_folder),
+       (modest_search_all_accounts): Actually search only in the specified folder, 
+       doing a simple match on the folder ID.
+       * src/modest-search.h: Added a folder field to the ModestSearch struct, 
+       and added some documentation.
+
 2007-06-22  Armin Burgmeier  <armin@openismus.com>
 
        * src/maemo/modest-maemo-utils.h:
index a5c8a24..6440c34 100644 (file)
@@ -957,15 +957,14 @@ static void
 on_dbus_method_search (DBusConnection *con, DBusMessage *message)
 {
        ModestDBusSearchFlags dbus_flags;
-       ModestSearch  search;
        DBusMessage  *reply = NULL;
        dbus_bool_t  res;
        dbus_int64_t sd_v;
        dbus_int64_t ed_v;
        dbus_int32_t flags_v;
        dbus_uint32_t size_v;
-       char *folder;
-       char *query;
+       const char *folder;
+       const char *query;
        time_t start_date;
        time_t end_date;
        GList *hits;
@@ -979,7 +978,7 @@ on_dbus_method_search (DBusConnection *con, DBusMessage *message)
        res = dbus_message_get_args (message,
                                     &error,
                                     DBUS_TYPE_STRING, &query,
-                                    DBUS_TYPE_STRING, &folder,
+                                    DBUS_TYPE_STRING, &folder, /* e.g. "INBOX/drafts": TODO: Use both an ID and a display name. */
                                     DBUS_TYPE_INT64, &sd_v,
                                     DBUS_TYPE_INT64, &ed_v,
                                     DBUS_TYPE_INT32, &flags_v,
@@ -990,14 +989,27 @@ on_dbus_method_search (DBusConnection *con, DBusMessage *message)
        start_date = (time_t) sd_v;
        end_date = (time_t) ed_v;
 
+       ModestSearch search;
        memset (&search, 0, sizeof (search));
+       
+       /* Remember what folder we are searching in:
+        *
+        * Note that we don't copy the strings, 
+        * because this struct will only be used for the lifetime of this function.
+        */
+       search.folder = folder;
+
+   /* Remember the text to search for: */
 #ifdef MODEST_HAVE_OGS
        search.query  = query;
 #endif
+
+       /* Other criteria: */
        search.before = start_date;
        search.after  = end_date;
        search.flags  = 0;
 
+       /* Text to serach for in various parts of the message: */
        if (dbus_flags & MODEST_DBUS_SEARCH_SUBJECT) {
                search.flags |= MODEST_SEARCH_SUBJECT;
                search.subject = query;
index 0b0dbb3..45fc996 100644 (file)
@@ -374,12 +374,19 @@ static gboolean search_mime_part_and_child_parts (TnyMimePart *part, ModestSearc
  * @folder: a #TnyFolder instance
  * @search: a #ModestSearch query
  *
- * This operation will search @folder for headers that match the query @search.
+ * This operation will search @folder for headers that match the query @search,
+ * if the folder itself matches the query.
  * It will return a doubly linked list with URIs that point to the message.
  **/
 GList *
 modest_search_folder (TnyFolder *folder, ModestSearch *search)
 {
+       /* Check that we should be searching this folder. */
+       /* Note that we don't try to search sub-folders. 
+        * Maybe we should, but that should be specified. */
+       if (search->folder && (strcmp (tny_folder_get_id (folder), search->folder) != 0))
+               return NULL;
+               
        GList *retval = NULL;
        TnyIterator *iter = NULL;
        TnyList *list = NULL;
@@ -547,6 +554,7 @@ modest_search_account (TnyAccount *account, ModestSearch *search)
 GList *
 modest_search_all_accounts (ModestSearch *search)
 {
+       /* printf ("DEBUG: %s: query=%s\n", __FUNCTION__, search->query); */
        ModestTnyAccountStore *astore;
        TnyList               *accounts;
        TnyIterator           *iter;
index 0db1a31..0d1999f 100644 (file)
@@ -59,12 +59,20 @@ typedef enum {
 } ModestSearchFlags;
 
 typedef struct {
-       gchar *subject, *from, *recipient, *body;
+       const gchar *folder; /* The folder to search in */
+       
+       /* Text to search for in various parts: */
+       const gchar *subject;
+       const gchar *from;
+       const gchar *recipient;
+       const gchar *body;
+       
+       /* Other criteria: */
        time_t before, after;
        guint32 minsize;
        ModestSearchFlags flags;
 #ifdef MODEST_HAVE_OGS
-       const gchar     *query;
+       const gchar     *query; /* The text to search for. */
        OgsTextSearcher *text_searcher; 
 #endif
 } ModestSearch;