* Fixes NB#85378, show the connection specific SMTP and not the account settings...
[modest] / src / modest-ui-actions.c
index 765dc88..f69a922 100644 (file)
@@ -526,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 */
@@ -648,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);
@@ -656,18 +655,6 @@ modest_ui_actions_on_accounts (GtkAction *action,
        }
 }
 
-#ifdef MODEST_PLATFORM_MAEMO
-static void
-on_smtp_servers_window_hide (GtkWindow* window, gpointer user_data)
-{
-       /* Save any changes. */
-       modest_connection_specific_smtp_window_save_server_accounts (
-                       MODEST_CONNECTION_SPECIFIC_SMTP_WINDOW (window));
-       gtk_widget_destroy (GTK_WIDGET (window));
-}
-#endif
-
-
 void
 modest_ui_actions_on_smtp_servers (GtkAction *action, ModestWindow *win)
 {
@@ -683,14 +670,10 @@ modest_ui_actions_on_smtp_servers (GtkAction *action, ModestWindow *win)
                MODEST_CONNECTION_SPECIFIC_SMTP_WINDOW (specific_window), 
                modest_runtime_get_account_mgr());
 
-       /* Show the window: */  
-       gtk_window_set_transient_for (GTK_WINDOW (specific_window), GTK_WINDOW (win));
-       gtk_window_set_modal (GTK_WINDOW (specific_window), TRUE);
+       /* Show the window: */
+       modest_window_mgr_set_modal (modest_runtime_get_window_mgr (), 
+                                    GTK_WINDOW (specific_window));
        gtk_widget_show (specific_window);
-    
-       /* Save changes when the window is hidden: */
-       g_signal_connect (specific_window, "hide", 
-               G_CALLBACK (on_smtp_servers_window_hide), win);
 #endif /* MODEST_PLATFORM_MAEMO */
 }
 
@@ -849,7 +832,8 @@ open_msg_banner_idle (gpointer userdata)
        gdk_threads_enter ();
        banner_info->idle_handler = 0;
        banner_info->banner = modest_platform_animation_banner (NULL, NULL, banner_info->message);
-       g_object_ref (banner_info->banner);
+       if (banner_info)
+               g_object_ref (banner_info->banner);
        
        gdk_threads_leave ();
 
@@ -904,7 +888,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 */
@@ -945,17 +929,28 @@ open_msg_cb (ModestMailOperation *mail_op,
                if (from_header) {
                        GSList *accounts = modest_account_mgr_account_names (mgr, TRUE);
                        GSList *node = NULL;
+                       gchar *from_header_email;
+
+                       from_header_email = modest_text_utils_get_email_address ((const gchar *) from_header);
+
                        for (node = accounts; node != NULL; node = g_slist_next (node)) {
-                               gchar *from = modest_account_mgr_get_from_string (mgr, node->data);
+                               gchar *from, *from_email;
                                
-                               if (from && (strcmp (from_header, from) == 0)) {
-                                       g_free (account);
-                                       account = g_strdup (node->data);
+                               from = modest_account_mgr_get_from_string (mgr, node->data);
+                               if (from) {
+                                       from_email = modest_text_utils_get_email_address ((const gchar *) from);
+                                       if (strcmp (from_header_email, from_email) == 0) {
+                                               g_free (account);
+                                               account = g_strdup (node->data);
+                                               g_free (from_email);
+                                               g_free (from);
+                                               break;
+                                       }
+                                       g_free (from_email);
                                        g_free (from);
-                                       break;
                                }
-                               g_free (from);
                        }
+                       g_free (from_header_email);
                        g_free (from_header);
                        g_slist_foreach (accounts, (GFunc) g_free, NULL);
                        g_slist_free (accounts);
@@ -1703,6 +1698,7 @@ reply_forward (ReplyForwardAction action, ModestWindow *win)
                                
                                modest_mail_operation_get_msg (mail_op,
                                                               header,
+                                                              TRUE,
                                                               reply_forward_cb,
                                                               rf_helper);
                                /* Clean */
@@ -1997,7 +1993,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,
@@ -2189,6 +2185,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));
 
@@ -2206,6 +2203,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)); */
@@ -3121,7 +3122,7 @@ on_rename_folder_cb (ModestMailOperation *mail_op,
 
        /* If the window was closed when renaming a folder this could
           happen */
-       if (MODEST_IS_FOLDER_VIEW (user_data))
+       if (!MODEST_IS_FOLDER_VIEW (user_data))
                return;
 
        folder_view = MODEST_FOLDER_VIEW (user_data);
@@ -3131,6 +3132,7 @@ on_rename_folder_cb (ModestMailOperation *mail_op,
        } else {
                modest_folder_view_select_first_inbox_or_local (folder_view);
        }
+       gtk_widget_grab_focus (GTK_WIDGET (folder_view));       
 }
 
 static void
@@ -3363,6 +3365,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,
@@ -3374,6 +3400,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)
@@ -3434,11 +3461,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);
@@ -3490,6 +3522,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) {
@@ -3553,6 +3594,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); */
 }
@@ -3732,8 +3774,10 @@ paste_as_attachment_free (gpointer data)
 {
        PasteAsAttachmentHelper *helper = (PasteAsAttachmentHelper *) data;
 
-       gtk_widget_destroy (helper->banner);
-       g_object_unref (helper->banner);
+       if (helper->banner) {
+               gtk_widget_destroy (helper->banner);
+               g_object_unref (helper->banner);
+       }
        g_free (helper);
 }
 
@@ -3787,7 +3831,6 @@ modest_ui_actions_on_paste (GtkAction *action,
                        mail_op = modest_mail_operation_new (G_OBJECT (window));
                        if (helper->banner != NULL) {
                                g_object_ref (G_OBJECT (helper->banner));
-                               gtk_window_set_modal (GTK_WINDOW (helper->banner), FALSE);
                                gtk_widget_show (GTK_WIDGET (helper->banner));
                        }
 
@@ -4623,8 +4666,10 @@ move_to_cb (ModestMailOperation *mail_op,
         }
 
        /* Close the "Pasting" information banner */
-       gtk_widget_destroy (GTK_WIDGET(helper->banner));
-       g_object_unref (helper->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);
@@ -4819,7 +4864,7 @@ modest_ui_actions_on_main_window_remove_attachments (GtkAction *action,
                                                                         modest_ui_actions_disk_operations_error_handler,
                                                                         NULL, NULL);
                modest_mail_operation_queue_add (modest_runtime_get_mail_operation_queue (), mail_op);
-               modest_mail_operation_get_msg (mail_op, header, open_msg_for_purge_cb, win);
+               modest_mail_operation_get_msg (mail_op, header, FALSE, open_msg_for_purge_cb, win);
                
                g_object_unref (mail_op);
        }
@@ -4993,7 +5038,6 @@ xfer_messages_performer  (gboolean canceled,
                                                           _CS("ckct_nw_pasting"));
        if (helper->banner != NULL)  {
                g_object_ref (helper->banner);
-               gtk_window_set_modal (GTK_WINDOW(helper->banner), FALSE);
                gtk_widget_show (GTK_WIDGET(helper->banner));
        }
 
@@ -5051,7 +5095,6 @@ on_move_folder_cb (gboolean canceled, GError *err, GtkWindow *parent_window,
                        _CS("ckct_nw_pasting"));
        if (helper->banner != NULL)  {
                g_object_ref (helper->banner);
-               gtk_window_set_modal (GTK_WINDOW(helper->banner), FALSE);
                gtk_widget_show (GTK_WIDGET(helper->banner));
        }
        /* Clean folder on header view before moving it */