[evolution-patches] Patch for 67411



This isn't really an Evolution bug, but the patch will improve the
address book's behavior when faced with a broken gconf setup.

Intended for gnome-2-8 and HEAD.

-- 
Hans Petter
? 61069.patch
? 65537.patch
? 66369.patch
? 67411.patch
Index: ChangeLog
===================================================================
RCS file: /cvs/gnome/evolution/addressbook/ChangeLog,v
retrieving revision 1.1822.2.10
diff -u -p -r1.1822.2.10 ChangeLog
--- ChangeLog	1 Oct 2004 18:11:42 -0000	1.1822.2.10
+++ ChangeLog	9 Oct 2004 01:17:58 -0000
@@ -1,3 +1,17 @@
+2004-10-08  Hans Petter Jansson  <hpj ximian com>
+
+	* gui/component/addressbook-component.c (ensure_sources): Implement
+	based on the create_groups () function in addressbook-migrate.c.
+	(addressbook_component_init): Call ensure_sources (). This will create
+	the necessary addressbook source groups if they somehow disappeared
+	from GConf.
+
+	* gui/component/addressbook-config.c (addressbook_add_server_dialog):
+	If we can't get any source groups, just issue a console warning and
+	return NULL. Creating sources without groups is meaningless.
+	(addressbook_config_create_new_source): Return NULL if dialog
+	creation failed.
+
 2004-10-01  William Jon McCann  <mccann jhu edu>
 
 	* gui/component/component-factory.c (factory): Quiet debug messages.
Index: gui/component/addressbook-component.c
===================================================================
RCS file: /cvs/gnome/evolution/addressbook/gui/component/addressbook-component.c,v
retrieving revision 1.130
diff -u -p -r1.130 addressbook-component.c
--- gui/component/addressbook-component.c	26 Jul 2004 15:37:44 -0000	1.130
+++ gui/component/addressbook-component.c	9 Oct 2004 01:17:59 -0000
@@ -45,6 +45,8 @@
 #include "smime/gui/component.h"
 #endif
 
+#define LDAP_BASE_URI "ldap://";
+#define PERSONAL_RELATIVE_URI "system"
 
 #define PARENT_TYPE bonobo_object_get_type ()
 static BonoboObjectClass *parent_class = NULL;
@@ -54,6 +56,89 @@ struct _AddressbookComponentPrivate {
 	char *base_directory;
 };
 
+static void
+ensure_sources (AddressbookComponent *component)
+{
+	GSList *groups;
+	ESourceList *source_list;
+	ESourceGroup *group;
+	ESourceGroup *on_this_computer;
+	ESourceGroup *on_ldap_servers;
+	ESource *personal_source;
+	char *base_uri, *base_uri_proto;
+
+	on_this_computer = NULL;
+	on_ldap_servers = NULL;
+	personal_source = NULL;
+
+	if (!e_book_get_addressbooks (&source_list, NULL)) {
+		g_warning ("Could not get addressbook source list from GConf!");
+		return;
+	}
+
+	base_uri = g_build_filename (addressbook_component_peek_base_directory (component),
+				     "addressbook", "local",
+				     NULL);
+
+	base_uri_proto = g_strconcat ("file://", base_uri, NULL);
+
+	groups = e_source_list_peek_groups (source_list);
+	if (groups) {
+		/* groups are already there, we need to search for things... */
+		GSList *g;
+
+		for (g = groups; g; g = g->next) {
+
+			group = E_SOURCE_GROUP (g->data);
+
+			if (!on_this_computer && !strcmp (base_uri_proto, e_source_group_peek_base_uri (group)))
+				on_this_computer = group;
+			else if (!on_ldap_servers && !strcmp (LDAP_BASE_URI, e_source_group_peek_base_uri (group)))
+				on_ldap_servers = group;
+		}
+	}
+
+	if (on_this_computer) {
+		/* make sure "Personal" shows up as a source under
+		   this group */
+		GSList *sources = e_source_group_peek_sources (on_this_computer);
+		GSList *s;
+		for (s = sources; s; s = s->next) {
+			ESource *source = E_SOURCE (s->data);
+			if (!strcmp (PERSONAL_RELATIVE_URI, e_source_peek_relative_uri (source))) {
+				personal_source = source;
+				break;
+			}
+		}
+	}
+	else {
+		/* create the local source group */
+		group = e_source_group_new (_("On This Computer"), base_uri_proto);
+		e_source_list_add_group (source_list, group, -1);
+
+		on_this_computer = group;
+	}
+
+	if (!personal_source) {
+		/* Create the default Person addressbook */
+		ESource *source = e_source_new (_("Personal"), PERSONAL_RELATIVE_URI);
+		e_source_group_add_source (on_this_computer, source, -1);
+
+		personal_source = source;
+	}
+
+	if (!on_ldap_servers) {
+		/* Create the LDAP source group */
+		group = e_source_group_new (_("On LDAP Servers"), LDAP_BASE_URI);
+		e_source_list_add_group (source_list, group, -1);
+
+		on_ldap_servers = group;
+	}
+
+	g_free (base_uri_proto);
+	g_free (base_uri);
+}
+
 /* Evolution::Component CORBA methods.  */
 
 static void
