[evolution-patches] fix for bug #41789



http://bugzilla.ximian.com/show_bug.cgi?id=41789

the solution proposed at yesterday's meeting was to only allow
components for things evolution knew how to display (evo components -
minicard view and meeting thingy) and for any components that the user
hand-set in the gconf database. The attached patch implements this.

Jeff

-- 
Jeffrey Stedfast
Evolution Hacker - Ximian, Inc.
fejj ximian com  - www.ximian.com
? 41730.patch
? 41789.patch
? accounts.xml
? crash.txt
? evolution-mail-account.schemas
? mail-account-list.h
? mail-account.c
? mail-account.h
? mail-composer-prefs.patch
? ml-load-save-state.c
Index: ChangeLog
===================================================================
RCS file: /cvs/gnome/evolution/mail/ChangeLog,v
retrieving revision 1.2705
diff -u -r1.2705 ChangeLog
--- ChangeLog	24 Apr 2003 19:09:04 -0000	1.2705
+++ ChangeLog	25 Apr 2003 18:26:44 -0000
@@ -1,3 +1,19 @@
+2003-04-24  Jeffrey Stedfast  <fejj ximian com>
+
+	* mail-config.c (mail_config_init): Cache the allowable
+	mime-types.
+	(mail_config_get_allowable_mime_types): New public function to get
+	an array of allowable mime-types.
+
+	* mail-format.c (mail_lookup_handler): Only allow a
+	bonobo-component handler if the mime-type is something handled by
+	evolution or the user has specifically chosen that type as
+	available for viewing with a bonobo component in the gconf
+	database.
+	(mime_type_uses_evolution_component): New convenience function.
+	(mime_type_can_use_component): Checks gconf to see if the user has
+	allowed the mime-type to be viewed by a component.
+
 2003-04-24  Radek Doulik  <rodo ximian com>
 
 	* mail-display.c (html_button_press_event): as below
Index: evolution-mail.schemas
===================================================================
RCS file: /cvs/gnome/evolution/mail/evolution-mail.schemas,v
retrieving revision 1.12
diff -u -r1.12 evolution-mail.schemas
--- evolution-mail.schemas	16 Apr 2003 21:45:39 -0000	1.12
+++ evolution-mail.schemas	25 Apr 2003 18:26:44 -0000
@@ -149,6 +149,23 @@
     </schema>
 
     <schema>
+      <key>/schemas/apps/evolution/mail/display/mime_types</key>
+      <applyto>/apps/evolution/mail/display/mime_types</applyto>
+      <owner>evolution-mail</owner>
+      <type>list</type>
+      <list_type>string</list_type>
+      <default></default>
+      <locale name="C">
+         <short>List of mime types to check for bonobo component viewers</short>
+         <long>
+           If there isn't a builtin viewer for a particular mime-type inside Evolution,
+           any mime-types appearing in this list which map to a bonobo-component viewer
+           in GNOME's mime-type database may be used for displaying content.
+         </long>
+      </locale>
+    </schema>
+
+    <schema>
       <key>/schemas/apps/evolution/mail/display/xmailer_mask</key>
       <applyto>/apps/evolution/mail/display/xmailer_mask</applyto>
       <owner>evolution-mail</owner>
Index: mail-config.c
===================================================================
RCS file: /cvs/gnome/evolution/mail/mail-config.c,v
retrieving revision 1.272
diff -u -r1.272 mail-config.c
--- mail-config.c	9 Apr 2003 09:52:30 -0000	1.272
+++ mail-config.c	25 Apr 2003 18:26:46 -0000
@@ -85,7 +85,11 @@
 	
 	GSList *labels;
 	guint label_notify_id;
+	
 	guint font_notify_id;
+	
+	GPtrArray *mime_types;
+	guint mime_types_notify_id;
 } MailConfig;
 
 static MailConfig *config = NULL;
@@ -395,6 +399,33 @@
 }
 
 static void
+config_clear_mime_types (void)
+{
+	int i;
+	
+	for (i = 0; i < config->mime_types->len; i++)
+		g_free (config->mime_types->pdata[i]);
+	
+	g_ptr_array_set_size (config->mime_types, 0);
+}
+
+static void
+config_cache_mime_types (void)
+{
+	GSList *n, *nn;
+	
+	n = gconf_client_get_list (config->gconf, "/apps/evolution/mail/display/mime_types", GCONF_VALUE_STRING, NULL);
+	while (n != NULL) {
+		nn = n->next;
+		g_ptr_array_add (config->mime_types, n->data);
+		g_slist_free_1 (n);
+		n = nn;
+	}
+	
+	g_ptr_array_add (config->mime_types, NULL);
+}
+
+static void
 config_write_fonts (void)
 {
 	char *filename;
@@ -450,21 +481,31 @@
 
 static void
 gconf_fonts_changed (GConfClient *client, guint cnxn_id,
-		      GConfEntry *entry, gpointer user_data)
+		     GConfEntry *entry, gpointer user_data)
 {
 	config_write_fonts ();
 }
 
