[evolution-patches] Re: [Evolution] Patch to handle "file://" uri in Mail-component.



On Tue, 2005-07-26 at 16:47 +0800, Not Zed wrote:
> file uri's are too generic to be supported by only one component.
> 
Ok, now the attached patch will try to invoke the appropriate component
for certain specific URIs.

Let me know your comments.

Thanks,

V. Varadhan
Index: configure.in
===================================================================
RCS file: /cvs/gnome/evolution/configure.in,v
retrieving revision 1.837
diff -u -p -r1.837 configure.in
--- configure.in	20 Jul 2005 08:19:50 -0000	1.837
+++ configure.in	26 Jul 2005 12:52:25 -0000
@@ -1220,7 +1220,7 @@ EVO_SET_COMPILE_FLAGS(E_NAME, libgnomeui
 AC_SUBST(E_NAME_CFLAGS)
 AC_SUBST(E_NAME_LIBS)
 
-EVO_SET_COMPILE_FLAGS(E_UTIL, gthread-2.0 gconf-2.0 libxml-2.0 libbonoboui-2.0 >= $BONOBOUI_REQUIRED libglade-2.0 libgnomeui-2.0 libgnome-2.0 libgnomecanvas-2.0 libgnomeprintui-2.2 libedataserver-$EDS_PACKAGE libedataserverui-$EDS_PACKAGE >= $EDS_REQUIRED $mozilla_nspr $mono_package, $THREADS_CFLAGS $MANUAL_NSPR_CFLAGS, $THREADS_LIBS $MANUAL_NSPR_LIBS)
+EVO_SET_COMPILE_FLAGS(E_UTIL, gthread-2.0 gconf-2.0 libxml-2.0 libbonoboui-2.0 >= $BONOBOUI_REQUIRED gnome-vfs-2.0 gnome-vfs-module-2.0 libglade-2.0 libgnomeui-2.0 libgnome-2.0 libgnomecanvas-2.0 libgnomeprintui-2.2 libedataserver-$EDS_PACKAGE libedataserverui-$EDS_PACKAGE >= $EDS_REQUIRED $mozilla_nspr $mono_package, $THREADS_CFLAGS $MANUAL_NSPR_CFLAGS, $THREADS_LIBS $MANUAL_NSPR_LIBS)
 AC_SUBST(E_UTIL_CFLAGS)
 AC_SUBST(E_UTIL_LIBS)
 
Index: e-util/Makefile.am
===================================================================
RCS file: /cvs/gnome/evolution/e-util/Makefile.am,v
retrieving revision 1.134
diff -u -p -r1.134 Makefile.am
--- e-util/Makefile.am	23 Jun 2005 09:11:06 -0000	1.134
+++ e-util/Makefile.am	26 Jul 2005 12:52:48 -0000
@@ -56,6 +56,7 @@ eutilinclude_HEADERS = 				\
 	e-list-iterator.h			\
 	e-list.h				\
 	e-menu.h				\
+	e-mimeutils.h				\
 	e-mktemp.h				\
 	e-print.h				\
 	e-plugin.h				\
@@ -105,6 +106,7 @@ libeutil_la_SOURCES =				\
 	e-list-iterator.c			\
 	e-list.c				\
 	e-menu.c				\
+	e-mimeutils.c				\
 	e-mktemp.c				\
 	e-plugin.c				\
 	e-popup.c				\
--- /dev/null	2005-03-19 12:36:14.000000000 -0700
+++ e-util/e-mimeutils.c	2005-07-26 16:35:51.000000000 -0600
@@ -0,0 +1,74 @@
+/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*-
+ *
+ * Authors: Veerapuram Varadhan <vvaradhan novell com>
+ *
+ * Copyright 2004 Ximian, Inc. (www.ximian.com)
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of version 2 of the GNU General Public
+ * License as published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Street #330, Boston, MA 02111-1307, USA.
+ *
+ */
+
+#ifdef HAVE_CONFIG_H
+#include <config.h>
+#endif
+
+#include <string.h>
+
+#include <libgnomevfs/gnome-vfs.h>
+#include <libgnomevfs/gnome-vfs-mime.h>
+
+#include <libedataserver/e-url.h>
+
+static
+gboolean is_file_uri (const char* uri) 
+{
+	return (!strncmp (uri, "file://", 7));
+}
+
+/**
+ * e_mimeutils_guess_mime_type:
+ * @file_name:   
+ * 
+ * Find the mime-type of @file_name.
+ * 
+ * Return value: Non-NULL value representing the mime-type of @file_name.
+ * Returns NULL on any error.
+ **/
+char *
+e_mimeutils_guess_mime_type (const char *uri)
+{
+	GnomeVFSFileInfo *info;
+	GnomeVFSResult result;
+	char *type = NULL;
+	char *file_name = NULL; 
+
+	if (is_file_uri (uri)) {
+		EUri* euri = e_uri_new (uri);
+		file_name = g_strdup (euri->path);
+		e_uri_free (euri);
+	} else
+		file_name = g_strdup (uri);
+
+	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);
+	g_free (file_name);
+	return type;
+}
--- /dev/null	2005-03-19 12:36:14.000000000 -0700
+++ e-util/e-mimeutils.h	2005-07-26 16:27:38.000000000 -0600
@@ -0,0 +1,33 @@
+/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*-
+ *
+ * Authors: Veerapuram Varadhan <vvaradhan novell com>
+ *
+ * Copyright 2004 Ximian, Inc. (www.ximian.com)
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of version 2 of the GNU General Public
+ * License as published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Street #330, Boston, MA 02111-1307, USA.
+ *
+ */
+
+#ifndef E_MIMEUTILS_H
+#define E_MIMEUTILS_H
+
+#include <glib.h>
+
+G_BEGIN_DECLS
+
+char* e_mimeutils_guess_mime_type(const char* filename);
+
+G_END_DECLS
+
+#endif /* !E_MIMEUTILS_H */
Index: widgets/misc/e-attachment.c
===================================================================
RCS file: /cvs/gnome/evolution/widgets/misc/e-attachment.c,v
retrieving revision 1.2
diff -u -p -r1.2 e-attachment.c
--- widgets/misc/e-attachment.c	20 Jul 2005 11:17:42 -0000	1.2
+++ widgets/misc/e-attachment.c	26 Jul 2005 12:53:55 -0000
@@ -39,6 +39,7 @@
 #include <libgnome/gnome-i18n.h>
 
 #include "e-util/e-mktemp.h"
