[evolution-data-server] Camel: Fetch quota information asynchronously.



commit ae35e89ff2af3874f5e424ddbb06cf139829ac2c
Author: Matthew Barnes <mbarnes redhat com>
Date:   Sat May 14 14:37:19 2011 -0400

    Camel: Fetch quota information asynchronously.
    
    This bumps the libcamel soname again.
    
    It turns out, camel_folder_get_quota_info() blocks.  So convert it to be
    asynchronous like the other blocking functions, with corresponding class
    methods:
    
      camel_folder_get_quota_info_sync()
      camel_folder_get_quota_info()
      camel_folder_get_quota_finish()
    
    Also update the IMAP provider to make fetching IMAP quotas cancellable.
    This is the only provider that currently implements this method.

 camel/camel-folder.c                        |  227 +++++++++++++++++++++++----
 camel/camel-folder.h                        |   33 ++++-
 camel/providers/imap/camel-imap-folder.c    |   13 +-
 configure.ac                                |    2 +-
 docs/reference/camel/camel-sections.txt     |    4 +-
 docs/reference/camel/tmpl/camel-folder.sgml |   43 ++++-
 6 files changed, 275 insertions(+), 47 deletions(-)
---
diff --git a/camel/camel-folder.c b/camel/camel-folder.c
index 7a26844..0bcddf9 100644
--- a/camel/camel-folder.c
+++ b/camel/camel-folder.c
@@ -76,6 +76,7 @@ struct _AsyncContext {
 
 	/* results */
 	GPtrArray *transferred_uids;
+	CamelFolderQuotaInfo *quota_info;
 };
 
 struct _CamelFolderChangeInfoPrivate {
@@ -144,6 +145,9 @@ async_context_free (AsyncContext *async_context)
 		g_ptr_array_free (async_context->transferred_uids, TRUE);
 	}
 
+	if (async_context->quota_info != NULL)
+		camel_folder_quota_info_free (async_context->quota_info);
+
 	g_free (async_context->message_uid);
 
 	g_slice_free (AsyncContext, async_context);
@@ -829,12 +833,6 @@ folder_is_frozen (CamelFolder *folder)
 	return folder->priv->frozen != 0;
 }
 
