[evolution-patches] patch for #67724 (calendar & contacts)



The attached patch for contacts updates the base uri of On this computer
group when user home dir changes.

Calendar patch has the above change as well as changes to ensure the
default sources are alwasy present. See #67411. this is earlier fixed
for contacts case.

Siva
Index: ChangeLog
===================================================================
RCS file: /cvs/gnome/evolution/addressbook/ChangeLog,v
retrieving revision 1.1920
diff -u -p -r1.1920 ChangeLog
--- ChangeLog	14 Feb 2005 18:58:21 -0000	1.1920
+++ ChangeLog	19 Feb 2005 06:42:40 -0000
@@ -1,3 +1,12 @@
+2005-02-19  Sivaiah Nallagatla <snallagatla novell com>
+
+	* gui/component/addressbook-component.c 
+	(ensure_sources) : update the base uri 
+	of the "On This Computer" group when user home dir 
+	changes. Also unref personal source if created here.
+
+	Fixes #67724  
+	
 2005-02-09  Sivaiah Nallagatla <snallagatla novell com>
                                                                                 
         * gui/component/addressbook-config.c
Index: gui/component/addressbook-component.c
===================================================================
RCS file: /cvs/gnome/evolution/addressbook/gui/component/addressbook-component.c,v
retrieving revision 1.133
diff -u -p -r1.133 addressbook-component.c
--- gui/component/addressbook-component.c	3 Feb 2005 07:06:10 -0000	1.133
+++ gui/component/addressbook-component.c	19 Feb 2005 06:42:42 -0000
@@ -95,7 +95,10 @@ ensure_sources (AddressbookComponent *co
 
 			group = E_SOURCE_GROUP (g->data);
 
-			if (!on_this_computer && !strcmp (base_uri_proto, e_source_group_peek_base_uri (group)))
+			/* compare only file:// part. If user home dir name changes we do not want to create 
+			   one more group  */
+
+			if (!on_this_computer && !strncmp (base_uri_proto, e_source_group_peek_base_uri (group), 7))
 				on_this_computer = group;
 			else if (!on_ldap_servers && !strcmp (LDAP_BASE_URI, e_source_group_peek_base_uri (group)))
 				on_ldap_servers = group;
@@ -114,6 +117,16 @@ ensure_sources (AddressbookComponent *co
 				break;
 			}
 		}
+		/* Make sure we have the correct base uri. This can change when user's
+		   homedir name changes */
+		if (strcmp (base_uri_proto, e_source_group_peek_base_uri (on_this_computer))) {
+		    e_source_group_set_base_uri (on_this_computer, base_uri_proto);
+		    
+		    /* *sigh* . We shouldn't  need this sync call here as set_base_uri
+		       call results in synching to gconf, but that happens in idle loop
+		       and too late to prevent user seeing "Can not Open ... because of invalid uri" error.*/
+		    e_source_list_sync (source_list,NULL);
+		}
 	}
 	else {
 		/* create the local source group */
@@ -138,7 +151,8 @@ ensure_sources (AddressbookComponent *co
 
 		on_ldap_servers = group;
 	}
-
+	if (personal_source)
+		g_object_unref (personal_source);
 	g_free (base_uri_proto);
 	g_free (base_uri);
 }
Index: ChangeLog
===================================================================
RCS file: /cvs/gnome/evolution/calendar/ChangeLog,v
retrieving revision 1.2668
diff -u -p -r1.2668 ChangeLog
--- ChangeLog	18 Feb 2005 13:33:00 -0000	1.2668
+++ ChangeLog	19 Feb 2005 06:35:23 -0000
@@ -1,3 +1,19 @@
+2005-02-19  Sivaiah Nallagatla <snallagatla novell com>
+
+	* gui/calendar-component.c (ensure_sources) :
+	Make sure all the default source groups and sources
+	are present by adding missing ones. Also update the
+	base uri of "On This Computer" group to take care 
+	of change in user home dir.
+	(calendar_component_init) : call ensure_sources 
+
+	* gui/tasks-component.c (ensure_sources)
+	(tasks_component_init) : ditto
+
+	Takes care of #67411 & #67724 for
+	calendar and tasks components. 
+
+
 2005-02-18  Rodrigo Moya <rodrigo novell com>
 
 	* gui/alarm-notify/alarm-notify.c (cal_opened_cb): if opening
Index: gui/calendar-component.c
===================================================================
RCS file: /cvs/gnome/evolution/calendar/gui/calendar-component.c,v
retrieving revision 1.196
diff -u -p -r1.196 calendar-component.c
--- gui/calendar-component.c	2 Feb 2005 12:29:26 -0000	1.196
+++ gui/calendar-component.c	19 Feb 2005 06:35:31 -0000
@@ -62,6 +62,10 @@
 #define CREATE_MEETING_ID      "meeting"
 #define CREATE_ALLDAY_EVENT_ID "allday-event"
 #define CREATE_CALENDAR_ID      "calendar"
