Fix for bug 324742 [gtkhtml] [UI]

Rohini <[email protected]>
Newsgroups gmane.comp.gnome.evolution.patches
Message-ID <[email protected]>
Hi

Attached fix for Bug 324742 – regression: inline images with DnD

Please Review

Thanks,
Rohini

_______________________________________________
Evolution-patches mailing list
[email protected]
http://mail.gnome.org/mailman/listinfo/evolution-patches
bug324742a.diff (text/x-patch, 2.6 KB)
Index: e-msg-composer.c
===================================================================
RCS file: /cvs/gnome/evolution/composer/e-msg-composer.c,v
retrieving revision 1.529
diff -u -p -r1.529 e-msg-composer.c
--- e-msg-composer.c	30 Jan 2006 09:51:18 -0000	1.529
+++ e-msg-composer.c	16 Feb 2006 12:59:55 -0000
@@ -2884,10 +2884,30 @@ e_msg_composer_get_remote_download_count
 				(E_ATTACHMENT_BAR (p->attachment_bar));
 }
 
+static char *
+attachment_guess_mime_type (const char *file_name)
+{
+	GnomeVFSFileInfo *info;
+	GnomeVFSResult result;
+	char *type = NULL;
+
+	info = gnome_vfs_file_info_new ();
+	result = gnome_vfs_get_file_info (file_name, info,
+					  GNOME_VFS_FILE_INFO_GET_MIME_TYPE |
+					  GNOME_VFS_FILE_INFO_FORCE_SLOW_MIME_TYPE |
+					  GNOME_VFS_FILE_INFO_FOLLOW_LINKS);
+	if (result == GNOME_VFS_OK)
+		type = g_strdup (gnome_vfs_file_info_get_mime_type (info));
+
+	gnome_vfs_file_info_unref (info);
+
+	return type;
+}
+
 static void
 drop_action(EMsgComposer *composer, GdkDragContext *context, guint32 action, GtkSelectionData *selection, guint info, guint time)
 {
-	char *tmp, *str, **urls;
+	char *tmp, *str, **urls, *type;
 	CamelMimePart *mime_part;
 	CamelStream *stream;
 	CamelURL *url;
@@ -2939,12 +2959,14 @@ drop_action(EMsgComposer *composer, GdkD
 					continue;
 				}
 
-				if (!g_ascii_strcasecmp (url->protocol, "file"))
-					e_attachment_bar_attach
-						(E_ATTACHMENT_BAR (p->attachment_bar),
-					 	url->path,
-						"attachment");
-				else	{
+				if (!g_ascii_strcasecmp (url->protocol, "file")) {
+						type=attachment_guess_mime_type (str);
+						if (strncmp (type, "image", 5) || (!p->send_html && !strncmp (type, "image", 5)))
+							e_attachment_bar_attach
+							(E_ATTACHMENT_BAR (p->attachment_bar),
+						 	url->path,
+							"attachment");
+				} else	{
 					e_attachment_bar_attach_remote_file 
 						(E_ATTACHMENT_BAR (p->attachment_bar),
 						str);
Index: ChangeLog
===================================================================
RCS file: /cvs/gnome/evolution/composer/ChangeLog,v
retrieving revision 1.735
diff -u -p -r1.735 ChangeLog
--- ChangeLog	15 Feb 2006 23:33:45 -0000	1.735
+++ ChangeLog	16 Feb 2006 13:06:53 -0000
@@ -1,3 +1,11 @@
+2006-02-16  Rohini S  <[email protected]>
+
+	** Fixes bug #324742
+
+	* e-msg-composer.c (drop_action) (attachment_guess_mime_type):
+	Modified to add images in plain text mode and other files in both 
+	html and plain text mode as attachment during DnD. 
+
 2006-02-16  Tor Lillqvist  <[email protected]>
 
 	* e-msg-composer-hdrs.c (e_msg_composer_hdrs_get_to)
bug324742b.diff (text/x-patch, 3 KB)
Index: gtkhtml.c
===================================================================
RCS file: /cvs/gnome/gtkhtml/src/gtkhtml.c,v
retrieving revision 1.613
diff -u -p -r1.613 gtkhtml.c
--- gtkhtml.c	6 Feb 2006 09:59:36 -0000	1.613
+++ gtkhtml.c	16 Feb 2006 13:12:11 -0000
@@ -2582,6 +2582,31 @@ static gchar *known_protocols [] = {
 };
 
 static HTMLObject *
+new_img_obj_from_uri (HTMLEngine *e, char *uri, char *title, gint len)
+{
+	gint i;
+
+	if (!strncmp (uri, "file:", 5)) {
+		if (!HTML_IS_PLAIN_PAINTER(e->painter)) {
+			GdkPixbuf *pixbuf = NULL;
+			char *img_path = g_filename_from_uri (uri, NULL, NULL);
+			if (img_path) {
+				pixbuf = gdk_pixbuf_new_from_file(img_path, NULL);
+				g_free(img_path);
+			}
+			if (pixbuf) {
+				g_object_unref (pixbuf);
+				return html_image_new (html_engine_get_image_factory (e), uri,
+						       NULL, NULL, -1, -1, FALSE, FALSE, 0,
+						       html_colorset_get_color (e->settings->color_set, HTMLTextColor),
+						       HTML_VALIGN_BOTTOM, TRUE);
+			}
+		}
+	}
+	return NULL;
+}
+
+static HTMLObject *
 new_obj_from_uri (HTMLEngine *e, char *uri, char *title, gint len)
 {
 	gint i;
@@ -2660,8 +2685,25 @@ drag_data_received (GtkWidget *widget, G
 		selection_received (widget, selection_data, time);
 		pasted = TRUE;
 		break;
-	case DND_TARGET_TYPE_MOZILLA_URL  : 
-	case DND_TARGET_TYPE_TEXT_URI_LIST: 
+        case DND_TARGET_TYPE_MOZILLA_URL  : 
+		break; 	 
+        case DND_TARGET_TYPE_TEXT_URI_LIST: 	 
+		if(!HTML_IS_PLAIN_PAINTER (engine->painter)) {
+                 HTMLObject *obj; 	 
+                 gint list_len, len; 	 
+                 gchar *uri; 	 
+                 html_undo_level_begin (engine->undo, "Dropped URI(s)", "Remove Dropped URI(s)"); 	 
+                 list_len = selection_data->length;
+                 do { 	 
+                         uri = next_uri (&selection_data->data, &len, &list_len); 	 
+                         obj = new_img_obj_from_uri (engine, uri, NULL, -1); 	
+                         if (obj) { 	 
+                                 html_engine_paste_object (engine, obj, html_object_get_length (obj)); 	 
+                                 pasted = TRUE; 	 
+                         } 	 
+                 } while (list_len); 	 
+                 html_undo_level_end (engine->undo); 	 
+	}
 	break;
 	}
 	gtk_drag_finish (context, pasted, FALSE, time);
Index: ChangeLog
===================================================================
RCS file: /cvs/gnome/gtkhtml/src/ChangeLog,v
retrieving revision 1.2163
diff -u -p -r1.2163 ChangeLog
--- ChangeLog	15 Feb 2006 15:09:07 -0000	1.2163
+++ ChangeLog	16 Feb 2006 13:16:53 -0000
@@ -1,3 +1,10 @@
+2006-02-16  Rohini S  <[email protected]>
+
+	* gtkhtml.c (drag_data_received, new_img_obj_from_uri): Function modified to
+	add images to editor in html mode during DnD.
+
+	Fixes bug #324742
+
 2006-02-15  Rohini S  <[email protected]>
 
 	* htmlsearch.c (html_search_new): Function modified to include offset zero too.
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.