@@ -255,6 +340,8 @@ addressbook_component_init (AddressbookC
 	priv->base_directory = g_build_filename (g_get_home_dir (), ".evolution", NULL);
 
 	component->priv = priv;
+
+	ensure_sources (component);
 
 #ifdef ENABLE_SMIME
 	smime_component_init ();
Index: gui/component/addressbook-config.c
===================================================================
RCS file: /cvs/gnome/evolution/addressbook/gui/component/addressbook-config.c,v
retrieving revision 1.88
diff -u -p -r1.88 addressbook-config.c
--- gui/component/addressbook-config.c	25 Aug 2004 16:26:15 -0000	1.88
+++ gui/component/addressbook-config.c	9 Oct 2004 01:17:59 -0000
@@ -935,6 +935,19 @@ addressbook_add_server_dialog (void)
 	GConfClient *gconf_client;
 	GSList *source_groups;
 	
+	gconf_client = gconf_client_get_default ();
+	sdialog->source_list = e_source_list_new_for_gconf (gconf_client, "/apps/evolution/addressbook/sources");
+	g_object_unref (gconf_client);
+
+	source_groups = e_source_list_peek_groups (sdialog->source_list);
+	if (!source_groups) {
+		g_warning ("Addressbook source groups are missing! Check your GConf setup.");
+		g_free (sdialog);
+		return NULL;
+	}
+
+	sdialog->menu_source_groups = g_slist_copy (source_groups);
+
 	sdialog->gui = glade_xml_new (EVOLUTION_GLADEDIR "/" GLADE_FILE_NAME, "account-add-window", NULL);
 
 	sdialog->window = glade_xml_get_widget (sdialog->gui, "account-add-window");
@@ -947,10 +960,6 @@ addressbook_add_server_dialog (void)
 	g_signal_connect (sdialog->display_name, "changed",
 			  G_CALLBACK (add_folder_modify), sdialog);
 
-	gconf_client = gconf_client_get_default ();
-	sdialog->source_list = e_source_list_new_for_gconf (gconf_client, "/apps/evolution/addressbook/sources");
-	source_groups = e_source_list_peek_groups (sdialog->source_list);
-	sdialog->menu_source_groups = g_slist_copy (source_groups);
 #ifndef HAVE_LDAP
 	for ( ; source_groups != NULL; source_groups = g_slist_next (source_groups))
 		if (!strcmp ("ldap://";, e_source_group_peek_base_uri (source_groups->data)))	
@@ -994,8 +1003,6 @@ addressbook_add_server_dialog (void)
 	g_object_weak_ref (G_OBJECT (sdialog->window),
 			   addressbook_source_dialog_destroy, sdialog);
 
-	g_object_unref (gconf_client);
-
 	/* make sure we fill in the default values */
 	source_to_dialog (sdialog);
 
@@ -1286,5 +1293,5 @@ addressbook_config_create_new_source (Gt
 
 	dialog = addressbook_add_server_dialog ();
 
-	return dialog->window;
+	return dialog ? dialog->window : NULL;
 }


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