Index: calendar/ChangeLog
===================================================================
RCS file: /cvs/gnome/evolution/calendar/ChangeLog,v
retrieving revision 1.2727
diff -u -p -r1.2727 ChangeLog
--- calendar/ChangeLog	10 May 2005 08:14:41 -0000	1.2727
+++ calendar/ChangeLog	12 May 2005 08:17:31 -0000
@@ -1,3 +1,25 @@
+2005-05-12  Not Zed  <NotZed@Ximian.com>
+
+	** See bug #261836
+
+	* gui/calendar-component.c (create_component_view): listen for
+	free/busy list changes, and update ui to match.
+
+	* calendar-errors.xml: added error for freebusy publish failure.
+
+	* gui/e-pub-utils.c (e_pub_publish): add error prompt/disable a
+	f/b url if publishing or resolving fails.
+	(e_pub_publish): fix a bunch of memory/logic problems.
+
+	* gui/calendar-commands.c (have_freebusy): util to find out if we
+	have any freebusy info.
+	(calendar_control_sensitize_calendar_commands): sensitise the
+	publishfreebusy menu based on if there are any freebusy things
+	setup.
+
+	* gui/e-pub-utils.c (e_pub_uri_free): add a free func, fixes some mem leaks.
+	(e_pub_publish): free the xml list contents(!).
+
 2005-05-09  Rodrigo Moya <rodrigo@novell.com>
 
 	Fixes #301350
Index: calendar/calendar-errors.xml
===================================================================
RCS file: /cvs/gnome/evolution/calendar/calendar-errors.xml,v
retrieving revision 1.12
diff -u -p -r1.12 calendar-errors.xml
--- calendar/calendar-errors.xml	6 May 2005 05:17:05 -0000	1.12
+++ calendar/calendar-errors.xml	12 May 2005 08:17:31 -0000
@@ -213,4 +213,12 @@
  <secondary>You are connecting to an unsupported GroupWise server and may encounter problems using Evolution. For best results the server should be upgraded to a supported version</secondary>
  </error>
 
+ <error id="prompt-freebusy-publish-fail" type="warning" default="GTK_RESPONSE_YES">
+  <title>Free/Busy Failure</title> 
+  <primary>Unable to publish free/busy information to &quot;{0}&quot;.</primary>
+  <secondary>You may choose to disable this free/busy URL, or continue.  If the URL is disabled, then it can be re-enabled from preferences.</secondary>
+  <button label="_Disable" response="GTK_RESPONSE_CANCEL"/>
+  <button label="_Continue" response="GTK_RESPONSE_YES"/>
+ </error>
+
 </error-list>
Index: calendar/calendar-errors.xml.h
===================================================================
RCS file: /cvs/gnome/evolution/calendar/calendar-errors.xml.h,v
retrieving revision 1.13
diff -u -p -r1.13 calendar-errors.xml.h
--- calendar/calendar-errors.xml.h	6 May 2005 05:13:19 -0000	1.13
+++ calendar/calendar-errors.xml.h	12 May 2005 08:17:31 -0000
@@ -148,3 +148,10 @@ char *s = N_("Server Version");
 char *s = N_("Some features may not work properly with your current server");
 /* calendar:server-version secondary */
 char *s = N_("You are connecting to an unsupported GroupWise server and may encounter problems using Evolution. For best results the server should be upgraded to a supported version");
+/* calendar:prompt-freebusy-publish-fail title */
+char *s = N_("Free/Busy Failure");
+/* calendar:prompt-freebusy-publish-fail primary */
+char *s = N_("Unable to publish free/busy information to \"{0}\".");
+/* calendar:prompt-freebusy-publish-fail secondary */
+char *s = N_("You may choose to disable this free/busy URL, or continue.  If the URL is disabled, then it can be re-enabled from preferences.");
+char *s = N_("_Disable");
Index: calendar/gui/calendar-commands.c
===================================================================
RCS file: /cvs/gnome/evolution/calendar/gui/calendar-commands.c,v
retrieving revision 1.159
diff -u -p -r1.159 calendar-commands.c
--- calendar/gui/calendar-commands.c	1 Feb 2005 11:46:33 -0000	1.159
+++ calendar/gui/calendar-commands.c	12 May 2005 08:17:31 -0000
@@ -416,6 +416,29 @@ static struct _sensitize_item calendar_s
 	{ 0 }
 };
 
