These changes add support for searching in outbox folder (fixes
authorJose Dapena Paz <jdapena@igalia.com>
Wed, 3 Oct 2007 09:37:15 +0000 (09:37 +0000)
committerJose Dapena Paz <jdapena@igalia.com>
Wed, 3 Oct 2007 09:37:15 +0000 (09:37 +0000)
NB#57740).
* src/dbus_api/modest-dbus-callbacks.c:
        * (find_message_by_url): if the url prefix is merge we assume
          we're trying to retrieve a message in outbox.
        * (on_dbus_method_search): we remove the MAND: and USER: strings
          in the received folder name.
        * (add_single_folder_to_list): if folder is merge folder, and
          name is Outbox, we add it to the list of folders as
          MAND:outbox.
        * (add_single_folder_to_list): now we add MAND: prefix if the
          folder is a mandatory folder (inbox, sent, drafts, archive).
          If not, we add the USER: prefix.
* src/modest-search.c:
        * (modest_search_folder): if we search in a specific folder,
          make "outbox" folder name match any folder of type outbox.
* src/modest-tny-account-store.[ch]:
        * Added new method
(modest_tny_account_store_find_msg_in_outboxes)
          that finds a message uri (with the merge:// format) in outbox
          folders, to open it properly. This way, we can open a message
          in an outbox folder from global search emails list.

pmo-trunk-r3457

src/dbus_api/modest-dbus-callbacks.c
src/modest-search.c
src/modest-tny-account-store.c
src/modest-tny-account-store.h

index 6778438..b89afd1 100644 (file)
@@ -497,7 +497,6 @@ static gint on_compose_mail(GArray * arguments, gpointer data, osso_rpc_t * retv
        return OSSO_OK;
 }
 
-
 static TnyMsg *
 find_message_by_url (const char *uri,  TnyAccount **ac_out)
 {
@@ -516,6 +515,12 @@ find_message_by_url (const char *uri,  TnyAccount **ac_out)
                return NULL;
        }
 
+       if (uri && g_str_has_prefix (uri, "merge://")) {
+               /* we assume we're talking about outbox folder, as this 
+                * is the only merge folder we work with in modest */
+               return modest_tny_account_store_find_msg_in_outboxes (astore, uri, ac_out);
+       }
+       
        printf ("DEBUG: %s: uri=%s\n", __FUNCTION__, uri);
        /* TODO: When tinymail is built with the extra DBC assertion checks, 
         * this will crash for local folders (such as drafts),
@@ -1165,7 +1170,13 @@ on_dbus_method_search (DBusConnection *con, DBusMessage *message)
         * Note that we don't copy the strings, 
         * because this struct will only be used for the lifetime of this function.
         */
-       search.folder = folder;
+       if (folder && g_str_has_prefix (folder, "MAND:")) {
+               search.folder = folder + strlen ("MAND:");
+       } else if (folder && g_str_has_prefix (folder, "USER:")) {
+               search.folder = folder + strlen ("USER:");
+       } else {
+               search.folder = folder;
+       }
 
    /* Remember the text to search for: */
 #ifdef MODEST_HAVE_OGS
@@ -1305,6 +1316,7 @@ add_single_folder_to_list (TnyFolder *folder, GList** list)
                return;
                
        if (TNY_IS_MERGE_FOLDER (folder)) {
+               const gchar * folder_name;
                /* Ignore these because their IDs ares
                 * a) not always unique or sensible.
                 * b) not human-readable, and currently need a human-readable 
@@ -1315,7 +1327,11 @@ add_single_folder_to_list (TnyFolder *folder, GList** list)
                 * We could hack our D-Bus API to understand "outbox" as the merged outboxes, 
                 * but that seems unwise. murrayc.
                 */
-                return;        
+               folder_name = tny_folder_get_name (folder);
+               if (folder_name && !strcmp (folder_name, "Outbox")) {
+                       *list = g_list_append(*list, g_strdup ("MAND:outbox"));
+               }
+               return; 
        }
                
        /* Add this folder to the list: */
@@ -1330,9 +1346,31 @@ add_single_folder_to_list (TnyFolder *folder, GList** list)
                 * TODO: osso-global search should probably be changed to 
                 * take an ID and a Name.
                 */
-               const gchar * id =  tny_folder_get_id (folder);
-               if (id && strlen(id))
-                       *list = g_list_append(*list, g_strdup (id));
+       const gchar * id =  tny_folder_get_id (folder);
+       if (id && strlen(id)) {
+               const gchar *prefix = NULL;
+               TnyFolderType folder_type;
+                       
+               /* dbus global search api expects a prefix identifying the type of
+                * folder here. Mandatory folders should have MAND: prefix, and
+                * other user created folders should have USER: prefix
+                */
+               folder_type = modest_tny_folder_guess_folder_type (folder);
+               switch (folder_type) {
+               case TNY_FOLDER_TYPE_INBOX:
+               case TNY_FOLDER_TYPE_OUTBOX:
+               case TNY_FOLDER_TYPE_DRAFTS:
+               case TNY_FOLDER_TYPE_SENT:
+               case TNY_FOLDER_TYPE_ARCHIVE:
+                       prefix = "MAND:";
+                       break;
+               default:
+                       prefix = "USER:";
+               }
+               
+
+               *list = g_list_append(*list, g_strdup_printf ("%s%s", prefix, id));
+       }
                /*
                else {
                        g_warning ("DEBUG: %s: folder has no name or ID.\n", __FUNCTION__);     
index f1500a7..32f387f 100644 (file)
@@ -52,6 +52,7 @@
 #include "modest-account-mgr.h"
 #include "modest-tny-account-store.h"
 #include "modest-tny-account.h"
+#include "modest-tny-folder.h"
 #include "modest-search.h"
 #include "modest-runtime.h"
 #include "modest-platform.h"
@@ -388,8 +389,15 @@ 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 && strlen (search->folder) && (strcmp (tny_folder_get_id (folder), search->folder) != 0))
-               return NULL;
+       if (search->folder && strlen (search->folder)) {
+               if (!strcmp (search->folder, "outbox")) {
+                       if (modest_tny_folder_guess_folder_type (folder) != TNY_FOLDER_TYPE_OUTBOX) {
+                               return NULL;
+                       }
+               } else if (strcmp (tny_folder_get_id (folder), search->folder) != 0) {
+                       return NULL;
+               }
+       }
        
        GList *retval = NULL;
        TnyIterator *iter = NULL;
index 6d59f34..9f117c5 100644 (file)
@@ -1710,3 +1710,49 @@ add_connection_specific_transport_accounts (ModestTnyAccountStore *self)
                iter = g_slist_next (iter);
        }
 }
+
+TnyMsg *
+modest_tny_account_store_find_msg_in_outboxes (ModestTnyAccountStore *self, 
+                                              const gchar *uri,
+                                              TnyAccount **ac_out)
+{
+       TnyIterator *acc_iter;
+       ModestTnyAccountStorePrivate *priv;
+       TnyMsg *msg = NULL;
+       TnyAccount *msg_account = NULL;
+
+       g_return_val_if_fail (MODEST_IS_TNY_ACCOUNT_STORE (self), NULL);
+       priv = MODEST_TNY_ACCOUNT_STORE_GET_PRIVATE (self);
+
+       acc_iter = tny_list_create_iterator (priv->store_accounts_outboxes);
+       while (!msg && !tny_iterator_is_done (acc_iter)) {
+               TnyList *folders = tny_simple_list_new ();
+               TnyAccount *account = TNY_ACCOUNT (tny_iterator_get_current (acc_iter));
+               TnyIterator *folders_iter = NULL;
+
+               tny_folder_store_get_folders (TNY_FOLDER_STORE (account), folders, NULL, NULL);
+               folders_iter = tny_list_create_iterator (folders);
+
+               while (msg == NULL && !tny_iterator_is_done (folders_iter)) {
+                       TnyFolder *folder = TNY_FOLDER (tny_iterator_get_current (folders_iter));
+                       msg = tny_folder_find_msg (folder, uri, NULL);
+
+                       if (msg)
+                               msg_account = g_object_ref (account);
+
+                       g_object_unref (folder);
+                       tny_iterator_next (folders_iter);
+               }
+
+               g_object_unref (folders);
+               g_object_unref (account);
+               tny_iterator_next (acc_iter);
+       }
+
+       g_object_unref (acc_iter);
+
+       if (ac_out != NULL)
+               *ac_out = msg_account;
+
+       return msg;
+}
index 336359e..b116c71 100644 (file)
@@ -177,6 +177,20 @@ TnyAccount * modest_tny_account_store_get_local_folders_account (ModestTnyAccoun
   **/
 void modest_tny_account_store_forget_already_asked (ModestTnyAccountStore *self, TnyAccount *account);
 
+/**
+ * modest_tny_account_store_find_msg_in_outboxes:
+ * @self: a #ModestTnyAccountStore
+ * @uri: the uri of the message
+ * @ac_out: output attribute, %NULL, or the #TnyAccount of the message
+ *
+ * finds a message in the set of outboxes, using the uri.
+ *
+ * Returns: %NULL or a #TnyMsg
+ **/
+TnyMsg *modest_tny_account_store_find_msg_in_outboxes (ModestTnyAccountStore *self, 
+                                                      const gchar *uri,
+                                                      TnyAccount **ac_out);
+
 
 G_END_DECLS