X-Git-Url: http://git.maemo.org/git/?p=modest;a=blobdiff_plain;f=src%2Fmodest-search.c;h=32f387f49e8e348da8cc7cb8306452e56541932f;hp=572989b1f5308a34fc3ad7b5e100384f70e4f68e;hb=06941d1065d0885758d057108e8f6b317a02d952;hpb=725f4235f9afe77f4525cc17547c905284a92be8 diff --git a/src/modest-search.c b/src/modest-search.c index 572989b..32f387f 100644 --- a/src/modest-search.c +++ b/src/modest-search.c @@ -43,6 +43,8 @@ #include #include #include +#include +#include #include @@ -50,8 +52,10 @@ #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" static gchar * g_strdup_or_null (const gchar *str) @@ -65,87 +69,6 @@ g_strdup_or_null (const gchar *str) return string; } -typedef struct -{ - GMainLoop* loop; - TnyAccount *account; - gboolean is_online; - gint count_tries; -} UtilIdleData; - -#define NUMBER_OF_TRIES 10 /* Try approx every second, ten times. */ - -static gboolean -on_timeout_check_account_is_online(gpointer user_data) -{ - printf ("DEBUG: %s:\n", __FUNCTION__); - UtilIdleData *data = (UtilIdleData*)user_data; - - gboolean stop_trying = FALSE; - if (data && data->account && - (tny_account_get_connection_status (data->account) == TNY_CONNECTION_STATUS_CONNECTED) ) - { - data->is_online = TRUE; - - stop_trying = TRUE; - } - else { - /* Give up if we have tried too many times: */ - if (data->count_tries >= NUMBER_OF_TRIES) - { - stop_trying = TRUE; - } - else { - /* Wait for another timeout: */ - ++(data->count_tries); - } - } - - if (stop_trying) { - /* Allow the function that requested this idle callback to continue: */ - if (data->loop) - g_main_loop_quit (data->loop); - - return FALSE; /* Don't call this again. */ - } else { - return TRUE; /* Call this timeout callback again. */ - } -} - -/* Return TRUE immediately if the account is already online, - * otherwise check every second for NUMBER_OF_TRIES seconds and return TRUE as - * soon as the account is online, or FALSE if the account does - * not become online in the NUMBER_OF_TRIES seconds. - * This is useful when the D-Bus method was run immediately after - * the application was started (when using D-Bus activation), - * because the account usually takes a short time to go online. - */ -static gboolean -check_and_wait_for_account_is_online(TnyAccount *account) -{ - if (tny_account_get_connection_status (account) == TNY_CONNECTION_STATUS_CONNECTED) - return TRUE; - - /* This blocks on the result: */ - UtilIdleData *data = g_slice_new0 (UtilIdleData); - data->is_online = FALSE; - - GMainContext *context = NULL; /* g_main_context_new (); */ - data->loop = g_main_loop_new (context, FALSE /* not running */); - - g_timeout_add (1000, &on_timeout_check_account_is_online, data); - - /* This main loop will run until the idle handler has stopped it: */ - g_main_loop_run (data->loop); - - g_main_loop_unref (data->loop); - /* g_main_context_unref (context); */ - - g_slice_free (UtilIdleData, data); - - return data->is_online; -} - static GList* add_hit (GList *list, TnyHeader *header, TnyFolder *folder) { @@ -189,7 +112,7 @@ add_hit (GList *list, TnyHeader *header, TnyFolder *folder) hit->msize = tny_header_get_message_size (header); hit->has_attachment = flags & TNY_HEADER_FLAG_ATTACHMENTS; hit->is_unread = ! (flags & TNY_HEADER_FLAG_SEEN); - hit->timestamp = tny_header_get_date_received (header); + hit->timestamp = MIN (tny_header_get_date_received (header), tny_header_get_date_sent (header)); return g_list_prepend (list, hit); } @@ -375,7 +298,7 @@ search_mime_part_strcmp (TnyMimePart *part, ModestSearch *search) buffer, TRUE); - if (found) { + if ((found)||(nread == 0)) { break; } @@ -466,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; @@ -672,16 +602,16 @@ modest_search_all_accounts (ModestSearch *search) /* Give the account time to go online if necessary, * for instance if this is immediately after startup, * after D-Bus activation: */ - if (check_and_wait_for_account_is_online (account)) { - /* Search: */ - res = modest_search_account (account, search); - - if (res != NULL) { - if (hits == NULL) { - hits = res; - } else { - hits = g_list_concat (hits, res); - } + modest_platform_check_and_wait_for_account_is_online (account); + + /* Search: */ + res = modest_search_account (account, search); + + if (res != NULL) { + if (hits == NULL) { + hits = res; + } else { + hits = g_list_concat (hits, res); } }