Re: [evolution-patches] fix for the bug 300432 [calendar]



The problem was the default client was not getting unreffed when the
backend dies in both model and gcal. Also the new client created in
setup_create_ecal (calendar-component.c) was not set as a default
client. Have attached the fix for the same.

thanks, chenthill.

On Thu, 2005-04-21 at 15:22 +0530, chenthill wrote:
> This happens while creating new appointments using a script.
> 
> thanks, chenthill.
> 
> On Thu, 2005-04-21 at 11:24 +0200, Rodrigo Moya wrote:
> > On Thu, 2005-04-21 at 14:42 +0530, chenthill wrote:
> > > Hi,
> > >   Have attached the fix for the bug. This bug happens if EDS has
> > > restarted and so the client is not in a loaded state. We should open the
> > > editor only if the client has been loaded.
> > > 
> > if the event is shown in the view, the client should be already loaded.
> > And if E-D-S restarts, the GUI will take a backend_died signal and
> > unload all clients. So, how can this happen?
> _______________________________________________
> evolution-patches mailing list
> evolution-patches lists ximian com
> http://lists.ximian.com/mailman/listinfo/evolution-patches
? .ChangeLog.swp
? 300432.diff
? meeting_page.diff
? temp
? tmp
? gui/.calendar-component.c.swp
? gui/apps_evolution_calendar-2.4.schemas
Index: ChangeLog
===================================================================
RCS file: /cvs/gnome/evolution/calendar/ChangeLog,v
retrieving revision 1.2714
diff -u -p -r1.2714 ChangeLog
--- ChangeLog	18 Apr 2005 14:32:16 -0000	1.2714
+++ ChangeLog	26 Apr 2005 09:16:44 -0000
@@ -1,3 +1,27 @@
+2005-04-26  Chenthill Palanisamy  <pchenthill novell com>
+
+	Fixes #300432
+	* gui/calendar-component.c: 
+	(setup_create_ecal): Set the opened client as the default client
+	in gcal.
+	(create_new_event): Unref the create_ecal since it will be ref'ed while
+      	setting as the default client.	
+	* gui/e-cal-model.c: 
+	(remove_client): Added a boolean variable to remove the default client which is
+	also the selected source if the backend dies.
+	(e_cal_model_set_default_client) 
+	(e_cal_model_remove_client),
+	(e_cal_model_remove_all_clients): Added the boolean variable to remove client.
+	* gui/gnome-cal.c: 
+	(client_cal_opened_cb),	(default_client_cal_opened_cb) 
+      	(default_backend_died_cb): Removed the debug messages.
+	(gnome_calendar_add_source), (gnome_calendar_set_default_source): Connected 
+	the backend died signal to the remove the default client.
+	(default_backend_died_cb) : Added a call back function for default client.
+	* gui/gnome-cal.[ch]:
+	(gnome_calendar_set_default_client): Added a function for setting the default
+	client.
+	
 2005-04-18  Chenthill Palanisamy  <pchenthill novell com>
 
 	Fixes #274476
Index: 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
--- gui/calendar-component.c	22 Mar 2005 15:09:10 -0000	1.201
+++ gui/calendar-component.c	26 Apr 2005 09:16:45 -0000
@@ -1159,6 +1159,8 @@ setup_create_ecal (CalendarComponent *ca
 		return NULL;
 	}		
 
+	gnome_calendar_set_default_client (component_view->calendar, priv->create_ecal);
+	
 	/* Handle the fact it may change on us */
 	not = calendar_config_add_notification_primary_calendar (config_create_ecal_changed_cb, 
 								 calendar_component);