-static CamelFolderQuotaInfo *
-folder_get_quota_info (CamelFolder *folder)
-{
-	return NULL;
-}
-
 static gboolean
 folder_refresh_info_sync (CamelFolder *folder,
                           GCancellable *cancellable,
@@ -1102,6 +1100,89 @@ folder_get_message_finish (CamelFolder *folder,
 }
 
 static void
+folder_get_quota_info_thread (GSimpleAsyncResult *simple,
+                              GObject *object,
+                              GCancellable *cancellable)
+{
+	AsyncContext *async_context;
+	GError *error = NULL;
+
+	async_context = g_simple_async_result_get_op_res_gpointer (simple);
+
+	async_context->quota_info = camel_folder_get_quota_info_sync (
+		CAMEL_FOLDER (object), cancellable, &error);
+
+	if (error != NULL) {
+		g_simple_async_result_set_from_error (simple, error);
+		g_error_free (error);
+	}
+}
+
+static CamelFolderQuotaInfo *
+folder_get_quota_info_sync (CamelFolder *folder,
+                            GCancellable *cancellable,
+                            GError **error)
+{
+	g_set_error (
+		error, G_IO_ERROR, G_IO_ERROR_NOT_SUPPORTED,
+		_("Quota information not supported for folder '%s'"),
+		camel_folder_get_display_name (folder));
+
+	return NULL;
+}
+
+static void
+folder_get_quota_info (CamelFolder *folder,
+                       gint io_priority,
+                       GCancellable *cancellable,
+                       GAsyncReadyCallback callback,
+                       gpointer user_data)
+{
+	GSimpleAsyncResult *simple;
+	AsyncContext *async_context;
+
+	async_context = g_slice_new0 (AsyncContext);
+
+	simple = g_simple_async_result_new (
+		G_OBJECT (folder), callback,
+		user_data, folder_get_quota_info);
+
+	g_simple_async_result_set_op_res_gpointer (
+		simple, async_context, (GDestroyNotify) async_context_free);
+
+	g_simple_async_result_run_in_thread (
+		simple, folder_get_quota_info_thread,
+		io_priority, cancellable);
+
+	g_object_unref (simple);
+}
+
+static CamelFolderQuotaInfo *
+folder_get_quota_info_finish (CamelFolder *folder,
+                              GAsyncResult *result,
+                              GError **error)
+{
+	GSimpleAsyncResult *simple;
+	AsyncContext *async_context;
+	CamelFolderQuotaInfo *quota_info;
+
+	g_return_val_if_fail (
+		g_simple_async_result_is_valid (
+		result, G_OBJECT (folder), folder_get_quota_info), NULL);
+
+	simple = G_SIMPLE_ASYNC_RESULT (result);
+	async_context = g_simple_async_result_get_op_res_gpointer (simple);
+
+	if (g_simple_async_result_propagate_error (simple, error))
+		return NULL;
+
+	quota_info = async_context->quota_info;
+	async_context->quota_info = NULL;
+
+	return quota_info;
+}
+
+static void
 folder_refresh_info_thread (GSimpleAsyncResult *simple,
                             GObject *object,
                             GCancellable *cancellable)
@@ -1495,7 +1576,7 @@ camel_folder_class_init (CamelFolderClass *class)
 	class->freeze = folder_freeze;
 	class->thaw = folder_thaw;
 	class->is_frozen = folder_is_frozen;
-	class->get_quota_info = folder_get_quota_info;
+	class->get_quota_info_sync = folder_get_quota_info_sync;
 	class->refresh_info_sync = folder_refresh_info_sync;
 	class->transfer_messages_to_sync = folder_transfer_messages_to_sync;
 	class->changed = folder_changed;
@@ -1506,6 +1587,8 @@ camel_folder_class_init (CamelFolderClass *class)
 	class->expunge_finish = folder_expunge_finish;
 	class->get_message = folder_get_message;
 	class->get_message_finish = folder_get_message_finish;
+	class->get_quota_info = folder_get_quota_info;
+	class->get_quota_info_finish = folder_get_quota_info_finish;
 	class->refresh_info = folder_refresh_info;
 	class->refresh_info_finish = folder_refresh_info_finish;
 	class->synchronize = folder_synchronize;
@@ -2704,27 +2787,6 @@ camel_folder_get_frozen_count (CamelFolder *folder)
 }
 
 /**
- * camel_folder_get_quota_info:
- * @folder: a #CamelFolder
- *
- * Returns: list of known quota(s) for the folder.
- *
- * Since: 2.24
- **/
-CamelFolderQuotaInfo *
-camel_folder_get_quota_info (CamelFolder *folder)
-{
-	CamelFolderClass *class;
-
-	g_return_val_if_fail (CAMEL_IS_FOLDER (folder), NULL);
-
-	class = CAMEL_FOLDER_GET_CLASS (folder);
-	g_return_val_if_fail (class->get_quota_info != NULL, NULL);
-
-	return class->get_quota_info (folder);
-}
-
-/**
  * camel_folder_quota_info_new:
  * @name: Name of the quota.
  * @used: Current usage of the quota.
@@ -3265,6 +3327,115 @@ camel_folder_get_message_finish (CamelFolder *folder,
 }
 
 /**
+ * camel_folder_get_quota_info_sync:
+ * @folder: a #CamelFolder
+ * @cancellable: optional #GCancellable object, or %NULL
+ * @error: return location for a #GError, or %NULL
+ *
+ * Gets a list of known quotas for @folder.  Free the returned
+ * #CamelFolderQuotaInfo struct with camel_folder_quota_info_free().
+ *
+ * If quotas are not supported for @folder, the function returns %NULL
+ * and sets @error to #G_IO_ERROR_NOT_SUPPORTED.
+ *
+ * Returns: a #CamelFolderQuotaInfo, or %NULL
+ *
+ * Since: 3.2
+ **/
+CamelFolderQuotaInfo *
+camel_folder_get_quota_info_sync (CamelFolder *folder,
+                                  GCancellable *cancellable,
+                                  GError **error)
+{
+	CamelFolderClass *class;
+	CamelFolderQuotaInfo *quota_info;
+
+	g_return_val_if_fail (CAMEL_IS_FOLDER (folder), NULL);
+
+	class = CAMEL_FOLDER_GET_CLASS (folder);
+	g_return_val_if_fail (class->get_quota_info_sync != NULL, NULL);
+
+	camel_operation_push_message (
+		cancellable, _("Retrieving quota information for '%s'"),
+		camel_folder_get_display_name (folder));
+
+	quota_info = class->get_quota_info_sync (folder, cancellable, error);
+	CAMEL_CHECK_GERROR (
+		folder, get_quota_info_sync, quota_info != NULL, error);
+
+	camel_operation_pop_message (cancellable);
+
+	return quota_info;
+}
+
+/**
+ * camel_folder_get_quota_info:
+ * @folder: a #CamelFolder
+ * @io_priority: the I/O priority of the request
+ * @cancellable: optional #GCancellable object, or %NULL
+ * @callback: a #GAsyncReadyCallback to call when the request is satisfied
+ * @user_data: data to pass to the callback function
+ *
+ * Asynchronously gets a list of known quotas for @folder.
+ *
+ * When the operation is finished, @callback will be called.  You can
+ * then call camel_folder_get_quota_info_finish() to get the result of
+ * the operation.
+ *
+ * Since: 3.2
+ **/
+void
+camel_folder_get_quota_info (CamelFolder *folder,
+                             gint io_priority,
+                             GCancellable *cancellable,
+                             GAsyncReadyCallback callback,
+                             gpointer user_data)
+{
+	CamelFolderClass *class;
+
+	g_return_if_fail (CAMEL_IS_FOLDER (folder));
+
+	class = CAMEL_FOLDER_GET_CLASS (folder);
+	g_return_if_fail (class->get_quota_info != NULL);
+
+	class->get_quota_info (
+		folder, io_priority,
+		cancellable, callback, user_data);
+}
+
+/**
+ * camel_folder_get_quota_info_finish:
+ * @folder: a #CamelFolder
+ * @result: a #GAsyncResult
+ * @error: return location for a #GError or %NULL
+ *
+ * Finishes the operation started with camel_folder_get_quota_info().
+ * Free the returned #CamelFolderQuotaInfo struct with
+ * camel_folder_quota_info_free().
+ *
+ * If quotas are not supported for @folder, the function returns %NULL
+ * and sets @error to #G_IO_ERROR_NOT_SUPPORTED.
+ *
+ * Returns: a #CamelFolderQuotaInfo, or %NULL
+ *
+ * Since: 3.2
+ **/
+CamelFolderQuotaInfo *
+camel_folder_get_quota_info_finish (CamelFolder *folder,
+                                    GAsyncResult *result,
+                                    GError **error)
+{
+	CamelFolderClass *class;
+
+	g_return_val_if_fail (CAMEL_IS_FOLDER (folder), NULL);
+
+	class = CAMEL_FOLDER_GET_CLASS (folder);
+	g_return_val_if_fail (class->get_quota_info_finish != NULL, NULL);
+
+	return class->get_quota_info_finish (folder, result, error);
+}
+
+/**
  * camel_folder_refresh_info_sync:
  * @folder: a #CamelFolder
  * @cancellable: optional #GCancellable object, or %NULL
diff --git a/camel/camel-folder.h b/camel/camel-folder.h
index dbc033b..983ba49 100644
--- a/camel/camel-folder.h
+++ b/camel/camel-folder.h
@@ -204,8 +204,6 @@ struct _CamelFolderClass {
 	void		(*freeze)		(CamelFolder *folder);
 	void		(*thaw)			(CamelFolder *folder);
 	gboolean	(*is_frozen)		(CamelFolder *folder);
-	CamelFolderQuotaInfo *
-			(*get_quota_info)	(CamelFolder *folder);
 	guint32		(*count_by_expression)	(CamelFolder *folder,
 						 const gchar *expression,
 						 GError **error);
@@ -231,6 +229,10 @@ struct _CamelFolderClass {
 						 const gchar *message_uid,
 						 GCancellable *cancellable,
 						 GError **error);
+	CamelFolderQuotaInfo *
+			(*get_quota_info_sync)	(CamelFolder *folder,
+						 GCancellable *cancellable,
+						 GError **error);
 	gboolean	(*refresh_info_sync)	(CamelFolder *folder,
 						 GCancellable *cancellable,
 						 GError **error);
@@ -283,6 +285,16 @@ struct _CamelFolderClass {
 			(*get_message_finish)	(CamelFolder *folder,
 						 GAsyncResult *result,
 						 GError **error);
+	void		(*get_quota_info)	(CamelFolder *folder,
+						 gint io_priority,
+						 GCancellable *cancellable,
+						 GAsyncReadyCallback callback,
+						 gpointer user_data);
+	CamelFolderQuotaInfo *
+			(*get_quota_info_finish)
+						(CamelFolder *folder,
+						 GAsyncResult *result,
+						 GError **error);
 	void		(*refresh_info)		(CamelFolder *folder,
 						 gint io_priority,
 						 GCancellable *cancellable,
@@ -441,8 +453,6 @@ void		camel_folder_thaw		(CamelFolder *folder);
 gboolean	camel_folder_is_frozen		(CamelFolder *folder);
 gint		camel_folder_get_frozen_count	(CamelFolder *folder);
 CamelFolderQuotaInfo *
-		camel_folder_get_quota_info	(CamelFolder *folder);
-CamelFolderQuotaInfo *
 		camel_folder_quota_info_new	(const gchar *name,
 						 guint64 used,
 						 guint64 total);
@@ -508,6 +518,21 @@ CamelMimeMessage *
 		camel_folder_get_message_finish	(CamelFolder *folder,
 						 GAsyncResult *result,
 						 GError **error);
+CamelFolderQuotaInfo *
+		camel_folder_get_quota_info_sync
+						(CamelFolder *folder,
+						 GCancellable *cancellable,
+						 GError **error);
+void		camel_folder_get_quota_info	(CamelFolder *folder,
+						 gint io_priority,
+						 GCancellable *cancellable,
+						 GAsyncReadyCallback callback,
+						 gpointer user_data);
+CamelFolderQuotaInfo *
+		camel_folder_get_quota_info_finish
+						(CamelFolder *folder,
+						 GAsyncResult *result,
+						 GError **error);
 gboolean	camel_folder_refresh_info_sync	(CamelFolder *folder,
 						 GCancellable *cancellable,
 						 GError **error);
diff --git a/camel/providers/imap/camel-imap-folder.c b/camel/providers/imap/camel-imap-folder.c
index d39049b..d2a035e 100644
--- a/camel/providers/imap/camel-imap-folder.c
+++ b/camel/providers/imap/camel-imap-folder.c
@@ -119,7 +119,10 @@ static GPtrArray *imap_search_by_uids	    (CamelFolder *folder, const gchar *exp
 static void       imap_search_free          (CamelFolder *folder, GPtrArray *uids);
 
 static void imap_thaw (CamelFolder *folder);
-static CamelFolderQuotaInfo *imap_get_quota_info (CamelFolder *folder);
+static CamelFolderQuotaInfo *
+		imap_get_quota_info_sync	(CamelFolder *folder,
+						 GCancellable *cancellable,
+						 GError **error);
 
 static GData *parse_fetch_response (CamelImapFolder *imap_folder, gchar *msg_att);
 
@@ -272,12 +275,12 @@ camel_imap_folder_class_init (CamelImapFolderClass *class)
 	folder_class->search_by_uids = imap_search_by_uids;
 	folder_class->search_free = imap_search_free;
 	folder_class->thaw = imap_thaw;
-	folder_class->get_quota_info = imap_get_quota_info;
 	folder_class->get_uncached_uids = imap_get_uncached_uids;
 	folder_class->get_filename = imap_get_filename;
 	folder_class->append_message_sync = imap_append_online;
 	folder_class->expunge_sync = imap_expunge_sync;
 	folder_class->get_message_sync = imap_get_message_sync;
+	folder_class->get_quota_info_sync = imap_get_quota_info_sync;
 	folder_class->refresh_info_sync = imap_refresh_info_sync;
 	folder_class->synchronize_sync = imap_synchronize_sync;
 	folder_class->synchronize_message_sync = imap_synchronize_message_sync;
@@ -4582,7 +4585,9 @@ parse_fetch_response (CamelImapFolder *imap_folder, gchar *response)
 
 /* it uses connect_lock, thus be sure it doesn't run in main thread */
 static CamelFolderQuotaInfo *
