* Fixes NB#60606 show proper error in memory full conditions
authorSergio Villar Senin <svillar@igalia.com>
Tue, 18 Mar 2008 08:44:07 +0000 (08:44 +0000)
committerSergio Villar Senin <svillar@igalia.com>
Tue, 18 Mar 2008 08:44:07 +0000 (08:44 +0000)
* Fixes an invalid g_object_unref

pmo-trunk-r4322

src/modest-mail-operation.c
src/modest-ui-actions.c

index f1ecaa5..126e4a3 100644 (file)
@@ -1211,6 +1211,27 @@ update_account_get_msg_async_cb (TnyFolder *folder,
 }
 
 static void
+update_account_notify_user_and_free (UpdateAccountInfo *info, 
+                                    TnyList *new_headers)
+{
+       /* Set the account back to not busy */
+       modest_account_mgr_set_account_busy (modest_runtime_get_account_mgr (), 
+                                            info->account_name, FALSE);
+       
+       /* User callback */
+       if (info->callback)
+               info->callback (info->mail_op, new_headers, info->user_data);
+       
+       /* Mail operation end */
+       modest_mail_operation_notify_end (info->mail_op);
+
+       /* Frees */
+       if (new_headers)
+               g_object_unref (new_headers);
+       destroy_update_account_info (info);
+}
+
+static void
 inbox_refreshed_cb (TnyFolder *inbox, 
                    gboolean canceled, 
                    GError *err, 
@@ -1231,7 +1252,20 @@ inbox_refreshed_cb (TnyFolder *inbox,
        priv = MODEST_MAIL_OPERATION_GET_PRIVATE (info->mail_op);
        mgr = modest_runtime_get_account_mgr ();
 
-       if (canceled || err || !inbox) {
+       if (canceled || err) {
+               priv->status = MODEST_MAIL_OPERATION_STATUS_FAILED;
+               if (err)
+                       priv->error = g_error_copy (err);
+               else
+                       g_set_error (&(priv->error), MODEST_MAIL_OPERATION_ERROR,
+                                    MODEST_MAIL_OPERATION_ERROR_OPERATION_CANCELED,
+                                    "canceled");
+               /* Notify the user about the error and then exit */
+               update_account_notify_user_and_free (info, NULL);
+               return;
+       }
+
+       if (!inbox) {
                /* Try to send anyway */
                goto send_mail;
        }
@@ -1383,20 +1417,8 @@ inbox_refreshed_cb (TnyFolder *inbox,
        if (!priv->error)
                priv->status = MODEST_MAIL_OPERATION_STATUS_SUCCESS;
 
-       /* Set the account back to not busy */
-       modest_account_mgr_set_account_busy (mgr, info->account_name, FALSE);
-
-       /* Call the user callback */
-       if (info->callback)
-               info->callback (info->mail_op, new_headers, info->user_data);
-
-       /* Notify about operation end */
-       modest_mail_operation_notify_end (info->mail_op);
-
-       /* Frees */
-       if (new_headers)
-               g_object_unref (new_headers);
-       destroy_update_account_info (info);
+       /* Call the user callback and free */
+       update_account_notify_user_and_free (info, new_headers);
 }
 
 static void 
@@ -1413,7 +1435,17 @@ recurse_folders_async_cb (TnyFolderStore *folder_store,
        priv = MODEST_MAIL_OPERATION_GET_PRIVATE (info->mail_op);
 
        if (err || canceled) {
-               /* Try to continue anyway */
+               /* If the error was previosly set by another callback
+                  don't set it again */
+               if (!priv->error) {
+                       priv->status = MODEST_MAIL_OPERATION_STATUS_FAILED;
+                       if (err)
+                               priv->error = g_error_copy (err);
+                       else
+                               g_set_error (&(priv->error), MODEST_MAIL_OPERATION_ERROR,
+                                            MODEST_MAIL_OPERATION_ERROR_OPERATION_CANCELED,
+                                            "canceled");
+               }
        } else if (info->poke_all) {
                /* We're not getting INBOX children if we don't want to poke all */
                TnyIterator *iter = tny_list_create_iterator (list);
@@ -1447,6 +1479,12 @@ recurse_folders_async_cb (TnyFolderStore *folder_store,
                TnyIterator *iter_all_folders;
                TnyFolder *inbox = NULL;
 
+               /* If there was any error do not continue */
+               if (priv->error) {
+                       update_account_notify_user_and_free (info, NULL);
+                       return;
+               }
+
                iter_all_folders = tny_list_create_iterator (info->folders);
 
                /* Do a poke status over all folders */
index efa8abc..9961f4f 100644 (file)
@@ -975,9 +975,21 @@ cleanup:
        g_object_unref (folder);
 }
 
+static gboolean
+is_memory_full_error (GError *error)
+{
+       if (error->code == TNY_SYSTEM_ERROR_MEMORY ||
+           error->code == TNY_IO_ERROR_WRITE ||
+           error->code == TNY_IO_ERROR_READ) {
+               return TRUE;
+       } else {
+               return FALSE;
+       }
+}
+
 void
 modest_ui_actions_disk_operations_error_handler (ModestMailOperation *mail_op,
-                                                   gpointer user_data)
+                                                gpointer user_data)
 {
        const GError *error;
        GObject *win = NULL;
@@ -990,10 +1002,7 @@ modest_ui_actions_disk_operations_error_handler (ModestMailOperation *mail_op,
        /* If the mail op has been cancelled then it's not an error:
           don't show any message */
        if (status != MODEST_MAIL_OPERATION_STATUS_CANCELED) {
-               /* Show error */
-               if (error->code == TNY_SYSTEM_ERROR_MEMORY ||
-                   error->code == TNY_IO_ERROR_WRITE ||
-                   error->code == TNY_IO_ERROR_READ) {
+               if (is_memory_full_error ((GError *) error)) {
                        modest_platform_information_banner ((GtkWidget *) win,
                                                            NULL, dgettext("ke-recv",
                                                                           "cerm_device_memory_full"));
@@ -1109,6 +1118,13 @@ open_msgs_performer(gboolean canceled,
                                  modest_runtime_get_window_mgr ());
                /* Free the helper */
                open_msgs_helper_destroyer (helper);
+
+               /* In memory full conditions we could get this error here */
+               if (err && is_memory_full_error (err)) {
+                       modest_platform_information_banner ((GtkWidget *) parent_window,
+                                                           NULL, dgettext("ke-recv",
+                                                                          "cerm_device_memory_full"));
+               }
                goto clean;
        }
 
@@ -1819,6 +1835,12 @@ do_send_receive_performer (gboolean canceled,
        info = (SendReceiveInfo *) user_data;
 
        if (err || canceled) {
+               /* In memory full conditions we could get this error here */
+               if (err && is_memory_full_error (err)) {
+                       modest_platform_information_banner ((GtkWidget *) parent_window,
+                                                           NULL, dgettext("ke-recv",
+                                                                          "cerm_device_memory_full"));
+               }
                goto clean;
        }
 
@@ -1828,7 +1850,7 @@ do_send_receive_performer (gboolean canceled,
        }
        
        mail_op = modest_mail_operation_new_with_error_handling ((info->win) ? G_OBJECT (info->win) : NULL,
-                                                                modest_ui_actions_send_receive_error_handler,
+                                                                modest_ui_actions_disk_operations_error_handler,
                                                                 NULL, NULL);
 
        if (info->win && MODEST_IS_MAIN_WINDOW (info->win))
@@ -2874,6 +2896,12 @@ create_folder_performer (gboolean canceled,
        TnyFolderStore *parent_folder = TNY_FOLDER_STORE (user_data);
 
        if (canceled || err) {
+               /* In memory full conditions we could get this error here */
+               if (err && is_memory_full_error (err)) {
+                       modest_platform_information_banner ((GtkWidget *) parent_window,
+                                                           NULL, dgettext("ke-recv",
+                                                                          "cerm_device_memory_full"));
+               }
                goto frees;
        }
 
@@ -2975,7 +3003,14 @@ on_rename_folder_performer (gboolean canceled,
        GtkWidget *folder_view = NULL;
        RenameFolderInfo *data = (RenameFolderInfo*)user_data;
 
-       if (!canceled && (err == NULL) && MODEST_IS_MAIN_WINDOW(parent_window)) {
+       if (canceled || err) {
+               /* In memory full conditions we could get this error here */
+               if (err && is_memory_full_error (err)) {
+                       modest_platform_information_banner ((GtkWidget *) parent_window,
+                                                           NULL, dgettext("ke-recv",
+                                                                          "cerm_device_memory_full"));
+               }
+       } else if (MODEST_IS_MAIN_WINDOW(parent_window)) {
 
                folder_view = modest_main_window_get_child_widget (
                                MODEST_MAIN_WINDOW (parent_window),
@@ -2999,9 +3034,9 @@ on_rename_folder_performer (gboolean canceled,
                                                     (const gchar *) (data->new_name),
                                                     on_rename_folder_cb,
                                                     folder_view);
+               g_object_unref (mail_op);
        }
 
-       g_object_unref (mail_op);
        g_free (data->new_name);
        g_free (data);
 }
@@ -4535,29 +4570,6 @@ modest_ui_actions_move_folder_error_handler (ModestMailOperation *mail_op,
                g_object_unref (win);
 }
 
-void
-modest_ui_actions_send_receive_error_handler (ModestMailOperation *mail_op, 
-                                             gpointer user_data)
-{
-       GObject *win = modest_mail_operation_get_source (mail_op);
-       const GError *error = modest_mail_operation_get_error (mail_op);
-
-       g_return_if_fail (error != NULL);
-       if (error->message != NULL)             
-               g_printerr ("modest: %s\n", error->message);
-       else
-               g_printerr ("modest: unkonw error on send&receive operation");
-
-       /* Show error message */
-/*     if (modest_mail_operation_get_id (mail_op) == MODEST_MAIL_OPERATION_TYPE_RECEIVE) */
-/*             modest_platform_run_information_dialog ((win) ? GTK_WINDOW (win) : NULL, */
-/*                                                     _CS("sfil_ib_unable_to_receive")); */
-/*     else  */
-/*             modest_platform_run_information_dialog ((win) ? GTK_WINDOW (win) : NULL, */
-/*                                                     _CS("sfil_ib_unable_to_send")); */
-       g_object_unref (win);
-}
-
 static void
 open_msg_for_purge_cb (ModestMailOperation *mail_op, 
                       TnyHeader *header, 
@@ -4800,8 +4812,14 @@ xfer_messages_performer  (gboolean canceled,
        gboolean dst_is_pop = FALSE;
 
        if (canceled || err) {
-               /* Show the proper error message */
-               modest_ui_actions_on_account_connection_error (parent_window, account);
+               if (err && is_memory_full_error (err)) {
+                       modest_platform_information_banner ((GtkWidget *) parent_window,
+                                                           NULL, dgettext("ke-recv",
+                                                                          "cerm_device_memory_full"));
+               } else {
+                       /* Show the proper error message */
+                       modest_ui_actions_on_account_connection_error (parent_window, account);
+               }
                g_object_unref (dst_folder);
                return;
        }
@@ -5267,6 +5285,11 @@ retrieve_msg_contents_performer (gboolean canceled,
        TnyList *headers = TNY_LIST (user_data);
 
        if (err || canceled) {
+               if (err && is_memory_full_error (err)) {
+                       modest_platform_information_banner ((GtkWidget *) parent_window,
+                                                           NULL, dgettext("ke-recv",
+                                                                          "cerm_device_memory_full"));
+               }
                goto out;
        }