* The account dialog is now modal (registered as modal in the window manager) this...
[modest] / src / modest-mail-operation.c
index 96bf48a..c67acb8 100644 (file)
@@ -101,6 +101,7 @@ struct _ModestMailOperationPrivate {
        GError                    *error;
        ErrorCheckingUserCallback  error_checking;
        gpointer                   error_checking_user_data;
+       ErrorCheckingUserDataDestroyer error_checking_user_data_destroyer;
        ModestMailOperationStatus  status;      
        ModestMailOperationTypeOperation op_type;
 };
@@ -330,7 +331,8 @@ modest_mail_operation_new (GObject *source)
 ModestMailOperation*
 modest_mail_operation_new_with_error_handling (GObject *source,
                                               ErrorCheckingUserCallback error_handler,
-                                              gpointer user_data)
+                                              gpointer user_data,
+                                              ErrorCheckingUserDataDestroyer error_handler_destroyer)
 {
        ModestMailOperation *obj;
        ModestMailOperationPrivate *priv;
@@ -341,6 +343,7 @@ modest_mail_operation_new_with_error_handling (GObject *source,
        g_return_val_if_fail (error_handler != NULL, obj);
        priv->error_checking = error_handler;
        priv->error_checking_user_data = user_data;
+       priv->error_checking_user_data_destroyer = error_handler_destroyer;
 
        return obj;
 }
@@ -353,6 +356,7 @@ modest_mail_operation_execute_error_handler (ModestMailOperation *self)
        priv = MODEST_MAIL_OPERATION_GET_PRIVATE(self);
        g_return_if_fail(priv->status != MODEST_MAIL_OPERATION_STATUS_SUCCESS);     
 
+       /* Call the user callback */
        if (priv->error_checking != NULL)
                priv->error_checking (self, priv->error_checking_user_data);
 }