+#include "e-util/e-mimeutils.h"
 
 #include "e-attachment.h"
 
@@ -170,26 +171,6 @@ e_attachment_get_type (void)
 	return type;
 }
 
-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;
-}
-
 
 /**
  * e_attachment_new:
@@ -238,7 +219,7 @@ e_attachment_new (const char *file_name,
 		return NULL;
 	}
 	
-	mime_type = attachment_guess_mime_type (file_name);
+	mime_type = e_mimeutils_guess_mime_type (file_name);
 	if (mime_type) {
 		if (!g_ascii_strcasecmp (mime_type, "message/rfc822")) {
 			wrapper = (CamelDataWrapper *) camel_mime_message_new ();
@@ -439,7 +420,7 @@ e_attachment_build_remote_file (const ch
 		return;
 	}
 	
-	mime_type = attachment_guess_mime_type (file_name);
+	mime_type = e_mimeutils_guess_mime_type (file_name);
 	if (mime_type) {
 		if (!g_ascii_strcasecmp (mime_type, "message/rfc822")) {
 			wrapper = (CamelDataWrapper *) camel_mime_message_new ();
@@ -729,7 +710,7 @@ e_attachment_edit (EAttachment *attachme
 			   attachment->file_name);
 		set_entry (editor_gui, "description_entry",
 			   attachment->description);
-		type = attachment_guess_mime_type (attachment->file_name);
+		type = e_mimeutils_guess_mime_type (attachment->file_name);
 		if (type) {
 			set_entry (editor_gui, "mime_type_entry", type);
 			g_free (type);
Index: shell/e-shell.c
===================================================================
RCS file: /cvs/gnome/evolution/shell/e-shell.c,v
retrieving revision 1.266
diff -u -p -r1.266 e-shell.c
--- shell/e-shell.c	12 Jul 2005 04:04:13 -0000	1.266
+++ shell/e-shell.c	26 Jul 2005 12:54:26 -0000
@@ -33,6 +33,7 @@
 #include "e-util/e-bconf-map.h"
 #include "e-util/e-fsutils.h"
 #include "e-util/e-error.h"
+#include "e-util/e-mimeutils.h"
 
 #include "e-shell-constants.h"
 #include "e-shell-offline-handler.h"
@@ -243,7 +244,7 @@ impl_Shell_handleURI (PortableServer_Ser
 		      CORBA_Environment *ev)
 {
 	EShell *shell = E_SHELL (bonobo_object_from_servant (servant));
-	EComponentInfo *component_info;
+	EComponentInfo *component_info = NULL;
 	char *schema, *p;
 	int show = FALSE;
 
@@ -253,10 +254,29 @@ impl_Shell_handleURI (PortableServer_Ser
 	if (p)
 		*p = 0;
 
- 	component_info = e_component_registry_peek_info(shell->priv->component_registry, ECR_FIELD_SCHEMA, schema);
-	if (component_info == NULL) {
-		show = TRUE;
-		component_info = e_component_registry_peek_info(shell->priv->component_registry, ECR_FIELD_ALIAS, schema);
+	if (!strcmp (schema, "file")) {
+		char* mime_type;
+		mime_type = e_mimeutils_guess_mime_type(uri);
+		if (mime_type) {
+			if (!strcmp (mime_type, "text/calendar") ||
+			    !strcmp (mime_type, "text/x-calendar")) {
+				    component_info = e_component_registry_peek_info(shell->priv->component_registry, ECR_FIELD_ALIAS, "calendar");
+				    show = TRUE;
+			} else if (!strcmp(mime_type, "text/x-vcard") ||
+				   !strcmp(mime_type, "text/vcard")) {
+				    component_info = e_component_registry_peek_info(shell->priv->component_registry, ECR_FIELD_ALIAS, "contacts");
+				    show = TRUE;
+			} else {				    
+				    component_info = e_component_registry_peek_info(shell->priv->component_registry, ECR_FIELD_SCHEMA, "mailto");
+			}
+		}
+		g_free(mime_type);
+	} else {
+		component_info = e_component_registry_peek_info(shell->priv->component_registry, ECR_FIELD_SCHEMA, schema);
+		if (component_info == NULL) {
+			show = TRUE;
+			component_info = e_component_registry_peek_info(shell->priv->component_registry, ECR_FIELD_ALIAS, schema);
+		}
 	}
 
 	if (component_info == NULL) {
Index: mail/ChangeLog
===================================================================
RCS file: /cvs/gnome/evolution/mail/ChangeLog,v
retrieving revision 1.3660
diff -u -p -r1.3660 ChangeLog
--- mail/ChangeLog	25 Jul 2005 04:23:40 -0000	1.3660
+++ mail/ChangeLog	26 Jul 2005 12:56:31 -0000
@@ -1,3 +1,13 @@
+2005-07-26  Veerapuram Varadhan <vvaradhan novell com>
+
+	* mail-component.c (impl_handleURI): Support "file:" uri.
+	(handleuri_got_file): if we get a "file" uri, handle it
+	according to the parameters that are passed. By default, we
+	will open a composer window and attach the file pointed to 
+	by the URI.
+
+	* GNOME_Evolution_Mail.server.in.in: Support "file" uri.
+	
 2005-07-25  Srinivasa Ragavan <sragavan novell com>
 
 	* em-format-html-display.c: (efhd_init) (efhd_finalise) ()
Index: mail/mail-component.c
===================================================================
RCS file: /cvs/gnome/evolution/mail/mail-component.c,v
retrieving revision 1.122
diff -u -p -r1.122 mail-component.c
--- mail/mail-component.c	10 Jul 2005 10:03:56 -0000	1.122
+++ mail/mail-component.c	26 Jul 2005 12:56:50 -0000
@@ -79,10 +79,13 @@
 
 #include <camel/camel-file-utils.h>
 #include <camel/camel-vtrash-folder.h>
+#include <camel/camel-stream-fs.h>
 
 #include <bonobo/bonobo-control.h>
 #include <bonobo/bonobo-widget.h>
 
+#include <libedataserver/e-url.h>
+
 #define d(x) 
 
 static void create_local_item_cb(EUserCreatableItemsHandler *handler, const char *item_type_name, void *data);
@@ -819,7 +822,7 @@ static void
 handleuri_got_folder(char *uri, CamelFolder *folder, void *data)
 {
 	CamelURL *url = data;
-	EMMessageBrowser *emmb;
+ 	EMMessageBrowser *emmb;
 
 	if (folder != NULL) {
 		const char *reply = camel_url_get_param(url, "reply");
@@ -873,8 +876,111 @@ handleuri_got_folder(char *uri, CamelFol
 }
 
 static void
+handleuri_got_file (MailComponent* mc, const char* uri)
+{
+	char* name = NULL;
+	const char* compose_mode = NULL;
+	const char* action = NULL;
+	EUri* euri = NULL;
+	char* mime_type;
+
+	EMsgComposer* composer = NULL;
+
+	/* Example uri: 
+	   file:///home/foo/mails/bar[;action=<view/compose>[mode=<edit/attached>]] 
+	*/
+	
+	euri = e_uri_new(uri);
+	mime_type = e_mimeutils_guess_mime_type (uri);
+	if (mime_type && (!strcmp(mime_type, "message/rfc822") ||
+			  !strcmp(mime_type, "text/plain"))) {
+		action = e_uri_get_param(euri, "action");
+		compose_mode = e_uri_get_param(euri, "mode");
+	}
+
+	g_free (mime_type);
+
+	if (action && ((compose_mode && !strcmp(compose_mode, "edit"))
+		    || !strcmp(action, "view"))) {
+		CamelStream* msg_stream = NULL;
+		CamelMimeMessage* message;
+
+		if ((name = euri->path) == NULL)
+			return;
+		
+		if ((msg_stream = camel_stream_fs_new_with_name(name, O_RDONLY, 0)) == NULL)
+			return;
+		/* FIXME: We need to handle mbox files in a nicer way,
+		   may be just load the "top-most" message.
+		*/
+		message = camel_mime_message_new();
+		if (camel_data_wrapper_construct_from_stream((CamelDataWrapper *)message, msg_stream) == -1) {
+			camel_object_unref((CamelObject *)msg_stream);
+			camel_object_unref((CamelObject *)message);
+			return;
+		}
+
+		if (!strcmp(action, "view")) {
+			EMMessageBrowser *emmb;
+			CamelFolder* folder;
+			CamelException* ex;
+			const char* folder_uri;
+			char* appended_uid;
+
+			ex = camel_exception_new();
+			
+			emmb = (EMMessageBrowser *)em_message_browser_window_new();
+			
+			/* FIXME: session needs to be passed easier than this */
+			em_format_set_session((EMFormat *)((EMFolderView *)emmb)->preview, session);
+			
+			folder = mail_component_get_folder(mc, MAIL_COMPONENT_FOLDER_LOCAL_INBOX);
+			folder_uri = mail_component_get_folder_uri(mc, MAIL_COMPONENT_FOLDER_LOCAL_INBOX);
+			if (folder && folder_uri) {
+				/* FIXME: Should we need to delete this message 
+				   once the message brower window is closed?
+				*/
+				camel_folder_append_message(folder, message, NULL, &appended_uid, ex);
+				em_folder_view_set_folder((EMFolderView *)emmb, folder, folder_uri);
+				em_folder_view_set_message((EMFolderView *)emmb, appended_uid, FALSE);
+				gtk_widget_show(emmb->window);
+			} 
+			camel_exception_free (ex);
+		} else if (!strcmp (action, "compose")){ 
+			/* FIXME: Should check for "mbox" files */
+			em_utils_edit_message(message);
+		}
+		    
+		camel_object_unref((CamelObject *)msg_stream);
+		camel_object_unref((CamelObject *)message);
+	} else { 
+
+		/* Defaults to "action=compose; mode=attach" */		   
+		GSList* file_names_list = NULL;
+		CamelMimePart* part = NULL;
+		
+		file_names_list = g_slist_append(file_names_list, euri->path);
+		
+		composer = e_msg_composer_new ();
+		while (file_names_list) {
+			part = e_msg_composer_add_inline_image_from_file(composer,
+									 file_names_list->data);
+			if (part)
+				e_msg_composer_attach(composer, part);
+			camel_object_unref(part);
+			file_names_list = g_slist_next (file_names_list);
+		}
+		g_slist_free(file_names_list);
+		e_msg_composer_set_headers (composer, NULL, NULL, NULL, NULL, "");
+		gtk_widget_show ((GtkWidget*)composer);
+	}
+	e_uri_free(euri);
+}
+
+static void
 impl_handleURI (PortableServer_Servant servant, const char *uri, CORBA_Environment *ev)
 {
+	MailComponent *mail_component = MAIL_COMPONENT (bonobo_object_from_servant (servant));
 	if (!strncmp (uri, "mailto:";, 7)) {
 		if (!em_utils_check_user_can_send_mail(NULL))
 			return;
@@ -892,6 +998,8 @@ impl_handleURI (PortableServer_Servant s
 			g_warning("email uri's must include a uid parameter");
 			camel_url_free(url);
 		}
+	} else if (!strncmp(uri, "file:", 5)) {
+		handleuri_got_file (mail_component, uri);
 	}
 }
 
