* Added an attribute sent to the msg edit window that specifies that the mail has...
[modest] / src / maemo / modest-msg-edit-window.c
index 40880c1..c120bb0 100644 (file)
 #include "modest-scroll-area.h"
 
 #include "modest-hildon-includes.h"
+#ifdef MODEST_HAVE_HILDON0_WIDGETS
+#include <hildon-widgets/hildon-color-chooser.h>
+#endif
 #include "widgets/modest-msg-edit-window-ui.h"
+#ifdef MODEST_HAVE_HILDON0_WIDGETS
+#include <libgnomevfs/gnome-vfs-mime-utils.h>
+#else
 #include <libgnomevfs/gnome-vfs-mime.h>
+#endif
+#include "modest-maemo-utils.h"
 
 
 #define DEFAULT_FONT_SIZE 3
 #define DEFAULT_SIZE_COMBOBOX_WIDTH 80
 #define DEFAULT_MAIN_VBOX_SPACING 6
 #define SUBJECT_MAX_LENGTH 1000
+#define IMAGE_MAX_WIDTH 640
 
 static void  modest_msg_edit_window_class_init   (ModestMsgEditWindowClass *klass);
 static void  modest_msg_edit_window_init         (ModestMsgEditWindow *obj);
 static void  modest_msg_edit_window_finalize     (GObject *obj);
 
 static gboolean msg_body_focus (GtkWidget *focus, GdkEventFocus *event, gpointer userdata);
-static void  to_field_changed (GtkTextBuffer *buffer, ModestMsgEditWindow *editor);
+static void  recpt_field_changed (GtkTextBuffer *buffer, ModestMsgEditWindow *editor);
 static void  send_insensitive_press (GtkWidget *widget, ModestMsgEditWindow *editor);
 static void  style_insensitive_press (GtkWidget *widget, ModestMsgEditWindow *editor);
+static void  remove_attachment_insensitive_press (GtkWidget *widget, ModestMsgEditWindow *editor);
+static void  zoom_insensitive_press (GtkWidget *widget, ModestMsgEditWindow *editor);
+static void  paste_insensitive_press (GtkWidget *widget, ModestMsgEditWindow *editor);
 static void  setup_insensitive_handlers (ModestMsgEditWindow *editor);
 static void  reset_modified (ModestMsgEditWindow *editor);
-static gboolean is_modified (ModestMsgEditWindow *editor);
 
 static void  text_buffer_refresh_attributes (WPTextBuffer *buffer, ModestMsgEditWindow *window);
 static void  text_buffer_delete_range (GtkTextBuffer *buffer, GtkTextIter *start, GtkTextIter *end, gpointer userdata);
@@ -116,9 +127,24 @@ static void modest_msg_edit_window_show_toolbar   (ModestWindow *window,
 static void modest_msg_edit_window_clipboard_owner_change (GtkClipboard *clipboard,
                                                           GdkEvent *event,
                                                           ModestMsgEditWindow *window);
+static void modest_msg_edit_window_system_clipboard_owner_change (GtkClipboard *clipboard,
+                                                                 GdkEvent *event,
+                                                                 ModestMsgEditWindow *window);
 static void update_window_title (ModestMsgEditWindow *window);
 static void update_dimmed (ModestMsgEditWindow *window);
-
+static void update_paste_dimming (ModestMsgEditWindow *window);
+static void update_select_all_dimming (ModestMsgEditWindow *window);
+static void update_zoom_dimming (ModestMsgEditWindow *window);
+
+/* Find toolbar */
+static void modest_msg_edit_window_find_toolbar_search (GtkWidget *widget,
+                                                       ModestMsgEditWindow *window);
+static void modest_msg_edit_window_find_toolbar_close (GtkWidget *widget,
+                                                      ModestMsgEditWindow *window);
+static void edit_menu_activated (GtkAction *action,
+                                gpointer userdata);
+static void view_menu_activated (GtkAction *action,
+                                gpointer userdata);
 
 /* list my signals */
 enum {
@@ -156,8 +182,11 @@ struct _ModestMsgEditWindowPrivate {
        GtkWidget   *font_tool_button_label;
        GSList      *size_items_group;
        GtkWidget   *size_tool_button_label;
+       
+       GtkWidget   *find_toolbar;
 
        GtkWidget   *scroll;
+       GtkWidget   *scroll_area;
 
        gint last_cid;
        GList *attachments;
@@ -167,8 +196,10 @@ struct _ModestMsgEditWindowPrivate {
        gdouble zoom_level;
        
        gulong      clipboard_change_handler_id;
+       gulong      system_clipboard_change_handler_id;
 
        TnyMsg      *draft_msg;
+       gboolean    sent;
 };
 
 #define MODEST_MSG_EDIT_WINDOW_GET_PRIVATE(o)      (G_TYPE_INSTANCE_GET_PRIVATE((o), \
@@ -265,8 +296,12 @@ modest_msg_edit_window_init (ModestMsgEditWindow *obj)
 
        priv->priority_flags = 0;
 
+       priv->find_toolbar = NULL;
+
        priv->draft_msg = NULL;
        priv->clipboard_change_handler_id = 0;
+       priv->system_clipboard_change_handler_id = 0;
+       priv->sent = FALSE;
 }
 
 
@@ -282,11 +317,11 @@ get_transports (void)
        
        ModestAccountMgr *account_mgr = modest_runtime_get_account_mgr();
        GSList *accounts = modest_account_mgr_account_names (account_mgr, 
-                                               TRUE /* only enabled accounts. */); 
+                                                            TRUE /* only enabled accounts. */); 
                                                
        GSList *cursor = accounts;
        while (cursor) {
-               const gchar *account_name = cursor->data;
+               gchar *account_name = cursor->data;
                gchar *from_string  = NULL;
                if (account_name) {
                        from_string = modest_account_mgr_get_from_string (account_mgr,
@@ -294,7 +329,7 @@ get_transports (void)
                }
                
                if (from_string && account_name) {
-                       gchar *name = g_strdup (account_name);
+                       gchar *name = account_name;
                        ModestPair *pair = modest_pair_new ((gpointer) name,
                                                (gpointer) from_string , TRUE);
                        transports = g_slist_prepend (transports, pair);
@@ -302,7 +337,8 @@ get_transports (void)
                
                cursor = cursor->next;
        }
-       g_slist_free (accounts);
+       g_slist_free (accounts); /* only free the accounts, not the elements,
+                                 * because they are used in the pairlist */
        return transports;
 }
 
@@ -316,9 +352,9 @@ init_window (ModestMsgEditWindow *obj)
 
        GtkSizeGroup *size_group;
        GtkWidget *frame;
-       GtkWidget *scroll_area;
        GtkWidget *subject_box;
        GtkWidget *attachment_icon;
+       GtkWidget *window_box;
 
        priv = MODEST_MSG_EDIT_WINDOW_GET_PRIVATE(obj);
 
@@ -338,7 +374,8 @@ init_window (ModestMsgEditWindow *obj)
        priv->priority_icon = gtk_image_new ();
        gtk_box_pack_start (GTK_BOX (subject_box), priv->priority_icon, FALSE, FALSE, 0);
        priv->subject_field = gtk_entry_new_with_max_length (SUBJECT_MAX_LENGTH);
-       g_object_set (G_OBJECT (priv->subject_field), "hildon-input-mode", HILDON_GTK_INPUT_MODE_FULL, NULL);
+       hildon_gtk_entry_set_input_mode (GTK_ENTRY (priv->subject_field), 
+                                        HILDON_GTK_INPUT_MODE_FULL | HILDON_GTK_INPUT_MODE_AUTOCAP);
        gtk_box_pack_start (GTK_BOX (subject_box), priv->subject_field, TRUE, TRUE, 0);
        priv->add_attachment_button = gtk_button_new ();
        GTK_WIDGET_UNSET_FLAGS (GTK_WIDGET (priv->add_attachment_button), GTK_CAN_FOCUS);
@@ -385,6 +422,9 @@ init_window (ModestMsgEditWindow *obj)
 /*     gtk_text_buffer_set_can_paste_rich_text (priv->text_buffer, TRUE); */
        wp_text_buffer_reset_buffer (WP_TEXT_BUFFER (priv->text_buffer), TRUE);
 
+       priv->find_toolbar = hildon_find_toolbar_new (NULL);
+       gtk_widget_set_no_show_all (priv->find_toolbar, TRUE);
+
        g_signal_connect (G_OBJECT (priv->text_buffer), "refresh_attributes",
                          G_CALLBACK (text_buffer_refresh_attributes), obj);
        g_signal_connect (G_OBJECT (priv->text_buffer), "delete-range",
@@ -409,10 +449,17 @@ init_window (ModestMsgEditWindow *obj)
        g_signal_connect (G_OBJECT (priv->msg_body), "focus-out-event",
                          G_CALLBACK (msg_body_focus), obj);
        g_signal_connect (G_OBJECT (modest_recpt_editor_get_buffer (MODEST_RECPT_EDITOR (priv->to_field))),
-                         "changed", G_CALLBACK (to_field_changed), obj);
-       to_field_changed (modest_recpt_editor_get_buffer (MODEST_RECPT_EDITOR (priv->to_field)), MODEST_MSG_EDIT_WINDOW (obj));
+                         "changed", G_CALLBACK (recpt_field_changed), obj);
+       g_signal_connect (G_OBJECT (modest_recpt_editor_get_buffer (MODEST_RECPT_EDITOR (priv->cc_field))),
+                         "changed", G_CALLBACK (recpt_field_changed), obj);
+       g_signal_connect (G_OBJECT (modest_recpt_editor_get_buffer (MODEST_RECPT_EDITOR (priv->bcc_field))),
+                         "changed", G_CALLBACK (recpt_field_changed), obj);
+       recpt_field_changed (modest_recpt_editor_get_buffer (MODEST_RECPT_EDITOR (priv->to_field)), MODEST_MSG_EDIT_WINDOW (obj));
        g_signal_connect (G_OBJECT (priv->subject_field), "changed", G_CALLBACK (subject_field_changed), obj);
 
+       g_signal_connect (G_OBJECT (priv->find_toolbar), "close", G_CALLBACK (modest_msg_edit_window_find_toolbar_close), obj);
+       g_signal_connect (G_OBJECT (priv->find_toolbar), "search", G_CALLBACK (modest_msg_edit_window_find_toolbar_search), obj);
+
        priv->scroll = gtk_scrolled_window_new (NULL, NULL);
        gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (priv->scroll), GTK_POLICY_NEVER, GTK_POLICY_AUTOMATIC);
        gtk_scrolled_window_set_shadow_type (GTK_SCROLLED_WINDOW (priv->scroll), GTK_SHADOW_NONE);
@@ -436,14 +483,24 @@ init_window (ModestMsgEditWindow *obj)
                gtk_widget_hide (priv->bcc_caption);
        }
 
