Index: ChangeLog
===================================================================
RCS file: /cvs/gnome/evolution/shell/ChangeLog,v
retrieving revision 1.1458
diff -u -3 -r1.1458 ChangeLog
--- ChangeLog	22 Jun 2004 00:44:58 -0000	1.1458
+++ ChangeLog	24 Jun 2004 08:10:16 -0000
@@ -1,3 +1,24 @@
+2004-06-24  Not Zed  <NotZed@Ximian.com>
+
+	** See bug #57367.
+
+	* e-shell-window.c (e_shell_window_new): fix gconf client leak and
+	clean up some logic.
+	
+	* e-shell.c (e_shell_construct): dont activate the components
+	individually, component registry does that implictly.
+
+	* e-component-registry.c (init): dont call query_components here.
+	(query_components): setup a run-once guard.  before adding a
+	component info to the list, make sure we can activate it.
+	(component_info_new): take the interface as a construct argument
+	now.
+	(e_component_registry_peek_list): perform the component list query
+	if we haven't already.
+	(e_component_registry_peek_info): same.
+	(e_component_registry_activate): just always return
+	the reffed component, it isn't added unless it was already activated.
+
 2004-06-21  Chris Toshok  <toshok@ximian.com>
 
 	* e-user-creatable-items-handler.c (impl_finalize): free
Index: e-component-registry.c
===================================================================
RCS file: /cvs/gnome/evolution/shell/e-component-registry.c,v
retrieving revision 1.50
diff -u -3 -r1.50 e-component-registry.c
--- e-component-registry.c	1 Jun 2004 04:16:26 -0000	1.50
+++ e-component-registry.c	24 Jun 2004 08:10:17 -0000
@@ -45,6 +45,8 @@
 
 struct _EComponentRegistryPrivate {
 	GSList *infos;
+
+	int init:1;
 };
 
 
@@ -52,6 +54,7 @@
 
 static EComponentInfo *
 component_info_new (const char *id,
+		    GNOME_Evolution_Component iface,
 		    const char *alias,
 		    const char *button_label,
 		    const char *menu_label,
@@ -63,6 +66,7 @@
 	EComponentInfo *info = g_new0 (EComponentInfo, 1);
 
 	info->id = g_strdup (id);
+	info->iface = bonobo_object_dup_ref(iface, NULL);
 	info->alias = g_strdup (alias);
 	info->button_label = g_strdup (button_label);
 	info->menu_label = g_strdup (menu_label);
@@ -151,6 +155,11 @@
 	char *query;
 	int i;
 
+	if (registry->priv->init)
+		return;
+
+	registry->priv->init = TRUE;
+
 	CORBA_exception_init (&ev);
 	query = g_strdup_printf ("repo_ids.has ('IDL:GNOME/Evolution/Component:%s')", BASE_VERSION);
 	info_list = bonobo_activation_query (query, NULL, &ev);
@@ -179,8 +188,20 @@
 		GdkPixbuf *icon = NULL, *menuicon = NULL;
 		EComponentInfo *info;
 		int sort_order;
+		GNOME_Evolution_Component iface;
 
 		id = info_list->_buffer[i].iid;
+		iface = bonobo_activation_activate_from_id (id, 0, NULL, &ev);
+		if (BONOBO_EX (&ev) || iface == CORBA_OBJECT_NIL) {
+			char *ex_text = bonobo_exception_get_text (&ev);
+
+			g_warning("Cannot activate '%s': %s\n", id, ex_text);
+			g_free(ex_text);
+			CORBA_exception_free(&ev);
+			CORBA_exception_init(&ev);
+			continue;
+		}
+
 		label = bonobo_server_info_prop_lookup (& info_list->_buffer[i], "evolution:button_label", language_list);
 		if (label == NULL)
 			label = g_strdup (_("Unknown"));
@@ -206,7 +227,7 @@
 		else
 			sort_order = atoi (sort_order_string);
 
-		info = component_info_new (id, alias, label, menu_label,
+		info = component_info_new (id, iface, alias, label, menu_label,
 					   menu_accelerator, sort_order, icon, menuicon);
 		set_schemas (info, & info_list->_buffer [i]);
 
@@ -214,6 +235,7 @@
 
 		if (icon != NULL)
 			g_object_unref (icon);
+		bonobo_object_release_unref(iface, NULL);
 	}
 	g_slist_free(language_list);
 
@@ -259,8 +281,6 @@
 init (EComponentRegistry *registry)
 {
 	registry->priv = g_new0 (EComponentRegistryPrivate, 1);
-
-	query_components (registry);
 }
 
 
@@ -276,6 +296,8 @@
 {
 	g_return_val_if_fail (E_IS_COMPONENT_REGISTRY (registry), NULL);
 
+	query_components(registry);
+
 	return registry->priv->infos;
 }
 
@@ -289,6 +311,8 @@
 
 	g_return_val_if_fail (E_IS_COMPONENT_REGISTRY (registry), NULL);
 
+	query_components(registry);
+
 	for (p = registry->priv->infos; p != NULL; p = p->next) {
 		EComponentInfo *info = p->data;
 
@@ -327,15 +351,7 @@
 		return CORBA_OBJECT_NIL;
 	}
 
-	if (info->iface != CORBA_OBJECT_NIL)
-		return bonobo_object_dup_ref (info->iface, NULL);
-
-	info->iface = bonobo_activation_activate_from_id (info->id, 0, NULL, ev);
-	if (BONOBO_EX (ev) || info->iface == CORBA_OBJECT_NIL) {
-		info->iface = CORBA_OBJECT_NIL;
-		return CORBA_OBJECT_NIL;
-	}
-
+	/* it isn't in the registry unless it is already activated */
 	return bonobo_object_dup_ref (info->iface, NULL);
 }
 
