* Fixes NB#85964, do not crash when opening Drafts in memory full condition
[modest] / src / modest-ui-actions.c
index 13eca36..f460812 100644 (file)
@@ -805,7 +805,8 @@ modest_ui_actions_msg_retrieval_check (ModestMailOperation *mail_op,
 
                /* If it's a memory low issue, then show a banner */
                error = modest_mail_operation_get_error (mail_op);
-               if (error && error->code == MODEST_MAIL_OPERATION_ERROR_LOW_MEMORY) {
+               if (error && error->domain == MODEST_MAIL_OPERATION_ERROR &&
+                   error->code == MODEST_MAIL_OPERATION_ERROR_LOW_MEMORY) {
                        GObject *source = modest_mail_operation_get_source (mail_op);
                        modest_platform_run_information_dialog (GTK_IS_WINDOW (source) ? GTK_WINDOW (source) : NULL,
                                                                dgettext("ke-recv","memr_ib_operation_disabled"),
@@ -901,13 +902,15 @@ open_msg_cb (ModestMailOperation *mail_op,
                        account = g_strdup(modest_tny_account_get_parent_modest_account_name_for_server_account(
                                                   TNY_ACCOUNT(traccount)));
                        send_queue = modest_runtime_get_send_queue(traccount, TRUE);
-                       msg_id = modest_tny_send_queue_get_msg_id (header);
-                       status = modest_tny_send_queue_get_msg_status(send_queue, msg_id);
-                       /* Only open messages in outbox with the editor if they are in Failed state */
-                       if (status == MODEST_TNY_SEND_QUEUE_FAILED) {
-                               open_in_editor = TRUE;
+                       if (TNY_IS_SEND_QUEUE (send_queue)) {
+                               msg_id = modest_tny_send_queue_get_msg_id (header);
+                               status = modest_tny_send_queue_get_msg_status(send_queue, msg_id);
+                               /* Only open messages in outbox with the editor if they are in Failed state */
+                               if (status == MODEST_TNY_SEND_QUEUE_FAILED) {
+                                       open_in_editor = TRUE;
+                               }
+                               g_free(msg_id);
                        }
-                       g_free(msg_id);
                        g_object_unref(traccount);
                } else {
                        g_warning("Cannot get transport account for message in outbox!!");
@@ -2310,7 +2313,8 @@ folder_refreshed_cb (ModestMailOperation *mail_op,
 
        /* Check if the operation failed due to memory low conditions */
        error = modest_mail_operation_get_error (mail_op);
-       if (error && error->code == MODEST_MAIL_OPERATION_ERROR_LOW_MEMORY) {
+       if (error && error->domain == MODEST_MAIL_OPERATION_ERROR && 
+           error->code == MODEST_MAIL_OPERATION_ERROR_LOW_MEMORY) {
                modest_platform_run_information_dialog (GTK_WINDOW (win),
                                                        dgettext("ke-recv","memr_ib_operation_disabled"),
                                                        TRUE);
@@ -4685,6 +4689,21 @@ modest_ui_actions_msgs_move_to_confirmation (ModestWindow *win,
 }
 
 static void
+move_to_helper_destroyer (gpointer user_data)
+{
+       MoveToHelper *helper = (MoveToHelper *) user_data;
+
+       /* Close the "Pasting" information banner */
+       if (helper->banner) {
+               gtk_widget_destroy (GTK_WIDGET (helper->banner));
+               g_object_unref (helper->banner);
+       }
+       if (helper->reference != NULL)
+               gtk_tree_row_reference_free (helper->reference);
+       g_free (helper);
+}
+
+static void
 move_to_cb (ModestMailOperation *mail_op, 
            gpointer user_data)
 {
@@ -4722,15 +4741,8 @@ move_to_cb (ModestMailOperation *mail_op,
                }
                g_object_unref (object);
         }
-
-       /* Close the "Pasting" information banner */
-       if (helper->banner) {
-               gtk_widget_destroy (GTK_WIDGET(helper->banner));
-               g_object_unref (helper->banner);
-       }
-       if (helper->reference != NULL)
-               gtk_tree_row_reference_free (helper->reference);
-       g_free (helper);
+       /* Destroy the helper */
+       move_to_helper_destroyer (helper);
 }
 
 static void
@@ -5017,7 +5029,7 @@ xfer_messages_error_handler (ModestMailOperation *mail_op,
                             gpointer user_data)
 {
        ModestWindow *main_window = NULL;
-       
+
        /* Disable next automatic folder selection */
        main_window = modest_window_mgr_get_main_window (modest_runtime_get_window_mgr (),
                                                         FALSE); /* don't create */
@@ -5029,6 +5041,7 @@ xfer_messages_error_handler (ModestMailOperation *mail_op,
                if (win)
                        g_object_unref (win);
        }
+       move_to_helper_destroyer (user_data);
 }
 
 /**
@@ -5109,7 +5122,7 @@ xfer_messages_performer  (gboolean canceled,
        ModestMailOperation *mail_op = 
                modest_mail_operation_new_with_error_handling (G_OBJECT(win),
                                                               xfer_messages_error_handler,
-                                                              NULL, NULL);
+                                                              helper, NULL);
        modest_mail_operation_queue_add (modest_runtime_get_mail_operation_queue (), 
                                         mail_op);
 
@@ -5506,15 +5519,40 @@ modest_ui_actions_on_help (GtkAction *action,
 {
        const gchar *help_id;
 
-       g_return_if_fail (action);
        g_return_if_fail (win && GTK_IS_WINDOW(win));
        
        help_id = modest_window_mgr_get_help_id (modest_runtime_get_window_mgr(), win);
-       
-       if (help_id)
-               modest_platform_show_help (GTK_WINDOW (win), help_id);
+
+        if (help_id)
+                modest_platform_show_help (GTK_WINDOW (win), help_id);
+}
+
+void 
+modest_ui_actions_on_csm_help (GtkAction *action, 
+                              GtkWindow *win)
+{
+       const gchar* help_id = NULL;
+       GtkWidget *folder_view;
+       TnyFolderStore *folder_store;
+
+       g_return_if_fail (win && MODEST_IS_MAIN_WINDOW (win));
+
+       /* Get selected folder */
+       folder_view = modest_main_window_get_child_widget (MODEST_MAIN_WINDOW (win),
+                                                          MODEST_MAIN_WINDOW_WIDGET_TYPE_FOLDER_VIEW);
+       folder_store = modest_folder_view_get_selected (MODEST_FOLDER_VIEW (folder_view));
+
+       /* Switch help_id */
+       if (folder_store && TNY_IS_FOLDER (folder_store))
+               help_id = modest_tny_folder_get_help_id (TNY_FOLDER (folder_store));
+
+       if (folder_store)
+               g_object_unref (folder_store);
+
+        if (help_id)
+                modest_platform_show_help (GTK_WINDOW (win), help_id);
        else
-               g_warning ("%s: no help for window %p", __FUNCTION__, win);
+               modest_ui_actions_on_help (action, win);
 }
 
 static void