Do not lose focus when rename fails (fixes NB#84791).
[modest] / src / modest-ui-actions.c
index e119a10..9e8cd82 100644 (file)
@@ -164,11 +164,6 @@ static GtkWidget* get_folder_view_from_move_to_dialog (GtkWidget *move_to_dialog
 
 static TnyAccount *get_account_from_folder_store (TnyFolderStore *folder_store);
 
-static void transfer_messages_helper (GtkWindow *win,
-                                     TnyFolder *src_folder,
-                                     TnyList *headers,
-                                     TnyFolder *dst_folder);
-
 /*
  * This function checks whether a TnyFolderStore is a pop account
  */
@@ -531,7 +526,7 @@ modest_ui_actions_on_delete_message (GtkAction *action, ModestWindow *win)
                        if (prev_row_reference != NULL) 
                                gtk_tree_row_reference_free (prev_row_reference);
                        if (prev_path != NULL) 
-                               gtk_tree_path_free (prev_path);                         
+                               gtk_tree_path_free (prev_path);
                }
                
                /* Update toolbar dimming state */
@@ -653,7 +648,6 @@ modest_ui_actions_on_accounts (GtkAction *action,
        } else {
                /* Show the list of accounts */
                GtkWindow *account_win = GTK_WINDOW (modest_account_view_window_new ());
-               gtk_window_set_transient_for (account_win, GTK_WINDOW (win));
                
                /* The accounts dialog must be modal */
                modest_window_mgr_set_modal (modest_runtime_get_window_mgr (), account_win);
@@ -754,7 +748,7 @@ modest_ui_actions_compose_msg(ModestWindow *win,
                body = use_signature ? g_strconcat("\n", signature, NULL) : g_strdup("");
        }
 
-       msg = modest_tny_msg_new (to_str, from_str, cc_str, bcc_str, subject_str, body, NULL);
+       msg = modest_tny_msg_new (to_str, from_str, cc_str, bcc_str, subject_str, body, NULL, NULL);
        if (!msg) {
                g_printerr ("modest: failed to create new msg\n");
                goto cleanup;
@@ -772,7 +766,7 @@ modest_ui_actions_compose_msg(ModestWindow *win,
                                attachments->data, allowed_size);
 
                if (total_size > allowed_size) {
-                       g_warning ("%s: total size: %u", 
+                       g_warning ("%s: total size: %u",
                                   __FUNCTION__, (unsigned int)total_size);
                        break;
                }
@@ -909,7 +903,7 @@ open_msg_cb (ModestMailOperation *mail_op,
                        char *msg_id;
                        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);
+                       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 */
@@ -1037,6 +1031,9 @@ modest_ui_actions_disk_operations_error_handler (ModestMailOperation *mail_op,
                        modest_platform_information_banner ((GtkWidget *) win,
                                                            NULL, dgettext("ke-recv",
                                                                           "cerm_device_memory_full"));
+               } else if (error->code == MODEST_MAIL_OPERATION_ERROR_FILE_IO) {
+                       modest_platform_information_banner ((GtkWidget *) win,
+                                                           NULL, dgettext ("hildon-common-strings", "sfil_ni_unable_to_open_file_not_found"));
                } else if (user_data) {
                        modest_platform_information_banner ((GtkWidget *) win, 
                                                            NULL, user_data);
@@ -1999,7 +1996,7 @@ modest_ui_actions_do_cancel_send (const gchar *account_name,
        }
 
        /* Get send queue*/
-       send_queue = TNY_SEND_QUEUE (modest_runtime_get_send_queue (transport_account));
+       send_queue = TNY_SEND_QUEUE (modest_runtime_get_send_queue (transport_account, TRUE));
        if (!TNY_IS_SEND_QUEUE(send_queue)) {
                g_set_error (&error, MODEST_MAIL_OPERATION_ERROR,
                             MODEST_MAIL_OPERATION_ERROR_ITEM_NOT_FOUND,
@@ -2191,6 +2188,7 @@ modest_ui_actions_on_header_activated (ModestHeaderView *header_view,
                                       ModestMainWindow *main_window)
 {
        TnyList *headers;
+       GtkWidget *open_widget;
 
        g_return_if_fail (MODEST_IS_MAIN_WINDOW(main_window));
 
@@ -2208,6 +2206,10 @@ modest_ui_actions_on_header_activated (ModestHeaderView *header_view,
        if (modest_platform_check_memory_low (MODEST_WINDOW(main_window)))
                return;
 
+       modest_ui_actions_check_menu_dimming_rules (MODEST_WINDOW (main_window));
+       open_widget = modest_window_get_action_widget (MODEST_WINDOW (main_window), "/MenuBar/EmailMenu/EmailOpenMenu");
+       if (!GTK_WIDGET_IS_SENSITIVE (open_widget))
+               return;
 
 /*     headers = tny_simple_list_new (); */
 /*     tny_list_prepend (headers, G_OBJECT (header)); */
@@ -2514,7 +2516,6 @@ modest_ui_actions_on_save_to_drafts (GtkWidget *widget, ModestMsgEditWindow *edi
                return FALSE;
        }
 
-               
        /*
         * djcb: if we're in low-memory state, we only allow for
         * saving messages smaller than
@@ -2529,6 +2530,21 @@ modest_ui_actions_on_save_to_drafts (GtkWidget *widget, ModestMsgEditWindow *edi
                }
        }
 
+       /*
+        * djcb: we also make sure that the attachments are smaller than the max size
+        * this is for the case where we'd try to forward a message with attachments 
+        * bigger than our max allowed size, or sending an message from drafts which
+        * somehow got past our checks when attaching.
+        */
+       if (expected_size > MODEST_MAX_ATTACHMENT_SIZE) {
+               modest_platform_run_information_dialog (
+                       GTK_WINDOW(edit_window),
+                       dgettext("ke-recv","memr_ib_operation_disabled"),
+                       TRUE);
+               modest_msg_edit_window_free_msg_data (edit_window, data);
+               return FALSE;
+       }
+
        account_name = g_strdup (data->account_name);
        account_mgr = modest_runtime_get_account_mgr();
        if (!account_name)
@@ -2684,6 +2700,20 @@ modest_ui_actions_on_send (GtkWidget *widget, ModestMsgEditWindow *edit_window)
                }
        }
 
+       /*
+        * djcb: we also make sure that the attachments are smaller than the max size
+        * this is for the case where we'd try to forward a message with attachments 
+        * bigger than our max allowed size, or sending an message from drafts which
+        * somehow got past our checks when attaching.
+        */
+       if (expected_size > MODEST_MAX_ATTACHMENT_SIZE) {
+               modest_platform_run_information_dialog (
+                       GTK_WINDOW(edit_window),
+                       dgettext("ke-recv","memr_ib_operation_disabled"),
+                       TRUE);
+               modest_msg_edit_window_free_msg_data (edit_window, data);
+               return FALSE;
+       }
 
        ModestAccountMgr *account_mgr = modest_runtime_get_account_mgr();
        gchar *account_name = g_strdup (data->account_name);
@@ -2718,7 +2748,7 @@ modest_ui_actions_on_send (GtkWidget *widget, ModestMsgEditWindow *edit_window)
        gchar *from = modest_account_mgr_get_from_string (account_mgr, account_name);
 
        /* Create the mail operation */
-       ModestMailOperation *mail_operation = modest_mail_operation_new (NULL);
+       ModestMailOperation *mail_operation = modest_mail_operation_new_with_error_handling (NULL, modest_ui_actions_disk_operations_error_handler, NULL, NULL);
        modest_mail_operation_queue_add (modest_runtime_get_mail_operation_queue (), mail_operation);
 
        modest_mail_operation_send_new_mail (mail_operation,
@@ -3093,6 +3123,11 @@ on_rename_folder_cb (ModestMailOperation *mail_op,
 {
        ModestFolderView *folder_view;
 
+       /* If the window was closed when renaming a folder this could
+          happen */
+       if (!MODEST_IS_FOLDER_VIEW (user_data))
+               return;
+
        folder_view = MODEST_FOLDER_VIEW (user_data);
        /* Note that if the rename fails new_folder will be NULL */
        if (new_folder) {
@@ -3332,6 +3367,30 @@ modest_ui_actions_on_move_folder_to_trash_folder (GtkAction *action, ModestMainW
 }
 
 
+typedef struct _PasswordDialogFields {
+       GtkWidget *username;
+       GtkWidget *password;
+       GtkWidget *dialog;
+} PasswordDialogFields;
+
+static void
+password_dialog_check_field (GtkEditable *editable,
+                            PasswordDialogFields *fields)
+{
+       const gchar *value;
+       gboolean any_value_empty = FALSE;
+
+       value = gtk_entry_get_text (GTK_ENTRY (fields->username));
+       if ((value == NULL) || value[0] == '\0') {
+               any_value_empty = TRUE;
+       }
+       value = gtk_entry_get_text (GTK_ENTRY (fields->password));
+       if ((value == NULL) || value[0] == '\0') {
+               any_value_empty = TRUE;
+       }
+       gtk_dialog_set_response_sensitive (GTK_DIALOG (fields->dialog), GTK_RESPONSE_ACCEPT, !any_value_empty);
+}
+
 void
 modest_ui_actions_on_password_requested (TnyAccountStore *account_store, 
                                         const gchar* server_account_name,
@@ -3343,6 +3402,7 @@ modest_ui_actions_on_password_requested (TnyAccountStore *account_store,
 {
        g_return_if_fail(server_account_name);
        gboolean completed = FALSE;
+       PasswordDialogFields *fields = NULL;
        
        /* Initalize output parameters: */
        if (cancel)
@@ -3403,11 +3463,16 @@ modest_ui_actions_on_password_requested (TnyAccountStore *account_store,
                gtk_entry_set_text (GTK_ENTRY (entry_username), initial_username);
        /* Dim this if a connection has ever succeeded with this username,
         * as per the UI spec: */
-       const gboolean username_known = 
-               modest_account_mgr_get_server_account_username_has_succeeded(
-                       modest_runtime_get_account_mgr(), server_account_name);
-       gtk_widget_set_sensitive (entry_username, !username_known);
-       
+       /* const gboolean username_known =  */
+       /*      modest_account_mgr_get_server_account_username_has_succeeded( */
+       /*              modest_runtime_get_account_mgr(), server_account_name); */
+       /* gtk_widget_set_sensitive (entry_username, !username_known); */
+
+       /* We drop the username sensitive code and disallow changing it here
+        * as tinymail does not support really changing the username in the callback
+        */
+       gtk_widget_set_sensitive (entry_username, FALSE);
+
 #ifdef MODEST_PLATFORM_MAEMO
        /* Auto-capitalization is the default, so let's turn it off: */
        hildon_gtk_entry_set_input_mode (GTK_ENTRY (entry_username), HILDON_GTK_INPUT_MODE_FULL);
@@ -3459,6 +3524,15 @@ modest_ui_actions_on_password_requested (TnyAccountStore *account_store,
                            TRUE, FALSE, 0);
 */
 
+       fields = g_slice_new0 (PasswordDialogFields);
+       fields->username = entry_username;
+       fields->password = entry_password;
+       fields->dialog = dialog;
+
+       g_signal_connect (entry_username, "changed", G_CALLBACK (password_dialog_check_field), fields);
+       g_signal_connect (entry_password, "changed", G_CALLBACK (password_dialog_check_field), fields);
+       password_dialog_check_field (NULL, fields);
+
        gtk_widget_show_all (GTK_WIDGET(GTK_DIALOG(dialog)->vbox));
 
        while (!completed) {
@@ -3522,6 +3596,7 @@ modest_ui_actions_on_password_requested (TnyAccountStore *account_store,
 */
 
        gtk_widget_destroy (dialog);
+       g_slice_free (PasswordDialogFields, fields);
        
        /* printf ("DEBUG: %s: cancel=%d\n", __FUNCTION__, *cancel); */
 }
@@ -4944,10 +5019,9 @@ xfer_messages_performer  (gboolean canceled,
        headers = get_selected_headers (MODEST_WINDOW (win));
        if (!headers) {
                g_warning ("%s: no headers selected", __FUNCTION__);
-               return;
+               goto end;
        }
 
-
        if (dst_is_pop) {
                modest_platform_information_banner (GTK_WIDGET (win),
                                                    NULL,
@@ -4955,7 +5029,7 @@ xfer_messages_performer  (gboolean canceled,
                                                             "mail_in_ui_folder_move_targets_error",
                                                             tny_list_get_length (headers)));
                g_object_unref (headers);
-               return;
+               goto end;
        }
 
        MoveToHelper *helper = g_new0 (MoveToHelper, 1);
@@ -5135,8 +5209,8 @@ modest_ui_actions_on_main_window_move_to (GtkAction *action,
                headers = modest_header_view_get_selected_headers(header_view);
 
                /* Transfer the messages */
-               transfer_messages_helper (GTK_WINDOW (win), TNY_FOLDER (src_folder), 
-                                         headers, TNY_FOLDER (dst_folder));
+               modest_ui_actions_transfer_messages_helper (GTK_WINDOW (win), TNY_FOLDER (src_folder), 
+                                                           headers, TNY_FOLDER (dst_folder));
 
                g_object_unref (headers);
        }
@@ -5146,11 +5220,11 @@ modest_ui_actions_on_main_window_move_to (GtkAction *action,
 }
 
 
-static void
-transfer_messages_helper (GtkWindow *win,
-                         TnyFolder *src_folder,
-                         TnyList *headers,
-                         TnyFolder *dst_folder)
+void
+modest_ui_actions_transfer_messages_helper (GtkWindow *win,
+                                           TnyFolder *src_folder,
+                                           TnyList *headers,
+                                           TnyFolder *dst_folder)
 {
        gboolean need_connection = TRUE;
        gboolean do_xfer = TRUE;
@@ -5176,8 +5250,7 @@ transfer_messages_helper (GtkWindow *win,
        } else {
                TnyAccount *src_account = get_account_from_folder_store (TNY_FOLDER_STORE (src_folder));
                xfer_messages_performer (FALSE, NULL, GTK_WINDOW (win),
-                                        src_account, 
-                                        g_object_ref (dst_folder));
+                                        src_account, g_object_ref (dst_folder));
                g_object_unref (src_account);
        }
 }
@@ -5204,8 +5277,8 @@ modest_ui_actions_on_msg_view_window_move_to (GtkAction *action,
        tny_list_append (headers, G_OBJECT (header));
 
        /* Transfer the messages */
-       transfer_messages_helper (GTK_WINDOW (win), src_folder, headers, 
-                                 TNY_FOLDER (dst_folder));
+       modest_ui_actions_transfer_messages_helper (GTK_WINDOW (win), src_folder, headers, 
+                                                   TNY_FOLDER (dst_folder));
 
        /* Frees */
        g_object_unref (header);