+#define WEB_BASE_URI "webcal://"
+#define CONTACTS_BASE_URI "contacts://"
+#define WEATHER_BASE_URI "weather://"
+#define PERSONAL_RELATIVE_URI "system"
 
 enum DndTargetType {
 	DND_TARGET_TYPE_CALENDAR_LIST,
@@ -121,6 +125,142 @@ struct _CalendarComponentPrivate {
 /* FIXME This should be gnome cal likely */
 extern ECompEditorRegistry *comp_editor_registry;
 
+static void
+ensure_sources (CalendarComponent *component)
+{
+	GSList *groups;
+	ESourceList *source_list;
+	ESourceGroup *group;
+	ESourceGroup *on_this_computer;
+	ESourceGroup *on_the_web;
+	ESourceGroup *contacts;
+	ESourceGroup *weather;
+	ESource *personal_source;
+	ESource *birthdays_source;
+	char *base_uri, *base_uri_proto;
+
+	on_this_computer = NULL;
+	on_the_web = NULL;
+	contacts = NULL;
+	weather = NULL;
+	personal_source = NULL;
+	birthdays_source = NULL;
+
+	if (!e_cal_get_sources (&source_list, E_CAL_SOURCE_TYPE_EVENT, NULL)) {
+		g_warning ("Could not get calendar source list from GConf!");
+		return;
+	}
+
+	base_uri = g_build_filename (calendar_component_peek_base_directory (component),
+				     "calendar", "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);
+
+			/* compare only file:// part. If user home dir name changes we do not want to create 
+			   one more group  */
+
+			if (!on_this_computer && !strncmp (base_uri_proto, e_source_group_peek_base_uri (group), 7))
+				on_this_computer = group;
+			else if (!on_the_web && !strcmp (WEB_BASE_URI, e_source_group_peek_base_uri (group)))
+				on_the_web = group;
+			else if (!contacts && !strcmp (CONTACTS_BASE_URI, e_source_group_peek_base_uri (group)))
+				contacts = group;
+			else if (!weather && !strcmp (WEATHER_BASE_URI, e_source_group_peek_base_uri (group)))
+				weather = 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;
+			}
+		}
+		/* Make sure we have the correct base uri. This can change when user's
+		   homedir name changes */
+		if (strcmp (base_uri_proto, e_source_group_peek_base_uri (on_this_computer))) {
+		    e_source_group_set_base_uri (on_this_computer, base_uri_proto);
+		  
+		    /* *sigh* . We shouldn't  need this sync call here as set_base_uri
+		       call results in synching to gconf, but that happens in idle loop
+		       and too late to prevent user seeing "Can not Open ... because of invalid uri" error.*/
+		    e_source_list_sync (source_list,NULL); 
+		}
+	}
+	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 */
+		personal_source = e_source_new (_("Personal"), PERSONAL_RELATIVE_URI);
+		e_source_group_add_source (on_this_computer, personal_source, -1);
+
+	}
+
+	if (!on_the_web) {
+		/* Create the On the web source group */
+		group = e_source_group_new (_("On The Web"), WEB_BASE_URI);
+		e_source_list_add_group (source_list, group, -1);
+
+		on_the_web = group;
+	}
+	if (contacts) {
+		GSList *sources = e_source_group_peek_sources (contacts);
+		if (sources) 
+			birthdays_source = E_SOURCE (sources->data); /* There is only one source under Contacts Group*/
+	}
+	else  {
+		/* Create the contacts group */
+		group = e_source_group_new (_("Contacts"), CONTACTS_BASE_URI);
+		e_source_list_add_group (source_list, group, -1);
+		contacts = group;
+	}
+	
+	if (!birthdays_source) {
+		birthdays_source = e_source_new (_("Birthdays & Anniversaries"), "/");
+		e_source_group_add_source (contacts, birthdays_source, -1);
+	}
+		
+	if (!weather) {
+		/* Create the weather group */
+		group = e_source_group_new (_("Weather"), WEATHER_BASE_URI);
+		e_source_list_add_group (source_list, group, -1);
+		weather = group;
+	}
+		
+	component->priv->source_list = source_list;
+
+	if (personal_source)
+		g_object_unref (personal_source);
+	if (birthdays_source)
+		g_object_unref (birthdays_source);
+			
+	g_free (base_uri_proto);
+	g_free (base_uri);
+}
+
+
 /* Utility functions.  */
 
 static gboolean
