[evolution-mapi] Properly propagate Cancelled GError



commit 7390c24bf87907fb1546a511bfeac1a3458aaae5
Author: Milan Crha <mcrha redhat com>
Date:   Mon Nov 28 15:23:32 2011 +0100

    Properly propagate Cancelled GError

 src/addressbook/e-book-backend-mapi.c   |    5 +++
 src/calendar/e-cal-backend-mapi.c       |    5 +++
 src/camel/camel-mapi-folder.c           |   45 ++++++++++++++++--------------
 src/camel/camel-mapi-store.c            |   43 +++++++++++++++++------------
 src/camel/camel-mapi-transport.c        |    8 +++--
 src/libexchangemapi/e-mapi-connection.c |   12 +++++++-
 src/libexchangemapi/e-mapi-utils.c      |   13 +++++++++
 src/libexchangemapi/e-mapi-utils.h      |    3 ++
 8 files changed, 90 insertions(+), 44 deletions(-)
---
diff --git a/src/addressbook/e-book-backend-mapi.c b/src/addressbook/e-book-backend-mapi.c
index 3e74584..e5324aa 100644
--- a/src/addressbook/e-book-backend-mapi.c
+++ b/src/addressbook/e-book-backend-mapi.c
@@ -1925,6 +1925,11 @@ mapi_error_to_edb_error (GError **perror, const GError *mapi_error, EDataBookSta
 	if (!perror)
 		return;
 
+	if (g_error_matches (mapi_error, G_IO_ERROR, G_IO_ERROR_CANCELLED)) {
+		g_propagate_error (perror, g_error_copy (mapi_error));
+		return;
+	}
+
 	if (code == E_DATA_BOOK_STATUS_OTHER_ERROR && mapi_error && mapi_error->domain == E_MAPI_ERROR) {
 		/* Change error to more accurate only with OTHER_ERROR */
 		switch (mapi_error->code) {
diff --git a/src/calendar/e-cal-backend-mapi.c b/src/calendar/e-cal-backend-mapi.c
index 8a3ca16..0b29951 100644
--- a/src/calendar/e-cal-backend-mapi.c
+++ b/src/calendar/e-cal-backend-mapi.c
@@ -113,6 +113,11 @@ mapi_error_to_edc_error (GError **perror, const GError *mapi_error, EDataCalCall
 	if (!perror)
 		return;
 
+	if (g_error_matches (mapi_error, G_IO_ERROR, G_IO_ERROR_CANCELLED)) {
+		g_propagate_error (perror, g_error_copy (mapi_error));
+		return;
+	}
+
 	if (code == OtherError && mapi_error && mapi_error->domain == E_MAPI_ERROR) {
 		/* Change error to more accurate only with OtherError */
 		switch (mapi_error->code) {
diff --git a/src/camel/camel-mapi-folder.c b/src/camel/camel-mapi-folder.c
index d4822c1..646ab39 100644
--- a/src/camel/camel-mapi-folder.c
+++ b/src/camel/camel-mapi-folder.c
@@ -1013,9 +1013,10 @@ mapi_refresh_folder (CamelFolder *folder, GCancellable *cancellable, GError **er
 
 	if (!status) {
 		if (mapi_error) {
-			g_set_error (
-				error, CAMEL_SERVICE_ERROR, CAMEL_SERVICE_ERROR_INVALID,
-				_("Fetching items failed: %s"), mapi_error->message);
+			if (!e_mapi_utils_propagate_cancelled_error (mapi_error, error))
+				g_set_error (
+					error, CAMEL_SERVICE_ERROR, CAMEL_SERVICE_ERROR_INVALID,
+					_("Fetching items failed: %s"), mapi_error->message);
 			g_error_free (mapi_error);
 		} else {
 			g_set_error_literal (
@@ -1273,7 +1274,8 @@ mapi_folder_append_message_sync (CamelFolder *folder,
 
 	if (!mid) {
 		if (mapi_error) {
-			g_set_error_literal (error, CAMEL_ERROR, CAMEL_ERROR_GENERIC, mapi_error->message);
+			if (!e_mapi_utils_propagate_cancelled_error (mapi_error, error))
+				g_set_error_literal (error, CAMEL_ERROR, CAMEL_ERROR_GENERIC, mapi_error->message);
 			g_error_free (mapi_error);
 		} else {
 			g_set_error (error, CAMEL_ERROR, CAMEL_ERROR_GENERIC, _("Offline."));
@@ -1346,9 +1348,10 @@ mapi_folder_expunge_sync (CamelFolder *folder,
 			mapi_summary_clear (folder->summary, TRUE);
 			camel_folder_thaw (folder);
 		} else if (mapi_error) {
-			g_set_error (
-				error, CAMEL_ERROR, CAMEL_ERROR_GENERIC,
-				_("Failed to empty Trash: %s"), mapi_error->message);
+			if (!e_mapi_utils_propagate_cancelled_error (mapi_error, error))
+				g_set_error (
+					error, CAMEL_ERROR, CAMEL_ERROR_GENERIC,
+					_("Failed to empty Trash: %s"), mapi_error->message);
 			g_error_free (mapi_error);
 		} else {
 			g_set_error_literal (
@@ -1561,10 +1564,10 @@ mapi_folder_get_message_sync (CamelFolder *folder,
 
 	if (!msg) {
 		if (mapi_error) {
-			g_set_error (
-				error, CAMEL_SERVICE_ERROR,
-				CAMEL_SERVICE_ERROR_INVALID,
-				_("Could not get message: %s"), mapi_error->message);
+			if (!e_mapi_utils_propagate_cancelled_error (mapi_error, error))
+				g_set_error (
+					error, CAMEL_SERVICE_ERROR, CAMEL_SERVICE_ERROR_INVALID,
+					_("Could not get message: %s"), mapi_error->message);
 			g_error_free (mapi_error);
 		} else {
 			g_set_error (
@@ -1866,11 +1869,11 @@ mapi_folder_transfer_messages_to_sync (CamelFolder *source,
 		GError *err = NULL;
 
 		if (!e_mapi_connection_move_items (camel_mapi_store_get_connection (mapi_store), src_mapi_folder->folder_id, src_fid_options, des_mapi_folder->folder_id, dest_fid_options, src_msg_ids, cancellable, &err)) {
-			g_set_error (
-				error, CAMEL_ERROR, CAMEL_ERROR_GENERIC,
-				"%s", err ? err->message : _("Unknown error"));
-			if (err)
-				g_error_free (err);
+			if (!e_mapi_utils_propagate_cancelled_error (err, error))
+				g_set_error (
+					error, CAMEL_ERROR, CAMEL_ERROR_GENERIC,
+					"%s", err ? err->message : _("Unknown error"));
+			g_clear_error (&err);
 			success = FALSE;
 		} else {
 			changes = camel_folder_change_info_new ();
@@ -1887,11 +1890,11 @@ mapi_folder_transfer_messages_to_sync (CamelFolder *source,
 		GError *err = NULL;
 
 		if (!e_mapi_connection_copy_items (camel_mapi_store_get_connection (mapi_store), src_mapi_folder->folder_id, src_fid_options, des_mapi_folder->folder_id, dest_fid_options, src_msg_ids, cancellable, &err)) {
-			g_set_error (
-				error, CAMEL_ERROR, CAMEL_ERROR_GENERIC,
-				"%s", err ? err->message : _("Unknown error"));
-			if (err)
-				g_error_free (err);
+			if (!e_mapi_utils_propagate_cancelled_error (err, error))
+				g_set_error (
+					error, CAMEL_ERROR, CAMEL_ERROR_GENERIC,
+					"%s", err ? err->message : _("Unknown error"));
+			g_clear_error (&err);
 			success = FALSE;
 		}
 	}
diff --git a/src/camel/camel-mapi-store.c b/src/camel/camel-mapi-store.c
index 53267f7..a513910 100644
--- a/src/camel/camel-mapi-store.c
+++ b/src/camel/camel-mapi-store.c
@@ -1068,9 +1068,10 @@ mapi_store_create_folder_sync (CamelStore *store,
 		camel_subscribable_folder_subscribed (CAMEL_SUBSCRIBABLE (store), root);
 	} else {
 		if (mapi_error) {
-			g_set_error (
-				error, CAMEL_ERROR, CAMEL_ERROR_GENERIC,
-				_("Cannot create folder '%s': %s"), folder_name, mapi_error->message);
+			if (!e_mapi_utils_propagate_cancelled_error (mapi_error, error))
+				g_set_error (
+					error, CAMEL_ERROR, CAMEL_ERROR_GENERIC,
+					_("Cannot create folder '%s': %s"), folder_name, mapi_error->message);
 			g_error_free (mapi_error);
 		} else {
 			g_set_error (
@@ -1130,10 +1131,11 @@ mapi_store_delete_folder_sync (CamelStore *store,
 		success = FALSE;
 
 		if (local_error) {
-			g_set_error (
-				error, CAMEL_ERROR, CAMEL_ERROR_GENERIC,
-				_("Cannot remove folder '%s': %s"),
-				folder_name, local_error->message);
+			if (!e_mapi_utils_propagate_cancelled_error (local_error, error))
+				g_set_error (
+					error, CAMEL_ERROR, CAMEL_ERROR_GENERIC,
+					_("Cannot remove folder '%s': %s"),
+					folder_name, local_error->message);
 
 			g_error_free (local_error);
 		} else {
@@ -1242,12 +1244,13 @@ mapi_store_rename_folder_sync (CamelStore *store,
 		/* renaming in the same folder, thus no MoveFolder necessary */
 		if (!e_mapi_connection_rename_folder (priv->conn, old_fid, 0, tmp ? tmp : new_name, cancellable, &local_error)) {
 			if (local_error) {
-				g_set_error (
-					error, CAMEL_ERROR, CAMEL_ERROR_GENERIC,
-					/* Translators: '%s to %s' is current name of the folder and new name of the folder.
-					   The last '%s' is a detailed error message. */
-					_("Cannot rename MAPI folder '%s' to '%s': %s"),
-					old_name, new_name, local_error->message);
+				if (!e_mapi_utils_propagate_cancelled_error (local_error, error))
+					g_set_error (
+						error, CAMEL_ERROR, CAMEL_ERROR_GENERIC,
+						/* Translators: '%s to %s' is current name of the folder and new name of the folder.
+						   The last '%s' is a detailed error message. */
+						_("Cannot rename MAPI folder '%s' to '%s': %s"),
+						old_name, new_name, local_error->message);
 				g_error_free (local_error);
 			} else {
 				g_set_error (
@@ -1307,10 +1310,11 @@ mapi_store_rename_folder_sync (CamelStore *store,
 			   !e_mapi_connection_move_folder (priv->conn, old_fid, old_parent_fid, 0, new_parent_fid, 0, tmp, cancellable, &local_error)) {
 			camel_service_unlock (service, CAMEL_SERVICE_REC_CONNECT_LOCK);
 			if (local_error) {
-				g_set_error (
-					error, CAMEL_ERROR, CAMEL_ERROR_GENERIC,
-					_("Cannot rename MAPI folder '%s' to '%s': %s"),
-					old_name, new_name, local_error->message);
+				if (!e_mapi_utils_propagate_cancelled_error (local_error, error))
+					g_set_error (
+						error, CAMEL_ERROR, CAMEL_ERROR_GENERIC,
+						_("Cannot rename MAPI folder '%s' to '%s': %s"),
+						old_name, new_name, local_error->message);
 				g_error_free (local_error);
 			} else {
 				g_set_error (
@@ -1813,7 +1817,10 @@ mapi_authenticate_sync (CamelService *service,
 		g_return_val_if_fail (
 			mapi_error != NULL,
 			CAMEL_AUTHENTICATION_ERROR);
-		g_propagate_error (error, mapi_error);
+		if (!e_mapi_utils_propagate_cancelled_error (mapi_error, error))
+			g_propagate_error (error, mapi_error);
+		else
+			g_clear_error (&mapi_error);
 		result = CAMEL_AUTHENTICATION_ERROR;
 	}
 
diff --git a/src/camel/camel-mapi-transport.c b/src/camel/camel-mapi-transport.c
index bdcd682..a39f14c 100644
--- a/src/camel/camel-mapi-transport.c
+++ b/src/camel/camel-mapi-transport.c
@@ -47,6 +47,7 @@
 
 #include <e-mapi-defs.h>
 #include "e-mapi-mail-utils.h"
+#include "e-mapi-utils.h"
 
 #define STREAM_SIZE 4000
 
@@ -158,9 +159,10 @@ mapi_send_to_sync (CamelTransport *transport,
 
 	if (st == 0) {
 		if (mapi_error) {
-			g_set_error (
-				error, CAMEL_ERROR, CAMEL_ERROR_GENERIC,
-				_("Could not send message: %s"), mapi_error->message);
+			if (!e_mapi_utils_propagate_cancelled_error (mapi_error, error))
+				g_set_error (
+					error, CAMEL_ERROR, CAMEL_ERROR_GENERIC,
+					_("Could not send message: %s"), mapi_error->message);
 			g_error_free (mapi_error);
 		} else {
 			g_set_error (
diff --git a/src/libexchangemapi/e-mapi-connection.c b/src/libexchangemapi/e-mapi-connection.c
index efc4840..1023088 100644
--- a/src/libexchangemapi/e-mapi-connection.c
+++ b/src/libexchangemapi/e-mapi-connection.c
@@ -92,6 +92,7 @@ make_mapi_error (GError **perror, const gchar *context, enum MAPISTATUS mapi_sta
 {
 	const gchar *error_msg = NULL, *status_name;
 	gchar *to_free = NULL;
+	GQuark error_domain;
 	GError *error;
 
 	if (!perror)
@@ -134,13 +135,20 @@ make_mapi_error (GError **perror, const gchar *context, enum MAPISTATUS mapi_sta
 
 	g_return_if_fail (error_msg != NULL);
 
+	error_domain = E_MAPI_ERROR;
+
+	if (mapi_status == MAPI_E_USER_CANCEL) {
+		error_domain = G_IO_ERROR;
+		mapi_status = G_IO_ERROR_CANCELLED;
+	}
+
 	if (context && *context) {
 		/* Translators: The first '%s' is replaced with an error context,
 		   aka where the error occurred, the second '%s' is replaced with
 		   the error message. */
-		error = g_error_new (E_MAPI_ERROR, mapi_status, C_("EXCHANGEMAPI_ERROR", "%s: %s"), context, error_msg);
+		error = g_error_new (error_domain, mapi_status, C_("EXCHANGEMAPI_ERROR", "%s: %s"), context, error_msg);
 	} else {
-		error = g_error_new_literal (E_MAPI_ERROR, mapi_status, error_msg);
+		error = g_error_new_literal (error_domain, mapi_status, error_msg);
 	}
 
 	g_free (to_free);
diff --git a/src/libexchangemapi/e-mapi-utils.c b/src/libexchangemapi/e-mapi-utils.c
index 6d3ff42..1c6e6d8 100644
--- a/src/libexchangemapi/e-mapi-utils.c
+++ b/src/libexchangemapi/e-mapi-utils.c
@@ -1184,6 +1184,19 @@ e_mapi_util_time_t_to_filetime (const time_t tt, struct FILETIME *filetime)
 	filetime->dwHighDateTime = nt & 0xFFFFFFFF;
 }
 
+gboolean
+e_mapi_utils_propagate_cancelled_error (const GError *mapi_error,
+					GError **error)
+{
+	if (!g_error_matches (mapi_error, G_IO_ERROR, G_IO_ERROR_CANCELLED) &&
+	    !g_error_matches (mapi_error, E_MAPI_ERROR, MAPI_E_USER_CANCEL))
+		return FALSE;
+
+	g_set_error_literal (error, G_IO_ERROR, G_IO_ERROR_CANCELLED, mapi_error->message);
+
+	return TRUE;
+}
+
 static void
 manage_global_lock (gboolean lock)
 {
diff --git a/src/libexchangemapi/e-mapi-utils.h b/src/libexchangemapi/e-mapi-utils.h
index a40d39f..6be9ac9 100644
--- a/src/libexchangemapi/e-mapi-utils.h
+++ b/src/libexchangemapi/e-mapi-utils.h
@@ -103,6 +103,9 @@ void e_mapi_util_free_binary_r (struct Binary_r *bin);
 time_t e_mapi_util_filetime_to_time_t (const struct FILETIME *filetime);
 void e_mapi_util_time_t_to_filetime (const time_t tt, struct FILETIME *filetime);
 
+gboolean	e_mapi_utils_propagate_cancelled_error		(const GError *mapi_error,
+								 GError **error);
+
 void		e_mapi_utils_global_lock			(void);
 void		e_mapi_utils_global_unlock			(void);
 gboolean	e_mapi_utils_create_mapi_context		(struct mapi_context **mapi_ctx,



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