@@ -804,6 +808,7 @@ modest_mail_operation_send_new_mail (ModestMailOperation *self,
 
        priv = MODEST_MAIL_OPERATION_GET_PRIVATE(self);
        priv->op_type = MODEST_MAIL_OPERATION_TYPE_SEND;
+       priv->account = TNY_ACCOUNT (g_object_ref (transport_account));
 
        /* Check parametters */
        if (to == NULL) {
@@ -1506,6 +1511,7 @@ modest_mail_operation_update_account (ModestMailOperation *self,
                goto error;
        }
 
+       priv->account = g_object_ref (store_account);
        
        /* Get the transport account, we can not do it in the thread
           due to some problems with dbus */
@@ -1586,6 +1592,9 @@ modest_mail_operation_create_folder (ModestMailOperation *self,
        
        priv = MODEST_MAIL_OPERATION_GET_PRIVATE (self);
        priv->op_type = MODEST_MAIL_OPERATION_TYPE_INFO;
+       priv->account = (TNY_IS_ACCOUNT (parent)) ? 
+               g_object_ref (parent) : 
+               modest_tny_folder_get_account (TNY_FOLDER (parent));
 
        /* Check for already existing folder */
        if (modest_tny_folder_has_subfolder_with_name (parent, name)) {
@@ -2008,42 +2017,31 @@ modest_mail_operation_get_msg (ModestMailOperation *self,
        priv->status = MODEST_MAIL_OPERATION_STATUS_IN_PROGRESS;
        priv->op_type = MODEST_MAIL_OPERATION_TYPE_RECEIVE;
 
-       /* Get message from folder */
-       if (folder) {
-               /* Get account and set it into mail_operation */
-               priv->account = modest_tny_folder_get_account (TNY_FOLDER(folder));
+       /* Get account and set it into mail_operation */
+       priv->account = modest_tny_folder_get_account (TNY_FOLDER(folder));
+       
+       /* Check for cached messages */
+       if (tny_header_get_flags (header) & TNY_HEADER_FLAG_CACHED)
+               priv->op_type = MODEST_MAIL_OPERATION_TYPE_OPEN;
+       else 
+               priv->op_type = MODEST_MAIL_OPERATION_TYPE_RECEIVE;
+       
+       helper = g_slice_new0 (GetMsgAsyncHelper);
+       helper->mail_op = self;
+       helper->user_callback = user_callback;
+       helper->user_data = user_data;
+       helper->header = g_object_ref (header);
                
-               /* Check for cached messages */
-               if (tny_header_get_flags (header) & TNY_HEADER_FLAG_CACHED)
-                       priv->op_type = MODEST_MAIL_OPERATION_TYPE_OPEN;
-               else 
-                       priv->op_type = MODEST_MAIL_OPERATION_TYPE_RECEIVE;
-
-               helper = g_slice_new0 (GetMsgAsyncHelper);
-               helper->mail_op = self;
-               helper->user_callback = user_callback;
-               helper->user_data = user_data;
-               helper->header = g_object_ref (header);
-
-               // The callback's reference so that the mail op is not
-               // finalized until the async operation is completed even if
-               // the user canceled the request meanwhile.
-               g_object_ref (G_OBJECT (helper->mail_op));
-
-               modest_mail_operation_notify_start (self);
-               tny_folder_get_msg_async (folder, header, get_msg_cb, get_msg_status_cb, helper);
+       /* The callback's reference so that the mail op is not
+        * finalized until the async operation is completed even if
+        * the user canceled the request meanwhile.
+        */
+       g_object_ref (G_OBJECT (helper->mail_op));
 
-               g_object_unref (G_OBJECT (folder));
-       } else {
-               /* Set status failed and set an error */
-               priv->status = MODEST_MAIL_OPERATION_STATUS_FAILED;
-               g_set_error (&(priv->error), MODEST_MAIL_OPERATION_ERROR,
-                            MODEST_MAIL_OPERATION_ERROR_ITEM_NOT_FOUND,
-                            _("Error trying to get a message. No folder found for header"));
+       modest_mail_operation_notify_start (self);
+       tny_folder_get_msg_async (folder, header, get_msg_cb, get_msg_status_cb, helper);
 
-               /* Notify the queue */
-               modest_mail_operation_notify_end (self);
-       }
+       g_object_unref (G_OBJECT (folder));
 }
 
 static void
@@ -2320,10 +2318,8 @@ modest_mail_operation_get_msgs_full (ModestMailOperation *self,
                        folder = tny_header_get_folder (header);
                        if (folder) {           
                                priv->account = modest_tny_folder_get_account (TNY_FOLDER(folder));
-
                                g_object_unref (folder);
                        }
-
                        g_object_unref (header);
                }
 
@@ -2722,8 +2718,6 @@ on_refresh_folder (TnyFolder   *folder,
        if (error) {
                priv->error = g_error_copy (error);
                priv->status = MODEST_MAIL_OPERATION_STATUS_FAILED;
-               printf("DEBUG: %s: Operation error:\n %s", __FUNCTION__,
-                      error->message);
                goto out;
        }
 
@@ -2733,11 +2727,11 @@ on_refresh_folder (TnyFolder   *folder,
                             MODEST_MAIL_OPERATION_ERROR_ITEM_NOT_FOUND,
                             _("Error trying to refresh the contents of %s"),
                             tny_folder_get_name (folder));
-               printf("DEBUG: %s: Operation cancelled.\n", __FUNCTION__);
                goto out;
        }
 
        priv->status = MODEST_MAIL_OPERATION_STATUS_SUCCESS;
+ out:
 
        /* Call user defined callback, if it exists */
        if (helper->user_callback) {
@@ -2747,7 +2741,6 @@ on_refresh_folder (TnyFolder   *folder,
                helper->user_callback (self, folder, helper->user_data);
        }
 
- out:
        /* Free */
        g_slice_free   (RefreshAsyncHelper, helper);
 
@@ -2862,6 +2855,10 @@ modest_mail_operation_notify_end (ModestMailOperation *self)
           not wrapp this emission because we assume that this
           function is always called from within the main lock */
        g_signal_emit (G_OBJECT (self), signals[OPERATION_FINISHED_SIGNAL], 0, NULL);
+
+       /* Remove the error user data */
+       if (priv->error_checking_user_data && priv->error_checking_user_data_destroyer)
+               priv->error_checking_user_data_destroyer (priv->error_checking_user_data);
 }
 
 TnyAccount *