-       gtk_container_add (GTK_CONTAINER(obj), priv->scroll);
-       scroll_area = modest_scroll_area_new (priv->scroll, priv->msg_body);
-       gtk_container_add (GTK_CONTAINER (frame), scroll_area);
+       window_box = gtk_vbox_new (FALSE, 0);
+       gtk_box_pack_start (GTK_BOX (window_box), priv->scroll, TRUE, TRUE, 0);
+       gtk_box_pack_end (GTK_BOX (window_box), priv->find_toolbar, FALSE, FALSE, 0);
+       gtk_container_add (GTK_CONTAINER(obj), window_box);
+       priv->scroll_area = modest_scroll_area_new (priv->scroll, priv->msg_body);
+       gtk_container_add (GTK_CONTAINER (frame), priv->scroll_area);
+       
+       /*
+        TODO: scroll_area was never instantiated.
+        Stop building without warnings-as-errors. murrayc.
        gtk_container_set_focus_vadjustment (GTK_CONTAINER (scroll_area), 
                                             gtk_scrolled_window_get_vadjustment (GTK_SCROLLED_WINDOW (priv->scroll)));
+       */
 
        priv->clipboard_change_handler_id = g_signal_connect (G_OBJECT (gtk_clipboard_get (GDK_SELECTION_PRIMARY)), "owner-change",
                                                              G_CALLBACK (modest_msg_edit_window_clipboard_owner_change), obj);
+       priv->system_clipboard_change_handler_id = g_signal_connect (G_OBJECT (gtk_clipboard_get (GDK_SELECTION_CLIPBOARD)), "owner-change",
+                                                             G_CALLBACK (modest_msg_edit_window_system_clipboard_owner_change), obj);
 }
        
 
@@ -453,56 +510,23 @@ modest_msg_edit_window_finalize (GObject *obj)
 {
        ModestMsgEditWindowPrivate *priv = MODEST_MSG_EDIT_WINDOW_GET_PRIVATE (obj);
 
-       
        if (priv->clipboard_change_handler_id > 0) {
                g_signal_handler_disconnect (gtk_clipboard_get (GDK_SELECTION_PRIMARY), priv->clipboard_change_handler_id);
                priv->clipboard_change_handler_id = 0;
        }
        
+       if (priv->system_clipboard_change_handler_id > 0) {
+               g_signal_handler_disconnect (gtk_clipboard_get (GDK_SELECTION_CLIPBOARD), 
+                                            priv->system_clipboard_change_handler_id);
+               priv->system_clipboard_change_handler_id = 0;
+       }
+       
        /* This had to stay alive for as long as the combobox that used it: */
        modest_pair_list_free (priv->from_field_protos);
        
        G_OBJECT_CLASS(parent_class)->finalize (obj);
 }
 
