Move header window to src/widgets
[modest] / src / modest-ui-actions.c
index f5dd2fd..0c8dd2e 100644 (file)
 #include <tny-camel-folder.h>
 #include <tny-camel-imap-folder.h>
 #include <tny-camel-pop-folder.h>
+#include <widgets/modest-header-window.h>
 #ifdef MODEST_TOOLKIT_HILDON2
 #include <modest-accounts-window.h>
-#include <hildon/hildon-pannable-area.h>
 #include <hildon/hildon-gtk.h>
-#include <modest-header-window.h>
 #include <modest-folder-window.h>
 #include <modest-maemo-utils.h>
 #endif
-
-#ifdef MODEST_PLATFORM_MAEMO
-#include "maemo/modest-osso-state-saving.h"
-#endif /* MODEST_PLATFORM_MAEMO */
-#ifndef MODEST_TOOLKIT_GTK
-#include "maemo/modest-hildon-includes.h"
-#include "maemo/modest-connection-specific-smtp-window.h"
-#endif /* !MODEST_TOOLKIT_GTK */
-#include <modest-utils.h>
-
+#include "modest-utils.h"
+#include "widgets/modest-connection-specific-smtp-window.h"
 #include "widgets/modest-ui-constants.h"
 #include <widgets/modest-main-window.h>
 #include <widgets/modest-msg-view-window.h>
