new API proposal find_msg_async
- From: Sergio Villar Senin <svillar igalia com>
- To: tinymail-devel-list <tinymail-devel-list gnome org>
- Subject: new API proposal find_msg_async
- Date: Mon, 21 Apr 2008 19:31:32 +0200
Hi,
this is a proposal for a new API, tny_folder_find_msg_async which will
make the sync version obsolete. I reused the sync version implementation
for this async version. Most of methods could be shared with
tny_camel_folder_get_msg_async but I decided not to use the same as long
as it's not done in any other place in tinymail.
What I actually reused was the GetMsgInfo structure, so maybe we could
decide to share some of the _destroy and _callback methods with get_msg
Opinions.
Br
Index: libtinymail-camel/tny-camel-folder.c
===================================================================
--- libtinymail-camel/tny-camel-folder.c (revision 3607)
+++ libtinymail-camel/tny-camel-folder.c (working copy)
@@ -2366,6 +2366,7 @@
TnySessionCamel *session;
TnyIdleStopper *stopper;
gboolean cancelled;
+ gchar *url_string;
} GetMsgInfo;
@@ -2597,8 +2598,183 @@
return;
}
+static void
+tny_camel_folder_find_msg_async_destroyer (gpointer thr_user_data)
+{
+ GetMsgInfo *info = (GetMsgInfo *) thr_user_data;
+ TnyCamelFolderPriv *priv = TNY_CAMEL_FOLDER_GET_PRIVATE (info->self);
+ /* thread reference */
+ _tny_camel_folder_unreason (priv);
+ g_object_unref (info->self);
+ if (info->err)
+ g_error_free (info->err);
+
+ tny_idle_stopper_destroy (info->stopper);
+ info->stopper = NULL;
+
+ /**/
+
+ camel_object_unref (info->session);
+
+ return;
+}
+
+static gboolean
+tny_camel_folder_find_msg_async_callback (gpointer thr_user_data)
+{
+ GetMsgInfo *info = (GetMsgInfo *) thr_user_data;
+ TnyFolderChange *change;
+
+ if (info->msg)
+ {
+ change = tny_folder_change_new (info->self);
+ tny_folder_change_set_check_duplicates (change, TRUE);
+ tny_folder_change_set_received_msg (change, info->msg);
+ notify_folder_observers_about (info->self, change, info->session);
+ g_object_unref (change);
+ }
+
+ if (info->callback) {
+ tny_lockable_lock (info->session->priv->ui_lock);
+ info->callback (info->self, info->cancelled, info->msg, info->err, info->user_data);
+ tny_lockable_unlock (info->session->priv->ui_lock);
+ }
+
+ if (info->msg)
+ g_object_unref (info->msg);
+
+ tny_idle_stopper_stop (info->stopper);
+
+ return FALSE;
+}
+
+
+static void
+tny_camel_folder_find_msg_async_status (struct _CamelOperation *op, const char *what, int sofar, int oftotal, void *thr_user_data)
+{
+ GetMsgInfo *oinfo = thr_user_data;
+ TnyProgressInfo *info = NULL;
+
+ info = tny_progress_info_new (G_OBJECT (oinfo->self), oinfo->status_callback,
+ TNY_FOLDER_STATUS, TNY_FOLDER_STATUS_CODE_FIND_MSG, what, sofar,
+ oftotal, oinfo->stopper, oinfo->session->priv->ui_lock, oinfo->user_data);
+
+ g_idle_add_full (TNY_PRIORITY_LOWER_THAN_GTK_REDRAWS,
+ tny_progress_info_idle_func, info,
+ tny_progress_info_destroy);
+
+ return;
+}
+
+static void
+tny_camel_folder_find_msg_async_cancelled_destroyer (gpointer thr_user_data)
+{
+ GetMsgInfo *info = (GetMsgInfo *) thr_user_data;
+ TnyCamelFolderPriv *priv = TNY_CAMEL_FOLDER_GET_PRIVATE (info->self);
+
+ /* thread reference */
+ _tny_camel_folder_unreason (priv);
+ g_object_unref (info->self);
+
+ if (info->err)
+ g_error_free (info->err);
+
+ tny_idle_stopper_destroy (info->stopper);
+ info->stopper = NULL;
+
+ /**/
+
+ camel_object_unref (info->session);
+
+ return;
+}
+
+static gboolean
+tny_camel_folder_find_msg_async_cancelled_callback (gpointer thr_user_data)
+{
+ GetMsgInfo *info = (GetMsgInfo *) thr_user_data;
+ if (info->callback) {
+ tny_lockable_lock (info->session->priv->ui_lock);
+ info->callback (info->self, TRUE, NULL, info->err, info->user_data);
+ tny_lockable_unlock (info->session->priv->ui_lock);
+ }
+ return FALSE;
+}
+
+static gpointer
+tny_camel_folder_find_msg_async_thread (gpointer thr_user_data)
+{
+ GetMsgInfo *info = (GetMsgInfo *) thr_user_data;
+ TnyCamelFolderPriv *priv = TNY_CAMEL_FOLDER_GET_PRIVATE (info->self);
+ CamelOperation *cancel;
+
+ info->msg = tny_folder_find_msg (info->self, info->url_string, &info->err);
+
+ info->cancelled = FALSE;
+ if (info->err != NULL) {
+ if (camel_strstrcase (info->err->message, "cancel") != NULL)
+ info->cancelled = TRUE;
+ }
+
+ /* Free the URL */
+ g_free (info->url_string);
+
+ return NULL;
+}
+
+static void
+tny_camel_folder_find_msg_async (TnyFolder *self, const gchar *url_string, TnyGetMsgCallback callback, TnyStatusCallback status_callback, gpointer user_data)
+{
+ TNY_CAMEL_FOLDER_GET_CLASS (self)->find_msg_async(self, url_string, callback, status_callback, user_data);
+ return;
+}
+
+
+static void
+tny_camel_folder_find_msg_async_default (TnyFolder *self, const gchar *url_string, TnyGetMsgCallback callback, TnyStatusCallback status_callback, gpointer user_data)
+{
+ GetMsgInfo *info;
+ TnyCamelFolderPriv *priv = TNY_CAMEL_FOLDER_GET_PRIVATE (self);
+ TnyCamelQueue *queue;
+
+ /* Idle info for the callbacks */
+ info = g_slice_new (GetMsgInfo);
+ info->cancelled = FALSE;
+ info->session = TNY_FOLDER_PRIV_GET_SESSION (priv);
+ camel_object_ref (info->session);
+ info->self = self;
+ info->url_string = g_strdup (url_string);
+ info->callback = callback;
+ info->status_callback = status_callback;
+ info->user_data = user_data;
+ info->err = NULL;
+
+ info->stopper = tny_idle_stopper_new();
+
+ /* thread reference */
+ _tny_camel_folder_reason (priv);
+ g_object_ref (info->self);
+
+ if (!TNY_IS_CAMEL_POP_FOLDER (self))
+ queue = TNY_FOLDER_PRIV_GET_MSG_QUEUE (priv);
+ else
+ queue = TNY_FOLDER_PRIV_GET_QUEUE (priv);
+
+ _tny_camel_queue_launch (queue,
+ tny_camel_folder_find_msg_async_thread,
+ tny_camel_folder_find_msg_async_callback,
+ tny_camel_folder_find_msg_async_destroyer,
+ tny_camel_folder_find_msg_async_cancelled_callback,
+ tny_camel_folder_find_msg_async_cancelled_destroyer,
+ &info->cancelled,
+ info, sizeof (GetMsgInfo),
+ __FUNCTION__);
+
+ return;
+}
+
static TnyMsgReceiveStrategy*
tny_camel_folder_get_msg_receive_strategy (TnyFolder *self)
{
@@ -5886,6 +6062,7 @@
klass->get_msg= tny_camel_folder_get_msg;
klass->find_msg= tny_camel_folder_find_msg;
klass->get_msg_async= tny_camel_folder_get_msg_async;
+ klass->find_msg_async= tny_camel_folder_find_msg_async;
klass->get_id= tny_camel_folder_get_id;
klass->get_name= tny_camel_folder_get_name;
klass->get_folder_type= tny_camel_folder_get_folder_type;
@@ -5952,6 +6129,7 @@
class->get_msg= tny_camel_folder_get_msg_default;
class->find_msg= tny_camel_folder_find_msg_default;
class->get_msg_async= tny_camel_folder_get_msg_async_default;
+ class->find_msg_async= tny_camel_folder_find_msg_async_default;
class->get_id= tny_camel_folder_get_id_default;
class->get_name= tny_camel_folder_get_name_default;
class->get_folder_type= tny_camel_folder_get_folder_type_default;
Index: libtinymail-camel/tny-camel-folder.h
===================================================================
--- libtinymail-camel/tny-camel-folder.h (revision 3607)
+++ libtinymail-camel/tny-camel-folder.h (working copy)
@@ -67,6 +67,7 @@
TnyMsg* (*get_msg) (TnyFolder *self, TnyHeader *header, GError **err);
TnyMsg* (*find_msg) (TnyFolder *self, const gchar *url_string, GError **err);
void (*get_msg_async) (TnyFolder *self, TnyHeader *header, TnyGetMsgCallback callback, TnyStatusCallback status_callback, gpointer user_data);
+ void (*find_msg_async) (TnyFolder *self, const gchar *url_string, TnyGetMsgCallback callback, TnyStatusCallback status_callback, gpointer user_data);
void (*get_headers) (TnyFolder *self, TnyList *headers, gboolean refresh, GError **err);
void (*get_headers_async) (TnyFolder *self, TnyList *headers, gboolean refresh, TnyGetHeadersCallback callback, TnyStatusCallback status_callback, gpointer user_data);
const gchar* (*get_name) (TnyFolder *self);
Index: libtinymail/tny-status.h
===================================================================
--- libtinymail/tny-status.h (revision 3607)
+++ libtinymail/tny-status.h (working copy)
@@ -49,7 +49,8 @@
TNY_FOLDER_STATUS_CODE_XFER_MSGS = 4,
TNY_FOLDER_STATUS_CODE_COPY_FOLDER = 5,
TNY_GET_SUPPORTED_SECURE_AUTH_STATUS_GET_SECURE_AUTH = 6,
- TNY_FOLDER_STATUS_CODE_SYNC = 7
+ TNY_FOLDER_STATUS_CODE_SYNC = 7,
+ TNY_FOLDER_STATUS_CODE_FIND_MSG = 8,
};
typedef enum _TnyStatusCode TnyStatusCode;
Index: libtinymail/tny-folder.c
===================================================================
--- libtinymail/tny-folder.c (revision 3607)
+++ libtinymail/tny-folder.c (working copy)
@@ -1288,6 +1288,22 @@
return;
}
+void
+tny_folder_find_msg_async (TnyFolder *self, const gchar *url_string, TnyGetMsgCallback callback, TnyStatusCallback status_callback, gpointer user_data)
+{
+#ifdef DBC /* require */
+ g_assert (TNY_IS_FOLDER (self));
+ g_assert (url_string);
+ g_assert (strlen (url_string) > 0);
+ g_assert (strstr (url_string, "://") != NULL);
+ g_assert (TNY_FOLDER_GET_IFACE (self)->get_msg_async!= NULL);
+#endif
+
+ TNY_FOLDER_GET_IFACE (self)->find_msg_async(self, url_string, callback, status_callback, user_data);
+
+ return;
+}
+
/**
* tny_folder_get_headers:
* @self: a #TnyFolder
Index: libtinymail/tny-folder.h
===================================================================
--- libtinymail/tny-folder.h (revision 3607)
+++ libtinymail/tny-folder.h (working copy)
@@ -109,6 +109,7 @@
TnyMsg* (*get_msg) (TnyFolder *self, TnyHeader *header, GError **err);
TnyMsg* (*find_msg) (TnyFolder *self, const gchar *url_string, GError **err);
void (*get_msg_async) (TnyFolder *self, TnyHeader *header, TnyGetMsgCallback callback, TnyStatusCallback status_callback, gpointer user_data);
+ void (*find_msg_async) (TnyFolder *self, const gchar *url_string, TnyGetMsgCallback callback, TnyStatusCallback status_callback, gpointer user_data);
void (*get_headers) (TnyFolder *self, TnyList *headers, gboolean refresh, GError **err);
void (*get_headers_async) (TnyFolder *self, TnyList *headers, gboolean refresh, TnyGetHeadersCallback callback, TnyStatusCallback status_callback, gpointer user_data);
const gchar* (*get_name) (TnyFolder *self);
@@ -149,6 +150,7 @@
void tny_folder_sync_async (TnyFolder *self, gboolean expunge, TnyFolderCallback callback, TnyStatusCallback status_callback, gpointer user_data);
TnyMsg* tny_folder_find_msg (TnyFolder *self, const gchar *url_string, GError **err);
void tny_folder_get_msg_async (TnyFolder *self, TnyHeader *header, TnyGetMsgCallback callback, TnyStatusCallback status_callback, gpointer user_data);
+void tny_folder_find_msg_async (TnyFolder *self, const gchar *url_string, TnyGetMsgCallback callback, TnyStatusCallback status_callback, gpointer user_data);
void tny_folder_get_headers_async (TnyFolder *self, TnyList *headers, gboolean refresh, TnyGetHeadersCallback callback, TnyStatusCallback status_callback, gpointer user_data);
TnyAccount* tny_folder_get_account (TnyFolder *self);
const gchar* tny_folder_get_id (TnyFolder *self);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]