* src/maemo/modest-msg-edit-window-ui.xml:
[modest] / src / maemo / modest-msg-edit-window.c
index ad6b342..d2423db 100644 (file)
@@ -82,6 +82,7 @@ static gboolean msg_body_focus (GtkWidget *focus, GdkEventFocus *event, gpointer
 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  setup_insensitive_handlers (ModestMsgEditWindow *editor);
 static void  reset_modified (ModestMsgEditWindow *editor);
 static gboolean is_modified (ModestMsgEditWindow *editor);
@@ -116,8 +117,12 @@ 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);
 
 /* Find toolbar */
 static void modest_msg_edit_window_find_toolbar_search (GtkWidget *widget,
@@ -125,7 +130,6 @@ static void modest_msg_edit_window_find_toolbar_search (GtkWidget *widget,
 static void modest_msg_edit_window_find_toolbar_close (GtkWidget *widget,
                                                       ModestMsgEditWindow *window);
 
-
 /* list my signals */
 enum {
        /* MY_SIGNAL_1, */
@@ -175,6 +179,7 @@ struct _ModestMsgEditWindowPrivate {
        gdouble zoom_level;
        
        gulong      clipboard_change_handler_id;
+       gulong      system_clipboard_change_handler_id;
 
        TnyMsg      *draft_msg;
 };
@@ -277,6 +282,7 @@ modest_msg_edit_window_init (ModestMsgEditWindow *obj)
 
        priv->draft_msg = NULL;
        priv->clipboard_change_handler_id = 0;
+       priv->system_clipboard_change_handler_id = 0;
 }
 
 
@@ -470,6 +476,8 @@ init_window (ModestMsgEditWindow *obj)
 
        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);
 }
        
 
@@ -484,6 +492,12 @@ modest_msg_edit_window_finalize (GObject *obj)
                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);
        
@@ -936,6 +950,8 @@ 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);
 
        /* set initial state of cc and bcc */
        action = gtk_ui_manager_get_action (parent_priv->ui_manager, "/MenuBar/ViewMenu/ViewCcFieldMenu");
@@ -956,6 +972,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;
 }
@@ -1401,6 +1419,7 @@ modest_msg_edit_window_insert_image (ModestMsgEditWindow *window)
        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"));
 
        response = gtk_dialog_run (GTK_DIALOG (dialog));
        switch (response) {
@@ -1479,36 +1498,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);
@@ -1533,24 +1557,35 @@ modest_msg_edit_window_attach_file (ModestMsgEditWindow *window)
                        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;
@@ -1584,6 +1619,8 @@ modest_msg_edit_window_attach_file_noninteractive (
                        close (file_id);
                        g_warning("file to be attached does not exist: %s", filename);
                }
+
+               g_free (filename);
        }
 }
 
@@ -1782,7 +1819,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, _("ckct_ib_max_zoom_level_reached"));
                return FALSE;
        }
 
@@ -1814,7 +1851,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, _("ckct_ib_min_zoom_level_reached"));
                        break;
                }
        }
@@ -2258,6 +2295,8 @@ 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);
 }
 
 static void  
@@ -2371,6 +2410,28 @@ send_insensitive_press (GtkWidget *widget, ModestMsgEditWindow *editor)
        hildon_banner_show_information (NULL, NULL, _("mcen_ib_add_recipients_first"));
 }
 
+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)
 {
@@ -2465,10 +2526,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));
@@ -2477,6 +2542,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 
@@ -2567,3 +2642,26 @@ modest_msg_edit_window_find_toolbar_close (GtkWidget *widget,
        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;
+
+       clipboard = gtk_clipboard_get (GDK_SELECTION_CLIPBOARD);
+
+       action = gtk_ui_manager_get_action (parent_priv->ui_manager, "/MenuBar/EditMenu/PasteMenu");
+       gtk_action_set_sensitive (action, gtk_clipboard_wait_is_text_available (clipboard));
+
+}
+
+static void
+modest_msg_edit_window_system_clipboard_owner_change (GtkClipboard *clipboard,
+                                                     GdkEvent *event,
+                                                     ModestMsgEditWindow *window)
+{
+       update_paste_dimming (window);
+}
+