Index: e-shell-window.c
===================================================================
RCS file: /cvs/gnome/evolution/shell/e-shell-window.c,v
retrieving revision 1.26
diff -u -3 -r1.26 e-shell-window.c
--- e-shell-window.c	2 Jun 2004 20:37:14 -0000	1.26
+++ e-shell-window.c	24 Jun 2004 08:10:17 -0000
@@ -751,6 +751,7 @@
 	EShellWindowPrivate *priv = window->priv;
 	GConfClient *gconf_client = gconf_client_get_default ();
 	BonoboUIContainer *ui_container;
+	char *default_component_id = NULL;
 
 	if (bonobo_window_construct (BONOBO_WINDOW (window),
 				     bonobo_ui_container_new (),
@@ -786,23 +787,18 @@
 
 	gtk_window_set_default_size (GTK_WINDOW (window), 640, 480);
 
-	if (component_id != NULL) {
-		e_shell_window_switch_to_component (window, component_id);
-	} else {
-		char *default_component_id;
-
-		default_component_id = gconf_client_get_string (gconf_client,
-								"/apps/evolution/shell/view_defaults/component_id",
-								NULL);
-		g_object_unref (gconf_client);
-
-		if (default_component_id == NULL) {
-			e_shell_window_switch_to_component (window, "mail");
-		} else {
-			e_shell_window_switch_to_component (window, default_component_id);
-			g_free (default_component_id);
-		}
+	if (component_id == NULL) {
+		component_id = default_component_id =
+			gconf_client_get_string (gconf_client,
+						 "/apps/evolution/shell/view_defaults/component_id",
+						 NULL);
+		if (component_id == NULL)
+			component_id = "mail";
 	}
+
+	e_shell_window_switch_to_component (window, component_id);
+	g_free(default_component_id);
+	g_object_unref (gconf_client);
 
 	gtk_window_set_default_size (GTK_WINDOW (window),
 				     gconf_client_get_int (gconf_client, "/apps/evolution/shell/view_defaults/width", NULL),
Index: e-shell.c
===================================================================
RCS file: /cvs/gnome/evolution/shell/e-shell.c,v
retrieving revision 1.249
diff -u -3 -r1.249 e-shell.c
--- e-shell.c	1 Jun 2004 04:16:26 -0000	1.249
+++ e-shell.c	24 Jun 2004 08:10:17 -0000
@@ -644,20 +644,8 @@
 	while (gtk_events_pending ())
 		gtk_main_iteration ();	
 	
-	/* activate all the components */
+	/* activate all the components (peek list does this implictly) */
 	component = e_component_registry_peek_list (shell->priv->component_registry);
-	while (component != NULL) {
-		const EComponentInfo *info = component->data;
-		CORBA_Environment ev;
-		
-		CORBA_exception_init (&ev);
-		
-		e_component_registry_activate (shell->priv->component_registry, info->id, &ev);
-		
-		CORBA_exception_free (&ev);
-		
-		component = component->next;
-	}
 	
 	attempt_upgrade(shell);
 