@@ -1175,10 +1177,19 @@ create_new_event (CalendarComponent *cal
 {
 	ECal *ecal;
 	ECalendarView *view;
+	CalendarComponentPrivate *priv;
 
 	ecal = setup_create_ecal (calendar_component, component_view);
 	if (!ecal)
 		return FALSE;
+
+	priv = calendar_component->priv;
+
+	/* create_ecal will be ref'ed and stored in gcal as default client so unreffing it here*/
+	if (priv->create_ecal) {
+		g_object_unref (priv->create_ecal);
+		priv->create_ecal = NULL;
+	}
 
 	if (component_view && (view = E_CALENDAR_VIEW (gnome_calendar_get_current_view_widget (component_view->calendar)))) {
 		GnomeCalendarViewType view_type;
Index: gui/e-cal-model.c
===================================================================
RCS file: /cvs/gnome/evolution/calendar/gui/e-cal-model.c,v
retrieving revision 1.56
diff -u -p -r1.56 e-cal-model.c
--- gui/e-cal-model.c	7 Apr 2005 18:12:50 -0000	1.56
+++ gui/e-cal-model.c	26 Apr 2005 09:16:45 -0000
@@ -94,7 +94,7 @@ static const char *ecm_get_color_for_com
 static ECalModelClient *add_new_client (ECalModel *model, ECal *client, gboolean do_query);
 static ECalModelClient *find_client_data (ECalModel *model, ECal *client);
 static void remove_client_objects (ECalModel *model, ECalModelClient *client_data);
-static void remove_client (ECalModel *model, ECalModelClient *client_data);
+static void remove_client (ECalModel *model, ECalModelClient *client_data, gboolean remove);
 
 /* Signal IDs */
 enum {
@@ -1153,7 +1153,7 @@ e_cal_model_set_default_client (ECalMode
 		g_assert (client_data);
 
 		if (!client_data->do_query)
-			remove_client (model, client_data);
+			remove_client (model, client_data, FALSE);
 	}
 	
 	/* Make sure its in the model */
@@ -1163,6 +1163,7 @@ e_cal_model_set_default_client (ECalMode
 	priv->default_client = client_data->client;	
 }
 
+
 /**
  * e_cal_model_get_client_list
  */
@@ -1595,7 +1596,7 @@ remove_client_objects (ECalModel *model,
 }
 
 static void
-remove_client (ECalModel *model, ECalModelClient *client_data)
+remove_client (ECalModel *model, ECalModelClient *client_data, gboolean remove)
 {
 	/* FIXME We might not want to disconnect the open signal for the default client */
 	g_signal_handlers_disconnect_matched (client_data->client, G_SIGNAL_MATCH_DATA, 0, 0, NULL, NULL, model);
@@ -1606,12 +1607,16 @@ remove_client (ECalModel *model, ECalMod
 
 	/* If this is the default client and we were querying (so it
 	 * was also a source), keep it around but don't query it */
-	if (model->priv->default_client == client_data->client && client_data->do_query) {
-		client_data->do_query = FALSE;
-		
-		return;
+	if (model->priv->default_client == client_data->client) {
+		if (client_data->do_query && !remove) {
+			client_data->do_query = FALSE;
+
+			return;
+		}
+		model->priv->default_client = NULL;
 	}
 
+
 	/* Remove the client from the list */
 	model->priv->clients = g_list_remove (model->priv->clients, client_data);
 
@@ -1638,7 +1643,7 @@ e_cal_model_remove_client (ECalModel *mo
 
 	client_data = find_client_data (model, client);
 	if (client_data)
-		remove_client (model, client_data);
+		remove_client (model, client_data, TRUE);
 }
 
 /**
@@ -1654,7 +1659,7 @@ e_cal_model_remove_all_clients (ECalMode
 	priv = model->priv;
 	while (priv->clients != NULL) {
 		ECalModelClient *client_data = (ECalModelClient *) priv->clients->data;
-		remove_client (model, client_data);
+		remove_client (model, client_data, TRUE);
 	}
 }
 
Index: gui/gnome-cal.c
===================================================================
RCS file: /cvs/gnome/evolution/calendar/gui/gnome-cal.c,v
retrieving revision 1.372
diff -u -p -r1.372 gnome-cal.c
--- gui/gnome-cal.c	7 Apr 2005 18:12:50 -0000	1.372
+++ gui/gnome-cal.c	26 Apr 2005 09:16:46 -0000
@@ -2199,10 +2199,8 @@ client_cal_opened_cb (ECal *ecal, ECalen
 	}
 	switch (status) {
 	case E_CALENDAR_STATUS_OK:
-		g_message ("********* the state  in ok is %d \n", state);
 		break;
 	case E_CALENDAR_STATUS_BUSY:
-		g_message ("********* the state is %d \n", state);
 		if (state == E_CAL_LOAD_NOT_LOADED)
 			e_cal_open_async (ecal, FALSE);
 		return;
@@ -2297,7 +2295,6 @@ default_client_cal_opened_cb (ECal *ecal
 	case E_CALENDAR_STATUS_OK:
 		break;
 	case E_CALENDAR_STATUS_BUSY:
-		g_message ("********* the state is %d \n", state);
 		if (state == E_CAL_LOAD_NOT_LOADED)
 			e_cal_open_async (ecal, FALSE);
 		return;
@@ -2394,6 +2391,26 @@ backend_error_cb (ECal *client, const ch
 	g_free (uristr);
 }
 
+/* Callback when the backend for the default client dies */
+static void
+default_backend_died_cb (ECal *ecal, gpointer data)
+{
+	GnomeCalendar *gcal;
+	GnomeCalendarPrivate *priv;
+	ECalModel *model;
+	ECalSourceType source_type;
+	int i;
+	
+	gcal = GNOME_CALENDAR (data);
+	priv = gcal->priv;
+	source_type = e_cal_get_source_type (ecal);
+
+	if (priv->default_client[source_type]) {
+		g_object_unref (priv->default_client[source_type]);
+		priv->default_client [source_type] = NULL;
+	}	
+}
+
 /* Callback when the backend dies */
 static void
 backend_died_cb (ECal *ecal, gpointer data)
@@ -2412,7 +2429,7 @@ backend_died_cb (ECal *ecal, gpointer da
 	/* Make sure the source doesn't go away on us since we use it below */
 	source_type = e_cal_get_source_type (ecal);
 	source = g_object_ref (e_cal_get_source (ecal));	
-		
+	
 	priv->clients_list[source_type] = g_list_remove (priv->clients_list[source_type], ecal);
 	g_hash_table_remove (priv->clients[source_type], e_source_peek_uid (source));
 
@@ -2538,6 +2555,39 @@ gnome_calendar_get_default_client (Gnome
 	return e_cal_model_get_default_client (e_calendar_view_get_model (gcal->priv->views[priv->current_view_type]));
 }
 
+/* Set the default client. The client passed here must be a loaded client */
+void
+gnome_calendar_set_default_client (GnomeCalendar *gcal, ECal *client)
+{
+	
+	GnomeCalendarPrivate *priv;
+	ECalSourceType source_type;
+	int i;
+
+	g_return_if_fail (gcal != NULL);
+	g_return_if_fail (GNOME_IS_CALENDAR (gcal));
+	g_return_if_fail (e_cal_get_load_state (client) == E_CAL_LOAD_LOADED);
+
+
+	priv = gcal->priv;
+	source_type = e_cal_get_source_type (client);
+
+	if (priv->default_client [source_type]) {
+		g_signal_handlers_disconnect_matched (priv->default_client [source_type], G_SIGNAL_MATCH_FUNC, 0, 0, NULL, default_backend_died_cb, gcal);
+		g_object_unref (priv->default_client[source_type]);
+	}
+
+	priv->default_client [source_type] = g_object_ref (client);
+	
+	for (i = 0; i < GNOME_CAL_LAST_VIEW; i++) {
+		e_cal_model_set_default_client (
+				e_calendar_view_get_model (E_CALENDAR_VIEW (priv->views[i])),
+				client);
+	}
+
+	g_signal_connect (G_OBJECT (client), "backend_died", G_CALLBACK (default_backend_died_cb), gcal);
+}
+
 /**
  * gnome_calendar_add_source:
  * @gcal: A GnomeCalendar.
@@ -2570,7 +2620,6 @@ gnome_calendar_add_source (GnomeCalendar
 		if (priv->default_client[source_type]) {
 			default_source = e_cal_get_source (priv->default_client[source_type]);
 
-			g_message ("Check if default client matches (%s %s)", e_source_peek_uid (default_source), e_source_peek_uid (source));
 			/* We don't have it but the default client is it */
 			if (!strcmp (e_source_peek_uid (default_source), e_source_peek_uid (source)))
 				client = g_object_ref (priv->default_client[source_type]);
@@ -2712,8 +2761,10 @@ gnome_calendar_set_default_source (Gnome
 
 	client = g_hash_table_lookup (priv->clients[source_type], e_source_peek_uid (source));
 
-	if (priv->default_client[source_type])
+	if (priv->default_client[source_type]) {
+		g_signal_handlers_disconnect_matched (priv->default_client [source_type], G_SIGNAL_MATCH_FUNC, 0, 0, NULL, default_backend_died_cb, gcal);
 		g_object_unref (priv->default_client[source_type]);
+	}
 
 	if (client) {
 		priv->default_client[source_type] = g_object_ref (client);
@@ -2723,6 +2774,7 @@ gnome_calendar_set_default_source (Gnome
 			return FALSE;
 	}
 
+	g_signal_connect (G_OBJECT (priv->default_client [source_type]), "backend_died", G_CALLBACK (default_backend_died_cb), gcal);
 	open_ecal (gcal, priv->default_client[source_type], FALSE, default_client_cal_opened_cb);
 
 	return TRUE;
Index: gui/gnome-cal.h
===================================================================
RCS file: /cvs/gnome/evolution/calendar/gui/gnome-cal.h,v
retrieving revision 1.102
diff -u -p -r1.102 gnome-cal.h
--- gui/gnome-cal.h	18 Oct 2004 04:08:47 -0000	1.102
+++ gui/gnome-cal.h	26 Apr 2005 09:16:46 -0000
@@ -185,6 +185,7 @@ void       gnome_calendar_delete_selecte
 void       gnome_calendar_purge                 (GnomeCalendar  *gcal,
 						 time_t older_than);
 
+void gnome_calendar_set_default_client (GnomeCalendar *gcal, ECal *client);
 
 
 G_END_DECLS


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