Index: mail/GNOME_Evolution_Mail.server.in.in
===================================================================
RCS file: /cvs/gnome/evolution/mail/GNOME_Evolution_Mail.server.in.in,v
retrieving revision 1.26
diff -u -p -r1.26 GNOME_Evolution_Mail.server.in.in
--- mail/GNOME_Evolution_Mail.server.in.in	18 Jun 2005 11:32:35 -0000	1.26
+++ mail/GNOME_Evolution_Mail.server.in.in	26 Jul 2005 12:57:31 -0000
@@ -42,6 +42,7 @@
     <oaf_attribute name="evolution:uri_schemas" type="stringv">
       <item value="mailto"/>
       <item value="email"/>
+      <item value="file"/>
     </oaf_attribute>
   </oaf_server>
 
Index: ChangeLog
===================================================================
RCS file: /cvs/gnome/evolution/ChangeLog,v
retrieving revision 1.1509
diff -u -p -r1.1509 ChangeLog
--- ChangeLog	20 Jul 2005 08:19:50 -0000	1.1509
+++ ChangeLog	26 Jul 2005 13:07:09 -0000
@@ -1,3 +1,8 @@
+2005-07-26  Veerapuram Varadhan <vvaradhan novell com>
+
+	* configure.in: Add gnome-vfs-2.0 and gnome-vfs-modules-2.0 to
+	E_UTIL_FLAGS.
+	
 2005-07-20  Tor Lillqvist  <tml novell com>
 
 	* configure.in: Add AC_LIBTOOL_WIN32_DLL. It is apparently