@@ -1466,19 +1606,14 @@ calendar_component_init (CalendarCompone
 	 * calendar_component_peek_gconf_client().  */
 	priv->gconf_client = gconf_client_get_default ();
 
-	
-	if (!e_cal_get_sources (&priv->source_list, E_CAL_SOURCE_TYPE_EVENT, NULL))
-		;
-	
-	if (!e_cal_get_sources (&priv->task_source_list, E_CAL_SOURCE_TYPE_TODO, NULL))
-		;
-
 	not = calendar_config_add_notification_primary_calendar (config_primary_selection_changed_cb, 
 								 component);
 	priv->notifications = g_list_prepend (priv->notifications, GUINT_TO_POINTER (not));
 
-
 	component->priv = priv;
+	ensure_sources (component);
+	if (!e_cal_get_sources (&priv->task_source_list, E_CAL_SOURCE_TYPE_TODO, NULL))
+		;
 }
 
 
Index: gui/tasks-component.c
===================================================================
RCS file: /cvs/gnome/evolution/calendar/gui/tasks-component.c,v
retrieving revision 1.83
diff -u -p -r1.83 tasks-component.c
--- gui/tasks-component.c	4 Jan 2005 10:10:30 -0000	1.83
+++ gui/tasks-component.c	19 Feb 2005 06:35:37 -0000
@@ -60,6 +60,9 @@ enum DndTargetType {
 };
 #define CALENDAR_TYPE "text/calendar"
 #define XCALENDAR_TYPE "text/x-calendar"
+#define WEB_BASE_URI "webcal://"
+#define PERSONAL_RELATIVE_URI "system"
+
 static GtkTargetEntry drag_types[] = {
 	{ CALENDAR_TYPE, 0, DND_TARGET_TYPE_CALENDAR_LIST },
 	{ XCALENDAR_TYPE, 0, DND_TARGET_TYPE_CALENDAR_LIST }
@@ -112,6 +115,103 @@ struct _TasksComponentPrivate {
 	GList *notifications;
 };
 
+static void
+ensure_sources (TasksComponent *component)
+{
+	GSList *groups;
+	ESourceList *source_list;
+	ESourceGroup *group;
+	ESourceGroup *on_this_computer;
+	ESourceGroup *on_the_web;
+	ESource *personal_source;
+	char *base_uri, *base_uri_proto;
+
+	on_this_computer = NULL;
+	on_the_web = NULL;
+	personal_source = NULL;
+
+	if (!e_cal_get_sources (&source_list, E_CAL_SOURCE_TYPE_TODO, NULL)) {
+		g_warning ("Could not get addressbook source list from GConf!");
+		return;
+	}
+
+	base_uri = g_build_filename (tasks_component_peek_base_directory (component),
+				     "tasks", "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);
+
+			/* compare only file:// part. If user home dir name changes we do not want to create 
+			   one more group  */
+
+			if (!on_this_computer && !strncmp (base_uri_proto, e_source_group_peek_base_uri (group), 7))
+				on_this_computer = group;
+			else if (!on_the_web && !strcmp (WEB_BASE_URI, e_source_group_peek_base_uri (group)))
+				on_the_web = 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;
+			}
+		}
+		/* Make sure we have the correct base uri. This can change when user's
+		   homedir name changes */
+		if (strcmp (base_uri_proto, e_source_group_peek_base_uri (on_this_computer))) {
+		    e_source_group_set_base_uri (on_this_computer, base_uri_proto);
+
+		    /* *sigh* . We shouldn't  need this sync call here as set_base_uri
+		       call results in synching to gconf, but that happens in idle loop
+		       and too late to prevent user seeing "Can not Open ... because of invalid uri" error.*/
+		    e_source_list_sync (source_list,NULL);
+		}
+	}
+	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_the_web) {
+		/* Create the LDAP source group */
+		group = e_source_group_new (_("On The Web"), WEB_BASE_URI);
+		e_source_list_add_group (source_list, group, -1);
+
+		on_the_web = group;
+	}
+
+	component->priv->source_list = source_list;
+	g_free (base_uri_proto);
+	g_free (base_uri);
+}
+
 /* Utility functions.  */
 /* FIXME Some of these are duplicated from calendar-component.c */
 static gboolean
@@ -1173,11 +1273,9 @@ tasks_component_init (TasksComponent *co
 	priv->config_directory = g_build_filename (g_get_home_dir (),
 						   ".evolution", "tasks", "config",
 						   NULL);
-
-	if (!e_cal_get_sources (&priv->source_list, E_CAL_SOURCE_TYPE_TODO, NULL))
-		;
-
+	
 	component->priv = priv;
+	ensure_sources (component);
 }
 
 /* Public API */


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