* src/maemo/modest-msg-edit-window.c:
[modest] / src / maemo / modest-msg-edit-window.c
index 14303eb..04b467d 100644 (file)
@@ -641,6 +641,30 @@ text_buffer_mark_set (GtkTextBuffer *buffer,
        gtk_text_buffer_end_user_action (buffer);
 }
 
+static void
+cut_clipboard_check (GtkTextView *text_view,
+                    gpointer userdata)
+{
+       GtkTextBuffer *buffer;
+       
+       buffer = gtk_text_view_get_buffer (text_view);
+       if (!modest_text_utils_buffer_selection_is_valid (buffer)) {
+               g_signal_stop_emission_by_name ((gpointer )text_view, "cut-clipboard");
+       }
+}
+
+static void
+copy_clipboard_check (GtkTextView *text_view,
+                    gpointer userdata)
+{
+       GtkTextBuffer *buffer;
+       
+       buffer = gtk_text_view_get_buffer (text_view);
+       if (!modest_text_utils_buffer_selection_is_valid (buffer)) {
+               g_signal_stop_emission_by_name ((gpointer )text_view, "copy-clipboard");
+       }
+}
+
 void vadj_changed (GtkAdjustment *adj,
                   ModestMsgEditWindow *window)
 {
@@ -720,6 +744,9 @@ connect_signals (ModestMsgEditWindow *obj)
                g_signal_connect (G_OBJECT (gtk_clipboard_get (GDK_SELECTION_CLIPBOARD)), "owner-change",
                                  G_CALLBACK (modest_msg_edit_window_clipboard_owner_change), obj);
 
+       g_signal_connect (G_OBJECT (priv->msg_body), "cut-clipboard", G_CALLBACK (cut_clipboard_check), NULL);
+       g_signal_connect (G_OBJECT (priv->msg_body), "copy-clipboard", G_CALLBACK (copy_clipboard_check), NULL);
+
 }
 
 static void