-imap_get_quota_info (CamelFolder *folder)
+imap_get_quota_info_sync (CamelFolder *folder,
+                          GCancellable *cancellable,
+                          GError **error)
 {
 	CamelStore *parent_store;
 	CamelImapStore *imap_store;
@@ -4605,7 +4610,7 @@ imap_get_quota_info (CamelFolder *folder)
 		CamelImapStoreNamespace *ns = camel_imap_store_summary_namespace_find_full (imap_store->summary, full_name);
 		gchar *folder_name = camel_imap_store_summary_path_to_full (imap_store->summary, full_name, ns ? ns->sep : '/');
 
-		response = camel_imap_command (imap_store, NULL, NULL, NULL, "GETQUOTAROOT \"%s\"", folder_name);
+		response = camel_imap_command (imap_store, NULL, cancellable, error, "GETQUOTAROOT \"%s\"", folder_name);
 
 		if (response) {
 			gint i;
diff --git a/configure.ac b/configure.ac
index 1fb23c2..afbd13e 100644
--- a/configure.ac
+++ b/configure.ac
@@ -102,7 +102,7 @@ LIBEGROUPWISE_CURRENT=13
 LIBEGROUPWISE_REVISION=1
 LIBEGROUPWISE_AGE=0
 
-LIBCAMEL_CURRENT=25
+LIBCAMEL_CURRENT=26
 LIBCAMEL_REVISION=0
 LIBCAMEL_AGE=0
 
diff --git a/docs/reference/camel/camel-sections.txt b/docs/reference/camel/camel-sections.txt
index f0b1b05..12ddac4 100644
--- a/docs/reference/camel/camel-sections.txt
+++ b/docs/reference/camel/camel-sections.txt
@@ -468,7 +468,6 @@ camel_folder_freeze
 camel_folder_thaw
 camel_folder_is_frozen
 camel_folder_get_frozen_count
-camel_folder_get_quota_info
 camel_folder_quota_info_new
 camel_folder_quota_info_clone
 camel_folder_quota_info_free
@@ -485,6 +484,9 @@ camel_folder_expunge_finish
 camel_folder_get_message_sync
 camel_folder_get_message
 camel_folder_get_message_finish
+camel_folder_get_quota_info_sync
+camel_folder_get_quota_info
+camel_folder_get_quota_info_finish
 camel_folder_refresh_info_sync
 camel_folder_refresh_info
 camel_folder_refresh_info_finish
diff --git a/docs/reference/camel/tmpl/camel-folder.sgml b/docs/reference/camel/tmpl/camel-folder.sgml
index ad02745..d8b656c 100644
--- a/docs/reference/camel/tmpl/camel-folder.sgml
+++ b/docs/reference/camel/tmpl/camel-folder.sgml
@@ -523,15 +523,6 @@ CamelFolder
 @Returns: 
 
 
-<!-- ##### FUNCTION camel_folder_get_quota_info ##### -->
-<para>
-
-</para>
-
- folder: 
- Returns: 
-
-
 <!-- ##### FUNCTION camel_folder_quota_info_new ##### -->
 <para>
 
@@ -708,6 +699,40 @@ CamelFolder
 @Returns: 
 
 
+<!-- ##### FUNCTION camel_folder_get_quota_info_sync ##### -->
+<para>
+
+</para>
+
+ folder: 
+ cancellable: 
+ error: 
+ Returns: 
+
+
+<!-- ##### FUNCTION camel_folder_get_quota_info ##### -->
+<para>
+
+</para>
+
+ folder: 
+ io_priority: 
+ cancellable: 
+ callback: 
+ user_data: 
+
+
+<!-- ##### FUNCTION camel_folder_get_quota_info_finish ##### -->
+<para>
+
+</para>
+
+ folder: 
+ result: 
+ error: 
+ Returns: 
+
+
 <!-- ##### FUNCTION camel_folder_refresh_info_sync ##### -->
 <para>
 



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