[evolution] Add e_activity_handle_cancellation().



commit ba8f1f78f4ec76aeaec6e2b55fcb9b2dec17ba65
Author: Matthew Barnes <mbarnes redhat com>
Date:   Wed May 11 12:19:17 2011 -0400

    Add e_activity_handle_cancellation().
    
    Convenience function for use in GAsyncReadyCallback functions.
    
    This acknowledges the cancellation, so that the activity's description
    changes from "(cancelling)" to "(cancelled)" and the description appears
    crossed out in the UI for a moment before disappearing.

 composer/e-msg-composer.c                |   12 +++------
 e-util/e-activity.c                      |   15 +++++++++++
 e-util/e-activity.h                      |    2 +
 e-util/e-file-utils.c                    |    4 +--
 mail/e-mail-backend.c                    |    4 +-
 mail/e-mail-reader-utils.c               |    4 +--
 mail/em-composer-utils.c                 |   38 ++++++++---------------------
 mail/mail-mt.c                           |    4 +--
 modules/mail/e-mail-shell-view-actions.c |    3 +-
 modules/mail/e-mail-shell-view-private.c |    3 +-
 10 files changed, 39 insertions(+), 50 deletions(-)
---
diff --git a/composer/e-msg-composer.c b/composer/e-msg-composer.c
index 98d1e6f..74a36cc 100644
--- a/composer/e-msg-composer.c
+++ b/composer/e-msg-composer.c
@@ -3548,8 +3548,7 @@ msg_composer_send_cb (EMsgComposer *composer,
 
 	message = e_msg_composer_get_message_finish (composer, result, &error);
 
-	/* Ignore cancellations. */
-	if (g_error_matches (error, G_IO_ERROR, G_IO_ERROR_CANCELLED)) {
+	if (e_activity_handle_cancellation (context->activity, error)) {
 		g_warn_if_fail (message == NULL);
 		async_context_free (context);
 		g_error_free (error);
@@ -3639,8 +3638,7 @@ msg_composer_save_to_drafts_cb (EMsgComposer *composer,
 	message = e_msg_composer_get_message_draft_finish (
 		composer, result, &error);
 
-	/* Ignore cancellations. */
-	if (g_error_matches (error, G_IO_ERROR, G_IO_ERROR_CANCELLED)) {
+	if (e_activity_handle_cancellation (context->activity, error)) {
 		g_warn_if_fail (message == NULL);
 		async_context_free (context);
 		g_error_free (error);
@@ -3722,8 +3720,7 @@ msg_composer_save_to_outbox_cb (EMsgComposer *composer,
 
 	message = e_msg_composer_get_message_finish (composer, result, &error);
 
-	/* Ignore cancellations. */
-	if (g_error_matches (error, G_IO_ERROR, G_IO_ERROR_CANCELLED)) {
+	if (e_activity_handle_cancellation (context->activity, error)) {
 		g_warn_if_fail (message == NULL);
 		async_context_free (context);
 		g_error_free (error);
@@ -3812,8 +3809,7 @@ msg_composer_print_cb (EMsgComposer *composer,
 	message = e_msg_composer_get_message_print_finish (
 		composer, result, &error);
 
-	/* Ignore cancellations. */
-	if (g_error_matches (error, G_IO_ERROR, G_IO_ERROR_CANCELLED)) {
+	if (e_activity_handle_cancellation (context->activity, error)) {
 		g_warn_if_fail (message == NULL);
 		async_context_free (context);
 		g_error_free (error);
diff --git a/e-util/e-activity.c b/e-util/e-activity.c
index 231de50..2e3a078 100644
--- a/e-util/e-activity.c
+++ b/e-util/e-activity.c
@@ -498,3 +498,18 @@ e_activity_set_text (EActivity *activity,
 	g_object_notify (G_OBJECT (activity), "text");
 }
 
+gboolean
+e_activity_handle_cancellation (EActivity *activity,
+                                const GError *error)
+{
+	gboolean handled = FALSE;
+
+	g_return_val_if_fail (E_IS_ACTIVITY (activity), FALSE);
+
+	if (g_error_matches (error, G_IO_ERROR, G_IO_ERROR_CANCELLED)) {
+		e_activity_set_state (activity, E_ACTIVITY_CANCELLED);
+		handled = TRUE;
+	}
+
+	return handled;
+}
diff --git a/e-util/e-activity.h b/e-util/e-activity.h
index 4602a56..3e56f99 100644
--- a/e-util/e-activity.h
+++ b/e-util/e-activity.h
@@ -84,6 +84,8 @@ void		e_activity_set_state		(EActivity *activity,
 const gchar *	e_activity_get_text		(EActivity *activity);
 void		e_activity_set_text		(EActivity *activity,
 						 const gchar *text);
+gboolean	e_activity_handle_cancellation	(EActivity *activity,
+						 const GError *error);
 
 G_END_DECLS
 
diff --git a/e-util/e-file-utils.c b/e-util/e-file-utils.c
index 2d5ff30..49fd4a0 100644
--- a/e-util/e-file-utils.c
+++ b/e-util/e-file-utils.c
@@ -85,9 +85,7 @@ file_replace_contents_cb (GFile *file,
 
 	g_file_replace_contents_finish (file, result, &new_etag, &error);
 
-	if (g_error_matches (error, G_IO_ERROR, G_IO_ERROR_CANCELLED))
-		e_activity_set_state (context->activity, E_ACTIVITY_CANCELLED);
-	else
+	if (!e_activity_handle_cancellation (context->activity, error))
 		e_activity_set_state (context->activity, E_ACTIVITY_COMPLETED);
 
 	if (error == NULL)
diff --git a/mail/e-mail-backend.c b/mail/e-mail-backend.c
index 3addb64..eaf3bd0 100644
--- a/mail/e-mail-backend.c
+++ b/mail/e-mail-backend.c
@@ -446,8 +446,8 @@ mail_backend_job_finished_cb (CamelSession *session,
 	activity = g_hash_table_lookup (priv->jobs, cancellable);
 	description = e_activity_get_text (activity);
 
-	if (g_error_matches (error, G_IO_ERROR, G_IO_ERROR_CANCELLED)) {
-		/* ignore cancellations */
+	if (e_activity_handle_cancellation (activity, error)) {
+		/* nothing to do */
 
 	} else if (error != NULL) {
 		EShell *shell;
diff --git a/mail/e-mail-reader-utils.c b/mail/e-mail-reader-utils.c
index 81712b8..0311b3d 100644
--- a/mail/e-mail-reader-utils.c
+++ b/mail/e-mail-reader-utils.c
@@ -369,10 +369,8 @@ mail_reader_remove_duplicates_cb (CamelFolder *folder,
 	duplicates = e_mail_folder_find_duplicate_messages_finish (
 		folder, result, &error);
 
-	/* Ignore cancellations. */
-	if (g_error_matches (error, G_IO_ERROR, G_IO_ERROR_CANCELLED)) {
+	if (e_activity_handle_cancellation (context->activity, error)) {
 		g_warn_if_fail (duplicates == NULL);
-		e_activity_set_state (context->activity, E_ACTIVITY_CANCELLED);
 		async_context_free (context);
 		g_error_free (error);
 		return;
diff --git a/mail/em-composer-utils.c b/mail/em-composer-utils.c
index 1431975..c91870f 100644
--- a/mail/em-composer-utils.c
+++ b/mail/em-composer-utils.c
@@ -503,9 +503,7 @@ composer_send_completed (EMailSession *session,
 
 	e_mail_session_send_to_finish (session, result, &error);
 
-	/* Ignore cancellations. */
-	if (g_error_matches (error, G_IO_ERROR, G_IO_ERROR_CANCELLED)) {
-		e_activity_set_state (context->activity, E_ACTIVITY_CANCELLED);
+	if (e_activity_handle_cancellation (context->activity, error)) {
 		g_error_free (error);
 		goto exit;
 	}
@@ -606,8 +604,7 @@ composer_save_to_drafts_complete (EMailSession *session,
 
 	e_mail_session_handle_draft_headers_finish (session, result, &error);
 
-	if (g_error_matches (error, G_IO_ERROR, G_IO_ERROR_CANCELLED)) {
-		e_activity_set_state (context->activity, E_ACTIVITY_CANCELLED);
+	if (e_activity_handle_cancellation (context->activity, error)) {
 		g_error_free (error);
 
 	} else if (error != NULL) {
@@ -645,15 +642,13 @@ composer_save_to_drafts_cleanup (CamelFolder *drafts_folder,
 	e_mail_folder_append_message_finish (
 		drafts_folder, result, &context->message_uid, &error);
 
-	/* Ignore cancellations. */
-	if (g_error_matches (error, G_IO_ERROR, G_IO_ERROR_CANCELLED)) {
+	if (e_activity_handle_cancellation (context->activity, error)) {
 		g_warn_if_fail (context->message_uid == NULL);
 		async_context_free (context);
 		g_error_free (error);
 		return;
-	}
 
-	if (error != NULL) {
+	} else if (error != NULL) {
 		g_warn_if_fail (context->message_uid == NULL);
 		e_alert_submit (
 			alert_sink,
@@ -715,15 +710,13 @@ composer_save_to_drafts_got_folder (EMailSession *session,
 	drafts_folder = e_mail_session_uri_to_folder_finish (
 		session, result, &error);
 
-	/* Ignore cancellations. */
-	if (g_error_matches (error, G_IO_ERROR, G_IO_ERROR_CANCELLED)) {
+	if (e_activity_handle_cancellation (context->activity, error)) {
 		g_warn_if_fail (drafts_folder == NULL);
 		async_context_free (context);
 		g_error_free (error);
 		return;
-	}
 
-	if (error != NULL) {
+	} else if (error != NULL) {
 		gint response;
 
 		g_warn_if_fail (drafts_folder == NULL);
@@ -807,14 +800,11 @@ composer_save_to_outbox_completed (CamelFolder *outbox_folder,
 	e_mail_folder_append_message_finish (
 		outbox_folder, result, NULL, &error);
 
-	/* Ignore cancellations. */
-	if (g_error_matches (error, G_IO_ERROR, G_IO_ERROR_CANCELLED)) {
-		e_activity_set_state (context->activity, E_ACTIVITY_CANCELLED);
+	if (e_activity_handle_cancellation (context->activity, error)) {
 		g_error_free (error);
 		goto exit;
-	}
 
-	if (error != NULL) {
+	} else if (error != NULL) {
 		e_alert_submit (
 			alert_sink,
 			"mail-composer:append-to-outbox-error",
@@ -1265,10 +1255,8 @@ edit_messages_cb (CamelFolder *folder,
 	hash_table = e_mail_folder_get_multiple_messages_finish (
 		folder, result, &error);
 
-	/* Ignore cancellations. */
-	if (g_error_matches (error, G_IO_ERROR, G_IO_ERROR_CANCELLED)) {
+	if (e_activity_handle_cancellation (context->activity, error)) {
 		g_warn_if_fail (hash_table == NULL);
-		e_activity_set_state (context->activity, E_ACTIVITY_CANCELLED);
 		async_context_free (context);
 		g_error_free (error);
 		return;
@@ -1466,11 +1454,9 @@ forward_attached_cb (CamelFolder *folder,
 	part = e_mail_folder_build_attachment_finish (
 		folder, result, &subject, &error);
 
-	/* Ignore cancellations. */
-	if (g_error_matches (error, G_IO_ERROR, G_IO_ERROR_CANCELLED)) {
+	if (e_activity_handle_cancellation (context->activity, error)) {
 		g_warn_if_fail (part == NULL);
 		g_warn_if_fail (subject == NULL);
-		e_activity_set_state (context->activity, E_ACTIVITY_CANCELLED);
 		async_context_free (context);
 		g_error_free (error);
 		return;
@@ -1629,10 +1615,8 @@ forward_got_messages_cb (CamelFolder *folder,
 	hash_table = e_mail_folder_get_multiple_messages_finish (
 		folder, result, &error);
 
-	/* Ignore cancellations. */
-	if (g_error_matches (error, G_IO_ERROR, G_IO_ERROR_CANCELLED)) {
+	if (e_activity_handle_cancellation (context->activity, error)) {
 		g_warn_if_fail (hash_table == NULL);
-		e_activity_set_state (context->activity, E_ACTIVITY_CANCELLED);
 		async_context_free (context);
 		g_error_free (error);
 		return;
diff --git a/mail/mail-mt.c b/mail/mail-mt.c
index a65f6e3..53ff132 100644
--- a/mail/mail-mt.c
+++ b/mail/mail-mt.c
@@ -208,10 +208,8 @@ mail_msg_check_error (gpointer msg)
 	checkmem (m->priv);
 #endif
 
-	if (g_error_matches (m->error, G_IO_ERROR, G_IO_ERROR_CANCELLED)) {
-		e_activity_set_state (m->activity, E_ACTIVITY_CANCELLED);
+	if (e_activity_handle_cancellation (m->activity, m->error))
 		return;
-	}
 
 	e_activity_set_state (m->activity, E_ACTIVITY_COMPLETED);
 
diff --git a/modules/mail/e-mail-shell-view-actions.c b/modules/mail/e-mail-shell-view-actions.c
index f311246..80c8a92 100644
--- a/modules/mail/e-mail-shell-view-actions.c
+++ b/modules/mail/e-mail-shell-view-actions.c
@@ -33,8 +33,7 @@ mail_folder_unsubscribe_done_cb (EMailSession *session,
 
 	e_mail_session_unsubscribe_folder_finish (session, result, &error);
 
-	if (g_error_matches (error, G_IO_ERROR, G_IO_ERROR_CANCELLED)) {
-		e_activity_set_state (activity, E_ACTIVITY_CANCELLED);
+	if (e_activity_handle_cancellation (activity, error)) {
 		g_error_free (error);
 
 	} else if (error != NULL) {
diff --git a/modules/mail/e-mail-shell-view-private.c b/modules/mail/e-mail-shell-view-private.c
index c5f555d..d99b643 100644
--- a/modules/mail/e-mail-shell-view-private.c
+++ b/modules/mail/e-mail-shell-view-private.c
@@ -62,8 +62,7 @@ mail_shell_view_got_folder_cb (CamelStore *store,
 
 	folder = camel_store_get_folder_finish (store, result, &error);
 
-	/* Ignore cancellations. */
-	if (g_error_matches (error, G_IO_ERROR, G_IO_ERROR_CANCELLED)) {
+	if (e_activity_handle_cancellation (context->activity, error)) {
 		g_warn_if_fail (folder == NULL);
 		async_context_free (context);
 		g_error_free (error);



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