Work for making select all work as expected in
[modest] / src / maemo / modest-msg-view-window.c
index 229cb72..5494a49 100644 (file)
@@ -38,6 +38,7 @@
 #include <modest-msg-view-window.h>
 #include <modest-attachments-view.h>
 #include <modest-main-window-ui.h>
+#include "modest-msg-view-window-ui-dimming.h"
 #include <modest-widget-memory.h>
 #include <modest-runtime.h>
 #include <modest-window-priv.h>
@@ -48,6 +49,7 @@
 #include "modest-defs.h"
 #include "modest-hildon-includes.h"
 #include <gtkhtml/gtkhtml-search.h>
+#include "modest-ui-dimming-manager.h"
 #include <gdk/gdkkeysyms.h>
 
 #define DEFAULT_FOLDER "MyDocs/.documents"
@@ -75,10 +77,6 @@ static gboolean modest_msg_view_window_window_state_event (GtkWidget *widget,
                                                           gpointer userdata);
 static void modest_msg_view_window_scroll_up (ModestWindow *window);
 static void modest_msg_view_window_scroll_down (ModestWindow *window);
-static gboolean modest_msg_view_window_is_last_message (ModestMsgViewWindow *window);
-static gboolean modest_msg_view_window_is_first_message (ModestMsgViewWindow *window);
-static TnyFolderType modest_msg_view_window_get_folder_type (ModestMsgViewWindow *window);
-static void modest_msg_view_window_update_dimmed (ModestMsgViewWindow *window);
 static void modest_msg_view_window_update_priority (ModestMsgViewWindow *window);
 
 static void modest_msg_view_window_show_toolbar   (ModestWindow *window,
@@ -103,6 +101,9 @@ static void set_toolbar_mode (ModestMsgViewWindow *self,
 
 static gboolean set_toolbar_transfer_mode     (ModestMsgViewWindow *self); 
 
+
+static void update_window_title (ModestMsgViewWindow *window);
+
 /* list my signals */
 enum {
        /* MY_SIGNAL_1, */
@@ -140,6 +141,7 @@ struct _ModestMsgViewWindowPrivate {
        GtkWidget   *cancel_toolitem;
        GtkWidget   *prev_toolitem;
        GtkWidget   *next_toolitem;
+       ModestToolBarModes current_toolbar_mode;
 
        /* Optimized view enabled */
        gboolean optimized_view;
@@ -151,6 +153,8 @@ struct _ModestMsgViewWindowPrivate {
        guint queue_change_handler;
 
        guint progress_bar_timeout;
+
+       gchar *msg_uid;
 };
 
 #define MODEST_MSG_VIEW_WINDOW_GET_PRIVATE(o)      (G_TYPE_INSTANCE_GET_PRIVATE((o), \
@@ -234,9 +238,11 @@ modest_msg_view_window_init (ModestMsgViewWindow *obj)
        priv->msg_view      = NULL;
        priv->header_model  = NULL;
        priv->clipboard_change_handler = 0;
+       priv->current_toolbar_mode = TOOLBAR_MODE_NORMAL;
 
        priv->optimized_view  = FALSE;
        priv->progress_bar_timeout = 0;
+       priv->msg_uid = NULL;
 }
 
 
@@ -272,6 +278,9 @@ set_toolbar_mode (ModestMsgViewWindow *self,
        parent_priv = MODEST_WINDOW_GET_PRIVATE(self);
        priv = MODEST_MSG_VIEW_WINDOW_GET_PRIVATE(self);
                        
+       /* Sets current toolbar mode */
+       priv->current_toolbar_mode = mode;
+
        switch (mode) {
        case TOOLBAR_MODE_NORMAL:
                widget = gtk_ui_manager_get_action (parent_priv->ui_manager, "/ToolBar/ToolbarMessageNew");
@@ -416,20 +425,20 @@ modest_msg_view_window_finalize (GObject *obj)
        ModestMsgViewWindowPrivate *priv;
 
        priv = MODEST_MSG_VIEW_WINDOW_GET_PRIVATE (obj);
-       if (priv->header_model != NULL) {
-               g_object_unref (priv->header_model);
-               priv->header_model = NULL;
-       }
        if (priv->clipboard_change_handler > 0) {
                g_signal_handler_disconnect (gtk_clipboard_get (GDK_SELECTION_PRIMARY), priv->clipboard_change_handler);
                priv->clipboard_change_handler = 0;
        }
-
-       /* disconnet operations queue observer */
        if (priv->queue_change_handler > 0) {
                g_signal_handler_disconnect (G_OBJECT (modest_runtime_get_mail_operation_queue ()), priv->queue_change_handler);
                priv->queue_change_handler = 0;
        }
+       if (priv->header_model != NULL) {
+               g_object_unref (priv->header_model);
+               priv->header_model = NULL;
+       }
+
+       /* disconnet operations queue observer */
        
        if (priv->progress_bar_timeout > 0) {
                g_source_remove (priv->progress_bar_timeout);
@@ -441,6 +450,11 @@ modest_msg_view_window_finalize (GObject *obj)
                priv->row_reference = NULL;
        }
 
+       if (priv->msg_uid) {
+               g_free (priv->msg_uid);
+               priv->msg_uid = NULL;
+       }
+
        G_OBJECT_CLASS(parent_class)->finalize (obj);
 }
 
@@ -454,13 +468,16 @@ on_delete_event (GtkWidget *widget, GdkEvent *event, ModestMsgViewWindow *self)
 }
 
 ModestWindow *
-modest_msg_view_window_new_with_header_model (TnyMsg *msg, const gchar *account_name,
-                                             GtkTreeModel *model, GtkTreeRowReference *row_reference)
+modest_msg_view_window_new_with_header_model (TnyMsg *msg, 
+                                             const gchar *account_name,
+                                             const gchar *msg_uid,
+                                             GtkTreeModel *model, 
+                                             GtkTreeRowReference *row_reference)
 {
        ModestMsgViewWindow *window = NULL;
        ModestMsgViewWindowPrivate *priv = NULL;
 
-       window = MODEST_MSG_VIEW_WINDOW(modest_msg_view_window_new (msg, account_name));
+       window = MODEST_MSG_VIEW_WINDOW(modest_msg_view_window_new (msg, account_name, msg_uid));
        g_return_val_if_fail (MODEST_IS_MSG_VIEW_WINDOW (window), NULL);
 
        priv = MODEST_MSG_VIEW_WINDOW_GET_PRIVATE (window);
@@ -471,33 +488,43 @@ modest_msg_view_window_new_with_header_model (TnyMsg *msg, const gchar *account_
 
        modest_msg_view_window_update_priority (window);
 
-       modest_msg_view_window_update_dimmed (window);
-
        return MODEST_WINDOW(window);
 }
 
 
 ModestWindow *
-modest_msg_view_window_new (TnyMsg *msg, const gchar *account_name)
+modest_msg_view_window_new (TnyMsg *msg, 
+                           const gchar *account_name,
+                           const gchar *msg_uid)
 {
-       GObject *obj;
-       ModestMsgViewWindowPrivate *priv;
-       ModestWindowPrivate *parent_priv;
-       GtkActionGroup *action_group;
+       ModestMsgViewWindow *self = NULL;
+       GObject *obj = NULL;
+       ModestMsgViewWindowPrivate *priv = NULL;
+       ModestWindowPrivate *parent_priv = NULL;
+       ModestDimmingRulesGroup *menu_rules_group = NULL;
+       ModestDimmingRulesGroup *toolbar_rules_group = NULL;
+       GtkActionGroup *action_group = NULL;
        GError *error = NULL;
        GdkPixbuf *window_icon = NULL;
-       GtkAction *action;
 
        g_return_val_if_fail (msg, NULL);
        
        obj = g_object_new(MODEST_TYPE_MSG_VIEW_WINDOW, NULL);
        priv = MODEST_MSG_VIEW_WINDOW_GET_PRIVATE(obj);
        parent_priv = MODEST_WINDOW_GET_PRIVATE(obj);
-       
+       self = MODEST_MSG_VIEW_WINDOW (obj);
+
+       priv->msg_uid = g_strdup (msg_uid);
+
        parent_priv->ui_manager = gtk_ui_manager_new();
+       parent_priv->ui_dimming_manager = modest_ui_dimming_manager_new();
+
        action_group = gtk_action_group_new ("ModestMsgViewWindowActions");
        gtk_action_group_set_translation_domain (action_group, GETTEXT_PACKAGE);
 
+       menu_rules_group = modest_dimming_rules_group_new ("ModestMenuDimmingRules");
+       toolbar_rules_group = modest_dimming_rules_group_new ("ModestToolbarDimmingRules");
+
        /* Add common actions */
        gtk_action_group_add_actions (action_group,
                                      modest_action_entries,
@@ -531,6 +558,22 @@ modest_msg_view_window_new (TnyMsg *msg, const gchar *account_name)
        }
        /* ****** */
 
+       /* Add common dimming rules */
+       modest_dimming_rules_group_add_rules (menu_rules_group, 
+                                             modest_msg_view_menu_dimming_entries,
+                                             G_N_ELEMENTS (modest_msg_view_menu_dimming_entries),
+                                             self);
+       modest_dimming_rules_group_add_rules (toolbar_rules_group, 
+                                             modest_msg_view_toolbar_dimming_entries,
+                                             G_N_ELEMENTS (modest_msg_view_toolbar_dimming_entries),
+                                             self);
+
+       /* Insert dimming rules group for this window */
+       modest_ui_dimming_manager_insert_rules_group (parent_priv->ui_dimming_manager, menu_rules_group);
+       modest_ui_dimming_manager_insert_rules_group (parent_priv->ui_dimming_manager, toolbar_rules_group);
+       g_object_unref (menu_rules_group);
+       g_object_unref (toolbar_rules_group);
+
        /* Add accelerators */
        gtk_window_add_accel_group (GTK_WINDOW (obj), 
                                    gtk_ui_manager_get_accel_group (parent_priv->ui_manager));
@@ -570,25 +613,30 @@ modest_msg_view_window_new (TnyMsg *msg, const gchar *account_name)
 
        priv->last_search = NULL;
 
-       modest_msg_view_window_update_dimmed (MODEST_MSG_VIEW_WINDOW (obj));
 
        /* Set window icon */
        window_icon = modest_platform_get_icon (MODEST_APP_MSG_VIEW_ICON);
        gtk_window_set_icon (GTK_WINDOW (obj), window_icon);
 
        /* Init the clipboard actions dim status */
-       action = gtk_ui_manager_get_action (parent_priv->ui_manager, "/MenuBar/EditMenu/EditCopyMenu");
-       gtk_action_set_sensitive (action, FALSE);
-
-       action = gtk_ui_manager_get_action (parent_priv->ui_manager, "/MenuBar/EditMenu/EditCutMenu");
-       gtk_action_set_sensitive (action, FALSE);
+       modest_msg_view_grab_focus(MODEST_MSG_VIEW (priv->msg_view));
 
-       gtk_widget_grab_focus (priv->msg_view);
+       update_window_title (MODEST_MSG_VIEW_WINDOW (obj));
 
        return MODEST_WINDOW(obj);
 }
 
 
+gboolean 
+modest_msg_view_window_toolbar_on_transfer_mode     (ModestMsgViewWindow *self)
+{
+       ModestMsgViewWindowPrivate *priv= NULL; 
+
+       g_return_val_if_fail (MODEST_IS_MSG_VIEW_WINDOW (self), FALSE);
+       priv = MODEST_MSG_VIEW_WINDOW_GET_PRIVATE (self);
+
+       return priv->current_toolbar_mode == TOOLBAR_MODE_TRANSFER;
+}
 
 TnyHeader*
 modest_msg_view_window_get_header (ModestMsgViewWindow *self)
@@ -631,23 +679,8 @@ modest_msg_view_window_get_message (ModestMsgViewWindow *self)
 const gchar*
 modest_msg_view_window_get_message_uid (ModestMsgViewWindow *self)
 {
-       TnyMsg *msg;
-       TnyHeader *header;
-       const gchar *retval = NULL;
-
-       msg = modest_msg_view_window_get_message (self);
-
-       if (!msg)
-               return NULL;
-
-       header = tny_msg_get_header (msg);
-       if (header) {
-               retval = tny_header_get_uid (header);
-               g_object_unref (header);
-       }
-       g_object_unref (msg);
-
-       return retval;
+       ModestMsgViewWindowPrivate *priv = MODEST_MSG_VIEW_WINDOW_GET_PRIVATE (self);
+       return (const gchar*) priv->msg_uid;
 }
 
 static void 
@@ -659,6 +692,7 @@ modest_msg_view_window_toggle_find_toolbar (GtkToggleAction *toggle,
 
        if (gtk_toggle_action_get_active (toggle)) {
                gtk_widget_show (priv->find_toolbar);
+               hildon_find_toolbar_highlight_entry (HILDON_FIND_TOOLBAR (priv->find_toolbar), TRUE);
        } else {
                gtk_widget_hide (priv->find_toolbar);
        }
@@ -826,8 +860,8 @@ modest_msg_view_window_scroll_down (ModestWindow *window)
        g_signal_emit_by_name (G_OBJECT (priv->main_scroll), "scroll-child", GTK_SCROLL_STEP_DOWN, FALSE);
 }
 
-static gboolean 
-modest_msg_view_window_is_last_message (ModestMsgViewWindow *window)
+gboolean
+modest_msg_view_window_last_message_selected (ModestMsgViewWindow *window)
 {
        GtkTreePath *path;
        ModestMsgViewWindowPrivate *priv;
@@ -861,8 +895,19 @@ modest_msg_view_window_is_last_message (ModestMsgViewWindow *window)
        
 }
 
-static gboolean 
-modest_msg_view_window_is_first_message (ModestMsgViewWindow *window)
+gboolean
+modest_msg_view_window_has_headers_model (ModestMsgViewWindow *window)
+{
+       ModestMsgViewWindowPrivate *priv;
+
+       g_return_val_if_fail (MODEST_IS_MSG_VIEW_WINDOW (window), TRUE);
+       priv = MODEST_MSG_VIEW_WINDOW_GET_PRIVATE (window);
+
+       return priv->header_model != NULL;
+}
+
+gboolean
+modest_msg_view_window_first_message_selected (ModestMsgViewWindow *window)
 {
        GtkTreePath *path;
        ModestMsgViewWindowPrivate *priv;
@@ -951,8 +996,10 @@ modest_msg_view_window_select_next_message (ModestMsgViewWindow *window)
                        if (!(flags & TNY_HEADER_FLAG_SEEN))
                                tny_header_set_flags (header, flags | TNY_HEADER_FLAG_SEEN);
 
+                       /* Msg download initied */
+
                        /* New mail operation */
-                       mail_op = modest_mail_operation_new (MODEST_MAIL_OPERATION_ID_RECEIVE, G_OBJECT(window));
+                       mail_op = modest_mail_operation_new (MODEST_MAIL_OPERATION_TYPE_RECEIVE, G_OBJECT(window));
                        modest_mail_operation_queue_add (modest_runtime_get_mail_operation_queue (), mail_op);
                        modest_mail_operation_get_msg (mail_op, header, view_msg_cb, NULL);
                        g_object_unref (mail_op);
@@ -999,7 +1046,7 @@ modest_msg_view_window_select_first_message (ModestMsgViewWindow *self)
                tny_header_set_flags (header, flags | TNY_HEADER_FLAG_SEEN);
        
        /* New mail operation */
-       mail_op = modest_mail_operation_new (MODEST_MAIL_OPERATION_ID_RECEIVE, G_OBJECT(self));
+       mail_op = modest_mail_operation_new (MODEST_MAIL_OPERATION_TYPE_RECEIVE, G_OBJECT(self));
        modest_mail_operation_queue_add (modest_runtime_get_mail_operation_queue (), mail_op);
        modest_mail_operation_get_msg (mail_op, header, view_msg_cb, NULL);
        g_object_unref (mail_op);
@@ -1046,7 +1093,7 @@ modest_msg_view_window_select_previous_message (ModestMsgViewWindow *window)
                                tny_header_set_flags (header, flags | TNY_HEADER_FLAG_SEEN);
 
                        /* New mail operation */
-                       mail_op = modest_mail_operation_new (MODEST_MAIL_OPERATION_ID_RECEIVE, G_OBJECT(window));
+                       mail_op = modest_mail_operation_new (MODEST_MAIL_OPERATION_TYPE_RECEIVE, G_OBJECT(window));
                        modest_mail_operation_queue_add (modest_runtime_get_mail_operation_queue (), mail_op);
                        modest_mail_operation_get_msg (mail_op, header, view_msg_cb, NULL);             
 
@@ -1076,12 +1123,12 @@ view_msg_cb (ModestMailOperation *mail_op,
 
        /* Set new message */
        modest_msg_view_set_message (MODEST_MSG_VIEW (priv->msg_view), msg);
-       modest_msg_view_window_update_dimmed (self);
        modest_msg_view_window_update_priority (self);
-       gtk_widget_grab_focus (priv->msg_view);
+       update_window_title (MODEST_MSG_VIEW_WINDOW (self));
+       modest_msg_view_grab_focus (MODEST_MSG_VIEW (priv->msg_view));
 }
 
-static TnyFolderType
+TnyFolderType
 modest_msg_view_window_get_folder_type (ModestMsgViewWindow *window)
 {
        ModestMsgViewWindowPrivate *priv;
@@ -1114,77 +1161,6 @@ modest_msg_view_window_get_folder_type (ModestMsgViewWindow *window)
        return folder_type;
 }
 
-static void
-modest_msg_view_window_update_dimmed (ModestMsgViewWindow *window)
-{
-       ModestWindowPrivate *parent_priv;
-       ModestMsgViewWindowPrivate *priv;
-       GtkAction *widget;
-       gboolean is_first, is_last;
-       TnyFolderType folder_type;
-       gboolean is_not_sent;
-       GList *attachments, *node;
-       gint n_selected;
-       gboolean selected_messages = FALSE;
-       gboolean nested_attachments = FALSE;
-
-       parent_priv = MODEST_WINDOW_GET_PRIVATE (window);
-       priv = MODEST_MSG_VIEW_WINDOW_GET_PRIVATE (window);
-
-       is_first = modest_msg_view_window_is_first_message (window);
-       is_last = modest_msg_view_window_is_last_message (window);
-
-       widget = gtk_ui_manager_get_action (parent_priv->ui_manager, "/ToolBar/ToolbarMessageBack");
-       gtk_action_set_sensitive (widget, !is_first);
-       widget = gtk_ui_manager_get_action (parent_priv->ui_manager, "/MenuBar/ViewMenu/ViewPreviousMessageMenu");
-       gtk_action_set_sensitive (widget, !is_first);
-               
-       widget = gtk_ui_manager_get_action (parent_priv->ui_manager, "/ToolBar/ToolbarMessageNext");
-       gtk_action_set_sensitive (widget, !is_last);
-       widget = gtk_ui_manager_get_action (parent_priv->ui_manager, "/MenuBar/ViewMenu/ViewNextMessageMenu");
-       gtk_action_set_sensitive (widget, !is_last);
-
-       folder_type = modest_msg_view_window_get_folder_type (MODEST_MSG_VIEW_WINDOW (window));
-       is_not_sent = ((folder_type == TNY_FOLDER_TYPE_DRAFTS)||(folder_type == TNY_FOLDER_TYPE_OUTBOX));
-       widget = gtk_ui_manager_get_action (parent_priv->ui_manager, "/ToolBar/ToolbarMessageReply");
-       gtk_action_set_sensitive (widget, !is_not_sent);
-       widget = gtk_ui_manager_get_action (parent_priv->ui_manager, "/MenuBar/MessageMenu/MessageReplyMenu");
-       gtk_action_set_sensitive (widget, !is_not_sent);
-       widget = gtk_ui_manager_get_action (parent_priv->ui_manager, "/MenuBar/MessageMenu/MessageReplyAllMenu");
-       gtk_action_set_sensitive (widget, !is_not_sent);
-       widget = gtk_ui_manager_get_action (parent_priv->ui_manager, "/MenuBar/MessageMenu/MessageForwardMenu");
-       gtk_action_set_sensitive (widget, !is_not_sent);
-
-       /* Attachment actions dimming */
-       attachments = modest_msg_view_get_selected_attachments (MODEST_MSG_VIEW (priv->msg_view));
-       n_selected = g_list_length (attachments);
-       for (node = attachments; node != NULL; node = g_list_next (node)) {
-               TnyMimePart *mime_part = TNY_MIME_PART (node->data);
-               TnyList *nested_list = tny_simple_list_new ();
-               if (!tny_mime_part_is_attachment (mime_part)) {
-                       selected_messages = TRUE;
-                       break;
-               }
-               tny_mime_part_get_parts (mime_part, nested_list);
-               if (tny_list_get_length (nested_list) > 0)
-                       nested_attachments = TRUE;
-               g_object_unref (nested_list);
-       }
-       g_list_free (attachments);
-
-       widget = gtk_ui_manager_get_action (parent_priv->ui_manager, "/MenuBar/AttachmentsMenu/ViewAttachmentMenu");
-       gtk_action_set_sensitive (widget, n_selected == 1);
-       widget = gtk_ui_manager_get_action (parent_priv->ui_manager, "/MenuBar/AttachmentsMenu/SaveAttachmentMenu");
-       gtk_action_set_sensitive (widget, (n_selected > 0) && (!selected_messages) &&  (!nested_attachments));
-
-       /* Dimming depending of message being an attachment or not. It's not an attachment if
-        * we opened it outside a folder view */
-       widget = gtk_ui_manager_get_action (parent_priv->ui_manager, "/MenuBar/MessageMenu/MessageDeleteMenu");
-       gtk_action_set_sensitive (widget, priv->header_model != NULL);
-       widget = gtk_ui_manager_get_action (parent_priv->ui_manager, "/MenuBar/EditMenu/EditMoveToMenu");
-       gtk_action_set_sensitive (widget, priv->header_model != NULL);
-
-}
 
 static void
 modest_msg_view_window_update_priority (ModestMsgViewWindow *window)
@@ -1340,7 +1316,7 @@ modest_msg_view_window_clipboard_owner_change (GtkClipboard *clipboard,
                                               ModestMsgViewWindow *window)
 {
        ModestWindowPrivate *parent_priv;
-       GtkAction *action;
+/*     GtkAction *action; */
        gboolean is_address;
        gchar *selection;
        GtkWidget *focused;
@@ -1350,19 +1326,19 @@ modest_msg_view_window_clipboard_owner_change (GtkClipboard *clipboard,
 
        is_address = ((selection != NULL) && (modest_text_utils_validate_recipient (selection)));
        
-       action = gtk_ui_manager_get_action (parent_priv->ui_manager, "/MenuBar/ToolsMenu/ToolsAddToContactsMenu");
-       gtk_action_set_sensitive (action, is_address);
+/*     action = gtk_ui_manager_get_action (parent_priv->ui_manager, "/MenuBar/ToolsMenu/ToolsAddToContactsMenu"); */
+/*     gtk_action_set_sensitive (action, is_address); */
 
        focused = gtk_window_get_focus (GTK_WINDOW (window));
 
-       action = gtk_ui_manager_get_action (parent_priv->ui_manager, "/MenuBar/EditMenu/EditCopyMenu");
-       gtk_action_set_sensitive (action, (selection != NULL) && (!MODEST_IS_ATTACHMENTS_VIEW (focused)));
+/*     action = gtk_ui_manager_get_action (parent_priv->ui_manager, "/MenuBar/EditMenu/EditCopyMenu"); */
+/*     gtk_action_set_sensitive (action, (selection != NULL) && (!MODEST_IS_ATTACHMENTS_VIEW (focused))); */
 
-       action = gtk_ui_manager_get_action (parent_priv->ui_manager, "/MenuBar/EditMenu/EditCutMenu");
-       gtk_action_set_sensitive (action, (selection != NULL) && (!MODEST_IS_ATTACHMENTS_VIEW (focused)));
+/*     action = gtk_ui_manager_get_action (parent_priv->ui_manager, "/MenuBar/EditMenu/EditCutMenu"); */
+/*     gtk_action_set_sensitive (action, (selection != NULL) && (!MODEST_IS_ATTACHMENTS_VIEW (focused))); */
 
        g_free (selection);
-       modest_msg_view_window_update_dimmed (window);
+/*     modest_msg_view_window_update_dimmed (window); */
        
 }
 
@@ -1413,7 +1389,7 @@ on_queue_changed (ModestMailOperationQueue *queue,
 {
        GSList *tmp;
        ModestMsgViewWindowPrivate *priv;
-       ModestMailOperationId op_id;
+       ModestMailOperationTypeOperation op_type;
        ModestToolBarModes mode;
        
        g_return_if_fail (MODEST_IS_MSG_VIEW_WINDOW (self));
@@ -1424,10 +1400,10 @@ on_queue_changed (ModestMailOperationQueue *queue,
            return;
 
        /* Get toolbar mode from operation id*/
-       op_id = modest_mail_operation_get_id (mail_op);
-       switch (op_id) {
-       case MODEST_MAIL_OPERATION_ID_SEND:
-       case MODEST_MAIL_OPERATION_ID_RECEIVE:
+       op_type = modest_mail_operation_get_type_operation (mail_op);
+       switch (op_type) {
+       case MODEST_MAIL_OPERATION_TYPE_SEND:
+       case MODEST_MAIL_OPERATION_TYPE_RECEIVE:
                mode = TOOLBAR_MODE_TRANSFER;
                break;
        default:
@@ -1468,6 +1444,20 @@ on_queue_changed (ModestMailOperationQueue *queue,
        }
 }
 
+GList *
+modest_msg_view_window_get_attachments (ModestMsgViewWindow *win) 
+{
+       ModestMsgViewWindowPrivate *priv;
+       GList *selected_attachments = NULL;
+       
+       g_return_val_if_fail (MODEST_IS_MSG_VIEW_WINDOW (win), NULL);
+       priv = MODEST_MSG_VIEW_WINDOW_GET_PRIVATE (win);
+
+       selected_attachments = modest_msg_view_get_selected_attachments (MODEST_MSG_VIEW (priv->msg_view));
+       
+       return selected_attachments;
+}
+
 void
 modest_msg_view_window_view_attachment (ModestMsgViewWindow *window, TnyMimePart *mime_part)
 {
@@ -1500,11 +1490,24 @@ modest_msg_view_window_view_attachment (ModestMsgViewWindow *window, TnyMimePart
 
        if (!TNY_IS_MSG (mime_part)) {
                gchar *filepath = NULL;
-               TnyFsStream *temp_stream = modest_maemo_utils_create_temp_stream (&filepath);
+               const gchar *att_filename = tny_mime_part_get_filename (mime_part);
+               gchar *extension = NULL;
+               TnyFsStream *temp_stream = NULL;
+
+               if (att_filename) {
+                       extension = g_strrstr (att_filename, ".");
+                       if (extension != NULL)
+                               extension++;
+               }
+
+               temp_stream = modest_maemo_utils_create_temp_stream (extension, &filepath);
 
                if (temp_stream) {
+                       const gchar *content_type;
+                       content_type = tny_mime_part_get_content_type (mime_part);
                        tny_mime_part_decode_to_stream (mime_part, TNY_STREAM (temp_stream));
-                       modest_platform_activate_file (filepath);
+                       
+                       modest_platform_activate_file (filepath, content_type);
                        g_object_unref (temp_stream);
                        g_free (filepath);
                        /* TODO: delete temporary file */
@@ -1513,18 +1516,17 @@ modest_msg_view_window_view_attachment (ModestMsgViewWindow *window, TnyMimePart
                /* message attachment */
                TnyHeader *header = NULL;
                ModestWindowMgr *mgr;
-               ModestWindow *msg_win;
+               ModestWindow *msg_win = NULL;
 
                header = tny_msg_get_header (TNY_MSG (mime_part));
                mgr = modest_runtime_get_window_mgr ();
-               /* TODO: this is not getting any uid */
-               msg_win = modest_window_mgr_find_window_by_msguid (mgr, tny_header_get_uid (header));
+               msg_win = modest_window_mgr_find_window_by_header (mgr, header);
 
                if (!msg_win) {
                        gchar *account = g_strdup (modest_window_get_active_account (MODEST_WINDOW (window)));
                        if (!account)
                                account = modest_account_mgr_get_default_account (modest_runtime_get_account_mgr ());
-                       msg_win = modest_msg_view_window_new (TNY_MSG (mime_part), account);
+                       msg_win = modest_msg_view_window_new (TNY_MSG (mime_part), account, NULL);
                        modest_window_mgr_register_window (mgr, msg_win);
                        gtk_window_set_transient_for (GTK_WINDOW (msg_win), GTK_WINDOW (window));
                }
@@ -1669,3 +1671,24 @@ modest_msg_view_window_remove_attachments (ModestMsgViewWindow *window, GList *m
 {
 /*     g_message ("not implemented %s", __FUNCTION__); */
 }
+
+
+static void
+update_window_title (ModestMsgViewWindow *window)
+{
+       ModestMsgViewWindowPrivate *priv = MODEST_MSG_VIEW_WINDOW_GET_PRIVATE (window);
+       TnyMsg *msg = NULL;
+       TnyHeader *header = NULL;
+       const gchar *subject = NULL;
+
+       msg = modest_msg_view_get_message (MODEST_MSG_VIEW (priv->msg_view));
+       if (msg != NULL) {
+               header = tny_msg_get_header (msg);
+               subject = tny_header_get_subject (header);
+       }
+
+       if ((subject == NULL)||(subject[0] == '\0'))
+               subject = _("mail_va_no_subject");
+
+       gtk_window_set_title (GTK_WINDOW (window), subject);
+}