From 444d56e917d8781e145aeac96576811fdaa17809 Mon Sep 17 00:00:00 2001 From: Jose Dapena Paz Date: Thu, 24 Jan 2008 13:17:09 +0000 Subject: [PATCH 1/1] * src/widgets/modest-folder-view.c: * Encapsulate the tny_folder_sync operation we do in finalize in a mail operation. This way this can be async, but protected by a mail operation. * src/modest-mail-operation.[ch]: * New mail operation that wraps a tny_folder_sync_async operation. pmo-trunk-r4085 --- src/modest-mail-operation.c | 38 ++++++++++++++++++++++++++++++++++++++ src/modest-mail-operation.h | 13 +++++++++++++ src/widgets/modest-folder-view.c | 10 ++++++++-- 3 files changed, 59 insertions(+), 2 deletions(-) diff --git a/src/modest-mail-operation.c b/src/modest-mail-operation.c index 790d162..de3ab30 100644 --- a/src/modest-mail-operation.c +++ b/src/modest-mail-operation.c @@ -2902,6 +2902,43 @@ modest_mail_operation_run_queue (ModestMailOperation *self, } static void +sync_folder_finish_callback (TnyFolder *self, gboolean cancelled, GError *err, ModestMailOperation *mail_op) +{ + ModestMailOperationPrivate *priv; + + priv = MODEST_MAIL_OPERATION_GET_PRIVATE (mail_op); + if (err != NULL) { + g_set_error (&(priv->error), MODEST_MAIL_OPERATION_ERROR, + MODEST_MAIL_OPERATION_ERROR_OPERATION_CANCELED, + err->message); + priv->status = MODEST_MAIL_OPERATION_STATUS_FAILED; + } else { + priv->status = MODEST_MAIL_OPERATION_STATUS_SUCCESS; + } + modest_mail_operation_notify_end (mail_op); + g_object_unref (mail_op); +} + +void +modest_mail_operation_sync_folder (ModestMailOperation *self, + TnyFolder *folder, gboolean expunge) +{ + ModestMailOperationPrivate *priv; + + g_return_if_fail (MODEST_IS_MAIL_OPERATION (self)); + g_return_if_fail (TNY_IS_FOLDER (folder)); + priv = MODEST_MAIL_OPERATION_GET_PRIVATE (self); + + priv->status = MODEST_MAIL_OPERATION_STATUS_IN_PROGRESS; + priv->account = TNY_ACCOUNT (tny_folder_get_account (folder)); + priv->op_type = MODEST_MAIL_OPERATION_TYPE_SYNC_FOLDER; + + modest_mail_operation_notify_start (self); + g_object_ref (self); + tny_folder_sync_async (folder, expunge, (TnyFolderCallback) sync_folder_finish_callback, NULL, self); +} + +static void modest_mail_operation_notify_start (ModestMailOperation *self) { ModestMailOperationPrivate *priv = NULL; @@ -2998,6 +3035,7 @@ modest_mail_operation_to_string (ModestMailOperation *self) case MODEST_MAIL_OPERATION_TYPE_DELETE: type= "DELETE"; break; case MODEST_MAIL_OPERATION_TYPE_INFO: type= "INFO"; break; case MODEST_MAIL_OPERATION_TYPE_RUN_QUEUE: type= "RUN-QUEUE"; break; + case MODEST_MAIL_OPERATION_TYPE_SYNC_FOLDER: type= "SYNC-FOLDER"; break; case MODEST_MAIL_OPERATION_TYPE_UNKNOWN: type= "UNKNOWN"; break; default: type = "UNEXPECTED"; break; } diff --git a/src/modest-mail-operation.h b/src/modest-mail-operation.h index 41ef7ab..abbdc9a 100644 --- a/src/modest-mail-operation.h +++ b/src/modest-mail-operation.h @@ -76,6 +76,7 @@ typedef enum { MODEST_MAIL_OPERATION_TYPE_DELETE, MODEST_MAIL_OPERATION_TYPE_INFO, MODEST_MAIL_OPERATION_TYPE_RUN_QUEUE, + MODEST_MAIL_OPERATION_TYPE_SYNC_FOLDER, MODEST_MAIL_OPERATION_TYPE_UNKNOWN, } ModestMailOperationTypeOperation; @@ -646,6 +647,18 @@ void modest_mail_operation_get_msgs_full (ModestMailOperation *self, void modest_mail_operation_run_queue (ModestMailOperation *self, ModestTnySendQueue *queue); +/** + * modest_mail_operation_sync_folder: + * @self: a #ModestMailOperation + * @folder: a #TnyFolder + * @expunge: a #gboolean + * + * mail operation wrapper around tny_folder_sync () method, to keep modest + * running while we do that sync operation. + */ +void modest_mail_operation_sync_folder (ModestMailOperation *self, + TnyFolder *folder, gboolean expunge); + /* Functions to control mail operations */ /** * modest_mail_operation_get_task_done: diff --git a/src/widgets/modest-folder-view.c b/src/widgets/modest-folder-view.c index 69910d8..a753113 100644 --- a/src/widgets/modest-folder-view.c +++ b/src/widgets/modest-folder-view.c @@ -1125,8 +1125,14 @@ modest_folder_view_finalize (GObject *obj) } if (priv->cur_folder_store) { - if (TNY_IS_FOLDER(priv->cur_folder_store)) - tny_folder_sync (TNY_FOLDER(priv->cur_folder_store), FALSE, NULL); + if (TNY_IS_FOLDER(priv->cur_folder_store)) { + ModestMailOperation *mail_op; + + mail_op = modest_mail_operation_new (NULL); + modest_mail_operation_queue_add (modest_runtime_get_mail_operation_queue (), + mail_op); + modest_mail_operation_sync_folder (mail_op, TNY_FOLDER (priv->cur_folder_store), FALSE); + } g_object_unref (priv->cur_folder_store); priv->cur_folder_store = NULL; -- 1.7.9.5