Now we wait for tny send queue wakeup to finish to show properly the
authorJose Dapena Paz <jdapena@igalia.com>
Thu, 26 Feb 2009 17:27:57 +0000 (17:27 +0000)
committerJose Dapena Paz <jdapena@igalia.com>
Thu, 26 Feb 2009 17:27:57 +0000 (17:27 +0000)
mail sent banner.

pmo-trunk-r7708

src/modest-mail-operation.c
src/modest-mail-operation.h
src/modest-tny-send-queue.c
src/modest-tny-send-queue.h

index d1a0e13..01787e0 100644 (file)
@@ -1435,8 +1435,12 @@ update_account_send_mail (UpdateAccountInfo *info)
                        }
                
                        if (num_messages != 0) {
                        }
                
                        if (num_messages != 0) {
+                               ModestMailOperation *mail_op;
                                /* Reenable suspended items */
                                /* Reenable suspended items */
-                               modest_tny_send_queue_wakeup (MODEST_TNY_SEND_QUEUE (send_queue));
+                               mail_op = modest_mail_operation_new (NULL);
+                               modest_mail_operation_queue_add (modest_runtime_get_mail_operation_queue (),
+                                                                mail_op);
+                               modest_mail_operation_queue_wakeup (mail_op, MODEST_TNY_SEND_QUEUE (send_queue));
                                
                                /* Try to send */
                                tny_camel_send_queue_flush (TNY_CAMEL_SEND_QUEUE (send_queue));
                                
                                /* Try to send */
                                tny_camel_send_queue_flush (TNY_CAMEL_SEND_QUEUE (send_queue));
@@ -3419,6 +3423,45 @@ modest_mail_operation_run_queue (ModestMailOperation *self,
 }
 
 static void
 }
 
 static void
+queue_wakeup_callback (ModestTnySendQueue *queue,
+                      gboolean cancelled,
+                      GError *error,
+                      gpointer userdata)
+{
+       ModestMailOperation *mail_op;
+       ModestMailOperationPrivate *priv;
+
+       mail_op = (ModestMailOperation *) userdata;
+       priv = MODEST_MAIL_OPERATION_GET_PRIVATE (mail_op);
+
+       priv->status = MODEST_MAIL_OPERATION_STATUS_SUCCESS;
+
+       /* Notify end */
+       modest_mail_operation_notify_end (mail_op);
+       g_object_unref (mail_op);
+}
+
+void
+modest_mail_operation_queue_wakeup (ModestMailOperation *self,
+                                   ModestTnySendQueue *queue)
+{
+       ModestMailOperationPrivate *priv;
+
+       g_return_if_fail (MODEST_IS_MAIL_OPERATION (self));
+       g_return_if_fail (MODEST_IS_TNY_SEND_QUEUE (queue));
+       priv = MODEST_MAIL_OPERATION_GET_PRIVATE (self);
+
+       priv->status = MODEST_MAIL_OPERATION_STATUS_IN_PROGRESS;
+       priv->account = TNY_ACCOUNT (tny_camel_send_queue_get_transport_account (TNY_CAMEL_SEND_QUEUE (queue)));
+       priv->op_type = MODEST_MAIL_OPERATION_TYPE_QUEUE_WAKEUP;
+
+       g_object_ref (self);
+
+       modest_tny_send_queue_wakeup (queue, queue_wakeup_callback, self);
+       modest_mail_operation_notify_start (self);
+}
+
+static void
 shutdown_callback (ModestTnyAccountStore *account_store, gpointer userdata)
 {
        ModestMailOperation *self = (ModestMailOperation *) userdata;
 shutdown_callback (ModestTnyAccountStore *account_store, gpointer userdata)
 {
        ModestMailOperation *self = (ModestMailOperation *) userdata;
index b45df3d..e57e9d4 100644 (file)
@@ -78,6 +78,7 @@ typedef enum {
        MODEST_MAIL_OPERATION_TYPE_RUN_QUEUE,
        MODEST_MAIL_OPERATION_TYPE_SYNC_FOLDER,
        MODEST_MAIL_OPERATION_TYPE_SHUTDOWN,
        MODEST_MAIL_OPERATION_TYPE_RUN_QUEUE,
        MODEST_MAIL_OPERATION_TYPE_SYNC_FOLDER,
        MODEST_MAIL_OPERATION_TYPE_SHUTDOWN,
+       MODEST_MAIL_OPERATION_TYPE_QUEUE_WAKEUP,
        MODEST_MAIL_OPERATION_TYPE_UNKNOWN,
 } ModestMailOperationTypeOperation;
 
        MODEST_MAIL_OPERATION_TYPE_UNKNOWN,
 } ModestMailOperationTypeOperation;
 
@@ -636,6 +637,18 @@ void          modest_mail_operation_run_queue       (ModestMailOperation *self,
                                                     ModestTnySendQueue *queue);
 
 /**
                                                     ModestTnySendQueue *queue);
 
 /**
+ * modest_mail_operation_queue_wakeup:
+ * @self: a #ModestMailOperation
+ * @queue: a #ModestTnySendQueue
+ *
+ * This mail operation is special. It should be running every time the send queue
+ * wakeup is running and we should notify end of the operation
+ * after wakeup has done msg-sent notification.
+ */
+void          modest_mail_operation_queue_wakeup       (ModestMailOperation *self,
+                                                       ModestTnySendQueue *queue);
+
+/**
  * modest_mail_operation_sync_folder:
  * @self: a #ModestMailOperation
  * @folder: a #TnyFolder
  * modest_mail_operation_sync_folder:
  * @self: a #ModestMailOperation
  * @folder: a #TnyFolder
index 9fec6ce..62c75c6 100644 (file)
@@ -439,6 +439,7 @@ new_queue_get_headers_async_cb (TnyFolder *folder,
        ModestTnySendQueue *self;
        TnyIterator *iter;
        GetHeadersInfo *info;
        ModestTnySendQueue *self;
        TnyIterator *iter;
        GetHeadersInfo *info;
+       ModestMailOperation *wakeup_op;
 
        info = (GetHeadersInfo *) user_data;
        self = MODEST_TNY_SEND_QUEUE (info->queue);
 
        info = (GetHeadersInfo *) user_data;
        self = MODEST_TNY_SEND_QUEUE (info->queue);
@@ -457,7 +458,10 @@ new_queue_get_headers_async_cb (TnyFolder *folder,
        }
 
        /* Reenable suspended items */
        }
 
        /* Reenable suspended items */