@@ -986,19 +1013,25 @@ pixbuf_from_stream (TnyStream *stream, const gchar *mime_type, guint64 *stream_s
 
        tny_stream_reset (TNY_STREAM (stream));
        while (!tny_stream_is_eos (TNY_STREAM (stream))) {
+               GError *error = NULL;
                unsigned char read_buffer[128];
                gint readed;
                readed = tny_stream_read (TNY_STREAM (stream), (char *) read_buffer, 128);
                size += readed;
-               if (!gdk_pixbuf_loader_write (loader, read_buffer, readed, NULL))
+               if (!gdk_pixbuf_loader_write (loader, read_buffer, readed, &error)) {
                        break;
+               }
        }
 
        pixbuf = gdk_pixbuf_loader_get_pixbuf (loader);
-       g_object_ref (pixbuf);
+       if (pixbuf) 
+               g_object_ref (pixbuf);
        gdk_pixbuf_loader_close (loader, NULL);
        g_object_unref (loader);
 
+       if (!pixbuf)
+               return NULL;
+
        if (gdk_pixbuf_get_width (pixbuf) > IMAGE_MAX_WIDTH) {
                GdkPixbuf *new_pixbuf;
                gint new_height;
@@ -1031,7 +1064,7 @@ replace_with_images (ModestMsgEditWindow *self, TnyList *attachments)
                const gchar *mime_type = tny_mime_part_get_content_type (part);
                if ((cid != NULL)&&(mime_type != NULL)) {
                        guint64 stream_size;
-                       TnyStream *stream = tny_mime_part_get_stream (part);
+                       TnyStream *stream = tny_mime_part_get_decoded_stream (part);
                        GdkPixbuf *pixbuf = pixbuf_from_stream (stream, mime_type, &stream_size);
 
 
@@ -1228,7 +1261,7 @@ set_msg (ModestMsgEditWindow *self, TnyMsg *msg, gboolean preserve_is_rich)
        gtk_text_buffer_get_start_iter (priv->text_buffer, &iter);
        gtk_text_buffer_place_cursor (priv->text_buffer, &iter);
 
-       modest_msg_edit_window_reset_modified (self);
+       modest_msg_edit_window_set_modified (self, FALSE);
 
        modest_ui_actions_check_toolbar_dimming_rules (MODEST_WINDOW (self));
        modest_ui_actions_check_menu_dimming_rules (MODEST_WINDOW (self));
@@ -1528,7 +1561,6 @@ modest_msg_edit_window_new (TnyMsg *msg, const gchar *account_name, gboolean pre
        g_object_unref (menu_rules_group);
        g_object_unref (toolbar_rules_group);
        g_object_unref (clipboard_rules_group);
-       gtk_widget_show_all (GTK_WIDGET (obj));
        modest_msg_edit_window_clipboard_owner_change (NULL, NULL, MODEST_MSG_EDIT_WINDOW (obj));
 
        set_msg (MODEST_MSG_EDIT_WINDOW (obj), msg, preserve_is_rich);
@@ -1540,7 +1572,7 @@ modest_msg_edit_window_new (TnyMsg *msg, const gchar *account_name, gboolean pre
        modest_window_check_dimming_rules_group (MODEST_WINDOW (obj), MODEST_DIMMING_RULES_CLIPBOARD);
        priv->update_caption_visibility = TRUE;
 
-       modest_msg_edit_window_reset_modified (MODEST_MSG_EDIT_WINDOW (obj));
+       modest_msg_edit_window_set_modified (MODEST_MSG_EDIT_WINDOW (obj), FALSE);
 
        /* Track account-removed signal, this window should be closed
           in the case we're creating a mail associated to the account
@@ -1922,13 +1954,13 @@ text_buffer_refresh_attributes (WPTextBuffer *buffer, ModestMsgEditWindow *windo
        switch (buffer_format->justification)
        {
        case GTK_JUSTIFY_LEFT:
-               action = gtk_ui_manager_get_action (parent_priv->ui_manager, "/MenuBar/FormatMenu/AlignmentLeftMenu");
+               action = gtk_ui_manager_get_action (parent_priv->ui_manager, "/MenuBar/FormatMenu/AlignmentMenu/AlignmentLeftMenu");
                break;
        case GTK_JUSTIFY_CENTER:
-               action = gtk_ui_manager_get_action (parent_priv->ui_manager, "/MenuBar/FormatMenu/AlignmentCenterMenu");
+               action = gtk_ui_manager_get_action (parent_priv->ui_manager, "/MenuBar/FormatMenu/AlignmentMenu/AlignmentCenterMenu");
                break;
        case GTK_JUSTIFY_RIGHT:
-               action = gtk_ui_manager_get_action (parent_priv->ui_manager, "/MenuBar/FormatMenu/AlignmentRightMenu");
+               action = gtk_ui_manager_get_action (parent_priv->ui_manager, "/MenuBar/FormatMenu/AlignmentMenu/AlignmentRightMenu");
                break;
        default:
                break;
@@ -2995,18 +3027,19 @@ body_changed (GtkTextBuffer *buffer, ModestMsgEditWindow *editor)
 }
 
 void
-modest_msg_edit_window_reset_modified (ModestMsgEditWindow *editor)
+modest_msg_edit_window_set_modified (ModestMsgEditWindow *editor,
+                                    gboolean modified)
 {
        ModestMsgEditWindowPrivate *priv = MODEST_MSG_EDIT_WINDOW_GET_PRIVATE (editor);
        GtkTextBuffer *buffer;
 
        buffer = modest_recpt_editor_get_buffer (MODEST_RECPT_EDITOR(priv->to_field));
-       gtk_text_buffer_set_modified (buffer, FALSE);
+       gtk_text_buffer_set_modified (buffer, modified);
        buffer = modest_recpt_editor_get_buffer (MODEST_RECPT_EDITOR(priv->cc_field));
-       gtk_text_buffer_set_modified (buffer, FALSE);
+       gtk_text_buffer_set_modified (buffer, modified);
        buffer = modest_recpt_editor_get_buffer (MODEST_RECPT_EDITOR(priv->bcc_field));
-       gtk_text_buffer_set_modified (buffer, FALSE);
-       gtk_text_buffer_set_modified (priv->text_buffer, FALSE);
+       gtk_text_buffer_set_modified (buffer, modified);
+       gtk_text_buffer_set_modified (priv->text_buffer, modified);
 }
 
 gboolean