Do ignore '\n' when splitting addresses
[modest] / src / modest-ui-actions.c
index ed34ece..a471477 100644 (file)
 #include <tny-camel-pop-folder.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>
@@ -654,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",
@@ -701,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
@@ -2176,6 +2168,27 @@ modest_ui_actions_on_sort (GtkAction *action,
        modest_utils_run_sort_dialog (GTK_WINDOW (window), MODEST_SORT_HEADERS);
 }
 
+static void
+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)
 {
@@ -2192,18 +2205,18 @@ idle_refresh_folder (gpointer source)
                header_view = modest_header_window_get_header_view ((ModestHeaderWindow *) source);
 #else
        if (MODEST_IS_MAIN_WINDOW (source))
-               header_view = modest_main_window_get_child_widget ((ModestMainWindow *) source,
-                                                                  MODEST_MAIN_WINDOW_WIDGET_TYPE_HEADER_VIEW);
+               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) {
-                       /* 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,
-                                                      (ModestWindow *) source, NULL, NULL);
+                       /* 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);
                }
        }
 
@@ -2215,11 +2228,11 @@ update_account_cb (ModestMailOperation *self,
                   TnyList *new_headers,
                   gpointer user_data)
 {
-       GObject *source;
+       ModestWindow *top;
        gboolean show_visual_notifications;
 
-       source = modest_mail_operation_get_source (self);
-       show_visual_notifications = (source) ? FALSE : TRUE;
+       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
@@ -2267,15 +2280,14 @@ update_account_cb (ModestMailOperation *self,
                g_object_unref (actually_new_list);
        }
 
-       if (source) {
+       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 (source),
+                                g_object_ref (top),
                                 g_object_unref);
-               g_object_unref (source);
        }
 }
 
@@ -3175,7 +3187,8 @@ 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);
@@ -4010,19 +4023,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;
        }
@@ -4111,15 +4116,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 =  */
@@ -4159,11 +4159,7 @@ modest_ui_actions_on_password_requested (TnyAccountStore *account_store,
 #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), "*"); */
 
@@ -4172,14 +4168,9 @@ modest_ui_actions_on_password_requested (TnyAccountStore *account_store,
        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
        gtk_widget_show (entry_password);
        gtk_box_pack_start (GTK_BOX(GTK_DIALOG(dialog)->vbox), caption,
                FALSE, FALSE, MODEST_MARGIN_HALF);
@@ -4214,11 +4205,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) {
@@ -4244,11 +4231,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
@@ -6617,8 +6600,8 @@ 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