-       modest_tny_send_queue_wakeup (self);
+       wakeup_op = modest_mail_operation_new (NULL);
+       modest_mail_operation_queue_add (modest_runtime_get_mail_operation_queue (),
+                                        wakeup_op);
+       modest_mail_operation_queue_wakeup (wakeup_op, MODEST_TNY_SEND_QUEUE (self));
 
        /* Frees */
        g_object_unref (iter);
 
        /* Frees */
        g_object_unref (iter);
@@ -846,6 +850,24 @@ modest_tny_all_send_queues_get_msg_status (TnyHeader *header)
        return status;
 }
 
        return status;
 }
 
+typedef struct _WakeupHelper {
+       ModestTnySendQueue *self;
+       ModestTnySendQueueWakeupFunc callback;
+       gpointer userdata;
+} WakeupHelper;
+
+static void
+wakeup_sync_cb (TnyFolder *self, gboolean cancelled, GError *err, gpointer userdata)
+{
+       WakeupHelper *helper = (WakeupHelper *) userdata;
+
+       if (helper->callback) {
+               helper->callback (helper->self, cancelled, err, helper->userdata);
+       }
+       g_object_unref (helper->self);
+       g_slice_free (WakeupHelper, helper);
+}
+
 static void
 wakeup_get_headers_async_cb (TnyFolder *folder, 
                             gboolean cancelled, 
 static void
 wakeup_get_headers_async_cb (TnyFolder *folder, 
                             gboolean cancelled, 
@@ -856,13 +878,19 @@ wakeup_get_headers_async_cb (TnyFolder *folder,
        ModestTnySendQueue *self;
        ModestTnySendQueuePrivate *priv;
        TnyIterator *iter;
        ModestTnySendQueue *self;
        ModestTnySendQueuePrivate *priv;
        TnyIterator *iter;
+       WakeupHelper *helper = (WakeupHelper *) user_data;
 
 
-       self = MODEST_TNY_SEND_QUEUE (user_data);
+       self = MODEST_TNY_SEND_QUEUE (helper->self);
        priv = MODEST_TNY_SEND_QUEUE_GET_PRIVATE (self);
 
        if (cancelled || err) {
                g_debug ("Failed to wake up the headers of the send queue");
                g_object_unref (self);
        priv = MODEST_TNY_SEND_QUEUE_GET_PRIVATE (self);
 
        if (cancelled || err) {
                g_debug ("Failed to wake up the headers of the send queue");
                g_object_unref (self);
+               if (helper->callback) {
+                       helper->callback (helper->self, cancelled, err, helper->userdata);
+               }
+               g_object_unref (helper->self);
+               g_slice_free (WakeupHelper, helper);
                return;
        }
 
                return;
        }
 
@@ -900,7 +928,7 @@ wakeup_get_headers_async_cb (TnyFolder *folder,
        }
 
        /* Make changes persistent on disk */
        }
 
        /* Make changes persistent on disk */
-       tny_folder_sync_async (priv->outbox, FALSE, NULL, NULL, NULL);
+       tny_folder_sync_async (priv->outbox, FALSE, wakeup_sync_cb, NULL, helper);
 
        /* Frees */
        g_object_unref (iter);
 
        /* Frees */
        g_object_unref (iter);
@@ -908,21 +936,27 @@ wakeup_get_headers_async_cb (TnyFolder *folder,
        g_object_unref (self);
 }
 
        g_object_unref (self);
 }
 
-
 void   
 void   
-modest_tny_send_queue_wakeup (ModestTnySendQueue *self)
+modest_tny_send_queue_wakeup (ModestTnySendQueue *self, 
+                             ModestTnySendQueueWakeupFunc callback,
+                             gpointer userdata)
 {
        ModestTnySendQueuePrivate *priv;
        TnyList *headers;
 {
        ModestTnySendQueuePrivate *priv;
        TnyList *headers;
+       WakeupHelper *helper;
 
        g_return_if_fail (MODEST_IS_TNY_SEND_QUEUE (self));
 
        g_return_if_fail (MODEST_IS_TNY_SEND_QUEUE (self));
-
        priv = MODEST_TNY_SEND_QUEUE_GET_PRIVATE (self);
 
        priv = MODEST_TNY_SEND_QUEUE_GET_PRIVATE (self);
 
+       helper = g_slice_new (WakeupHelper);
+       helper->self = g_object_ref (self);
+       helper->callback = callback;
+       helper->userdata = userdata;
+
        headers = tny_simple_list_new ();
        tny_folder_get_headers_async (priv->outbox, headers, TRUE, 
                                      wakeup_get_headers_async_cb, 
        headers = tny_simple_list_new ();
        tny_folder_get_headers_async (priv->outbox, headers, TRUE, 
                                      wakeup_get_headers_async_cb, 
-                                     NULL, g_object_ref (self));
+                                     NULL, helper);
 }
 
 gboolean 
 }
 
 gboolean 
index a1cfedd..51e1fef 100644 (file)
@@ -145,6 +145,8 @@ modest_tny_all_send_queues_get_msg_status (TnyHeader *header);
  */
 gchar* modest_tny_send_queue_to_string (ModestTnySendQueue *self);
 
  */
 gchar* modest_tny_send_queue_to_string (ModestTnySendQueue *self);
 
+typedef void (*ModestTnySendQueueWakeupFunc) (ModestTnySendQueue *self, gboolean cancelled, GError *err, gpointer userdata);
+
 /**
  * modest_tny_send_queue_wakeup:
  * @self: a valid #ModestTnySendQueue instance
 /**
  * modest_tny_send_queue_wakeup:
  * @self: a valid #ModestTnySendQueue instance
@@ -153,7 +155,9 @@ gchar* modest_tny_send_queue_to_string (ModestTnySendQueue *self);
  * the send queue will try to send them again. Note that you'd
  * probably need a tny_send_queue_flush to force it
  */
  * the send queue will try to send them again. Note that you'd
  * probably need a tny_send_queue_flush to force it
  */
-void   modest_tny_send_queue_wakeup (ModestTnySendQueue *self);
+void   modest_tny_send_queue_wakeup (ModestTnySendQueue *self, 
+                                    ModestTnySendQueueWakeupFunc callback,
+                                    gpointer userdata);
 
 /**
  * modest_tny_send_queue_get_requested_send_receive:
 
 /**
  * modest_tny_send_queue_get_requested_send_receive: