* Fixes NB#97186, only messages in failed status can be opened in a viever
[modest] / src / modest-ui-actions.c
index 098aa41..9d8fff4 100644 (file)
@@ -952,13 +952,14 @@ get_header_view_from_window (ModestWindow *window)
 }
 
 static gchar *
-get_info_from_header (TnyHeader *header, gboolean *is_draft)
+get_info_from_header (TnyHeader *header, gboolean *is_draft, gboolean *can_open)
 {
        TnyFolder *folder;
        gchar *account = NULL;
        TnyFolderType folder_type = TNY_FOLDER_TYPE_UNKNOWN;
 
        *is_draft = FALSE;
+       *can_open = TRUE;
 
        folder = tny_header_get_folder (header);
        /* Gets folder type (OUTBOX headers will be opened in edit window */
@@ -967,7 +968,7 @@ get_info_from_header (TnyHeader *header, gboolean *is_draft)
                if (folder_type == TNY_FOLDER_TYPE_INVALID)
                        g_warning ("%s: BUG: TNY_FOLDER_TYPE_INVALID", __FUNCTION__);
        }
-               
+
        if (folder_type == TNY_FOLDER_TYPE_OUTBOX) {
                TnyTransportAccount *traccount = NULL;
                ModestTnyAccountStore *accstore = modest_runtime_get_account_store();
@@ -993,6 +994,7 @@ get_info_from_header (TnyHeader *header, gboolean *is_draft)
                                           open any message from
                                           outbox which is not in
                                           failed state */
+                                       *can_open = FALSE;
                                        g_object_unref(traccount);
                                 }
 #endif
@@ -1023,8 +1025,9 @@ open_msg_cb (ModestMailOperation *mail_op,
        ModestWindow *win = NULL;
        gchar *account = NULL;
        gboolean open_in_editor = FALSE;
+       gboolean can_open;
        OpenMsgHelper *helper = (OpenMsgHelper *) user_data;
-       
+
        /* Do nothing if there was any problem with the mail
           operation. The error will be shown by the error_handler of
           the mail operation */
@@ -1036,14 +1039,14 @@ open_msg_cb (ModestMailOperation *mail_op,
        /* Mark header as read */
        headers_action_mark_as_read (header, MODEST_WINDOW(parent_win), NULL);
 
-       account = get_info_from_header (header, &open_in_editor);
+       account = get_info_from_header (header, &open_in_editor, &can_open);
 
        /* Get account */
        if (!account)
                account = g_strdup (modest_window_get_active_account (MODEST_WINDOW (parent_win)));
        if (!account)
                account = modest_account_mgr_get_default_account (modest_runtime_get_account_mgr());
-       
+
        if (open_in_editor) {
                ModestAccountMgr *mgr = modest_runtime_get_account_mgr ();
                gchar *from_header = NULL, *acc_name;
@@ -1071,7 +1074,7 @@ open_msg_cb (ModestMailOperation *mail_op,
        } else {
                gchar *uid = modest_tny_folder_get_header_unique_id (header);
 
-               if (helper->rowref && helper->model) {          
+               if (helper->rowref && helper->model) {
                        win = modest_msg_view_window_new_with_header_model (msg, account, (const gchar*) uid,
                                                                            helper->model, helper->rowref);
                } else {
@@ -1079,7 +1082,7 @@ open_msg_cb (ModestMailOperation *mail_op,
                }
                g_free (uid);
        }
-       
+
        /* Register and show new window */
        if (win != NULL) {
                mgr = modest_runtime_get_window_mgr ();
@@ -1285,6 +1288,9 @@ open_msg_performer(gboolean canceled,
        TnyConnectionStatus status;
        gboolean show_open_draft = FALSE;
        OpenMsgHelper *helper = NULL;
+       ModestProtocol *protocol;
+       ModestProtocolRegistry *protocol_registry;
+       gchar *subject;
 
        helper = (OpenMsgHelper *) user_data;
 
@@ -1293,10 +1299,10 @@ open_msg_performer(gboolean canceled,
                modest_window_mgr_unregister_header (modest_runtime_get_window_mgr (), helper->header);
                /* Free the helper */
                open_msg_helper_destroyer (helper);
-               
+
                /* In memory full conditions we could get this error here */
                check_memory_full_error ((GtkWidget *) parent_window, err);
-               
+
                goto clean;
        }
 
@@ -1305,11 +1311,7 @@ open_msg_performer(gboolean canceled,
        if (proto == MODEST_PROTOCOL_REGISTRY_TYPE_INVALID) {
                proto = MODEST_PROTOCOLS_STORE_MAILDIR;
        }
-       
-       ModestProtocol *protocol;
-       ModestProtocolRegistry *protocol_registry;
-       gchar *subject;
-               
+
        protocol_registry = modest_runtime_get_protocol_registry ();
        subject = tny_header_dup_subject (helper->header);
 
@@ -1317,7 +1319,7 @@ open_msg_performer(gboolean canceled,
        error_msg = modest_protocol_get_translation (protocol, MODEST_PROTOCOL_TRANSLATION_MSG_NOT_AVAILABLE, subject);
        if (subject)
                g_free (subject);
-               
+
        if (error_msg == NULL) {
                error_msg = g_strdup (_("mail_ni_ui_folder_get_msg_folder_error"));
        }
@@ -1336,7 +1338,15 @@ open_msg_performer(gboolean canceled,
 
 #ifdef MODEST_TOOLKIT_HILDON2
        gboolean is_draft;
-       gchar *account_name = get_info_from_header (helper->header, &is_draft);
+       gboolean can_open;
+       gchar *account_name = get_info_from_header (helper->header, &is_draft, &can_open);
+
+       if (!can_open) {
+               modest_window_mgr_unregister_header (modest_runtime_get_window_mgr (), helper->header);
+               g_free (account_name);
+               open_msg_helper_destroyer (helper);
+               goto clean;
+       }
 
        if (!is_draft) {
                ModestWindow *window;
@@ -3126,11 +3136,10 @@ modest_ui_actions_on_select_editor_background_color (GtkAction *action,
 }
 
 void 
-modest_ui_actions_on_insert_image (GtkAction *action,
+modest_ui_actions_on_insert_image (GObject *object,
                                   ModestMsgEditWindow *window)
 {
        g_return_if_fail (MODEST_IS_MSG_EDIT_WINDOW (window));
-       g_return_if_fail (GTK_IS_ACTION (action));
 
 
        if (modest_platform_check_memory_low (MODEST_WINDOW(window), TRUE))
@@ -3268,17 +3277,17 @@ do_create_folder (GtkWindow *parent_window,
 {
        gint result;
        gchar *folder_name = NULL;
-       TnyFolderStore *parent_folder;
+       TnyFolderStore *parent_folder = NULL;
 
        result = modest_platform_run_new_folder_dialog (GTK_WINDOW (parent_window),
                                                        suggested_parent,
                                                        (gchar *) suggested_name,
                                                        &folder_name,
                                                        &parent_folder);
-       
+
        if (result == GTK_RESPONSE_ACCEPT && parent_folder) {
                ModestMailOperation *mail_op;
-               
+
                mail_op  = modest_mail_operation_new ((GObject *) parent_window);
                modest_mail_operation_queue_add (modest_runtime_get_mail_operation_queue (), 
                                                 mail_op);
@@ -3289,7 +3298,9 @@ do_create_folder (GtkWindow *parent_window,
                                                     folder_name);
                g_object_unref (mail_op);
        }
-       g_object_unref (parent_folder);
+
+       if (parent_folder)
+               g_object_unref (parent_folder);
 }
 
 static void
@@ -3323,13 +3334,20 @@ modest_ui_actions_create_folder(GtkWidget *parent_window,
 #ifdef MODEST_TOOLKIT_HILDON2
        const gchar *active_account;
        TnyAccount *account;
+       ModestTnyAccountStore *acc_store;
 
        /* In hildon 2.2 we use the current account as default parent */
+       acc_store = modest_runtime_get_account_store ();
        active_account = modest_window_get_active_account (MODEST_WINDOW (parent_window));
-       account = modest_tny_account_store_get_server_account (modest_runtime_get_account_store (),
-                                                              active_account,
-                                                              TNY_ACCOUNT_TYPE_STORE);
-       parent_folder = TNY_FOLDER_STORE (account);
+       if (active_account) {
+               account = modest_tny_account_store_get_server_account (acc_store,
+                                                                      active_account,
+                                                                      TNY_ACCOUNT_TYPE_STORE);
+               parent_folder = TNY_FOLDER_STORE (account);
+       } else {
+               parent_folder = (TnyFolderStore *) 
+                       modest_tny_account_store_get_local_folders_account (acc_store);
+       }
 #else
        parent_folder = modest_folder_view_get_selected (MODEST_FOLDER_VIEW(folder_view));
 #endif
@@ -4837,7 +4855,8 @@ on_move_to_dialog_response (GtkDialog *dialog,
        }
 
        /* Free the helper and exit */
-       g_object_unref (helper->list);
+       if (helper->list)
+               g_object_unref (helper->list);
        g_slice_free (MoveToInfo, helper);
        gtk_widget_destroy (GTK_WIDGET (dialog));
 }
@@ -5005,40 +5024,42 @@ move_to_cb (ModestMailOperation *mail_op,
            gpointer user_data)
 {
        MoveToHelper *helper = (MoveToHelper *) user_data;
+       GObject *object = modest_mail_operation_get_source (mail_op);
 
        /* Note that the operation could have failed, in that case do
           nothing */
-       if (modest_mail_operation_get_status (mail_op) == 
-           MODEST_MAIL_OPERATION_STATUS_SUCCESS) {
-
-               GObject *object = modest_mail_operation_get_source (mail_op);
-               if (MODEST_IS_MSG_VIEW_WINDOW (object)) {
-                       ModestMsgViewWindow *self = MODEST_MSG_VIEW_WINDOW (object);
+       if (modest_mail_operation_get_status (mail_op) != 
+           MODEST_MAIL_OPERATION_STATUS_SUCCESS)
+               goto frees;
 
-                       if (!modest_msg_view_window_select_next_message (self) &&
-                           !modest_msg_view_window_select_previous_message (self)) {
-                               /* No more messages to view, so close this window */
-                               modest_ui_actions_on_close_window (NULL, MODEST_WINDOW(self));
-                       }
-               } else if (MODEST_IS_MAIN_WINDOW (object) && 
-                          gtk_tree_row_reference_valid (helper->reference)) {
-                       GtkWidget *header_view;
-                       GtkTreePath *path;
-                       GtkTreeSelection *sel;
+       if (MODEST_IS_MSG_VIEW_WINDOW (object)) {
+               ModestMsgViewWindow *self = MODEST_MSG_VIEW_WINDOW (object);
 
-                       header_view = modest_main_window_get_child_widget (MODEST_MAIN_WINDOW(object),
-                                                                          MODEST_MAIN_WINDOW_WIDGET_TYPE_HEADER_VIEW);
-                       sel = gtk_tree_view_get_selection (GTK_TREE_VIEW (header_view));
-                       path = gtk_tree_row_reference_get_path (helper->reference);
-                       /* We need to unselect the previous one
-                          because we could be copying instead of
-                          moving */
-                       gtk_tree_selection_unselect_all (sel);
-                       gtk_tree_selection_select_path (sel, path);
-                       gtk_tree_path_free (path);
+               if (!modest_msg_view_window_select_next_message (self) &&
+                   !modest_msg_view_window_select_previous_message (self)) {
+                       /* No more messages to view, so close this window */
+                       modest_ui_actions_on_close_window (NULL, MODEST_WINDOW(self));
                }
-               g_object_unref (object);
-        }
+       } else if (MODEST_IS_MAIN_WINDOW (object) && 
+                  gtk_tree_row_reference_valid (helper->reference)) {
+               GtkWidget *header_view;
+               GtkTreePath *path;
+               GtkTreeSelection *sel;
+
+               header_view = modest_main_window_get_child_widget (MODEST_MAIN_WINDOW(object),
+                                                                  MODEST_MAIN_WINDOW_WIDGET_TYPE_HEADER_VIEW);
+               sel = gtk_tree_view_get_selection (GTK_TREE_VIEW (header_view));
+               path = gtk_tree_row_reference_get_path (helper->reference);
+               /* We need to unselect the previous one
+                  because we could be copying instead of
+                  moving */
+               gtk_tree_selection_unselect_all (sel);
+               gtk_tree_selection_select_path (sel, path);
+               gtk_tree_path_free (path);
+       }
+       g_object_unref (object);
+
+ frees:
        /* Destroy the helper */
        move_to_helper_destroyer (helper);
 }
@@ -5331,20 +5352,12 @@ static void
 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 */
-       if (main_window) {
-               GObject *win = modest_mail_operation_get_source (mail_op);
-               modest_platform_run_information_dialog ((GtkWindow *) win, 
-                                                       _("mail_in_ui_folder_move_target_error"), 
-                                                       FALSE);
-               if (win)
-                       g_object_unref (win);
-       }
-       move_to_helper_destroyer (user_data);
+       GObject *win = modest_mail_operation_get_source (mail_op);
+       modest_platform_run_information_dialog ((GtkWindow *) win, 
+                                               _("mail_in_ui_folder_move_target_error"), 
+                                               FALSE);
+       if (win)
+               g_object_unref (win);
 }
 
 typedef struct {
@@ -5398,12 +5411,15 @@ xfer_messages_performer  (gboolean canceled,
        }
 
        movehelper = g_new0 (MoveToHelper, 1);
+
+#ifndef MODEST_TOOLKIT_HILDON2
        movehelper->banner = modest_platform_animation_banner (GTK_WIDGET (win), NULL,
                                                               _CS("ckct_nw_pasting"));
        if (movehelper->banner != NULL)  {
                g_object_ref (movehelper->banner);
                gtk_widget_show (GTK_WIDGET (movehelper->banner));
        }
+#endif
 
        if (MODEST_IS_MAIN_WINDOW (win)) {
                GtkWidget *header_view = 
@@ -5447,14 +5463,14 @@ on_move_folder_cb (gboolean canceled, GError *err, GtkWindow *parent_window,
        MoveFolderInfo *info = (MoveFolderInfo*)user_data;
        GtkTreeSelection *sel;
        ModestMailOperation *mail_op = NULL;
-       
+
        if (canceled || err || !MODEST_IS_WINDOW (parent_window)) {
                g_object_unref (G_OBJECT (info->src_folder));
                g_object_unref (G_OBJECT (info->dst_folder));
                g_free (info);
                return;
        }
-       
+
        MoveToHelper *helper = g_new0 (MoveToHelper, 1);
        helper->banner = modest_platform_animation_banner (GTK_WIDGET (parent_window), NULL,
                        _CS("ckct_nw_pasting"));
@@ -6142,12 +6158,19 @@ modest_ui_actions_on_open_addressbook (GtkAction *action, ModestWindow *win)
 
 
 void
-modest_ui_actions_on_toggle_find_in_page (GtkToggleAction *action,
+modest_ui_actions_on_toggle_find_in_page (GtkAction *action,
                                          ModestWindow *window)
 {
+       gboolean active;
        g_return_if_fail (MODEST_IS_MSG_EDIT_WINDOW (window));
 
-       modest_msg_edit_window_toggle_find_toolbar (MODEST_MSG_EDIT_WINDOW (window), gtk_toggle_action_get_active (action));
+       if (GTK_IS_TOGGLE_ACTION (action))
+               active = gtk_toggle_action_get_active (GTK_TOGGLE_ACTION (action));
+       else
+               active = TRUE;
+
+       modest_msg_edit_window_toggle_find_toolbar (MODEST_MSG_EDIT_WINDOW (window), 
+                                                   active);
 }
 
 static void