+static gboolean
+have_freebusy(void)
+{
+	GSList *fblist, *l;
+	gboolean have = FALSE;
+
+	/* NB: Note the wild inefficiency of storing data structures in xml in memory! */
+
+	fblist = calendar_config_get_free_busy ();
+	for (l = fblist; l && !have; l=l->next) {
+		EPublishUri *uri;
+
+		uri = g_malloc0(sizeof(*uri));
+		e_pub_uri_from_xml(uri, l->data);
+		have = uri->enabled;
+		e_pub_uri_free(uri);
+	}
+	g_slist_foreach(fblist, (GFunc)g_free, NULL);
+	g_slist_free(fblist);
+
+	return have;
+}
+
 /* Sensitizes the UI Component menu/toolbar calendar commands based on the
  * number of selected events. (This will always be 0 or 1 currently.)  If enable
  * is FALSE, all will be disabled.  Otherwise, the currently-selected number of
@@ -456,6 +479,10 @@ calendar_control_sensitize_calendar_comm
 		t->target.mask = ~0;
 
 	sensitize_items(uic, calendar_sensitize_table, t->target.mask);
+
+	bonobo_ui_component_set_prop (uic, "/commands/PublishFreeBusy", "sensitive",
+				      enable && have_freebusy() ? "1" : "0",
+				      NULL);
 #if 0
 	/* retrieve read-onlyness of the default client */
 	e_cal = e_cal_model_get_default_client (gnome_calendar_get_calendar_model (gcal));
Index: calendar/gui/calendar-component.c
===================================================================
RCS file: /cvs/gnome/evolution/calendar/gui/calendar-component.c,v
retrieving revision 1.201
diff -u -p -r1.201 calendar-component.c
--- calendar/gui/calendar-component.c	22 Mar 2005 15:09:10 -0000	1.201
+++ calendar/gui/calendar-component.c	12 May 2005 08:17:31 -0000
@@ -98,6 +98,7 @@ typedef struct 
 	BonoboControl *sidebar_control;
 	BonoboControl *statusbar_control;
 
+	guint gconf_notify_id;
 	GList *notifications;
 
 	EUserCreatableItemsHandler *creatable_items_handler;
@@ -749,6 +750,18 @@ init_calendar_publishing_cb (gpointer da
 }
 
 static void
