evolution r37329 - trunk/mail



Author: mcrha
Date: Wed Feb 25 11:04:45 2009
New Revision: 37329
URL: http://svn.gnome.org/viewvc/evolution?rev=37329&view=rev

Log:
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.



Modified:
   trunk/mail/ChangeLog
   trunk/mail/em-utils.c

Modified: trunk/mail/em-utils.c
==============================================================================
--- trunk/mail/em-utils.c	(original)
+++ trunk/mail/em-utils.c	Wed Feb 25 11:04:45 2009
@@ -1998,8 +1998,10 @@
 
 	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 @@
 
 	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 @@
 	}
 
 	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 @@
 	/* 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 @@
 		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 @@
 
     	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 @@
 		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;



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]