-static gboolean
-on_delete_event (GtkWidget *widget, GdkEvent *event, ModestMsgEditWindow *self)
-{
-       GtkWidget *close_dialog;
-       ModestMsgEditWindowPrivate *priv;
-       gint response;
-
-       priv = MODEST_MSG_EDIT_WINDOW_GET_PRIVATE (self);
-       modest_window_save_state (MODEST_WINDOW (self));
-       if (is_modified (self)) {
-               close_dialog = hildon_note_new_confirmation (GTK_WINDOW (self), _("mcen_nc_no_email_message_modified_save_changes"));
-               response = gtk_dialog_run (GTK_DIALOG (close_dialog));
-               gtk_widget_destroy (close_dialog);
-
-               if (response != GTK_RESPONSE_CANCEL) {
-                       modest_ui_actions_on_save_to_drafts (NULL, self);
-               }
-       } 
-/*     /\* remove old message from drafts *\/ */
-/*     if (priv->draft_msg) { */
-/*             TnyHeader *header = tny_msg_get_header (priv->draft_msg); */
-/*             TnyAccount *account = modest_tny_account_store_get_tny_account_by_account (modest_runtime_get_account_store(), */
-/*                                                                                        account_name, */
-/*                                                                                        TNY_ACCOUNT_TYPE_STORE); */
-/*             TnyFolder *folder = modest_tny_account_get_special_folder (account, TNY_FOLDER_TYPE_DRAFTS); */
-/*             g_return_val_if_fail (TNY_IS_HEADER (header), FALSE); */
-/*             g_return_val_if_fail (TNY_IS_FOLDER (folder), FALSE); */
-/*             tny_folder_remove_msg (folder, header, NULL); */
-/*             g_object_unref (folder); */
-/*             g_object_unref (header); */
-/*             g_object_unref (priv->draft_msg); */
-/*             priv->draft_msg = NULL; */
-/*     } */
-       gtk_widget_destroy (GTK_WIDGET (self));
-       
-       return TRUE;
-}
-
 static GtkWidget *
 menubar_to_menu (GtkUIManager *ui_manager)
 {
@@ -537,6 +561,7 @@ set_msg (ModestMsgEditWindow *self, TnyMsg *msg)
        gchar *body;
        ModestMsgEditWindowPrivate *priv;
        GtkTextIter iter;
+       TnyHeaderFlags priority_flags;
        
        g_return_if_fail (MODEST_IS_MSG_EDIT_WINDOW (self));
        g_return_if_fail (TNY_IS_MSG (msg));
@@ -548,15 +573,30 @@ set_msg (ModestMsgEditWindow *self, TnyMsg *msg)
        cc      = tny_header_get_cc (header);
        bcc     = tny_header_get_bcc (header);
        subject = tny_header_get_subject (header);
+       priority_flags = tny_header_get_flags (header) & TNY_HEADER_FLAG_PRIORITY;
 
        if (to)
                modest_recpt_editor_set_recipients (MODEST_RECPT_EDITOR (priv->to_field),  to);
-       if (cc)
+       if (cc) {
                modest_recpt_editor_set_recipients (MODEST_RECPT_EDITOR (priv->cc_field),  cc);
-       if (bcc)
+               gtk_widget_set_no_show_all (priv->cc_caption, FALSE);
+               gtk_widget_show (priv->cc_caption);
+       } else if (!modest_conf_get_bool (modest_runtime_get_conf (), MODEST_CONF_SHOW_CC, NULL)) {
+               gtk_widget_set_no_show_all (priv->cc_caption, FALSE);
+               gtk_widget_hide (priv->cc_caption);
+       }
+       if (bcc) {
                modest_recpt_editor_set_recipients (MODEST_RECPT_EDITOR (priv->bcc_field), bcc);
+               gtk_widget_set_no_show_all (priv->cc_caption, FALSE);
+               gtk_widget_show (priv->bcc_caption);
+       } else if (!modest_conf_get_bool (modest_runtime_get_conf (), MODEST_CONF_SHOW_BCC, NULL)) {
+               gtk_widget_set_no_show_all (priv->bcc_caption, FALSE);
+               gtk_widget_hide (priv->bcc_caption);
+       } 
        if (subject)
                gtk_entry_set_text (GTK_ENTRY(priv->subject_field), subject);
+       modest_msg_edit_window_set_priority_flags (MODEST_MSG_EDIT_WINDOW(self),
+                                                  priority_flags);
 
        update_window_title (self);
 
@@ -593,8 +633,13 @@ set_msg (ModestMsgEditWindow *self, TnyMsg *msg)
        
        /* Add attachments to the view */
        modest_attachments_view_set_message (MODEST_ATTACHMENTS_VIEW (priv->attachments_view), msg);
-       if (priv->attachments == NULL)
-               gtk_widget_hide_all (priv->attachments_caption);
+       priv->attachments = modest_attachments_view_get_attachments (MODEST_ATTACHMENTS_VIEW (priv->attachments_view));
+       if (priv->attachments == NULL) {
+               gtk_widget_hide (priv->attachments_caption);
+       } else {
+               gtk_widget_set_no_show_all (priv->attachments_caption, FALSE);
+               gtk_widget_show_all (priv->attachments_caption);
+       }
 
        gtk_text_buffer_get_start_iter (priv->text_buffer, &iter);
        gtk_text_buffer_place_cursor (priv->text_buffer, &iter);
@@ -803,8 +848,10 @@ modest_msg_edit_window_new (TnyMsg *msg, const gchar *account_name)
        ModestConf *conf;
        gboolean prefer_formatted;
        gint file_format;
+       ModestPair *account_pair = NULL;
 
        g_return_val_if_fail (msg, NULL);
+       g_return_val_if_fail (account_name, NULL);
        
        obj = g_object_new(MODEST_TYPE_MSG_EDIT_WINDOW, NULL);
 
@@ -852,7 +899,8 @@ modest_msg_edit_window_new (TnyMsg *msg, const gchar *account_name)
        g_object_unref (action_group);
 
        /* Load the UI definition */
-       gtk_ui_manager_add_ui_from_file (parent_priv->ui_manager, MODEST_UIDIR "modest-msg-edit-window-ui.xml", &error);
+       gtk_ui_manager_add_ui_from_file (parent_priv->ui_manager, MODEST_UIDIR "modest-msg-edit-window-ui.xml",
+                                        &error);
        if (error != NULL) {
                g_warning ("Could not merge modest-msg-edit-window-ui.xml: %s", error->message);
                g_clear_error (&error);
@@ -873,15 +921,16 @@ modest_msg_edit_window_new (TnyMsg *msg, const gchar *account_name)
                
        gtk_window_set_icon_from_file (GTK_WINDOW(obj), MODEST_APP_ICON, NULL);
 
-       g_signal_connect (G_OBJECT(obj), "delete-event",
-                         G_CALLBACK(on_delete_event), obj);
-
        modest_window_set_active_account (MODEST_WINDOW(obj), account_name);
 
        modest_msg_edit_window_setup_toolbar (MODEST_MSG_EDIT_WINDOW (obj));
 
        setup_insensitive_handlers (MODEST_MSG_EDIT_WINDOW (obj));
 
+       account_pair = modest_pair_list_find_by_first_as_string (priv->from_field_protos, account_name);
+       if (account_pair != NULL)
+               modest_combo_box_set_active_id (MODEST_COMBO_BOX (priv->from_field), account_pair->first);
+
        set_msg (MODEST_MSG_EDIT_WINDOW (obj), msg);
 
        text_buffer_refresh_attributes (WP_TEXT_BUFFER (priv->text_buffer), MODEST_MSG_EDIT_WINDOW (obj));
@@ -895,6 +944,15 @@ modest_msg_edit_window_new (TnyMsg *msg, const gchar *account_name)
        gtk_action_set_sensitive (action, FALSE);
        action = gtk_ui_manager_get_action (parent_priv->ui_manager, "/MenuBar/EditMenu/CopyMenu");
        gtk_action_set_sensitive (action, FALSE);
+       action = gtk_ui_manager_get_action (parent_priv->ui_manager, "/MenuBar/AttachmentsMenu/RemoveAttachmentsMenu");
+       gtk_action_set_sensitive (action, FALSE);
+
+       /* Update select all */
+       update_select_all_dimming (MODEST_MSG_EDIT_WINDOW (obj));
+       action = gtk_ui_manager_get_action (parent_priv->ui_manager, "/MenuBar/EditMenu");
+       g_signal_connect (G_OBJECT (action), "activate", G_CALLBACK (edit_menu_activated), obj);
+       action = gtk_ui_manager_get_action (parent_priv->ui_manager, "/MenuBar/ViewMenu");
+       g_signal_connect (G_OBJECT (action), "activate", G_CALLBACK (view_menu_activated), obj);
 
        /* set initial state of cc and bcc */
        action = gtk_ui_manager_get_action (parent_priv->ui_manager, "/MenuBar/ViewMenu/ViewCcFieldMenu");
@@ -915,6 +973,8 @@ modest_msg_edit_window_new (TnyMsg *msg, const gchar *account_name)
                        MODEST_FILE_FORMAT_FORMATTED_TEXT : 
                        MODEST_FILE_FORMAT_PLAIN_TEXT;
        modest_msg_edit_window_set_file_format (MODEST_MSG_EDIT_WINDOW (obj), file_format);
+
+       update_paste_dimming (MODEST_MSG_EDIT_WINDOW (obj));
        
        return (ModestWindow*) obj;
 }
@@ -1145,7 +1205,7 @@ modest_msg_edit_window_set_format_state (ModestMsgEditWindow *self,
                wp_text_buffer_set_attribute (WP_TEXT_BUFFER (priv->text_buffer), WPT_BOLD, (gpointer) (buffer_format->font));
        }
        if (buffer_format->cs.bullet) {
-               wp_text_buffer_set_attribute (WP_TEXT_BUFFER (priv->text_buffer), WPT_BULLET, (gpointer) (buffer_format->bullet));
+               wp_text_buffer_set_attribute (WP_TEXT_BUFFER (priv->text_buffer), WPT_BULLET, (gpointer) ((int)buffer_format->bullet));
        }
 /*     wp_text_buffer_set_format (WP_TEXT_BUFFER (priv->text_buffer), buffer_format); */
        wp_text_buffer_thaw (WP_TEXT_BUFFER (priv->text_buffer));
@@ -1348,6 +1408,7 @@ modest_msg_edit_window_select_background_color (ModestMsgEditWindow *window)
 
 }
 