Index: e-util/ChangeLog
===================================================================
RCS file: /cvs/gnome/evolution/e-util/ChangeLog,v
retrieving revision 1.547
diff -u -p -r1.547 ChangeLog
--- e-util/ChangeLog	12 Jul 2005 04:04:11 -0000	1.547
+++ e-util/ChangeLog	26 Jul 2005 13:07:27 -0000
@@ -1,3 +1,8 @@
+2005-07-26 Veerapuram Varadhan <vvaradhan novell com>
+
+	* e-util/e-mimeutils.[ch]: Mime-type related utility functions.
+	* e-util/Makefile.am: Ditto.
+	
 2005-07-11 Vivek Jain <jvivek novell com>
 	
 	* e-config.c: (e_config_target_changed):
Index: widgets/misc/ChangeLog
===================================================================
RCS file: /cvs/gnome/evolution/widgets/misc/ChangeLog,v
retrieving revision 1.364
diff -u -p -r1.364 ChangeLog
--- widgets/misc/ChangeLog	25 Jul 2005 05:40:44 -0000	1.364
+++ widgets/misc/ChangeLog	26 Jul 2005 13:07:44 -0000
@@ -1,3 +1,9 @@
+2005-07-26  Veerapuram Varadhan <vvaradhan novell com>
+
+	* e-attachment.c: (attachment_guess_mime_type): removed
+	(e_attachment_new) (e_attachment_build_remote_file)
+	(e_attachment_edit): Use e_mimeutils_guess_mime_type ().
+	
 2005-07-25  Srinivasa Ragavan <sragavan novell com>
 
 	* e-attachment-bar,c: (e_attachment_bar_remove_selected) (e_attachment_bar_edit_selected)
Index: shell/ChangeLog
===================================================================
RCS file: /cvs/gnome/evolution/shell/ChangeLog,v
retrieving revision 1.1533
diff -u -p -r1.1533 ChangeLog
--- shell/ChangeLog	25 Jul 2005 08:15:34 -0000	1.1533
+++ shell/ChangeLog	26 Jul 2005 13:08:01 -0000
@@ -1,3 +1,9 @@
+2005-07-26  Veerapuram Varadhan <vvaradhan novell com>
+
+	* e-shell.c (imple_Shell_handleURI): Incase of "file://" uris,
+	check for the mime-type of the file pointed-to by the uri and
+	create the "component_info" objects accordingly.
+	
 2005-07-21  Sarfraaz Ahmed <asarfraaz novell com>
 
 	* e-component-registry.c (query_components): Dont enter default values 


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