+static void
+gconf_mime_types_changed (GConfClient *client, guint cnxn_id,
+			  GConfEntry *entry, gpointer user_data)
+{
+	config_clear_mime_types ();
+	config_cache_mime_types ();
+}
+
 /* Config struct routines */
 void
 mail_config_init (void)
 {
 	char *filename;
+	
 	if (config)
 		return;
 	
 	config = g_new0 (MailConfig, 1);
 	config->gconf = gconf_client_get_default ();
+	config->mime_types = g_ptr_array_new ();
 	
 	mail_config_clear ();
 
@@ -475,21 +516,27 @@
 	filename = g_build_filename (g_get_home_dir (), "/evolution", MAIL_CONFIG_RC, NULL);
 	gtk_rc_parse (filename);
 	g_free (filename);
-
+	
 	gconf_client_add_dir (config->gconf, "/apps/evolution/mail/display/fonts", 			      
 			      GCONF_CLIENT_PRELOAD_ONELEVEL, NULL);
 	config->font_notify_id = gconf_client_notify_add (config->gconf, "/apps/evolution/mail/display/fonts",
 							  gconf_fonts_changed, NULL, NULL, NULL);
 
-
 	gconf_client_add_dir (config->gconf, "/apps/evolution/mail/labels",
 			      GCONF_CLIENT_PRELOAD_ONELEVEL, NULL);
 	config->label_notify_id =
 		gconf_client_notify_add (config->gconf, "/apps/evolution/mail/labels",
 					 gconf_labels_changed, NULL, NULL, NULL);
-
+	
+	gconf_client_add_dir (config->gconf, "/apps/evolution/mail/mime_types",
+			      GCONF_CLIENT_PRELOAD_ONELEVEL, NULL);
+	config->mime_types_notify_id =
+		gconf_client_notify_add (config->gconf, "/apps/evolution/mail/mime_types",
+					 gconf_mime_types_changed, NULL, NULL, NULL);
+	
 	config_cache_labels ();
 	config_read_signatures ();
+	config_cache_mime_types ();
 	
 	config->accounts = e_account_list_new (config->gconf);
 }
@@ -506,6 +553,7 @@
 	}
 	
 	config_clear_labels ();
+	config_clear_mime_types ();
 }
 
 void
@@ -636,6 +684,12 @@
 		return label->colour;
 	
 	return NULL;
+}
+
+const char **
+mail_config_get_allowable_mime_types (void)
+{
+	return (const char **) config->mime_types->pdata;
 }
 
 gboolean
Index: mail-config.h
===================================================================
RCS file: /cvs/gnome/evolution/mail/mail-config.h,v
retrieving revision 1.109
diff -u -r1.109 mail-config.h
--- mail-config.h	7 Mar 2003 20:54:54 -0000	1.109
+++ mail-config.h	25 Apr 2003 18:26:46 -0000
@@ -107,6 +107,8 @@
 const char *mail_config_get_label_color_by_name (const char *name);
 const char *mail_config_get_label_color_by_index (int index);
 
+const char **mail_config_get_allowable_mime_types (void);
+
 void mail_config_service_set_save_passwd (EAccountService *service, gboolean save_passwd);
 
 gboolean      mail_config_find_account                 (EAccount *account);
Index: mail-format.c
===================================================================
RCS file: /cvs/gnome/evolution/mail/mail-format.c,v
retrieving revision 1.282
diff -u -r1.282 mail-format.c
--- mail-format.c	27 Mar 2003 15:38:11 -0000	1.282
+++ mail-format.c	25 Apr 2003 18:26:48 -0000
@@ -371,6 +371,27 @@
 	return FALSE;
 }
 
+static gboolean
+mime_type_uses_evolution_component (const char *mime_type)
+{
+	return (!strcmp (mime_type, "text/x-vcard") || !strcmp (mime_type, "text/calendar"));
+}
+
+static gboolean
+mime_type_can_use_component (const char *mime_type)
+{
+	const char **mime_types;
+	int i;
+	
+	mime_types = mail_config_get_allowable_mime_types ();
+	for (i = 0; mime_types[i]; i++) {
+		if (!strcmp (mime_types[i], mime_type))
+			return TRUE;
+	}
+	
+	return FALSE;
+}
+
 /**
  * mail_lookup_handler:
  * @mime_type: a MIME type
@@ -423,22 +444,26 @@
 		goto reg;
 	}
 	
-	/* Try for the first matching component. (we don't use get_short_list_comps
-	 * as that will return NULL if the oaf files don't have the short_list properties
-	 * defined). */
-	components = gnome_vfs_mime_get_all_components (mime_type);
-	for (iter = components; iter; iter = iter->next) {
-		if (component_supports (iter->data, mime_type)) {
-			handler->generic = FALSE;
-			handler->is_bonobo = TRUE;
-			handler->builtin = handle_via_bonobo;
-			handler->component = Bonobo_ServerInfo_duplicate (iter->data);
-			gnome_vfs_mime_component_list_free (components);
-			goto reg;
+	/* only allow using a bonobo component if it is an evo-component or the user has
+	 * specified that we can use a bonobo-component by setting the gconf key */
+	if (mime_type_uses_evolution_component (mime_type) || mime_type_can_use_component (mime_type)) {
+		/* Try for the first matching component. (we don't use get_short_list_comps
+		 * as that will return NULL if the oaf files don't have the short_list properties
+		 * defined). */
+		components = gnome_vfs_mime_get_all_components (mime_type);
+		for (iter = components; iter; iter = iter->next) {
+			if (component_supports (iter->data, mime_type)) {
+				handler->generic = FALSE;
+				handler->is_bonobo = TRUE;
+				handler->builtin = handle_via_bonobo;
+				handler->component = Bonobo_ServerInfo_duplicate (iter->data);
+				gnome_vfs_mime_component_list_free (components);
+				goto reg;
+			}
 		}
+		
+		gnome_vfs_mime_component_list_free (components);
 	}
-	
-	gnome_vfs_mime_component_list_free (components);
 	
 	/* Try for a generic builtin match. */
 	p = strchr (mime_type, '/');


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