+
 void
 modest_msg_edit_window_insert_image (ModestMsgEditWindow *window)
 {
@@ -1355,75 +1416,102 @@ modest_msg_edit_window_insert_image (ModestMsgEditWindow *window)
        ModestMsgEditWindowPrivate *priv;
        GtkWidget *dialog = NULL;
        gint response = 0;
-       gchar *filename = NULL;
+       GSList *uris = NULL;
+       GSList *uri_node = NULL;
        
        priv = MODEST_MSG_EDIT_WINDOW_GET_PRIVATE (window);
        
        dialog = hildon_file_chooser_dialog_new (GTK_WINDOW (window), GTK_FILE_CHOOSER_ACTION_OPEN);
+       gtk_window_set_title (GTK_WINDOW (dialog), _("mcen_ia_select_inline_image_title"));
+       gtk_file_chooser_set_select_multiple (GTK_FILE_CHOOSER (dialog), TRUE);
+
+       modest_maemo_utils_setup_images_filechooser (GTK_FILE_CHOOSER (dialog));
 
        response = gtk_dialog_run (GTK_DIALOG (dialog));
        switch (response) {
        case GTK_RESPONSE_OK:
-               filename = gtk_file_chooser_get_filename (GTK_FILE_CHOOSER (dialog));
+               uris = gtk_file_chooser_get_uris (GTK_FILE_CHOOSER (dialog));
                break;
        default:
                break;
        }
        gtk_widget_destroy (dialog);
 
-       if (filename) {
-               GdkPixbuf *pixbuf = NULL;
+       for (uri_node = uris; uri_node != NULL; uri_node = g_slist_next (uri_node)) {
+               const gchar *uri;
+               GnomeVFSHandle *handle = NULL;
+               GnomeVFSResult result;
                GtkTextIter position;
                GtkTextMark *insert_mark;
 
-               pixbuf = gdk_pixbuf_new_from_file (filename, NULL);
-               if (pixbuf) {
-                       gint image_file_id;
-                       GdkPixbufFormat *pixbuf_format;
-
-                       image_file_id = g_open (filename, O_RDONLY, 0);
-                       pixbuf_format = gdk_pixbuf_get_file_info (filename, NULL, NULL);
-                       if ((image_file_id != -1)&&(pixbuf_format != NULL)) {
-                               TnyMimePart *image_part;
-                               TnyStream *image_stream;
-                               gchar **mime_types;
-                               gchar *mime_type;
-                               gchar *basename;
-                               gchar *content_id;
-
-                               mime_types = gdk_pixbuf_format_get_mime_types (pixbuf_format);
-                               if ((mime_types != NULL) && (mime_types[0] != NULL)) {
-                                       mime_type = mime_types[0];
-                               } else {
-                                       mime_type = "image/unknown";
-                               }
-                               image_part = tny_platform_factory_new_mime_part
-                                       (modest_runtime_get_platform_factory ());
-                               image_stream = TNY_STREAM (tny_fs_stream_new (image_file_id));
-
-                               tny_mime_part_construct_from_stream (image_part, image_stream, mime_type);
-                               g_strfreev (mime_types);
-
-                               content_id = g_strdup_printf ("%d", priv->last_cid);
-                               tny_mime_part_set_content_id (image_part, content_id);
-                               g_free (content_id);
-                               priv->last_cid++;
-
-                               basename = g_path_get_basename (filename);
-                               tny_mime_part_set_filename (image_part, basename);
-                               g_free (basename);
-                               
+               uri = (const gchar *) uri_node->data;
+               result = gnome_vfs_open (&handle, uri, GNOME_VFS_OPEN_READ);
+               if (result == GNOME_VFS_OK) {
+                       GdkPixbufLoader *loader;
+                       GdkPixbuf *pixbuf;
+                       GnomeVFSFileInfo info;
+                       gchar *filename, *basename;
+                       TnyMimePart *mime_part;
+                       TnyStream *stream;
+                       gchar *content_id;
+                       const gchar *mime_type = NULL;
+
+                       filename = g_filename_from_uri (uri, NULL, NULL);
+                       if (gnome_vfs_get_file_info_from_handle (handle, &info, GNOME_VFS_FILE_INFO_GET_MIME_TYPE) 
+                           == GNOME_VFS_OK)
+                               mime_type = gnome_vfs_file_info_get_mime_type (&info);
+
+                       mime_part = tny_platform_factory_new_mime_part
+                               (modest_runtime_get_platform_factory ());
+                       stream = TNY_STREAM (tny_vfs_stream_new (handle));
+                       
+                       tny_mime_part_construct_from_stream (mime_part, stream, mime_type);
+                       
+                       content_id = g_strdup_printf ("%d", priv->last_cid);
+                       tny_mime_part_set_content_id (mime_part, content_id);
+                       g_free (content_id);
+                       priv->last_cid++;
+                       
+                       basename = g_path_get_basename (filename);
+                       tny_mime_part_set_filename (mime_part, basename);
+                       g_free (basename);
+                       
+                       priv->attachments = g_list_prepend (priv->attachments, mime_part);
+                       modest_attachments_view_add_attachment (MODEST_ATTACHMENTS_VIEW (priv->attachments_view),
+                                                               mime_part);
+                       gtk_widget_set_no_show_all (priv->attachments_caption, FALSE);
+                       gtk_widget_show_all (priv->attachments_caption);
+                       gtk_text_buffer_set_modified (priv->text_buffer, TRUE);
+                       g_free (filename);
+
+                       loader = gdk_pixbuf_loader_new_with_mime_type (mime_type, NULL);
+                       while (!tny_stream_is_eos (TNY_STREAM (stream))) {
+                               char read_buffer[128];
+                               gint readed;
+                               readed = tny_stream_read (TNY_STREAM (stream), read_buffer, 128);
+                               if (!gdk_pixbuf_loader_write (loader, read_buffer, readed, NULL))
+                                       break;
+                       }
+                       pixbuf = gdk_pixbuf_loader_get_pixbuf (loader);
+                       g_object_ref (pixbuf);
+                       gdk_pixbuf_loader_close (loader, NULL);
+                       g_object_unref (loader);
+
+                       if (gdk_pixbuf_get_width (pixbuf) > IMAGE_MAX_WIDTH) {
+                               GdkPixbuf *new_pixbuf;
+                               gint new_height;
+                               new_height = (gdk_pixbuf_get_height (pixbuf) * IMAGE_MAX_WIDTH) /
+                                       gdk_pixbuf_get_width (pixbuf);
+                               new_pixbuf = gdk_pixbuf_scale_simple (pixbuf, IMAGE_MAX_WIDTH, new_height, GDK_INTERP_BILINEAR);
+                               g_object_unref (pixbuf);
+                               pixbuf = new_pixbuf;
+                       }
+
+                       if (pixbuf != NULL) {
                                insert_mark = gtk_text_buffer_get_insert (GTK_TEXT_BUFFER (priv->text_buffer));
                                gtk_text_buffer_get_iter_at_mark (GTK_TEXT_BUFFER (priv->text_buffer), &position, insert_mark);
-                               wp_text_buffer_insert_image (WP_TEXT_BUFFER (priv->text_buffer), &position, g_strdup (tny_mime_part_get_content_id (image_part)), pixbuf);
-                               priv->attachments = g_list_prepend (priv->attachments, image_part);
-                               modest_attachments_view_add_attachment (MODEST_ATTACHMENTS_VIEW (priv->attachments_view),
-                                                                       image_part);
-                               gtk_widget_set_no_show_all (priv->attachments_caption, FALSE);
-                               gtk_widget_show_all (priv->attachments_caption);
-                       } else if (image_file_id == -1) {
-                               close (image_file_id);
-                       }
+                               wp_text_buffer_insert_image (WP_TEXT_BUFFER (priv->text_buffer), &position, g_strdup (tny_mime_part_get_content_id (mime_part)), pixbuf);
+                       } 
                }
        }
 
@@ -1437,36 +1525,41 @@ modest_msg_edit_window_attach_file (ModestMsgEditWindow *window)
        ModestMsgEditWindowPrivate *priv;
        GtkWidget *dialog = NULL;
        gint response = 0;
-       gchar *uri = NULL, *filename = NULL;
+       GSList *uris = NULL;
+       GSList *uri_node;
        
        priv = MODEST_MSG_EDIT_WINDOW_GET_PRIVATE (window);
        
        dialog = hildon_file_chooser_dialog_new (GTK_WINDOW (window), GTK_FILE_CHOOSER_ACTION_OPEN);
+       gtk_file_chooser_set_select_multiple (GTK_FILE_CHOOSER (dialog), TRUE);
 
        response = gtk_dialog_run (GTK_DIALOG (dialog));
        switch (response) {
        case GTK_RESPONSE_OK:
-               uri = gtk_file_chooser_get_uri (GTK_FILE_CHOOSER (dialog));
-               filename = gtk_file_chooser_get_filename (GTK_FILE_CHOOSER (dialog));
+               uris = gtk_file_chooser_get_uris (GTK_FILE_CHOOSER (dialog));
                break;
        default:
                break;
        }
        gtk_widget_destroy (dialog);
 
-       if (uri) {
-
+       for (uri_node = uris; uri_node != NULL; uri_node = g_slist_next (uri_node)) {
+               const gchar *uri;
                GnomeVFSHandle *handle = NULL;
                GnomeVFSResult result;
 
+               uri = (const gchar *) uri_node->data;
                result = gnome_vfs_open (&handle, uri, GNOME_VFS_OPEN_READ);
                if (result == GNOME_VFS_OK) {
                        TnyMimePart *mime_part;
                        TnyStream *stream;
                        const gchar *mime_type = NULL;
                        gchar *basename;
+                       gchar *filename;
                        gchar *content_id;
                        GnomeVFSFileInfo info;
+
+                       filename = g_filename_from_uri (uri, NULL, NULL);
                        
                        if (gnome_vfs_get_file_info_from_handle (handle, &info, GNOME_VFS_FILE_INFO_GET_MIME_TYPE) == GNOME_VFS_OK)
                                mime_type = gnome_vfs_file_info_get_mime_type (&info);
@@ -1490,24 +1583,36 @@ modest_msg_edit_window_attach_file (ModestMsgEditWindow *window)
                                                                mime_part);
                        gtk_widget_set_no_show_all (priv->attachments_caption, FALSE);
                        gtk_widget_show_all (priv->attachments_caption);
+                       gtk_text_buffer_set_modified (priv->text_buffer, TRUE);
+                       g_free (filename);
+
                } 
-               g_free (filename);
        }
+       g_slist_foreach (uris, (GFunc) g_free, NULL);
+       g_slist_free (uris);
 }
 
 void
 modest_msg_edit_window_attach_file_noninteractive (
                ModestMsgEditWindow *window,
-               gchar *filename)
+               const gchar *file_uri)
 {
        
        ModestMsgEditWindowPrivate *priv;
        
        priv = MODEST_MSG_EDIT_WINDOW_GET_PRIVATE (window);
 
-       if (filename) {
-               gint file_id;
+       if (file_uri) {
+               gint file_id = 0;
                
+               /* TODO: We should probably try to use only the URI,
+                * instead of using a filename.
+                */
+               gchar* filename = g_filename_from_uri (file_uri, NULL, NULL);
+               if (!filename) {
+                       g_warning("%s: g_filename_from_uri(%s) failed.\n", __FUNCTION__, file_uri);
+               }
+
                file_id = g_open (filename, O_RDONLY, 0);
                if (file_id != -1) {
                        TnyMimePart *mime_part;
@@ -1515,8 +1620,11 @@ modest_msg_edit_window_attach_file_noninteractive (
                        const gchar *mime_type;
                        gchar *basename;
                        gchar *content_id;
-                       
+#ifdef MODEST_HAVE_HILDON0_WIDGETS
+                       mime_type = gnome_vfs_get_mime_type(filename);
+#else
                        mime_type = gnome_vfs_get_file_mime_type_fast (filename, NULL);
+#endif
                        mime_part = tny_platform_factory_new_mime_part
                                (modest_runtime_get_platform_factory ());
                        stream = TNY_STREAM (tny_fs_stream_new (file_id));
@@ -1539,7 +1647,10 @@ modest_msg_edit_window_attach_file_noninteractive (
                        gtk_widget_show_all (priv->attachments_caption);
                } else if (file_id == -1) {
                        close (file_id);
+                       g_warning("file to be attached does not exist: %s", filename);
                }
+
+               g_free (filename);
        }
 }
 
@@ -1564,16 +1675,25 @@ modest_msg_edit_window_remove_attachments (ModestMsgEditWindow *window,
                GtkWidget *confirmation_dialog = NULL;
                gboolean dialog_response;
                GList *node;
+               gchar *message = NULL;
+               const gchar *filename = NULL;
+
                if (att_list->next == NULL) {
-                       gchar *message = g_strdup_printf (_("emev_nc_delete_attachment"), 
-                                                         tny_mime_part_get_filename (TNY_MIME_PART (att_list->data)));
-                       confirmation_dialog = hildon_note_new_confirmation (GTK_WINDOW (window), message);
-                       g_free (message);
+                       filename = tny_mime_part_get_filename (TNY_MIME_PART (att_list->data));
                } else {
-                       confirmation_dialog = hildon_note_new_confirmation (GTK_WINDOW (window), _("emev_nc_delete_attachments"));
+                       filename = "";
                }
+               message = g_strdup_printf (ngettext("emev_nc_delete_attachment", "emev_nc_delete_attachments",
+                                                   att_list->next == NULL), filename);
+               confirmation_dialog = hildon_note_new_confirmation (GTK_WINDOW (window), message);
+               g_free (message);
                dialog_response = (gtk_dialog_run (GTK_DIALOG (confirmation_dialog))==GTK_RESPONSE_OK);
                gtk_widget_destroy (confirmation_dialog);
+               if (!dialog_response) {
+                       if (clean_list)
+                               g_list_free (att_list);
+                       return;
+               }
                hildon_banner_show_information (NULL, NULL, _("mcen_ib_removing_attachment"));
 
                for (node = att_list; node != NULL; node = g_list_next (node)) {
@@ -1583,11 +1703,14 @@ modest_msg_edit_window_remove_attachments (ModestMsgEditWindow *window,
 
                        modest_attachments_view_remove_attachment (MODEST_ATTACHMENTS_VIEW (priv->attachments_view),
                                                                   mime_part);
+                       if (priv->attachments == NULL)
+                               gtk_widget_hide (priv->attachments_caption);
                        att_id = tny_mime_part_get_content_id (mime_part);
                        if (att_id != NULL)
                                text_buffer_delete_images_by_id (gtk_text_view_get_buffer (GTK_TEXT_VIEW (priv->msg_body)),
                                                                 att_id);
                        g_object_unref (mime_part);
+                       gtk_text_buffer_set_modified (priv->text_buffer, TRUE);
                }
        }
 
@@ -1603,13 +1726,13 @@ modest_msg_edit_window_color_button_change (ModestMsgEditWindow *window,
        GdkColor *new_color;
        priv = MODEST_MSG_EDIT_WINDOW_GET_PRIVATE (window);
        
-#ifdef MODEST_HILDON_VERSION_0 
+#ifdef MODEST_HAVE_HILDON0_WIDGETS     
        new_color = hildon_color_button_get_color (HILDON_COLOR_BUTTON (priv->font_color_button));
 #else 
        GdkColor col;
        hildon_color_button_get_color (HILDON_COLOR_BUTTON(priv->font_color_button), &col);
        new_color = &col;
-#endif /*MODEST_HILDON_VERSION_0*/
+#endif /*#ifdef MODEST_HAVE_HILDON0_WIDGETS*/
 
        wp_text_buffer_set_attribute (WP_TEXT_BUFFER (priv->text_buffer), WPT_FORECOLOR, (gpointer) new_color);
        
@@ -1693,12 +1816,25 @@ modest_msg_edit_window_set_zoom (ModestWindow *window,
                                 gdouble zoom)
 {
        ModestMsgEditWindowPrivate *priv;
+       ModestWindowPrivate *parent_priv;
+       GtkRadioAction *zoom_radio_action;
      
        g_return_if_fail (MODEST_IS_MSG_EDIT_WINDOW (window));
 
        priv = MODEST_MSG_EDIT_WINDOW_GET_PRIVATE (window);
+       parent_priv = MODEST_WINDOW_GET_PRIVATE (window);
        priv->zoom_level = zoom;
        wp_text_buffer_set_font_scaling_factor (WP_TEXT_BUFFER (priv->text_buffer), zoom);
+
+       /* Zoom level menu options should be updated with the current zoom level */
+       parent_priv = MODEST_WINDOW_GET_PRIVATE (window);
+       zoom_radio_action = GTK_RADIO_ACTION (gtk_ui_manager_get_action (parent_priv->ui_manager, 
+                                                                        "/MenuBar/ViewMenu/ZoomMenu/Zoom50Menu"));
+#ifdef MODEST_HAVE_HILDON0_WIDGETS
+       /* FIXME: Not availible before Gtk 2.10 */
+#else
+       gtk_radio_action_set_current_value (zoom_radio_action, (gint) (zoom*100.0+0.1));
+#endif
 }
 
 static gdouble
@@ -1713,12 +1849,27 @@ modest_msg_edit_window_get_zoom (ModestWindow *window)
 }
 
 static gboolean
+zoom_allowed (ModestMsgEditWindow *window)
+{
+       GtkWidget *focus;
+
+       focus = gtk_window_get_focus (GTK_WINDOW (window));
+       return (focus != NULL && WP_IS_TEXT_VIEW (focus));
+}
+
+static gboolean
 modest_msg_edit_window_zoom_plus (ModestWindow *window)
 {
        ModestWindowPrivate *parent_priv;
        GtkRadioAction *zoom_radio_action;
        GSList *group, *node;
 
+       /* First we check if the text view is focused. If not, zooming is not allowed */
+       if (!zoom_allowed (MODEST_MSG_EDIT_WINDOW (window))) {
+               hildon_banner_show_information (NULL, NULL, dgettext("hildon-common-strings", "ckct_ib_cannot_zoom_here"));
+               return FALSE;
+       }
+
        parent_priv = MODEST_WINDOW_GET_PRIVATE (window);
        zoom_radio_action = GTK_RADIO_ACTION (gtk_ui_manager_get_action (parent_priv->ui_manager, 
                                                                         "/MenuBar/ViewMenu/ZoomMenu/Zoom50Menu"));
@@ -1726,7 +1877,7 @@ modest_msg_edit_window_zoom_plus (ModestWindow *window)
        group = gtk_radio_action_get_group (zoom_radio_action);
 
        if (gtk_toggle_action_get_active (GTK_TOGGLE_ACTION (group->data))) {
-               hildon_banner_show_information (NULL, NULL, _("mcen_ib_max_zoom_level"));
+               hildon_banner_show_information (NULL, NULL, dgettext("hildon-common-strings", "ckct_ib_max_zoom_level_reached"));
                return FALSE;
        }
 
@@ -1746,6 +1897,12 @@ modest_msg_edit_window_zoom_minus (ModestWindow *window)
        GtkRadioAction *zoom_radio_action;
        GSList *group, *node;
 
+       /* First we check if the text view is focused. If not, zooming is not allowed */
+       if (!zoom_allowed (MODEST_MSG_EDIT_WINDOW (window))) {
+               hildon_banner_show_information (NULL, NULL, dgettext("hildon-common-strings", "ckct_ib_cannot_zoom_here"));
+               return FALSE;
+       }
+
        parent_priv = MODEST_WINDOW_GET_PRIVATE (window);
        zoom_radio_action = GTK_RADIO_ACTION (gtk_ui_manager_get_action (parent_priv->ui_manager, 
                                                                         "/MenuBar/ViewMenu/ZoomMenu/Zoom50Menu"));
@@ -1758,7 +1915,7 @@ modest_msg_edit_window_zoom_minus (ModestWindow *window)
                                gtk_toggle_action_set_active (GTK_TOGGLE_ACTION (node->next->data), TRUE);
                                return TRUE;
                        } else
-                               hildon_banner_show_information (NULL, NULL, _("mcen_ib_min_zoom_level"));
+                               hildon_banner_show_information (NULL, NULL, dgettext("hildon-common-strings", "ckct_ib_min_zoom_level_reached"));
                        break;
                }
        }
@@ -1809,11 +1966,13 @@ modest_msg_edit_window_show_cc (ModestMsgEditWindow *window,
                                gboolean show)
 {
        ModestMsgEditWindowPrivate *priv = NULL;
+       const gchar *recipients;
        g_return_if_fail (MODEST_IS_MSG_EDIT_WINDOW (window));
 
        priv = MODEST_MSG_EDIT_WINDOW_GET_PRIVATE (window);
        gtk_widget_set_no_show_all (priv->cc_caption, TRUE);
-       if (show)
+       recipients = modest_recpt_editor_get_recipients (MODEST_RECPT_EDITOR (priv->cc_field));
+       if ((show) || ((recipients != NULL) && (recipients[0] != '\0')))
                gtk_widget_show (priv->cc_caption);
        else
                gtk_widget_hide (priv->cc_caption);
@@ -1825,11 +1984,13 @@ modest_msg_edit_window_show_bcc (ModestMsgEditWindow *window,
                                 gboolean show)
 {
        ModestMsgEditWindowPrivate *priv = NULL;
+       const gchar *recipients;
        g_return_if_fail (MODEST_IS_MSG_EDIT_WINDOW (window));
 
        priv = MODEST_MSG_EDIT_WINDOW_GET_PRIVATE (window);
        gtk_widget_set_no_show_all (priv->bcc_caption, TRUE);
-       if (show)
+       recipients = modest_recpt_editor_get_recipients (MODEST_RECPT_EDITOR (priv->bcc_field));
+       if ((show) || ((recipients != NULL) && (recipients[0] != '\0')))
                gtk_widget_show (priv->bcc_caption);
        else
                gtk_widget_hide (priv->bcc_caption);
@@ -1908,13 +2069,16 @@ modest_msg_edit_window_set_priority_flags (ModestMsgEditWindow *window,
                                           TnyHeaderFlags priority_flags)
 {
        ModestMsgEditWindowPrivate *priv;
+       ModestWindowPrivate *parent_priv;
 
        g_return_if_fail (MODEST_IS_MSG_EDIT_WINDOW (window));
 
        priv = MODEST_MSG_EDIT_WINDOW_GET_PRIVATE (window);
-       priority_flags = priority_flags & (TNY_HEADER_FLAG_HIGH_PRIORITY);
+       parent_priv = MODEST_WINDOW_GET_PRIVATE (window);
+       priority_flags = priority_flags & (TNY_HEADER_FLAG_PRIORITY);
 
        if (priv->priority_flags != priority_flags) {
+               GtkAction *priority_action = NULL;
 
                priv->priority_flags = priority_flags;
 
@@ -1922,15 +2086,23 @@ modest_msg_edit_window_set_priority_flags (ModestMsgEditWindow *window,
                case TNY_HEADER_FLAG_HIGH_PRIORITY:
                        gtk_image_set_from_icon_name (GTK_IMAGE (priv->priority_icon), "qgn_list_messaging_high", GTK_ICON_SIZE_MENU);
                        gtk_widget_show (priv->priority_icon);
+                       priority_action = gtk_ui_manager_get_action (parent_priv->ui_manager, 
+                                                                    "/MenuBar/ToolsMenu/MessagePriorityMenu/MessagePriorityHighMenu");
                        break;
                case TNY_HEADER_FLAG_LOW_PRIORITY:
                        gtk_image_set_from_icon_name (GTK_IMAGE (priv->priority_icon), "qgn_list_messaging_low", GTK_ICON_SIZE_MENU);
                        gtk_widget_show (priv->priority_icon);
+                       priority_action = gtk_ui_manager_get_action (parent_priv->ui_manager, 
+                                                                    "/MenuBar/ToolsMenu/MessagePriorityMenu/MessagePriorityLowMenu");
                        break;
                default:
                        gtk_widget_hide (priv->priority_icon);
+                       priority_action = gtk_ui_manager_get_action (parent_priv->ui_manager, 
+                                                                    "/MenuBar/ToolsMenu/MessagePriorityMenu/MessagePriorityNormalMenu");
                        break;
                }
+               gtk_toggle_action_set_active (GTK_TOGGLE_ACTION (priority_action), TRUE);
+               gtk_text_buffer_set_modified (priv->text_buffer, TRUE);
        }
 }
 
@@ -2191,6 +2363,13 @@ setup_insensitive_handlers (ModestMsgEditWindow *window)
        widget = priv->font_face_toolitem;
        g_signal_connect (G_OBJECT (widget), "insensitive-press", G_CALLBACK (style_insensitive_press), window);
 
+       widget = gtk_ui_manager_get_widget (parent_priv->ui_manager, "/MenuBar/AttachmentsMenu/RemoveAttachmentsMenu");
+       g_signal_connect (G_OBJECT (widget), "insensitive-press", G_CALLBACK (remove_attachment_insensitive_press), window);
+       widget = gtk_ui_manager_get_widget (parent_priv->ui_manager, "/MenuBar/ViewMenu/ZoomMenu");
+       g_signal_connect (G_OBJECT (widget), "insensitive-press", G_CALLBACK (zoom_insensitive_press), window);
+
+       widget = gtk_ui_manager_get_widget (parent_priv->ui_manager, "/MenuBar/EditMenu/PasteMenu");
+       g_signal_connect (G_OBJECT (widget), "insensitive-press", G_CALLBACK (paste_insensitive_press), window);
 }
 
 static void  
@@ -2275,16 +2454,27 @@ msg_body_focus (GtkWidget *focus,
 }
 
 static void
-to_field_changed (GtkTextBuffer *buffer,
+recpt_field_changed (GtkTextBuffer *buffer,
                  ModestMsgEditWindow *editor)
 {
        ModestWindowPrivate *parent_priv = MODEST_WINDOW_GET_PRIVATE (editor);
+       ModestMsgEditWindowPrivate *priv = MODEST_MSG_EDIT_WINDOW_GET_PRIVATE (editor);
+       GtkTextBuffer *to_buffer, *cc_buffer, *bcc_buffer;
+       gboolean dim = FALSE;
        GtkAction *action;
 
+       to_buffer = modest_recpt_editor_get_buffer (MODEST_RECPT_EDITOR (priv->to_field));
+       cc_buffer = modest_recpt_editor_get_buffer (MODEST_RECPT_EDITOR (priv->cc_field));
+       bcc_buffer = modest_recpt_editor_get_buffer (MODEST_RECPT_EDITOR (priv->bcc_field));
+       
+       dim = ((gtk_text_buffer_get_char_count (to_buffer) + 
+               gtk_text_buffer_get_char_count (cc_buffer) +
+               gtk_text_buffer_get_char_count (bcc_buffer)) == 0);
+                       
        action = gtk_ui_manager_get_action (parent_priv->ui_manager, "/ToolBar/ToolbarSend");
-       gtk_action_set_sensitive (action, gtk_text_buffer_get_char_count (buffer) != 0);
+       gtk_action_set_sensitive (action, !dim);
        action = gtk_ui_manager_get_action (parent_priv->ui_manager, "/MenuBar/EmailMenu/SendMenu");
-       gtk_action_set_sensitive (action, gtk_text_buffer_get_char_count (buffer) != 0);
+       gtk_action_set_sensitive (action, !dim);
 }
 
 static void  
@@ -2293,6 +2483,34 @@ send_insensitive_press (GtkWidget *widget, ModestMsgEditWindow *editor)
        hildon_banner_show_information (NULL, NULL, _("mcen_ib_add_recipients_first"));
 }
 
+static void  
+zoom_insensitive_press (GtkWidget *widget, ModestMsgEditWindow *editor)
+{
+       hildon_banner_show_information (NULL, NULL, dgettext("hildon-common-strings", "ckct_ib_cannot_zoom_here"));
+}
+
+static void  
+remove_attachment_insensitive_press (GtkWidget *widget, ModestMsgEditWindow *editor)
+{
+       ModestWindowPrivate *parent_priv;
+       ModestMsgEditWindowPrivate *priv;
+       GList *selected_attachments = NULL;
+       gint n_att_selected = 0;
+
+       priv = MODEST_MSG_EDIT_WINDOW_GET_PRIVATE (editor);
+       parent_priv = MODEST_WINDOW_GET_PRIVATE (editor);
+
+       selected_attachments = modest_attachments_view_get_selection (MODEST_ATTACHMENTS_VIEW (priv->attachments_view));
+       n_att_selected = g_list_length (selected_attachments);
+       g_list_free (selected_attachments);
+
+       if (n_att_selected > 1)
+               hildon_banner_show_information (NULL, NULL, _("mcen_ib_unable_to_display_more"));
+       else if (n_att_selected == 0)
+               hildon_banner_show_information (NULL, NULL, _("TODO: select one attachment"));
+               
+}
+
 static void
 style_insensitive_press (GtkWidget *widget, ModestMsgEditWindow *editor)
 {
@@ -2323,8 +2541,8 @@ reset_modified (ModestMsgEditWindow *editor)
        gtk_text_buffer_set_modified (priv->text_buffer, FALSE);
 }
 
-static gboolean
-is_modified (ModestMsgEditWindow *editor)
+gboolean
+modest_msg_edit_window_is_modified (ModestMsgEditWindow *editor)
 {
        ModestMsgEditWindowPrivate *priv = MODEST_MSG_EDIT_WINDOW_GET_PRIVATE (editor);
        GtkTextBuffer *buffer;
@@ -2387,10 +2605,14 @@ modest_msg_edit_window_clipboard_owner_change (GtkClipboard *clipboard,
                                               ModestMsgEditWindow *window)
 {
        ModestWindowPrivate *parent_priv;
+       ModestMsgEditWindowPrivate *priv;
        GtkAction *action;
        gchar *selection;
        GtkWidget *focused;
+       GList *selected_attachments = NULL;
+       gint n_att_selected = 0;
 
+       priv = MODEST_MSG_EDIT_WINDOW_GET_PRIVATE (window);
        parent_priv = MODEST_WINDOW_GET_PRIVATE (window);
        selection = gtk_clipboard_wait_for_text (clipboard);
        focused = gtk_window_get_focus (GTK_WINDOW (window));
@@ -2399,6 +2621,16 @@ modest_msg_edit_window_clipboard_owner_change (GtkClipboard *clipboard,
        gtk_action_set_sensitive (action, (selection != NULL) && (!MODEST_IS_ATTACHMENTS_VIEW (focused)));
        action = gtk_ui_manager_get_action (parent_priv->ui_manager, "/MenuBar/EditMenu/CopyMenu");
        gtk_action_set_sensitive (action, (selection != NULL) && (!MODEST_IS_ATTACHMENTS_VIEW (focused)));
+
+       selected_attachments = modest_attachments_view_get_selection (MODEST_ATTACHMENTS_VIEW (priv->attachments_view));
+       n_att_selected = g_list_length (selected_attachments);
+       g_list_free (selected_attachments);
+
+       action = gtk_ui_manager_get_action (parent_priv->ui_manager, "/MenuBar/AttachmentsMenu/RemoveAttachmentsMenu");
+       gtk_action_set_sensitive (action, n_att_selected == 1);
+       
+
+       update_paste_dimming (window);
 }
 
 static void 
@@ -2420,5 +2652,190 @@ static void
 subject_field_changed (GtkEditable *editable, 
                       ModestMsgEditWindow *window)
 {
+       ModestMsgEditWindowPrivate *priv = MODEST_MSG_EDIT_WINDOW_GET_PRIVATE (window);
        update_window_title (window);
+       gtk_text_buffer_set_modified (priv->text_buffer, TRUE);
+}
+
+void
+modest_msg_edit_window_toggle_find_toolbar (ModestMsgEditWindow *window,
+                                           gboolean show)
+{
+       ModestMsgEditWindowPrivate *priv = NULL;
+
+       g_return_if_fail (MODEST_IS_MSG_EDIT_WINDOW (window));
+       priv = MODEST_MSG_EDIT_WINDOW_GET_PRIVATE (window);
+
+       gtk_widget_set_no_show_all (priv->find_toolbar, FALSE);
+       if (show) {
+               gtk_widget_show_all (priv->find_toolbar);
+               hildon_find_toolbar_highlight_entry (HILDON_FIND_TOOLBAR (priv->find_toolbar), TRUE);
+       } else {
+               gtk_widget_hide_all (priv->find_toolbar);
+               gtk_widget_grab_focus (priv->msg_body);
+       }
+    
+}
+
+static void 
+modest_msg_edit_window_find_toolbar_search (GtkWidget *widget,
+                                           ModestMsgEditWindow *window)
+{
+       gchar *current_search = NULL;
+       ModestMsgEditWindowPrivate *priv = MODEST_MSG_EDIT_WINDOW_GET_PRIVATE (window);
+       gboolean result;
+       GtkTextIter selection_start, selection_end;
+       GtkTextIter match_start, match_end;
+
+       g_object_get (G_OBJECT (widget), "prefix", &current_search, NULL);
+       if ((current_search == NULL) && (strcmp (current_search, "") == 0)) {
+               g_free (current_search);
+               return;
+       }
+
+       gtk_text_buffer_get_selection_bounds (priv->text_buffer, &selection_start, &selection_end);
+       result = gtk_text_iter_forward_search (&selection_end, current_search, GTK_TEXT_SEARCH_VISIBLE_ONLY, &match_start, &match_end, NULL);
+       if (!result) {
+               GtkTextIter buffer_start;
+               gtk_text_buffer_get_start_iter (priv->text_buffer, &buffer_start);
+               result = gtk_text_iter_forward_search (&buffer_start, current_search, GTK_TEXT_SEARCH_VISIBLE_ONLY, &match_start, &match_end, &selection_start);
+       }
+       if (result) {
+               gtk_text_buffer_select_range (priv->text_buffer, &match_start, &match_end);
+               gtk_text_view_scroll_to_iter (GTK_TEXT_VIEW (priv->msg_body), &match_start, 0.0, TRUE, 0.0, 0.0);
+       } else {
+               /* TODO: warning about non succesful search */
+       }
+       g_free (current_search);
+}
+
+static void
+modest_msg_edit_window_find_toolbar_close (GtkWidget *widget,
+                                          ModestMsgEditWindow *window)
+{
+       GtkToggleAction *toggle;
+       ModestWindowPrivate *parent_priv;
+       parent_priv = MODEST_WINDOW_GET_PRIVATE (window);
+
+       toggle = GTK_TOGGLE_ACTION (gtk_ui_manager_get_action (parent_priv->ui_manager, "/MenuBar/ToolsMenu/FindInMessageMenu"));
+       gtk_toggle_action_set_active (toggle, FALSE);
+}
+
+
+static void 
+update_paste_dimming (ModestMsgEditWindow *window)
+{
+       ModestWindowPrivate *parent_priv = MODEST_WINDOW_GET_PRIVATE (window);
+       GtkAction *action = NULL;
+       GtkClipboard *clipboard = NULL;
+       GtkWidget *focused;
+       gboolean active;
+
+       focused = gtk_window_get_focus (GTK_WINDOW (window));
+
+       clipboard = gtk_clipboard_get (GDK_SELECTION_CLIPBOARD);
+       active = gtk_clipboard_wait_is_text_available (clipboard);
+
+       if (active) {
+               if (MODEST_IS_ATTACHMENTS_VIEW (focused))
+                       active = FALSE;
+       }
+
+       action = gtk_ui_manager_get_action (parent_priv->ui_manager, "/MenuBar/EditMenu/PasteMenu");
+       gtk_action_set_sensitive (action, active);
+
+}
+
+static void  
+paste_insensitive_press (GtkWidget *widget, ModestMsgEditWindow *editor)
+{
+       GtkWidget *focused = gtk_window_get_focus (GTK_WINDOW (editor));
+
+       if (MODEST_IS_ATTACHMENTS_VIEW (focused))
+               hildon_banner_show_information (NULL, NULL, dgettext("hildon-common-strings", "ckct_ib_unable_to_paste_here"));
+       else
+               hildon_banner_show_information (NULL, NULL, dgettext("hildon-common-strings", "ecoc_ib_edwin_nothing_to_paste"));
+               
+}
+
+
+static void
+modest_msg_edit_window_system_clipboard_owner_change (GtkClipboard *clipboard,
+                                                     GdkEvent *event,
+                                                     ModestMsgEditWindow *window)
+{
+       update_paste_dimming (window);
+}
+
+static void 
+update_select_all_dimming (ModestMsgEditWindow *window)
+{
+       GtkWidget *focused;
+       gboolean dimmed = FALSE;
+       GtkAction *action;
+       ModestWindowPrivate *parent_priv = MODEST_WINDOW_GET_PRIVATE (window);
+
+       focused = gtk_window_get_focus (GTK_WINDOW (window));
+       if (GTK_IS_ENTRY (focused)) {
+               const gchar *current_text;
+               current_text = gtk_entry_get_text (GTK_ENTRY (focused));
+               dimmed = ((current_text == NULL) || (current_text[0] == '\0'));
+       } else if (GTK_IS_TEXT_VIEW (focused)) {
+               GtkTextBuffer *buffer = gtk_text_view_get_buffer (GTK_TEXT_VIEW (focused));
+               dimmed = (gtk_text_buffer_get_char_count (buffer) < 1);
+       } else if (MODEST_IS_ATTACHMENTS_VIEW (focused)) {
+               dimmed = FALSE;
+       }
+       action = gtk_ui_manager_get_action (parent_priv->ui_manager, "/MenuBar/EditMenu/SelectAllMenu");
+       gtk_action_set_sensitive (action, !dimmed);
+}
+
+static void 
+update_zoom_dimming (ModestMsgEditWindow *window)
+{
+       GtkWidget *focused;
+       gboolean dimmed = FALSE;
+       GtkAction *action;
+       ModestWindowPrivate *parent_priv = MODEST_WINDOW_GET_PRIVATE (window);
+
+       focused = gtk_window_get_focus (GTK_WINDOW (window));
+       dimmed = ! WP_IS_TEXT_VIEW (focused);
+       action = gtk_ui_manager_get_action (parent_priv->ui_manager, "/MenuBar/ViewMenu/ZoomMenu");
+       gtk_action_set_sensitive (action, !dimmed);
+}
+
+static void
+edit_menu_activated (GtkAction *action,
+                    gpointer userdata)
+{
+       ModestMsgEditWindow *window = MODEST_MSG_EDIT_WINDOW (userdata);
+
+       update_select_all_dimming (window);
+}
+static void
+view_menu_activated (GtkAction *action,
+                    gpointer userdata)
+{
+       ModestMsgEditWindow *window = MODEST_MSG_EDIT_WINDOW (userdata);
+
+       update_zoom_dimming (window);
+}
+
+gboolean 
+modest_msg_edit_window_get_sent (ModestMsgEditWindow *window)
+{
+       ModestMsgEditWindowPrivate *priv;
+
+       priv = MODEST_MSG_EDIT_WINDOW_GET_PRIVATE(window);
+       return priv->sent;
+}
+
+void 
+modest_msg_edit_window_set_sent (ModestMsgEditWindow *window, 
+                                gboolean sent)
+{
+       ModestMsgEditWindowPrivate *priv;
+
+       priv = MODEST_MSG_EDIT_WINDOW_GET_PRIVATE(window);
+       priv->sent = sent;
 }