* fix for compile breakage
[modest] / src / modest-mail-operation.c
index bad26b1..0237ad9 100644 (file)
@@ -395,7 +395,7 @@ typedef struct
 {
        ModestMailOperation *mail_op;
        TnyStoreAccount *account;
-       gpointer user_data;
+       TnyTransportAccount *transport_account;
 } UpdateAccountInfo;
 
 static void
@@ -431,9 +431,8 @@ notify_update_account_observers (gpointer data)
        ModestMailOperation *mail_op = MODEST_MAIL_OPERATION (data);
 
        g_signal_emit (G_OBJECT (mail_op), signals[PROGRESS_CHANGED_SIGNAL], 0, NULL);
-       g_object_unref (mail_op);
 
-       return FALSE;
+       return TRUE;
 }
 
 /* 
@@ -460,6 +459,8 @@ update_account_thread (gpointer thr_user_data)
        TnyIterator *iter = NULL;
        TnyFolderStoreQuery *query = NULL;
        ModestMailOperationPrivate *priv;
+       ModestTnySendQueue *send_queue;
+       gint timeout;
 
        info = (UpdateAccountInfo *) thr_user_data;
        priv = MODEST_MAIL_OPERATION_GET_PRIVATE(info->mail_op);
@@ -487,6 +488,14 @@ update_account_thread (gpointer thr_user_data)
        }
        g_object_unref (G_OBJECT (iter));
 
+       /* Update status and notify. We need to call the notification
+          with a source functopm in order to call it from the main
+          loop. We need that in order not to get into trouble with
+          Gtk+. We use a timeout in order to provide more status
+          information, because the sync tinymail call does not
+          provide it for the moment */
+       timeout = g_timeout_add (250, notify_update_account_observers, info->mail_op);
+
        /* Refresh folders */
        iter = tny_list_create_iterator (all_folders);
        while (!tny_iterator_is_done (iter) && !priv->error) {
@@ -498,19 +507,25 @@ update_account_thread (gpointer thr_user_data)
 
                if (priv->error) {
                        priv->status = MODEST_MAIL_OPERATION_STATUS_FAILED;
-               } else {
-                       /* Update status and notify. We need to call
-                          the notification with an idle in order to
-                          call it from the main loop. We need that in
-                          order not to get into trouble with Gtk+ */
-                       g_idle_add (notify_update_account_observers, g_object_ref (info->mail_op));
                }
 
                g_object_unref (G_OBJECT (folder));
                tny_iterator_next (iter);
        }
        g_object_unref (G_OBJECT (iter));
+       g_source_remove (timeout);
+
+       /* Perform send */
+       priv->id = MODEST_MAIL_OPERATION_ID_SEND;
+
+       send_queue = modest_tny_send_queue_new (TNY_CAMEL_TRANSPORT_ACCOUNT(info->transport_account));
 
+       timeout = g_timeout_add (250, notify_update_account_observers, info->mail_op);
+       modest_tny_send_queue_flush (send_queue);
+       g_source_remove (timeout);
+
+       g_object_unref (G_OBJECT(send_queue));
+       
        /* Check if the operation was a success */
        if (!priv->error) {
                priv->status = MODEST_MAIL_OPERATION_STATUS_SUCCESS;
@@ -532,6 +547,7 @@ update_account_thread (gpointer thr_user_data)
        g_object_unref (all_folders);
        g_object_unref (info->mail_op);
        g_object_unref (info->account);
+       g_object_unref (info->transport_account);
        g_slice_free (UpdateAccountInfo, info);
 
        return NULL;
@@ -545,6 +561,8 @@ modest_mail_operation_update_account (ModestMailOperation *self,
        UpdateAccountInfo *info;
        ModestMailOperationPrivate *priv;
        TnyStoreAccount *modest_account;
+       TnyTransportAccount *transport_account;
+       gchar *modest_acc_name;
 
        g_return_val_if_fail (MODEST_IS_MAIL_OPERATION (self), FALSE);
        g_return_val_if_fail (account_name, FALSE);
@@ -565,6 +583,25 @@ modest_mail_operation_update_account (ModestMailOperation *self,
 
        if (!modest_account) {
                priv->status = MODEST_MAIL_OPERATION_STATUS_FAILED;
+               g_set_error (&(priv->error), MODEST_MAIL_OPERATION_ERROR,
+                            MODEST_MAIL_OPERATION_ERROR_ITEM_NOT_FOUND,
+                            "cannot get tny store account for %s\n", account_name);
+               modest_mail_operation_queue_remove (modest_runtime_get_mail_operation_queue (), 
+                                                   self);
+               return FALSE;
+       }
+
+       /* Get the transport account, we can not do it in the thread
+          due to some problems with dbus */
+       modest_acc_name = (gchar *) g_object_get_data (G_OBJECT (modest_account), "modest_account");
+       transport_account = (TnyTransportAccount *)
+               modest_tny_account_store_get_transport_account_for_open_connection (modest_runtime_get_account_store(),
+                                                                                   modest_acc_name);
+       if (!transport_account) {
+               priv->status = MODEST_MAIL_OPERATION_STATUS_FAILED;
+               g_set_error (&(priv->error), MODEST_MAIL_OPERATION_ERROR,
+                            MODEST_MAIL_OPERATION_ERROR_ITEM_NOT_FOUND,
+                            "cannot get tny transport account for %s\n", modest_acc_name);
                modest_mail_operation_queue_remove (modest_runtime_get_mail_operation_queue (), 
                                                    self);
                return FALSE;
@@ -574,7 +611,7 @@ modest_mail_operation_update_account (ModestMailOperation *self,
        info = g_slice_new (UpdateAccountInfo);
        info->mail_op = g_object_ref (self);
        info->account = modest_account;
-       info->user_data = NULL;
+       info->transport_account = transport_account;
 
        thread = g_thread_create (update_account_thread, info, FALSE, NULL);
 
@@ -843,7 +880,7 @@ transfer_folder_status_cb (GObject *obj,
 
 
 static void
-transfer_folder_cb (TnyFolder *folder, TnyFolderStore *into, const gchar *new_name, gboolean cancelled, GError **err, gpointer user_data)
+transfer_folder_cb (TnyFolder *folder, TnyFolderStore *into, gboolean cancelled, TnyFolder *new_folder, GError **err, gpointer user_data)
 {
        XFerFolderAsyncHelper *helper = NULL;
        ModestMailOperation *self = NULL;
@@ -873,6 +910,7 @@ transfer_folder_cb (TnyFolder *folder, TnyFolderStore *into, const gchar *new_na
        g_slice_free   (XFerFolderAsyncHelper, helper);
        g_object_unref (folder);
        g_object_unref (into);
+       g_object_unref (new_folder);
 
        /* Notify the queue */
        modest_mail_operation_queue_remove (modest_runtime_get_mail_operation_queue (), self);