@@ -155,12 +146,14 @@ static void     reply_forward_cb       (ModestMailOperation *mail_op,
 
 static void     reply_forward          (ReplyForwardAction action, ModestWindow *win);
 
+#ifndef MODEST_TOOLKIT_HILDON2
 static void     folder_refreshed_cb    (ModestMailOperation *mail_op,
                                        TnyFolder *folder,
                                        gpointer user_data);
 
 static void     on_send_receive_finished (ModestMailOperation  *mail_op,
                                          gpointer user_data);
+#endif
 
 static gint header_list_count_uncached_msgs (TnyList *header_list);
 
@@ -176,11 +169,13 @@ static void     do_create_folder (GtkWindow *window,
 
 static TnyAccount *get_account_from_folder_store (TnyFolderStore *folder_store);
 
+#ifndef MODEST_TOOLKIT_HILDON2
 static void modest_ui_actions_on_main_window_move_to (GtkAction *action,
                                                      GtkWidget *folder_view,
                                                      TnyFolderStore *dst_folder,
                                                      ModestMainWindow *win);
-#ifdef MODEST_TOOLKIT_HILDON2
+
+#else
 static void modest_ui_actions_on_folder_window_move_to (GtkWidget *folder_view,
                                                        TnyFolderStore *dst_folder,
                                                        TnyList *selection,
@@ -325,14 +320,7 @@ modest_ui_actions_on_about (GtkAction *action, ModestWindow *win)
 static TnyList *
 get_selected_headers (ModestWindow *win)
 {
-       if (MODEST_IS_MAIN_WINDOW(win)) {
-               GtkWidget *header_view;
-
-               header_view = modest_main_window_get_child_widget (MODEST_MAIN_WINDOW(win),
-                                                                  MODEST_MAIN_WINDOW_WIDGET_TYPE_HEADER_VIEW);
-               return modest_header_view_get_selected_headers (MODEST_HEADER_VIEW(header_view));
-
-       } else if (MODEST_IS_MSG_VIEW_WINDOW (win)) {
+       if (MODEST_IS_MSG_VIEW_WINDOW (win)) {
                /* for MsgViewWindows, we simply return a list with one element */
                TnyHeader *header;
                TnyList *list = NULL;
@@ -345,18 +333,26 @@ get_selected_headers (ModestWindow *win)
                }
 
                return list;
+#ifndef MODEST_TOOLKIT_HILDON2
+       } else if (MODEST_IS_MAIN_WINDOW(win)) {
+               GtkWidget *header_view;
 
-#ifdef MODEST_TOOLKIT_HILDON2
+               header_view = modest_main_window_get_child_widget (MODEST_MAIN_WINDOW(win),
+                                                                  MODEST_MAIN_WINDOW_WIDGET_TYPE_HEADER_VIEW);
+               return modest_header_view_get_selected_headers (MODEST_HEADER_VIEW(header_view));
+#else
        } else if (MODEST_IS_HEADER_WINDOW (win)) {
                GtkWidget *header_view;
 
                header_view = GTK_WIDGET (modest_header_window_get_header_view (MODEST_HEADER_WINDOW (win)));
                return modest_header_view_get_selected_headers (MODEST_HEADER_VIEW(header_view));
 #endif
-       } else
+       } else {
                return NULL;
+       }
 }
 
+#ifndef MODEST_TOOLKIT_HILDON2
 static GtkTreeRowReference *
 get_next_after_selected_headers (ModestHeaderView *header_view)
 {
@@ -385,6 +381,7 @@ get_next_after_selected_headers (ModestHeaderView *header_view)
 
        return result;
 }
+#endif
 
 static void
 headers_action_mark_as_read (TnyHeader *header,
@@ -446,26 +443,29 @@ modest_ui_actions_on_edit_mode_delete_message (ModestWindow *win)
        gchar *desc = NULL;
        gint response;
        ModestWindowMgr *mgr;
-       GtkWidget *header_view = NULL;
        gboolean retval = TRUE;
 
        g_return_val_if_fail (MODEST_IS_WINDOW(win), FALSE);
 
+#ifndef MODEST_TOOLKIT_HILDON2
        /* Check first if the header view has the focus */
        if (MODEST_IS_MAIN_WINDOW (win)) {
+               GtkWidget *header_view = NULL;
+
                header_view =
                        modest_main_window_get_child_widget (MODEST_MAIN_WINDOW (win),
                                                             MODEST_MAIN_WINDOW_WIDGET_TYPE_HEADER_VIEW);
                if (!gtk_widget_is_focus (header_view))
                        return FALSE;
        }
-
+#endif
        /* Get the headers, either from the header view (if win is the main window),
         * or from the message view window: */
        header_list = get_selected_headers (win);
        if (!header_list) return FALSE;
 
        /* Check if any of the headers are already opened, or in the process of being opened */
+#ifndef MODEST_TOOLKIT_HILDON2
        if (MODEST_IS_MAIN_WINDOW (win)) {
                gint opened_headers = 0;
 
@@ -495,6 +495,7 @@ modest_ui_actions_on_edit_mode_delete_message (ModestWindow *win)
                        return FALSE;
                }
        }
+#endif
 
        /* Select message */
        if (tny_list_get_length(header_list) == 1) {
@@ -519,20 +520,20 @@ modest_ui_actions_on_edit_mode_delete_message (ModestWindow *win)
        response = modest_platform_run_confirmation_dialog (GTK_WINDOW (win),
                                                            message);
 
-
        if (response == GTK_RESPONSE_OK) {
-               ModestWindowMgr *mgr = NULL;
-               GtkTreeModel *model = NULL;
                GtkTreeSelection *sel = NULL;
-               GList *sel_list = NULL, *tmp = NULL;
-               GtkTreeRowReference *next_row_reference = NULL;
-               GtkTreeRowReference *prev_row_reference = NULL;
-               GtkTreePath *next_path = NULL;
-               GtkTreePath *prev_path = NULL;
+               GList *sel_list = NULL;
                ModestMailOperation *mail_op = NULL;
 
                /* Find last selected row */
+#ifndef MODEST_TOOLKIT_HILDON2
                if (MODEST_IS_MAIN_WINDOW (win)) {
+                       GList *tmp = NULL;
+                       ModestWindowMgr *mgr = NULL;
+                       GtkTreeModel *model = NULL;
+                       GtkTreeRowReference *next_row_reference = NULL, *prev_row_reference = NULL;
+                       GtkTreePath *next_path = NULL, *prev_path = NULL;
+
                        model = gtk_tree_view_get_model (GTK_TREE_VIEW (header_view));
                        sel = gtk_tree_view_get_selection (GTK_TREE_VIEW (header_view));
                        sel_list = gtk_tree_selection_get_selected_rows (sel, &model);
@@ -549,6 +550,7 @@ modest_ui_actions_on_edit_mode_delete_message (ModestWindow *win)
                                }
                        }
                }
+#endif
 
                /* Disable window dimming management */
                modest_window_disable_dimming (win);
@@ -571,6 +573,7 @@ modest_ui_actions_on_edit_mode_delete_message (ModestWindow *win)
 
                        /* Get main window */
                        mgr = modest_runtime_get_window_mgr ();
+#ifndef MODEST_TOOLKIT_HILDON2
                } else if (MODEST_IS_MAIN_WINDOW (win)) {
                        /* Select next or previous row */
                        if (gtk_tree_row_reference_valid (next_row_reference)) {
@@ -589,6 +592,7 @@ modest_ui_actions_on_edit_mode_delete_message (ModestWindow *win)
                                gtk_tree_row_reference_free (prev_row_reference);
                        if (prev_path != NULL)
                                gtk_tree_path_free (prev_path);
+#endif
                }
 
                /* Update toolbar dimming state */
@@ -621,6 +625,7 @@ modest_ui_actions_on_delete_message_or_folder (GtkAction *action, ModestWindow *
        g_return_if_fail (MODEST_IS_WINDOW(win));
 
        /* Check first if the header view has the focus */
+#ifndef MODEST_TOOLKIT_HILDON2
        if (MODEST_IS_MAIN_WINDOW (win)) {
                GtkWidget *w;
                w = modest_main_window_get_child_widget (MODEST_MAIN_WINDOW (win),
@@ -630,6 +635,7 @@ modest_ui_actions_on_delete_message_or_folder (GtkAction *action, ModestWindow *
                        return;
                }
        }
+#endif
        modest_ui_actions_on_delete_message (action, win);
 }
 
@@ -639,7 +645,7 @@ modest_ui_actions_on_quit (GtkAction *action, ModestWindow *win)
        ModestWindowMgr *mgr = NULL;
 
 #ifdef MODEST_PLATFORM_MAEMO
-       modest_osso_save_state();
+       modest_window_mgr_save_state_for_all_windows (modest_runtime_get_window_mgr ());
 #endif /* MODEST_PLATFORM_MAEMO */
 
        g_debug ("closing down, clearing %d item(s) from operation queue",
@@ -686,9 +692,10 @@ modest_ui_actions_on_close_window (GtkAction *action, ModestWindow *win)
 void
 modest_ui_actions_add_to_contacts (GtkAction *action, ModestWindow *win)
 {
-       g_return_if_fail (MODEST_IS_MSG_VIEW_WINDOW (win));
-
-       modest_msg_view_window_add_to_contacts (MODEST_MSG_VIEW_WINDOW (win));
+       if (MODEST_IS_MSG_VIEW_WINDOW (win))
+               modest_msg_view_window_add_to_contacts (MODEST_MSG_VIEW_WINDOW (win));
+       else if (MODEST_IS_MSG_EDIT_WINDOW (win))
+               modest_msg_edit_window_add_to_contacts (MODEST_MSG_EDIT_WINDOW (win));
 }
 
 void
@@ -700,12 +707,8 @@ modest_ui_actions_on_add_to_contacts (GtkAction *action, ModestWindow *win)
        clipboard = gtk_clipboard_get (GDK_SELECTION_PRIMARY);
        selection = gtk_clipboard_wait_for_text (clipboard);
 
-       /* Question: why is the clipboard being used here?
-        * It doesn't really make a lot of sense. */
-
-       if (selection)
-       {
-               modest_address_book_add_address (selection);
+       if (selection) {
+               modest_address_book_add_address (selection, (GtkWindow *) win);
                g_free (selection);
        }
 }
@@ -994,24 +997,42 @@ modest_ui_actions_msg_retrieval_check (ModestMailOperation *mail_op,
                              error->code == TNY_SERVICE_ERROR_MESSAGE_NOT_AVAILABLE)) {
                        gchar *subject, *msg, *format = NULL;
                        TnyAccount *account;
-                       
-                       subject = header?tny_header_dup_subject (header):NULL;
+
+                       subject = (header) ? tny_header_dup_subject (header) : NULL;
                        if (!subject)
                                subject = g_strdup (_("mail_va_no_subject"));
 
                        account = modest_mail_operation_get_account (mail_op);
                        if (account) {
-                               ModestProtocol *protocol;
-                               ModestProtocolType proto;
-                               proto = modest_tny_account_get_protocol_type (account);
-                               protocol = modest_protocol_registry_get_protocol_by_type (modest_runtime_get_protocol_registry (), proto);
-                               if (protocol)
-                                 format = modest_protocol_get_translation (protocol, MODEST_PROTOCOL_TRANSLATION_MSG_NOT_AVAILABLE, subject);
+                               ModestProtocolType proto = modest_tny_account_get_protocol_type (account);
+                               ModestProtocol *protocol = modest_protocol_registry_get_protocol_by_type (modest_runtime_get_protocol_registry (), proto);
+
+                               if (protocol) {
+                                       if (tny_account_get_connection_status (account) ==
+                                           TNY_CONNECTION_STATUS_CONNECTED) {
+                                               if (header) {
+                                                       format = modest_protocol_get_translation (protocol,
+                                                                                                 MODEST_PROTOCOL_TRANSLATION_MSG_NOT_AVAILABLE,
+                                                                                                 subject);
+                                               } else {
+                                                       format = modest_protocol_get_translation (protocol,
+                                                                                                 MODEST_PROTOCOL_TRANSLATION_MSG_NOT_AVAILABLE_LOST_HEADER);
+                                               }
+                                       } else {
+                                               format = g_strdup_printf (_("mail_ib_backend_server_invalid"),
+                                                                         tny_account_get_hostname (account));
+                                       }
+                               }
                                g_object_unref (account);
                        }
 
-                       if (!format)
-                               format = g_strdup (_("emev_ni_ui_imap_message_not_available_in_server"));
+                       if (!format) {
+                               if (header) {
+                                       format = g_strdup (_("emev_ni_ui_imap_message_not_available_in_server"));
+                               } else {
+                                       format = g_strdup (_("emev_ni_ui_pop3_msg_recv_error"));
+                               }
+                       }
 
                        msg = g_strdup_printf (format, subject);
                        modest_platform_run_information_dialog (NULL, msg, FALSE);
@@ -1065,11 +1086,12 @@ get_header_view_from_window (ModestWindow *window)
 {
        GtkWidget *header_view;
 
+#ifndef MODEST_TOOLKIT_HILDON2
        if (MODEST_IS_MAIN_WINDOW (window)) {
                header_view = modest_main_window_get_child_widget (MODEST_MAIN_WINDOW (window),
                                                                   MODEST_MAIN_WINDOW_WIDGET_TYPE_HEADER_VIEW);
-#ifdef MODEST_TOOLKIT_HILDON2
-       } else if (MODEST_IS_HEADER_WINDOW (window)){
+#else
+       if (MODEST_IS_HEADER_WINDOW (window)){
                header_view = GTK_WIDGET (modest_header_window_get_header_view (MODEST_HEADER_WINDOW (window)));
 #endif
        } else {
@@ -1236,10 +1258,12 @@ open_msg_cb (ModestMailOperation *mail_op,
                gtk_widget_show_all (GTK_WIDGET(win));
        }
 
+#ifndef MODEST_TOOLKIT_HILDON2
        /* Update toolbar dimming state */
        if (MODEST_IS_MAIN_WINDOW (parent_win)) {
                modest_ui_actions_check_toolbar_dimming_rules (MODEST_WINDOW (parent_win));
        }
+#endif
 
 cleanup:
        /* Free */
@@ -1540,7 +1564,7 @@ open_msg_from_header (TnyHeader *header, GtkTreeRowReference *rowref, ModestWind
        OpenMsgHelper *helper;
        ModestWindow *window;
 
-       g_return_if_fail (header != NULL && rowref != NULL);
+       g_return_if_fail (header != NULL && rowref != NULL && gtk_tree_row_reference_valid (rowref));
 
        mgr = modest_runtime_get_window_mgr ();
 
@@ -1924,7 +1948,7 @@ reply_forward (ReplyForwardAction action, ModestWindow *win)
        ReplyForwardHelper *rf_helper = NULL;
        guint reply_forward_type;
 
-       g_return_if_fail (MODEST_IS_WINDOW(win));
+       g_return_if_fail (win && MODEST_IS_WINDOW(win));
 
        /* we check for low-mem; in that case, show a warning, and don't allow
         * reply/forward (because it could potentially require a lot of memory */
@@ -2044,7 +2068,7 @@ reply_forward (ReplyForwardAction action, ModestWindow *win)
                        if (folder)
                                g_object_unref (folder);
                } else {
-                       reply_forward_cb (NULL, header, FALSE, NULL, NULL, rf_helper);
+                       reply_forward_cb (NULL, header, FALSE, NULL, NULL, NULL);
                }
                /* Frees */
                g_object_unref (header_list);
@@ -2080,6 +2104,7 @@ void
 modest_ui_actions_on_next (GtkAction *action,
                           ModestWindow *window)
 {
+#ifndef MODEST_TOOLKIT_HILDON2
        if (MODEST_IS_MAIN_WINDOW (window)) {
                GtkWidget *header_view;
 
@@ -2091,9 +2116,11 @@ modest_ui_actions_on_next (GtkAction *action,
 
                modest_header_view_select_next (
                                MODEST_HEADER_VIEW(header_view));
-       } else if (MODEST_IS_MSG_VIEW_WINDOW (window)) {
+#else
+       if (MODEST_IS_MSG_VIEW_WINDOW (window)) {
                modest_msg_view_window_select_next_message (
                                MODEST_MSG_VIEW_WINDOW (window));
+#endif
        } else {
                g_return_if_reached ();
        }
@@ -2105,6 +2132,7 @@ modest_ui_actions_on_prev (GtkAction *action,
 {
        g_return_if_fail (MODEST_IS_WINDOW(window));
 
+#ifndef MODEST_TOOLKIT_HILDON2
        if (MODEST_IS_MAIN_WINDOW (window)) {
                GtkWidget *header_view;
                header_view = modest_main_window_get_child_widget (MODEST_MAIN_WINDOW(window),
@@ -2113,8 +2141,10 @@ modest_ui_actions_on_prev (GtkAction *action,
                        return;
 
                modest_header_view_select_prev (MODEST_HEADER_VIEW(header_view));
-       } else if (MODEST_IS_MSG_VIEW_WINDOW (window)) {
+#else
+       if (MODEST_IS_MSG_VIEW_WINDOW (window)) {
                modest_msg_view_window_select_previous_message (MODEST_MSG_VIEW_WINDOW (window));
+#endif
        } else {
                g_return_if_reached ();
        }
@@ -2128,11 +2158,12 @@ modest_ui_actions_on_sort (GtkAction *action,
 
        g_return_if_fail (MODEST_IS_WINDOW(window));
 
+#ifndef MODEST_TOOLKIT_HILDON2
        if (MODEST_IS_MAIN_WINDOW (window)) {
                header_view = modest_main_window_get_child_widget (MODEST_MAIN_WINDOW(window),
                                                                   MODEST_MAIN_WINDOW_WIDGET_TYPE_HEADER_VIEW);
-#ifdef MODEST_TOOLKIT_HILDON2
-       } else if (MODEST_IS_HEADER_WINDOW (window)) {
+#else
+       if (MODEST_IS_HEADER_WINDOW (window)) {
                header_view = GTK_WIDGET (modest_header_window_get_header_view (MODEST_HEADER_WINDOW (window)));
 #endif
        }
@@ -2148,17 +2179,70 @@ modest_ui_actions_on_sort (GtkAction *action,
 }
 
 static void
-new_messages_arrived (ModestMailOperation *self,
-                     TnyList *new_headers,
-                     gpointer user_data)
+sync_folder_cb (ModestMailOperation *mail_op,
+               TnyFolder *folder,
+               gpointer user_data)
+{
+       ModestHeaderView *header_view = (ModestHeaderView *) user_data;
+
+       if (modest_mail_operation_get_status (mail_op) == MODEST_MAIL_OPERATION_STATUS_SUCCESS) {
+               ModestWindow *parent = (ModestWindow *) modest_mail_operation_get_source (mail_op);
+
+               /* We must clear first, because otherwise set_folder will ignore */
+               /*    the change as the folders are the same */
+               modest_header_view_clear (header_view);
+               modest_header_view_set_folder (header_view, folder, TRUE, parent, NULL, NULL);
+
+               g_object_unref (parent);
+       }
+
+       g_object_unref (header_view);
+}
+
+static gboolean
+idle_refresh_folder (gpointer source)
 {
-       GObject *source;
+       ModestHeaderView *header_view = NULL;
+
+       /* If the window still exists */
+       if (!GTK_IS_WIDGET (source) ||
+           !GTK_WIDGET_VISIBLE (source))
+               return FALSE;
+
+       /* Refresh the current view */
+#ifdef MODEST_TOOLKIT_HILDON2
+       if (MODEST_IS_HEADER_WINDOW (source))
+               header_view = modest_header_window_get_header_view ((ModestHeaderWindow *) source);
+#else
+       if (MODEST_IS_MAIN_WINDOW (source))
+               header_view = MODEST_HEADER_VIEW (modest_main_window_get_child_widget (MODEST_MAIN_WINDOW (source),
+                                                                                      MODEST_MAIN_WINDOW_WIDGET_TYPE_HEADER_VIEW));
+#endif
+       if (header_view) {
+               TnyFolder *folder = modest_header_view_get_folder (header_view);
+               if (folder) {
+                       /* Sync the folder status */
+                       ModestMailOperation *mail_op = modest_mail_operation_new (source);
+                       modest_mail_operation_queue_add (modest_runtime_get_mail_operation_queue (), mail_op);
+                       modest_mail_operation_sync_folder (mail_op, folder, FALSE, sync_folder_cb, g_object_ref (header_view));
+                       g_object_unref (folder);
+                       g_object_unref (mail_op);
+               }
+       }
+
+       return FALSE;
+}
+
+static void
+update_account_cb (ModestMailOperation *self,
+                  TnyList *new_headers,
+                  gpointer user_data)
+{
+       ModestWindow *top;
        gboolean show_visual_notifications;
 
-       source = modest_mail_operation_get_source (self);
-       show_visual_notifications = (source) ? FALSE : TRUE;
-       if (source)
-               g_object_unref (source);
+       top = modest_window_mgr_get_current_top (modest_runtime_get_window_mgr ());
+       show_visual_notifications = (top) ? FALSE : TRUE;
 
        /* Notify new messages have been downloaded. If the
           send&receive was invoked by the user then do not show any
@@ -2206,29 +2290,15 @@ new_messages_arrived (ModestMailOperation *self,
                g_object_unref (actually_new_list);
        }
 
-}
-
-gboolean
-retrieve_all_messages_cb (GObject *source,
-                         guint num_msgs,
-                         guint retrieve_limit)
-{
-       GtkWindow *window;
-       gchar *msg;
-       gint response;
-
-       window = GTK_WINDOW (source);
-       msg = g_strdup_printf (_("mail_nc_msg_count_limit_exceeded"),
-                              num_msgs, retrieve_limit);
-
-       /* Ask the user if they want to retrieve all the messages */
-       response =
-               modest_platform_run_confirmation_dialog_with_buttons (window, msg,
-                                                                     _("mcen_bd_get_all"),
-                                                                     _("mcen_bd_newest_only"));
-       /* Free and return */
-       g_free (msg);
-       return (response == GTK_RESPONSE_ACCEPT) ? TRUE : FALSE;
+       if (top) {
+               /* Refresh the current folder in an idle. We do this
+                  in order to avoid refresh cancelations if the
+                  currently viewed folder is the inbox */
+               g_idle_add_full (G_PRIORITY_DEFAULT_IDLE,
+                                idle_refresh_folder,
+                                g_object_ref (top),
+                                g_object_unref);
+       }
 }
 
 typedef struct {
@@ -2264,6 +2334,7 @@ do_send_receive_performer (gboolean canceled,
                goto clean;
        }
 
+#ifndef MODEST_TOOLKIT_HILDON2
        /* Set send/receive operation in progress */
        if (info->win && MODEST_IS_MAIN_WINDOW (info->win)) {
                modest_main_window_notify_send_receive_initied (MODEST_MAIN_WINDOW (info->win));
@@ -2273,11 +2344,12 @@ do_send_receive_performer (gboolean canceled,
                g_signal_connect (G_OBJECT (info->mail_op), "operation-finished",
                                  G_CALLBACK (on_send_receive_finished),
                                  info->win);
+#endif
 
        /* Send & receive. */
-       modest_mail_operation_update_account (info->mail_op, info->account_name, info->poke_status, info->interactive,
-                                             (info->win) ? retrieve_all_messages_cb : NULL,
-                                             new_messages_arrived, info->win);
+       modest_mail_operation_update_account (info->mail_op, info->account_name,
+                                             info->poke_status, info->interactive,
+                                             update_account_cb, info->win);
 
  clean:
        /* Frees */
@@ -2490,6 +2562,7 @@ modest_ui_actions_on_send_receive (GtkAction *action, ModestWindow *win)
                modest_ui_actions_on_accounts (NULL, win);
 
        /* Refresh the current folder. The if is always TRUE it's just an extra check */
+#ifndef MODEST_TOOLKIT_HILDON2
        if (MODEST_IS_MAIN_WINDOW (win)) {
                GtkWidget *folder_view;
                TnyFolderStore *folder_store;
@@ -2507,8 +2580,8 @@ modest_ui_actions_on_send_receive (GtkAction *action, ModestWindow *win)
                /* Refresh the active account. Force the connection if needed
                   and poke the status of all folders */
                modest_ui_actions_do_send_receive (NULL, TRUE, TRUE, TRUE, win);
-#ifdef MODEST_TOOLKIT_HILDON2
-       } else if (MODEST_IS_ACCOUNTS_WINDOW (win)) {
+#else
+       if (MODEST_IS_ACCOUNTS_WINDOW (win)) {
                modest_ui_actions_do_send_receive_all (win, TRUE, TRUE, TRUE);
 #endif
        } else {
@@ -2520,7 +2593,7 @@ modest_ui_actions_on_send_receive (GtkAction *action, ModestWindow *win)
 
 }
 
-
+#ifndef MODEST_TOOLKIT_HILDON2
 void
 modest_ui_actions_toggle_header_list_view (GtkAction *action, ModestMainWindow *main_window)
 {
@@ -2553,7 +2626,6 @@ modest_ui_actions_toggle_header_list_view (GtkAction *action, ModestMainWindow *
                                      MODEST_CONF_HEADER_VIEW_KEY);
 }
 
-
 void
 modest_ui_actions_on_header_selected (ModestHeaderView *header_view,
                                      TnyHeader *header,
@@ -2590,6 +2662,7 @@ modest_ui_actions_on_header_selected (ModestHeaderView *header_view,
        modest_ui_actions_check_menu_dimming_rules (MODEST_WINDOW (main_window));
        modest_ui_actions_check_toolbar_dimming_rules (MODEST_WINDOW (main_window));
 }
+#endif
 
 void
 modest_ui_actions_on_header_activated (ModestHeaderView *header_view,
@@ -2597,7 +2670,6 @@ modest_ui_actions_on_header_activated (ModestHeaderView *header_view,
                                       GtkTreePath *path,
                                       ModestWindow *window)
 {
-       GtkWidget *open_widget;
        GtkTreeRowReference *rowref;
 
        g_return_if_fail (MODEST_IS_WINDOW(window));
@@ -2616,18 +2688,22 @@ modest_ui_actions_on_header_activated (ModestHeaderView *header_view,
        if (modest_platform_check_memory_low (MODEST_WINDOW(window), TRUE))
                return;
 
+#ifndef MODEST_TOOLKIT_HILDON2
+       GtkWidget *open_widget;
        if (MODEST_IS_MAIN_WINDOW (window)) {
                modest_ui_actions_check_menu_dimming_rules (MODEST_WINDOW (window));
                open_widget = modest_window_get_action_widget (MODEST_WINDOW (window), "/MenuBar/EmailMenu/EmailOpenMenu");
                if (!GTK_WIDGET_IS_SENSITIVE (open_widget))
                        return;
        }
+#endif
 
        rowref = gtk_tree_row_reference_new (gtk_tree_view_get_model (GTK_TREE_VIEW (header_view)), path);
        open_msg_from_header (header, rowref, MODEST_WINDOW (window));
        gtk_tree_row_reference_free (rowref);
 }
 
+#ifndef MODEST_TOOLKIT_HILDON2
 static void
 set_active_account_from_tny_account (TnyAccount *account,
                                     ModestWindow *window)
@@ -2658,7 +2734,6 @@ set_active_account_from_tny_account (TnyAccount *account,
        g_object_unref (modest_server_account);
 }
 
-
 static void
 folder_refreshed_cb (ModestMailOperation *mail_op,
                     TnyFolder *folder,
@@ -2788,6 +2863,7 @@ modest_ui_actions_on_folder_selection_changed (ModestFolderView *folder_view,
        modest_ui_actions_check_menu_dimming_rules (MODEST_WINDOW (main_window));
        modest_ui_actions_check_toolbar_dimming_rules (MODEST_WINDOW (main_window));
 }
+#endif
 
 void
 modest_ui_actions_on_item_not_found (ModestHeaderView *header_view,ModestItemType type,
@@ -2973,7 +3049,6 @@ modest_ui_actions_on_save_to_drafts (GtkWidget *widget, ModestMsgEditWindow *edi
        gchar *account_name;
        ModestAccountMgr *account_mgr;
        gboolean had_error = FALSE;
-       ModestMainWindow *win = NULL;
 
        g_return_val_if_fail (MODEST_IS_MSG_EDIT_WINDOW(edit_window), FALSE);
 
@@ -3044,6 +3119,8 @@ modest_ui_actions_on_save_to_drafts (GtkWidget *widget, ModestMsgEditWindow *edi
        modest_platform_information_banner (NULL, NULL, text);
        g_free (text);
 #else
+       ModestMainWindow *win = NULL;
+
        /* Use the main window as the parent of the banner, if the
           main window does not exist it won't be shown, if the parent
           window exists then it's properly shown. We don't use the
@@ -3066,6 +3143,7 @@ modest_ui_actions_on_save_to_drafts (GtkWidget *widget, ModestMsgEditWindow *edi
 
        modest_msg_edit_window_free_msg_data (edit_window, data);
 
+#ifndef MODEST_TOOLKIT_HILDON2
        /* ** FIXME **
         * If the drafts folder is selected then make the header view
         * insensitive while the message is being saved to drafts
@@ -3100,6 +3178,7 @@ modest_ui_actions_on_save_to_drafts (GtkWidget *widget, ModestMsgEditWindow *edi
                        if (folder != NULL) g_object_unref(folder);
                }
        }
+#endif
 
        return !had_error;
 }
@@ -3118,17 +3197,12 @@ modest_ui_actions_on_send (GtkWidget *widget, ModestMsgEditWindow *edit_window)
 
        g_return_val_if_fail (MODEST_IS_MSG_EDIT_WINDOW(edit_window), TRUE);
 
-       if (!modest_msg_edit_window_check_names (edit_window, TRUE))
+       /* Check names but do not automatically add them to addressbook */
+       if (!modest_msg_edit_window_check_names (edit_window, FALSE))
                return TRUE;
 
        data = modest_msg_edit_window_get_msg_data (edit_window);
 
-       if (data->subject == NULL || data->subject[0] == '\0') {
-               /* Empty subject -> no send */
-               modest_msg_edit_window_free_msg_data (edit_window, data);
-               return FALSE;
-       }
-
        recipients = g_strconcat (data->to?data->to:"", 
                                  data->cc?data->cc:"",
                                  data->bcc?data->bcc:"",
@@ -3164,7 +3238,7 @@ modest_ui_actions_on_send (GtkWidget *widget, ModestMsgEditWindow *edit_window)
        }
 
        /* Get the currently-active transport account for this modest account: */
-       if (strcmp (account_name, MODEST_LOCAL_FOLDERS_ACCOUNT_ID) != 0) {
+       if (account_name && strcmp (account_name, MODEST_LOCAL_FOLDERS_ACCOUNT_ID) != 0) {
                transport_account =
                        TNY_TRANSPORT_ACCOUNT(modest_tny_account_store_get_server_account
                                              (modest_runtime_get_account_store (),
@@ -3423,11 +3497,13 @@ do_create_folder_cb (ModestMailOperation *mail_op,
                 * FIXME: any other? */
                GtkWidget *folder_view;
 
+#ifndef MODEST_TOOLKIT_HILDON2
                if (MODEST_IS_MAIN_WINDOW(source_win))
                        folder_view =
                                modest_main_window_get_child_widget (MODEST_MAIN_WINDOW (source_win),
                                                                     MODEST_MAIN_WINDOW_WIDGET_TYPE_FOLDER_VIEW);
                else
+#endif
                        folder_view = GTK_WIDGET(g_object_get_data (G_OBJECT (source_win),
                                                                    MODEST_MOVE_TO_DIALOG_FOLDER_VIEW));
 
@@ -3467,7 +3543,7 @@ do_create_folder_performer (gboolean canceled,
 
                /* This happens if we have selected the outbox folder
                   as the parent */
-               if (err->code == TNY_SERVICE_ERROR_UNKNOWN &&
+               if (err && err->code == TNY_SERVICE_ERROR_UNKNOWN &&
                    TNY_IS_MERGE_FOLDER (helper->parent)) {
                        /* Show an error and retry */
                        modest_platform_information_banner ((GtkWidget *) parent_window,
@@ -3562,6 +3638,7 @@ modest_ui_actions_on_new_folder (GtkAction *action, ModestWindow *window)
 
        g_return_if_fail (MODEST_IS_WINDOW(window));
 
+#ifndef MODEST_TOOLKIT_HILDON2
        if (MODEST_IS_MAIN_WINDOW (window)) {
                GtkWidget *folder_view;
 
@@ -3571,8 +3648,8 @@ modest_ui_actions_on_new_folder (GtkAction *action, ModestWindow *window)
                        return;
 
                modest_ui_actions_create_folder (GTK_WIDGET (window), folder_view, NULL);
-#ifdef MODEST_TOOLKIT_HILDON2
-       } else if (MODEST_IS_FOLDER_WINDOW (window)) {
+#else
+       if (MODEST_IS_FOLDER_WINDOW (window)) {
                GtkWidget *folder_view;
 
                folder_view = GTK_WIDGET (modest_folder_window_get_folder_view (MODEST_FOLDER_WINDOW (window)));
@@ -3644,8 +3721,10 @@ on_rename_folder_cb (ModestMailOperation *mail_op,
        /* Note that if the rename fails new_folder will be NULL */
        if (new_folder) {
                modest_folder_view_select_folder (folder_view, new_folder, FALSE);
+#ifndef MODEST_TOOLKIT_HILDON2
        } else {
                modest_folder_view_select_first_inbox_or_local (folder_view);
+#endif
        }
        gtk_widget_grab_focus (GTK_WIDGET (folder_view));
 }
@@ -3676,15 +3755,15 @@ on_rename_folder_performer (gboolean canceled,
 
                modest_mail_operation_queue_add (modest_runtime_get_mail_operation_queue (),
                                mail_op);
-
+#ifndef MODEST_TOOLKIT_HILDON2
                if (MODEST_IS_MAIN_WINDOW(parent_window)) {
 
                        folder_view = modest_main_window_get_child_widget (
                                MODEST_MAIN_WINDOW (parent_window),
                                MODEST_MAIN_WINDOW_WIDGET_TYPE_FOLDER_VIEW);
                }
-#ifdef MODEST_TOOLKIT_HILDON2
-               else if (MODEST_IS_FOLDER_WINDOW (parent_window)) {
+#else
+               if (MODEST_IS_FOLDER_WINDOW (parent_window)) {
                        ModestFolderWindow *folder_window = (ModestFolderWindow *) parent_window;
                        folder_view = GTK_WIDGET (modest_folder_window_get_folder_view (folder_window));
                }
@@ -3724,14 +3803,14 @@ modest_ui_actions_on_edit_mode_rename_folder (ModestWindow *window)
 
        g_return_val_if_fail (MODEST_IS_WINDOW(window), FALSE);
 
+#ifndef MODEST_TOOLKIT_HILDON2
        if (MODEST_IS_MAIN_WINDOW (window)) {
                folder_view = modest_main_window_get_child_widget (MODEST_MAIN_WINDOW (window),
                                                                   MODEST_MAIN_WINDOW_WIDGET_TYPE_FOLDER_VIEW);
                if (!folder_view)
                        return FALSE;
-
-#ifdef MODEST_TOOLKIT_HILDON2
-       } else if (MODEST_IS_FOLDER_WINDOW (window)) {
+#else
+       if (MODEST_IS_FOLDER_WINDOW (window)) {
                folder_view = GTK_WIDGET (modest_folder_window_get_folder_view (MODEST_FOLDER_WINDOW (window)));
 #endif
        } else {
@@ -3812,12 +3891,13 @@ on_delete_folder_cb (gboolean canceled,
                return;
        }
 
+#ifndef MODEST_TOOLKIT_HILDON2
        if (MODEST_IS_MAIN_WINDOW (parent_window)) {
                folder_view = modest_main_window_get_child_widget (
                        MODEST_MAIN_WINDOW (parent_window),
                        MODEST_MAIN_WINDOW_WIDGET_TYPE_FOLDER_VIEW);
-#ifdef MODEST_TOOLKIT_HILDON2
-       } else if (MODEST_IS_FOLDER_WINDOW (parent_window)) {
+#else
+       if (MODEST_IS_FOLDER_WINDOW (parent_window)) {
                folder_view = GTK_WIDGET (modest_folder_window_get_folder_view (MODEST_FOLDER_WINDOW (parent_window)));
 #endif
        } else {
@@ -3840,10 +3920,12 @@ on_delete_folder_cb (gboolean canceled,
                        mail_op);
        modest_mail_operation_remove_folder (mail_op, TNY_FOLDER (info->folder), info->move_to_trash);
 
+#ifndef MODEST_TOOLKIT_HILDON2
        modest_folder_view_select_first_inbox_or_local (MODEST_FOLDER_VIEW (folder_view));
+#endif
 
-       g_object_unref (G_OBJECT (mail_op));
-       g_object_unref (G_OBJECT (info->folder));
+       g_object_unref (mail_op);
+       g_object_unref (info->folder);
        g_free (info);
 }
 
@@ -3857,12 +3939,13 @@ delete_folder (ModestWindow *window, gboolean move_to_trash)
 
        g_return_val_if_fail (MODEST_IS_WINDOW(window), FALSE);
 
+#ifndef MODEST_TOOLKIT_HILDON2
        if (MODEST_IS_MAIN_WINDOW (window)) {
 
                folder_view = modest_main_window_get_child_widget (MODEST_MAIN_WINDOW (window),
                                                                   MODEST_MAIN_WINDOW_WIDGET_TYPE_FOLDER_VIEW);
-#ifdef MODEST_TOOLKIT_HILDON2
-       } else if (MODEST_IS_FOLDER_WINDOW (window)) {
+#else
+       if (MODEST_IS_FOLDER_WINDOW (window)) {
                folder_view = GTK_WIDGET (modest_folder_window_get_folder_view (MODEST_FOLDER_WINDOW (window)));
 #endif
        } else {
@@ -3893,22 +3976,23 @@ delete_folder (ModestWindow *window, gboolean move_to_trash)
        g_free (message);
 
        if (response == GTK_RESPONSE_OK) {
-               DeleteFolderInfo *info;
+               TnyAccount *account = NULL;
+               DeleteFolderInfo *info = NULL;
                info = g_new0(DeleteFolderInfo, 1);
-               info->folder = folder;
+               info->folder = g_object_ref (folder);
                info->move_to_trash = move_to_trash;
-               g_object_ref (G_OBJECT (info->folder));
-               TnyAccount *account = tny_folder_get_account (TNY_FOLDER (folder));
+
+               account = tny_folder_get_account (TNY_FOLDER (folder));
                modest_platform_connect_if_remote_and_perform (GTK_WINDOW (window),
                                                               TRUE,
                                                               TNY_FOLDER_STORE (account),
                                                               on_delete_folder_cb, info);
                g_object_unref (account);
+               g_object_unref (folder);
                return TRUE;
        } else {
                return FALSE;
        }
-       g_object_unref (G_OBJECT (folder));
 }
 
 void
@@ -3926,6 +4010,7 @@ modest_ui_actions_on_edit_mode_delete_folder (ModestWindow *window)
        return delete_folder (window, FALSE);
 }
 
+#ifndef MODEST_TOOLKIT_HILDON2
 void
 modest_ui_actions_on_move_folder_to_trash_folder (GtkAction *action, ModestMainWindow *main_window)
 {
@@ -3933,7 +4018,7 @@ modest_ui_actions_on_move_folder_to_trash_folder (GtkAction *action, ModestMainW
 
        delete_folder (MODEST_WINDOW (main_window), TRUE);
 }
-
+#endif
 
 typedef struct _PasswordDialogFields {
        GtkWidget *username;
@@ -3948,19 +4033,11 @@ password_dialog_check_field (GtkEditable *editable,
        const gchar *value;
        gboolean any_value_empty = FALSE;
 
-#ifdef MODEST_TOOLKIT_HILDON2
-       value = hildon_entry_get_text (HILDON_ENTRY (fields->username));
-#else
-       value = gtk_entry_get_text (GTK_ENTRY (fields->username));
-#endif
+       value = modest_entry_get_text (fields->username);
        if ((value == NULL) || value[0] == '\0') {
                any_value_empty = TRUE;
        }
-#ifdef MODEST_TOOLKIT_HILDON2
-       value = hildon_entry_get_text (HILDON_ENTRY (fields->password));
-#else
-       value = gtk_entry_get_text (GTK_ENTRY (fields->password));
-#endif
+       value = modest_entry_get_text (fields->password);
        if ((value == NULL) || value[0] == '\0') {
                any_value_empty = TRUE;
        }
@@ -4049,15 +4126,10 @@ modest_ui_actions_on_password_requested (TnyAccountStore *account_store,
        gchar *initial_username = modest_account_mgr_get_server_account_username (
                modest_runtime_get_account_mgr(), server_account_name);
 
-#ifdef MODEST_TOOLKIT_HILDON2
-       GtkWidget *entry_username = hildon_entry_new (HILDON_SIZE_FINGER_HEIGHT | HILDON_SIZE_AUTO_WIDTH);
+       GtkWidget *entry_username = modest_toolkit_factory_create_entry (modest_runtime_get_toolkit_factory ());
        if (initial_username)
-               hildon_entry_set_text (HILDON_ENTRY (entry_username), initial_username);
-#else
-       GtkWidget *entry_username = gtk_entry_new ();
-       if (initial_username)
-               gtk_entry_set_text (GTK_ENTRY (entry_username), initial_username);
-#endif
+               modest_entry_set_text (entry_username, initial_username);
+
        /* Dim this if a connection has ever succeeded with this username,
         * as per the UI spec: */
        /* const gboolean username_known =  */
@@ -4070,7 +4142,6 @@ modest_ui_actions_on_password_requested (TnyAccountStore *account_store,
         */
        gtk_widget_set_sensitive (entry_username, FALSE);
 
-#ifndef MODEST_TOOLKIT_GTK
        /* 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);
 
@@ -4079,54 +4150,33 @@ modest_ui_actions_on_password_requested (TnyAccountStore *account_store,
         * We use GTK_SIZE_GROUP_HORIZONTAL, so that the widths are the same. */
        GtkSizeGroup *sizegroup = gtk_size_group_new(GTK_SIZE_GROUP_HORIZONTAL);
 
-#ifdef MODEST_TOOLKIT_HILDON2
-       GtkWidget *caption = modest_maemo_utils_create_captioned (sizegroup, NULL,
-                                                                 _("mail_fi_username"), FALSE,
-                                                                 entry_username);
-#else
-       GtkWidget *caption = hildon_caption_new (sizegroup,
-               _("mail_fi_username"), entry_username, NULL, HILDON_CAPTION_MANDATORY);
-#endif
+       GtkWidget *caption = modest_toolkit_utils_create_captioned (sizegroup, NULL,
+                                                                   _("mail_fi_username"), FALSE,
+                                                                   entry_username);
        gtk_widget_show (entry_username);
        gtk_box_pack_start (GTK_BOX(GTK_DIALOG(dialog)->vbox), caption,
                FALSE, FALSE, MODEST_MARGIN_HALF);
        gtk_widget_show (caption);
-#else
-       gtk_box_pack_start (GTK_BOX(GTK_DIALOG(dialog)->vbox), entry_username,
-                           TRUE, FALSE, 0);
-#endif /* !MODEST_TOOLKIT_GTK */
 
        /* password: */
-#ifdef MODEST_TOOLKIT_HILDON2
-       GtkWidget *entry_password = hildon_entry_new (HILDON_SIZE_FINGER_HEIGHT | HILDON_SIZE_AUTO_WIDTH);
-#else
-       GtkWidget *entry_password = gtk_entry_new ();
-#endif
+       GtkWidget *entry_password = modest_toolkit_factory_create_entry (modest_runtime_get_toolkit_factory ());
        gtk_entry_set_visibility (GTK_ENTRY(entry_password), FALSE);
        /* gtk_entry_set_invisible_char (GTK_ENTRY(entry_password), "*"); */
 
-#ifndef MODEST_TOOLKIT_GTK
        /* Auto-capitalization is the default, so let's turn it off: */
+#ifdef MAEMO_CHANGES
        hildon_gtk_entry_set_input_mode (GTK_ENTRY (entry_password),
                HILDON_GTK_INPUT_MODE_FULL | HILDON_GTK_INPUT_MODE_INVISIBLE);
-
-#ifdef MODEST_TOOLKIT_HILDON2
-       caption = modest_maemo_utils_create_captioned (sizegroup, NULL,
-                                                      _("mail_fi_password"), FALSE,
-                                                      entry_password);
-#else
-       caption = hildon_caption_new (sizegroup,
-               _("mail_fi_password"), entry_password, NULL, HILDON_CAPTION_MANDATORY);
 #endif
+
+       caption = modest_toolkit_utils_create_captioned (sizegroup, NULL,
+                                                        _("mail_fi_password"), FALSE,
+                                                        entry_password);
        gtk_widget_show (entry_password);
        gtk_box_pack_start (GTK_BOX(GTK_DIALOG(dialog)->vbox), caption,
                FALSE, FALSE, MODEST_MARGIN_HALF);
        gtk_widget_show (caption);
        g_object_unref (sizegroup);
-#else
-       gtk_box_pack_start (GTK_BOX(GTK_DIALOG(dialog)->vbox), entry_password,
-                           TRUE, FALSE, 0);
-#endif /* !MODEST_TOOLKIT_GTK */
 
        if (initial_username != NULL)
                gtk_widget_grab_focus (GTK_WIDGET (entry_password));
@@ -4152,11 +4202,7 @@ modest_ui_actions_on_password_requested (TnyAccountStore *account_store,
 
                if (gtk_dialog_run (GTK_DIALOG(dialog)) == GTK_RESPONSE_ACCEPT) {
                        if (username) {
-#ifdef MODEST_TOOLKIT_HILDON2
-                               *username = g_strdup (hildon_entry_get_text (HILDON_ENTRY(entry_username)));
-#else
-                               *username = g_strdup (gtk_entry_get_text (GTK_ENTRY(entry_username)));
-#endif
+                               *username = g_strdup (modest_entry_get_text (entry_username));
 
                                /* Note that an empty field becomes the "" string */
                                if (*username && strlen (*username) > 0) {
@@ -4182,11 +4228,7 @@ modest_ui_actions_on_password_requested (TnyAccountStore *account_store,
                        }
 
                        if (password) {
-#ifdef MODEST_TOOLKIT_HILDON2
-                               *password = g_strdup (hildon_entry_get_text (HILDON_ENTRY(entry_password)));
-#else
-                               *password = g_strdup (gtk_entry_get_text (GTK_ENTRY(entry_password)));
-#endif
+                               *password = g_strdup (modest_entry_get_text (entry_password));
 
                                /* We do not save the password in the configuration,
                                 * because this function is only called for passwords that should
@@ -4359,16 +4401,16 @@ void
 modest_ui_actions_on_undo (GtkAction *action,
                           ModestWindow *window)
 {
-       ModestEmailClipboard *clipboard = NULL;
-
        if (MODEST_IS_MSG_EDIT_WINDOW (window)) {
                modest_msg_edit_window_undo (MODEST_MSG_EDIT_WINDOW (window));
+#ifndef MODEST_TOOLKIT_HILDON2
        } else if (MODEST_IS_MAIN_WINDOW (window)) {
+               ModestEmailClipboard *clipboard = NULL;
                /* Clear clipboard source */
                clipboard = modest_runtime_get_email_clipboard ();
                modest_email_clipboard_clear (clipboard);
-       }
-       else {
+#endif
+       } else {
                g_return_if_reached ();
        }
 }
@@ -4587,6 +4629,7 @@ modest_ui_actions_on_select_all (GtkAction *action,
                gtk_text_buffer_select_range (buffer, &start, &end);
        } else if (GTK_IS_HTML (focused_widget)) {
                gtk_html_select_all (GTK_HTML (focused_widget));
+#ifndef MODEST_TOOLKIT_HILDON2
        } else if (MODEST_IS_MAIN_WINDOW (window)) {
                GtkWidget *header_view = focused_widget;
                GtkTreeSelection *selection = NULL;
@@ -4610,6 +4653,7 @@ modest_ui_actions_on_select_all (GtkAction *action,
                modest_window_enable_dimming (MODEST_WINDOW(window));
                modest_ui_actions_check_menu_dimming_rules (MODEST_WINDOW (window));
                modest_ui_actions_check_toolbar_dimming_rules (MODEST_WINDOW (window));
+#endif
        }
 
 }
@@ -4774,7 +4818,7 @@ modest_ui_actions_on_details (GtkAction *action,
                        g_object_unref (header);
                }
                g_object_unref (msg);
-
+#ifndef MODEST_TOOLKIT_HILDON2
        } else if (MODEST_IS_MAIN_WINDOW (win)) {
                GtkWidget *folder_view, *header_view;
 
@@ -4804,7 +4848,7 @@ modest_ui_actions_on_details (GtkAction *action,
                        /* Show details of each header */
                        do_headers_action (win, headers_action_show_details, header_view);
                }
-#ifdef MODEST_TOOLKIT_HILDON2
+#else
        } else if (MODEST_IS_HEADER_WINDOW (win)) {
                TnyFolder *folder;
                GtkWidget *header_view;
@@ -4848,6 +4892,7 @@ modest_ui_actions_on_toggle_show_bcc (GtkToggleAction *toggle,
        modest_msg_edit_window_show_bcc (window, gtk_toggle_action_get_active (toggle));
 }
 
+#ifndef MODEST_TOOLKIT_HILDON2
 void
 modest_ui_actions_toggle_folders_view (GtkAction *action,
                                       ModestMainWindow *main_window)
@@ -4859,6 +4904,7 @@ modest_ui_actions_toggle_folders_view (GtkAction *action,
        else
                modest_main_window_set_style (main_window, MODEST_MAIN_WINDOW_STYLE_SIMPLE);
 }
+#endif
 
 void
 modest_ui_actions_on_toggle_toolbar (GtkToggleAction *toggle,
@@ -5087,7 +5133,6 @@ on_move_to_dialog_response (GtkDialog *dialog,
        parent_win = (GtkWidget *) helper->win;
        folder_view = MODEST_FOLDER_VIEW (g_object_get_data (G_OBJECT (dialog),
                                                             MODEST_MOVE_TO_DIALOG_FOLDER_VIEW));
-
        switch (response) {
                TnyFolderStore *dst_folder;
                TnyFolderStore *selected;
@@ -5104,6 +5149,7 @@ on_move_to_dialog_response (GtkDialog *dialog,
        case GTK_RESPONSE_OK:
                dst_folder = modest_folder_view_get_selected (folder_view);
 
+#ifndef MODEST_TOOLKIT_HILDON2
                if (MODEST_IS_MAIN_WINDOW (parent_win)) {
                        /* Clean list to move used for filtering */
                        modest_folder_view_set_list_to_move (folder_view, NULL);
@@ -5112,8 +5158,8 @@ on_move_to_dialog_response (GtkDialog *dialog,
                                                                  GTK_WIDGET (folder_view),
                                                                  dst_folder,
                                                                  MODEST_MAIN_WINDOW (parent_win));
-#ifdef MODEST_TOOLKIT_HILDON2
-               } else if (MODEST_IS_FOLDER_WINDOW (parent_win)) {
+#else
+               if (MODEST_IS_FOLDER_WINDOW (parent_win)) {
                        /* Clean list to move used for filtering */
                        modest_folder_view_set_list_to_move (folder_view, NULL);
 
@@ -5205,8 +5251,8 @@ create_move_to_dialog (GtkWindow *win,
 
                modest_folder_view_set_style (MODEST_FOLDER_VIEW (tree_view),
                                              MODEST_FOLDER_VIEW_STYLE_SHOW_ALL);
-               modest_folder_view_update_model (MODEST_FOLDER_VIEW (tree_view),
-                                                TNY_ACCOUNT_STORE (modest_runtime_get_account_store ()));
+               /* modest_folder_view_update_model (MODEST_FOLDER_VIEW (tree_view), */
+               /*                               TNY_ACCOUNT_STORE (modest_runtime_get_account_store ())); */
 
                active_account_name = modest_window_get_active_account (MODEST_WINDOW (win));
                mgr = modest_runtime_get_account_mgr ();
@@ -5344,6 +5390,7 @@ move_to_cb (ModestMailOperation *mail_op,
                        /* No more messages to view, so close this window */
                        modest_ui_actions_on_close_window (NULL, MODEST_WINDOW(self));
                }
+#ifndef MODEST_TOOLKIT_HILDON2
        } else if (MODEST_IS_MAIN_WINDOW (object) &&
                   gtk_tree_row_reference_valid (helper->reference)) {
                GtkWidget *header_view;
@@ -5360,6 +5407,7 @@ move_to_cb (ModestMailOperation *mail_op,
                gtk_tree_selection_unselect_all (sel);
                gtk_tree_selection_select_path (sel, path);
                gtk_tree_path_free (path);
+#endif
        }
        g_object_unref (object);
 
@@ -5373,11 +5421,12 @@ folder_move_to_cb (ModestMailOperation *mail_op,
                   TnyFolder *new_folder,
                   gpointer user_data)
 {
-       GtkWidget *folder_view;
        GObject *object;
 
        object = modest_mail_operation_get_source (mail_op);
+#ifndef MODEST_TOOLKIT_HILDON2
        if (MODEST_IS_MAIN_WINDOW (object)) {
+               GtkWidget *folder_view;
                folder_view = modest_main_window_get_child_widget (MODEST_MAIN_WINDOW(object),
                                                                   MODEST_MAIN_WINDOW_WIDGET_TYPE_FOLDER_VIEW);
                g_object_ref (folder_view);
@@ -5386,6 +5435,9 @@ folder_move_to_cb (ModestMailOperation *mail_op,
                modest_folder_view_select_folder (MODEST_FOLDER_VIEW (folder_view), new_folder, FALSE);
                g_object_unref (folder_view);
        } else {
+#else
+               {
+#endif
                move_to_cb (mail_op, user_data);
        }
 }
@@ -5447,6 +5499,7 @@ modest_ui_actions_move_folder_error_handler (ModestMailOperation *mail_op,
                g_object_unref (win);
 }
 
+#ifndef MODEST_TOOLKIT_HILDON2
 static void
 open_msg_for_purge_cb (ModestMailOperation *mail_op,
                       TnyHeader *header,
@@ -5589,6 +5642,7 @@ modest_ui_actions_on_main_window_remove_attachments (GtkAction *action,
        if (header_list)
                g_object_unref (header_list);
 }
+#endif
 
 /*
  * Checks if we need a connection to do the transfer and if the user
@@ -5679,20 +5733,20 @@ xfer_messages_error_handler (ModestMailOperation *mail_op,
 
        win = modest_mail_operation_get_source (mail_op);
        error = modest_mail_operation_get_error (mail_op);
-       account = modest_mail_operation_get_account (mail_op);
 
-       if (error && modest_tny_account_store_is_disk_full_error (modest_runtime_get_account_store(),
-                                                                 (GError *) error, account)) {
-               gchar *msg = g_strdup_printf (_KR("cerm_device_memory_full"), "");
-               modest_platform_information_banner ((GtkWidget *) win, NULL, msg);
-               g_free (msg);
-       } else {
+       /* We cannot get the account from the mail op as that is the
+          source account and for checking memory full conditions we
+          need the destination one */
+       account = TNY_ACCOUNT (user_data);
+
+       if (error &&
+           !modest_tny_account_store_check_disk_full_error (modest_runtime_get_account_store(),
+                                                            (GtkWidget *) win, (GError*) error,
+                                                            account, _KR("cerm_memory_card_full"))) {
                modest_platform_run_information_dialog ((GtkWindow *) win,
                                                        _("mail_in_ui_folder_move_target_error"),
                                                        FALSE);
        }
-       if (account)
-               g_object_unref (account);
        if (win)
                g_object_unref (win);
 }
@@ -5737,8 +5791,7 @@ xfer_messages_performer  (gboolean canceled,
        /* tinymail will return NULL for local folders it seems */
        dst_forbids_message_add = modest_protocol_registry_protocol_type_has_tag (modest_runtime_get_protocol_registry (),
                                                                                  modest_tny_account_get_protocol_type (dst_account),
-                                                                                 MODEST_PROTOCOL_REGISTRY_STORE_FORBID_MESSAGE_ADD);
-       g_object_unref (dst_account);
+                                                                                 MODEST_PROTOCOL_REGISTRY_STORE_FORBID_INCOMING_XFERS);
 
        if (dst_forbids_message_add) {
                modest_platform_information_banner (GTK_WIDGET (win),
@@ -5758,7 +5811,6 @@ xfer_messages_performer  (gboolean canceled,
                g_object_ref (movehelper->banner);
                gtk_widget_show (GTK_WIDGET (movehelper->banner));
        }
-#endif
 
        if (MODEST_IS_MAIN_WINDOW (win)) {
                GtkWidget *header_view =
@@ -5766,11 +5818,13 @@ xfer_messages_performer  (gboolean canceled,
                                                             MODEST_MAIN_WINDOW_WIDGET_TYPE_HEADER_VIEW);
                movehelper->reference = get_next_after_selected_headers (MODEST_HEADER_VIEW (header_view));
        }
+#endif
 
        /* Perform the mail operation */
        mail_op = modest_mail_operation_new_with_error_handling (G_OBJECT(win),
                                                                 xfer_messages_error_handler,
-                                                                movehelper, NULL);
+                                                                g_object_ref (dst_account),
+                                                                g_object_unref);
        modest_mail_operation_queue_add (modest_runtime_get_mail_operation_queue (),
                                         mail_op);
 
@@ -5783,6 +5837,8 @@ xfer_messages_performer  (gboolean canceled,
 
        g_object_unref (G_OBJECT (mail_op));
  end:
+       if (dst_account)
+               g_object_unref (dst_account);
        g_object_unref (helper->dst_folder);
        g_object_unref (helper->headers);
        g_slice_free (XferMsgsHelper, helper);
@@ -5850,10 +5906,12 @@ on_move_folder_cb (gboolean canceled,
        modest_mail_operation_queue_add (modest_runtime_get_mail_operation_queue (),
                                         mail_op);
 
+#ifndef MODEST_TOOLKIT_HILDON2
        if (MODEST_IS_MAIN_WINDOW (parent_window)) {
                modest_folder_view_select_folder (MODEST_FOLDER_VIEW(info->folder_view),
                                                  TNY_FOLDER (info->dst_folder), TRUE);
        }
+#endif
        modest_mail_operation_xfer_folder (mail_op,
                        TNY_FOLDER (info->src_folder),
                        info->dst_folder,
@@ -5880,6 +5938,7 @@ get_account_from_folder_store (TnyFolderStore *folder_store)
                return tny_folder_get_account (TNY_FOLDER (folder_store));
 }
 
+#ifndef MODEST_TOOLKIT_HILDON2
 /*
  * UI handler for the "Move to" action when invoked from the
  * ModestMainWindow
@@ -5948,6 +6007,7 @@ modest_ui_actions_on_main_window_move_to (GtkAction *action,
        /* Frees */
        g_object_unref (src_folder);
 }
+#endif
 
 #ifdef MODEST_TOOLKIT_HILDON2
 /*
@@ -6226,9 +6286,13 @@ void
 modest_ui_actions_remove_attachments (GtkAction *action,
                                      ModestWindow *window)
 {
+#ifndef MODEST_TOOLKIT_HILDON2
        if (MODEST_IS_MAIN_WINDOW (window)) {
                modest_ui_actions_on_main_window_remove_attachments (action, MODEST_MAIN_WINDOW (window));
        } else if (MODEST_IS_MSG_VIEW_WINDOW (window)) {
+#else
+       if (MODEST_IS_MSG_VIEW_WINDOW (window)) {
+#endif
                modest_msg_view_window_remove_attachments (MODEST_MSG_VIEW_WINDOW (window), FALSE);
        } else {
                /* not supported window for this action */
@@ -6533,10 +6597,11 @@ modest_ui_actions_on_toggle_find_in_page (GtkAction *action,
        else
                active = TRUE;
 
-       modest_msg_edit_window_toggle_find_toolbar (MODEST_MSG_EDIT_WINDOW (window),
-                                                   active);
+       modest_msg_edit_window_toggle_isearch_toolbar (MODEST_MSG_EDIT_WINDOW (window),
+                                                      active);
 }
 
+#ifndef MODEST_TOOLKIT_HILDON2
 static void
 on_send_receive_finished (ModestMailOperation  *mail_op,
                           gpointer user_data)
@@ -6589,7 +6654,7 @@ on_send_receive_finished (ModestMailOperation  *mail_op,
        if (folder_store)
                g_object_unref (folder_store);
 }
-
+#endif
 
 void
 modest_ui_actions_on_send_queue_error_happened (TnySendQueue *self,
@@ -6765,6 +6830,7 @@ modest_ui_actions_get_msg_already_deleted_error_msg (ModestWindow *win)
        ModestProtocol *protocol;
        TnyHeader *header = NULL;
 
+#ifndef MODEST_TOOLKIT_HILDON2
        if (MODEST_IS_MAIN_WINDOW (win)) {
                GtkWidget *header_view;
                TnyList* headers = NULL;
@@ -6782,8 +6848,8 @@ modest_ui_actions_get_msg_already_deleted_error_msg (ModestWindow *win)
                folder = TNY_FOLDER_STORE (tny_header_get_folder (header));
                g_object_unref (iter);
                g_object_unref (headers);
-#ifdef MODEST_TOOLKIT_HILDON2
-       } else if (MODEST_IS_HEADER_WINDOW (win)) {
+#else
+       if (MODEST_IS_HEADER_WINDOW (win)) {
                GtkWidget *header_view;
                TnyList* headers = NULL;
                TnyIterator *iter;