[evolution] EMFolderProperties: Fetch quota information asynchronously.



commit a37a66eed072e5f29390e6581739e0515b2bf402
Author: Matthew Barnes <mbarnes redhat com>
Date:   Sat May 14 14:53:53 2011 -0400

    EMFolderProperties: Fetch quota information asynchronously.

 mail/em-folder-properties.c |   63 +++++++++++++++++++++++++++++++++++-------
 1 files changed, 52 insertions(+), 11 deletions(-)
---
diff --git a/mail/em-folder-properties.c b/mail/em-folder-properties.c
index 60ac872..d61212f 100644
--- a/mail/em-folder-properties.c
+++ b/mail/em-folder-properties.c
@@ -353,24 +353,30 @@ emfp_dialog_run (AsyncContext *context)
 }
 
 static void
-emfp_dialog_got_folder (CamelStore *store,
-                        GAsyncResult *result,
-                        AsyncContext *context)
+emfp_dialog_got_quota_info (CamelFolder *folder,
+                            GAsyncResult *result,
+                            AsyncContext *context)
 {
 	EAlertSink *alert_sink;
 	GError *error = NULL;
 
 	alert_sink = e_activity_get_alert_sink (context->activity);
 
-	context->folder = camel_store_get_folder_finish (
-		store, result, &error);
+	context->quota_info =
+		camel_folder_get_quota_info_finish (folder, result, &error);
 
-	if (e_activity_handle_cancellation (context->activity, error)) {
-		g_warn_if_fail (context->folder == NULL);
+	/* If the folder does not implement quota info, just continue. */
+	if (g_error_matches (error, G_IO_ERROR, G_IO_ERROR_NOT_SUPPORTED)) {
+		g_warn_if_fail (context->quota_info == NULL);
+		g_error_free (error);
+
+	} else if (e_activity_handle_cancellation (context->activity, error)) {
+		g_warn_if_fail (context->quota_info == NULL);
 		async_context_free (context);
 		g_error_free (error);
 		return;
 
+	/* FIXME Add an EAlert for failing to get quota info. */
 	} else if (error != NULL) {
 		g_warn_if_fail (context->folder == NULL);
 		e_alert_submit (
@@ -381,10 +387,7 @@ emfp_dialog_got_folder (CamelStore *store,
 		return;
 	}
 
-	g_return_if_fail (CAMEL_IS_FOLDER (context->folder));
-
-	/* FIXME This blocks, but Camel does not offer an async function. */
-	context->quota_info = camel_folder_get_quota_info (context->folder);
+	/* Quota info may still be NULL here if not supported. */
 
 	/* Finalize the activity here so we don't leave a message
 	 * in the task bar while the properties window is shown. */
@@ -397,6 +400,44 @@ emfp_dialog_got_folder (CamelStore *store,
 	async_context_free (context);
 }
 
+static void
+emfp_dialog_got_folder (CamelStore *store,
+                        GAsyncResult *result,
+                        AsyncContext *context)
+{
+	EAlertSink *alert_sink;
+	GCancellable *cancellable;
+	GError *error = NULL;
+
+	alert_sink = e_activity_get_alert_sink (context->activity);
+	cancellable = e_activity_get_cancellable (context->activity);
+
+	context->folder = camel_store_get_folder_finish (
+		store, result, &error);
+
+	if (e_activity_handle_cancellation (context->activity, error)) {
+		g_warn_if_fail (context->folder == NULL);
+		async_context_free (context);
+		g_error_free (error);
+		return;
+
+	} else if (error != NULL) {
+		g_warn_if_fail (context->folder == NULL);
+		e_alert_submit (
+			alert_sink, "mail:folder-open",
+			error->message, NULL);
+		async_context_free (context);
+		g_error_free (error);
+		return;
+	}
+
+	g_return_if_fail (CAMEL_IS_FOLDER (context->folder));
+
+	camel_folder_get_quota_info (
+		context->folder, G_PRIORITY_DEFAULT, cancellable,
+		(GAsyncReadyCallback) emfp_dialog_got_quota_info, context);
+}
+
 /**
  * em_folder_properties_show:
  * @shell_view: an #EShellView



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