+component_conf_changed_callback (GConfClient *client,
+				 unsigned int connection_id,
+				 GConfEntry *entry,
+				 void *user_data)
+{
+	CalendarComponentView *component_view = user_data;
+
+	/* publish config changed, so update sensitivity */
+	calendar_control_sensitize_calendar_commands (component_view->view_control, component_view->calendar, TRUE);
+}
+
+static void
 conf_changed_callback (GConfClient *client,
 		       unsigned int connection_id,
 		       GConfEntry *entry,
@@ -1341,6 +1354,11 @@ create_component_view (CalendarComponent
 	g_signal_connect (component_view->calendar, "dates_shown_changed",
 			  G_CALLBACK (calendar_dates_changed_cb), component_view);
 
+	/* and monitor gconf values which affect the ui */
+	component_view->gconf_notify_id	= gconf_client_notify_add(priv->gconf_client, CALENDAR_CONFIG_PUBLISH,
+								  (GConfClientNotifyFunc) component_conf_changed_callback, component_view,
+								  NULL, NULL);
+
 	/* Load the selection from the last run */
 	update_selection (component_view);	
 	update_primary_selection (component_view);
@@ -1373,6 +1391,8 @@ destroy_component_view (CalendarComponen
 
 	if (component_view->source_selection)
 		e_source_selector_free_selection (component_view->source_selection);
+
+	gconf_client_notify_remove(calendar_component_peek()->priv->gconf_client, component_view->gconf_notify_id);
 	
 	for (l = component_view->notifications; l; l = l->next)
 		calendar_config_remove_notification (GPOINTER_TO_UINT (l->data));
Index: calendar/gui/e-pub-utils.c
===================================================================
RCS file: /cvs/gnome/evolution/calendar/gui/e-pub-utils.c,v
retrieving revision 1.7
diff -u -p -r1.7 e-pub-utils.c
--- calendar/gui/e-pub-utils.c	23 Feb 2005 18:56:56 -0000	1.7
+++ calendar/gui/e-pub-utils.c	12 May 2005 08:17:31 -0000
@@ -33,6 +33,8 @@
 #include "common/authentication.h"
 #include "itip-utils.h"
 #include "e-pub-utils.h"
+#include "widgets/misc/e-error.h"
+#include "gtk/gtkdialog.h"
 
 void
 e_pub_uri_from_xml (EPublishUri *uri, const gchar *xml)
@@ -131,6 +133,17 @@ e_pub_uri_to_xml (EPublishUri *uri)
 	return returned_buffer;
 }
 
+void
+e_pub_uri_free(EPublishUri *uri)
+{
+	g_free(uri->location);
+	g_free(uri->username);
+	g_free(uri->password);
+	g_free(uri->last_pub_time);
+	g_slist_foreach(uri->calendars, (GFunc)g_free, NULL);
+	g_free(uri);
+}
+
 static gboolean 
 is_publish_time (EPublishUri *uri) {
 	icaltimezone *utc;
@@ -194,13 +207,14 @@ just_published (gchar *last_pub_time) {
 }
 
 void
-e_pub_publish (gboolean publish) {
+e_pub_publish (gboolean publish)
+{
 	icaltimezone *utc;
 	time_t start = time (NULL), end;
-	GSList *uri_config_list, *l, *uri_list = NULL;
+	GSList *uri_config_list, *l;
 	ESourceList *source_list;
 	GConfClient *gconf_client;
-	gboolean published = FALSE;
+	gboolean listchanged = FALSE;
 	
 	gconf_client = gconf_client_get_default ();
 	source_list = e_source_list_new_for_gconf (gconf_client, "/apps/evolution/calendar/sources");
@@ -218,7 +232,7 @@ e_pub_publish (gboolean publish) {
 		gboolean cloned = FALSE;
 		ECal *client = NULL;
 		char *prompt;
-		gboolean remember = FALSE;
+		gboolean remember = FALSE, publishnow, changed=FALSE;
 		gchar *password;
 
 		gchar *xml = (gchar *)l->data;
@@ -232,25 +246,20 @@ e_pub_publish (gboolean publish) {
 		
 		/* TODO: make sure we're online */
 		/* skip this url if it isn't enabled or if it is manual */
-		if (!uri->enabled) {
-			uri_config_list = g_slist_next (uri_config_list);
+		if (!uri->enabled)
 			continue;
-		}	
-		
+
 		if (!publish) {
 			/* a g_idle publish, make sure we are not set to user only */
-			if (uri->publish_freq == URI_PUBLISH_USER) {
-				uri_config_list = g_slist_next (uri_config_list);
+			if (uri->publish_freq == URI_PUBLISH_USER)
 				continue;
-			}
 			
 			/* If not is it time to publish again? */
-			publish = is_publish_time (uri);
-				
+			publishnow = is_publish_time (uri);
 		}
 		
 		/* User published or config change */
-		if (publish) {
+		if (publish || publishnow) {
 			/* We still need to set the last_pub_time */
 			uri->last_pub_time = 0;
 			is_publish_time (uri);
@@ -267,7 +276,6 @@ e_pub_publish (gboolean publish) {
 
 				if (!client) {
 					g_warning (G_STRLOC ": Could not publish Free/Busy: Calendar backend no longer exists");
-
 					continue;
 				}
 			
@@ -305,33 +313,34 @@ e_pub_publish (gboolean publish) {
 								     &remember, NULL);
 
 				g_free (prompt);
-					
-				if (!password) {
-					g_slist_free (p);
-					continue;
-				}
 			}
 		
-			if (cloned && clone)
-				published = itip_publish_comp ((ECal *) client,
+			if (cloned && clone && password) {
+				if (itip_publish_comp ((ECal *) client,
 						       uri->location,
 						       uri->username, 
-						       password, &clone);
-			
-			g_slist_free (p);
+						       password, &clone)) {
+					changed = TRUE;
+				} else if (e_error_run(NULL, "calendar:prompt-freebusy-publish-fail", uri->location, NULL) == GTK_RESPONSE_CANCEL) {
+					uri->enabled = FALSE;
+					changed = TRUE;
+				}
+			}
 		}
-		xml = e_pub_uri_to_xml (uri);
-		if (xml != NULL) {
-			uri_list = g_slist_append (uri_list, xml);
+
+		if (changed) {
+			listchanged = TRUE;
+			g_free(l->data);
+			l->data = e_pub_uri_to_xml (uri);
 		}
-		g_free (uri);
+		e_pub_uri_free (uri);
 	}
 	
-	if (published) {
+	if (listchanged) {
 		/* Update gconf so we have the last_pub_time */
-		calendar_config_set_free_busy (uri_list);
+		calendar_config_set_free_busy (uri_config_list);
 	}
-		
+
+	g_slist_foreach(uri_config_list, (GFunc)g_free, NULL);
 	g_slist_free (uri_config_list);
-	g_slist_free (uri_list);
 }
Index: calendar/gui/e-pub-utils.h
===================================================================
RCS file: /cvs/gnome/evolution/calendar/gui/e-pub-utils.h,v
retrieving revision 1.1
diff -u -p -r1.1 e-pub-utils.h
--- calendar/gui/e-pub-utils.h	13 Jan 2004 01:59:28 -0000	1.1
+++ calendar/gui/e-pub-utils.h	12 May 2005 08:17:31 -0000
@@ -55,6 +55,7 @@ typedef struct _EPublishUri EPublishUri;
 
 void e_pub_uri_from_xml (EPublishUri *uri, const gchar *xml);
 gchar  *e_pub_uri_to_xml (EPublishUri *uri);
+void e_pub_uri_free (EPublishUri *);
 void e_pub_publish (gboolean publish) ;
 
 G_END_DECLS
