diff options
author | Milan Crha <mcrha@redhat.com> | 2009-02-25 19:04:45 +0800 |
---|---|---|
committer | Milan Crha <mcrha@src.gnome.org> | 2009-02-25 19:04:45 +0800 |
commit | 7a05751402b2f93604782568678fc91e8d47617a (patch) | |
tree | bb0c4a8ec956b0110ae6160852a0c68d4c19a3c0 /mail | |
parent | d95589c946716d72ccfb0c6d79233bb47631e883 (diff) | |
download | gsoc2013-evolution-7a05751402b2f93604782568678fc91e8d47617a.tar.gz gsoc2013-evolution-7a05751402b2f93604782568678fc91e8d47617a.tar.zst gsoc2013-evolution-7a05751402b2f93604782568678fc91e8d47617a.zip |
** Part of fix for bug #563212
2009-02-25 Milan Crha <mcrha@redhat.com>
** Part of fix for bug #563212
* em-utils.c: (try_open_e_book_cb), (try_open_e_book),
(is_local), (em_utils_in_addressbook), (em_utils_contact_photo):
Ensure empty GError before filling it. Check if group is local based
on its base_uri. Adapt to new e_book_cancel behaviour.
svn path=/trunk/; revision=37329
Diffstat (limited to 'mail')
-rw-r--r-- | mail/ChangeLog | 9 | ||||
-rw-r--r-- | mail/em-utils.c | 47 |
2 files changed, 47 insertions, 9 deletions
diff --git a/mail/ChangeLog b/mail/ChangeLog index 9c1b05cf28..6c48396f08 100644 --- a/mail/ChangeLog +++ b/mail/ChangeLog @@ -1,3 +1,12 @@ +2009-02-25 Milan Crha <mcrha@redhat.com> + + ** Part of fix for bug #563212 + + * em-utils.c: (try_open_e_book_cb), (try_open_e_book), + (is_local), (em_utils_in_addressbook), (em_utils_contact_photo): + Ensure empty GError before filling it. Check if group is local based + on its base_uri. Adapt to new e_book_cancel behaviour. + 2009-02-23 Milan Crha <mcrha@redhat.com> ** Fix for bug #572543 diff --git a/mail/em-utils.c b/mail/em-utils.c index 2bda6d4315..4a1a6eada9 100644 --- a/mail/em-utils.c +++ b/mail/em-utils.c @@ -1998,8 +1998,10 @@ try_open_e_book_cb (EBook *book, EBookStatus status, gpointer closure) data->result = status == E_BOOK_ERROR_OK; - if (!data->result) + if (!data->result) { + g_clear_error (data->error); g_set_error (data->error, E_BOOK_ERROR, status, "EBookStatus returned %d", status); + } e_flag_set (data->flag); } @@ -2024,6 +2026,7 @@ try_open_e_book (EBook *book, gboolean only_if_exists, GError **error) if (e_book_async_open (book, only_if_exists, try_open_e_book_cb, &data) != FALSE) { e_flag_free (flag); + g_clear_error (error); g_set_error (error, E_BOOK_ERROR, E_BOOK_ERROR_OTHER_ERROR, "Failed to call e_book_async_open."); return FALSE; } @@ -2038,14 +2041,25 @@ try_open_e_book (EBook *book, gboolean only_if_exists, GError **error) } if (canceled) { + g_clear_error (error); g_set_error (error, E_BOOK_ERROR, E_BOOK_ERROR_CANCELLED, "Operation has been canceled."); e_book_cancel_async_op (book, NULL); + /* it had been canceled, the above callback may not be called, thus setting flag here */ + e_flag_set (flag); } e_flag_wait (flag); e_flag_free (flag); - return data.result; + return data.result && (!error || !*error); +} + +static gboolean +is_local (ESourceGroup *group) +{ + return group && + e_source_group_peek_base_uri (group) && + g_str_has_prefix (e_source_group_peek_base_uri (group), "file://"); } gboolean @@ -2100,7 +2114,7 @@ em_utils_in_addressbook (CamelInternetAddress *iaddr, gboolean local_only) /* FIXME: this aint threadsafe by any measure, but what can you do eh??? */ for (g = e_source_list_peek_groups(emu_addr_list);g;g=g_slist_next(g)) { - if (local_only && e_source_group_peek_base_uri ((ESourceGroup *)g->data) && !g_str_has_prefix (e_source_group_peek_base_uri ((ESourceGroup *)g->data), "file://")) + if (local_only && !is_local (g->data)) continue; for (s = e_source_group_peek_sources((ESourceGroup *)g->data);s;s=g_slist_next(s)) { @@ -2126,20 +2140,24 @@ em_utils_in_addressbook (CamelInternetAddress *iaddr, gboolean local_only) book = e_book_new(source, &err); if (book == NULL) { - g_warning("Unable to create addressbook: %s", err->message); + if (err && !g_error_matches (err, E_BOOK_ERROR, E_BOOK_ERROR_CANCELLED)) + g_warning ("%s: Unable to create addressbook: %s", G_STRFUNC, err->message); g_clear_error(&err); continue; } + g_clear_error(&err); + hook = mail_cancel_hook_add(emu_addr_cancel_book, book); /* ignore errors, but cancellation errors we don't try to go further either */ if (!try_open_e_book (book, TRUE, &err) || !e_book_get_contacts(book, query, &contacts, &err)) { - stop = err && err->domain == E_BOOK_ERROR && err->code == E_BOOK_ERROR_CANCELLED; + stop = err && g_error_matches (err, E_BOOK_ERROR, E_BOOK_ERROR_CANCELLED); mail_cancel_hook_remove(hook); g_object_unref(book); - g_warning("Can't get contacts: %s", err->message); + if (err && !stop) + g_warning ("%s: Can't get contacts: %s", G_STRFUNC, err->message); g_clear_error(&err); continue; } @@ -2201,7 +2219,7 @@ em_utils_contact_photo (struct _CamelInternetAddress *cia, gboolean local) query = e_book_query_field_test(E_CONTACT_EMAIL, E_BOOK_QUERY_IS, addr); for (g = e_source_list_peek_groups(emu_addr_list); g; g = g_slist_next(g)) { - if (local && strcmp (e_source_group_peek_name ((ESourceGroup *)g->data), "On This Computer")) + if (local && !is_local (g->data)) continue; for (s = e_source_group_peek_sources((ESourceGroup *)g->data); s; s=g_slist_next(s)) { @@ -2219,14 +2237,25 @@ em_utils_contact_photo (struct _CamelInternetAddress *cia, gboolean local) source = s->data; book = e_book_new(source, &err); + if (!book) { + if (err && !g_error_matches (err, E_BOOK_ERROR, E_BOOK_ERROR_CANCELLED)) + g_warning ("%s: Unable to create addressbook: %s", G_STRFUNC, err->message); + g_clear_error (&err); + continue; + } + + g_clear_error (&err); + if (!try_open_e_book (book, TRUE, &err) || !e_book_get_contacts(book, query, &contacts, &err)) { - stop = err && err->domain == E_BOOK_ERROR && err->code == E_BOOK_ERROR_CANCELLED; + stop = err && g_error_matches (err, E_BOOK_ERROR, E_BOOK_ERROR_CANCELLED); g_object_unref(book); - g_warning("Can't get contacts: %s", err->message); + if (err && !stop) + g_warning ("%s: Can't get contacts: %s", G_STRFUNC, err->message); g_clear_error(&err); continue; } + g_clear_error (&err); if (contacts != NULL) { found = TRUE; |