evolution r36906 - trunk/composer



Author: mcrha
Date: Tue Dec 16 12:57:38 2008
New Revision: 36906
URL: http://svn.gnome.org/viewvc/evolution?rev=36906&view=rev

Log:
2008-12-16  Milan Crha  <mcrha redhat com>

	** Fix for bug #564248

	* e-msg-composer.c: (msg_composer_paste_clipboard):
	Attach images pasted from a clipboard.

Note: Requires at least gtkhtml revision 9067.


Modified:
   trunk/composer/ChangeLog
   trunk/composer/e-msg-composer.c

Modified: trunk/composer/e-msg-composer.c
==============================================================================
--- trunk/composer/e-msg-composer.c	(original)
+++ trunk/composer/e-msg-composer.c	Tue Dec 16 12:57:38 2008
@@ -67,6 +67,7 @@
 #include "e-util/e-plugin-ui.h"
 #include "e-util/e-util-private.h"
 #include "e-util/e-util.h"
+#include "e-util/e-mktemp.h"
 #include <mail/em-event.h>
 #include "e-signature-combo-box.h"
 
@@ -2454,6 +2455,7 @@
 	EMsgComposer *composer;
 	GtkWidget *parent;
 	GtkWidget *widget;
+	GtkClipboard *clipboard;
 
 	composer = E_MSG_COMPOSER (editor);
 	widget = gtk_window_get_focus (GTK_WINDOW (editor));
@@ -2464,8 +2466,37 @@
 		return;
 	}
 
-	/* Chain up to parent's paste_clipboard() method. */
-	GTKHTML_EDITOR_CLASS (parent_class)->paste_clipboard (editor);
+	clipboard = gtk_widget_get_clipboard (widget, GDK_SELECTION_CLIPBOARD);
+	if (clipboard && gtk_clipboard_wait_is_image_available (clipboard)) {
+		GdkPixbuf *pixbuf;
+
+		pixbuf = gtk_clipboard_wait_for_image (clipboard);
+		if (pixbuf) {
+			char *tmpl = g_strconcat (_("Image"), "-XXXXXX", NULL);
+			char *filename = e_mktemp (tmpl);
+
+			g_free (tmpl);
+
+			if (filename && gdk_pixbuf_save (pixbuf, filename, "png", NULL, NULL)) {
+				if (gtkhtml_editor_get_html_mode (editor)) {
+					char *uri = g_strconcat ("file://", filename, NULL);
+					/* this loads image async, thus cannot remove file from this */
+					gtkhtml_editor_insert_image (editor, uri);
+					g_free (uri);
+				} else {
+					/* this loads image immediately, remove file from cache to free up disk space */
+					e_attachment_bar_attach (E_ATTACHMENT_BAR (composer->priv->attachment_bar), filename, "image/png");
+					g_remove (filename);
+				}
+			}
+
+			g_free (filename);
+			g_object_unref (pixbuf);
+		}
+	} else {
+		/* Chain up to parent's paste_clipboard() method. */
+		GTKHTML_EDITOR_CLASS (parent_class)->paste_clipboard (editor);
+	}
 }
 
 static void



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]