[evolution-patches] Fix for reloading/unloading calendars when source list changes



Rodrigo's alarm daemon patch will conflict with this now, in
load_calendars_cb.  list_changed_cb would blow away the sources for the
source types it wasn't processing.

-JP
-- 
JP Rosevear <jpr novell com>
Novell, Inc.
Index: ChangeLog
===================================================================
RCS file: /cvs/gnome/evolution/calendar/ChangeLog,v
retrieving revision 1.2496
diff -u -r1.2496 ChangeLog
--- ChangeLog	26 Aug 2004 16:16:53 -0000	1.2496
+++ ChangeLog	27 Aug 2004 13:16:20 -0000
@@ -1,3 +1,17 @@
+2004-08-27  JP Rosevear  <jpr novell com>
+
+	* gui/alarm-notify/alarm-notify.h: update proto
+
+	* gui/alarm-notify/alarm-notify.c (list_changed_cb): use per
+	source type client hash
+	(alarm_notify_init): ditto
+	(alarm_notify_finalize): ditto
+	(cal_opened_cb): ditto
+	(alarm_notify_add_calendar): ditto
+	(alarm_notify_remove_calendar): ditto, take source_type arg
+	(load_calendars_cb): don't call list_changed if the source list is
+	NULL
+	
 2004-08-26  Christian Neumair  <chris gnome-de org>
 
 	* gui/GNOME_Evolution_Calendar.server.in.in:
Index: gui/alarm-notify/alarm-notify.c
===================================================================
RCS file: /cvs/gnome/evolution/calendar/gui/alarm-notify/alarm-notify.c,v
retrieving revision 1.43
diff -u -r1.43 alarm-notify.c
--- gui/alarm-notify/alarm-notify.c	18 Aug 2004 14:42:19 -0000	1.43
+++ gui/alarm-notify/alarm-notify.c	27 Aug 2004 13:16:20 -0000
@@ -39,7 +39,7 @@
 	/* Mapping from EUri's to LoadedClient structures */
 	/* FIXME do we need per source type uri hashes? or perhaps we
 	   just need to hash based on source */
-	GHashTable *uri_client_hash;
+	GHashTable *uri_client_hash [E_CAL_SOURCE_TYPE_LAST];
         ESourceList *source_lists [E_CAL_SOURCE_TYPE_LAST];	
         GMutex *mutex;
 };
@@ -93,7 +93,7 @@
 		for (q = sources; q != NULL; q = q->next) {
 			ESource *source = E_SOURCE (q->data);
 			char *source_uri;
-			
+
 			source_uri = e_source_get_uri (source);
 			if (strcmp (source_uri, uri) == 0)
 				found = TRUE;
@@ -142,7 +142,7 @@
 			char *uri;
 			
 			uri = e_source_get_uri (source);
-			if (!g_hash_table_lookup (priv->uri_client_hash, uri)) {
+			if (!g_hash_table_lookup (priv->uri_client_hash[source_type], uri)) {
 				g_message ("Adding %s", uri);
 				alarm_notify_add_calendar (an, source_type, source, FALSE);
 			}
@@ -154,11 +154,11 @@
 	prd.an = an;
 	prd.source_list = priv->source_lists[source_type];
 	prd.removals = NULL;
-	g_hash_table_foreach (priv->uri_client_hash, (GHFunc) process_removal_in_hash, &prd);
+	g_hash_table_foreach (priv->uri_client_hash[source_type], (GHFunc) process_removal_in_hash, &prd);
 
 	for (l = prd.removals; l; l = l->next) {
 		g_message ("Removing %s", (char *)l->data);
-		alarm_notify_remove_calendar (an, l->data);
+		alarm_notify_remove_calendar (an, source_type, l->data);
 	}
 	g_list_free (prd.removals);
 }
@@ -206,8 +206,11 @@
 	int i;
 	AlarmNotify *an =  ALARM_NOTIFY (data);
 	
-	for (i = 0; i < E_CAL_SOURCE_TYPE_LAST; i++)
-		list_changed_cb (an->priv->source_lists[i], an);
+	for (i = 0; i < E_CAL_SOURCE_TYPE_LAST; i++) {
+		if (an->priv->source_lists[i])
+			list_changed_cb (an->priv->source_lists[i], an);
+	}
+	
 	return FALSE;
 	
 }
@@ -221,7 +224,9 @@
 	priv = g_new0 (AlarmNotifyPrivate, 1);
 	an->priv = priv;
 	priv->mutex = g_mutex_new ();
-	priv->uri_client_hash = g_hash_table_new_full (g_str_hash, g_str_equal, g_free, g_object_unref);
+
+	for (i = 0; i < E_CAL_SOURCE_TYPE_LAST; i++)
+		priv->uri_client_hash[i] = g_hash_table_new_full (g_str_hash, g_str_equal, g_free, g_object_unref);
 
 	alarm_queue_init ();
 
@@ -244,14 +249,19 @@
 {
 	AlarmNotify *an;
 	AlarmNotifyPrivate *priv;
-
+	int i;
+	
 	g_return_if_fail (object != NULL);
 	g_return_if_fail (IS_ALARM_NOTIFY (object));
 
 	an = ALARM_NOTIFY (object);
 	priv = an->priv;
-	g_hash_table_foreach (priv->uri_client_hash, dequeue_client, NULL);
-	g_hash_table_destroy (priv->uri_client_hash);
+
+	for (i = 0; i < E_CAL_SOURCE_TYPE_LAST; i++) {
+		g_hash_table_foreach (priv->uri_client_hash[i], dequeue_client, NULL);
+		g_hash_table_destroy (priv->uri_client_hash[i]);
+	}
+	
 	g_mutex_free (priv->mutex);
 	g_free (priv);
 
@@ -291,7 +301,7 @@
 	if (status == E_CALENDAR_STATUS_OK)
 		alarm_queue_add_client (client);
 	else {
-		g_hash_table_remove (priv->uri_client_hash,
+		g_hash_table_remove (priv->uri_client_hash[e_cal_get_source_type (client)],
 				     e_cal_get_uri (client));
 	}
 }
@@ -322,7 +332,7 @@
 	
 	g_mutex_lock (an->priv->mutex);
 	/* See if we already know about this uri */
-	if (g_hash_table_lookup (priv->uri_client_hash, str_uri)) {
+	if (g_hash_table_lookup (priv->uri_client_hash[source_type], str_uri)) {
 		g_mutex_unlock (an->priv->mutex);
 		return;
 	}
@@ -337,7 +347,7 @@
 	client = auth_new_cal_from_source (source, source_type);
 
 	if (client) {
-		g_hash_table_insert (priv->uri_client_hash, g_strdup (str_uri), client);
+		g_hash_table_insert (priv->uri_client_hash[source_type], g_strdup (str_uri), client);
 		g_signal_connect (G_OBJECT (client), "cal_opened", G_CALLBACK (cal_opened_cb), an);
 		e_cal_open_async (client, FALSE);
 	}
@@ -345,16 +355,16 @@
 }
 
 void
-alarm_notify_remove_calendar (AlarmNotify *an, const char *str_uri)
+alarm_notify_remove_calendar (AlarmNotify *an, ECalSourceType source_type, const char *str_uri)
 {
 	AlarmNotifyPrivate *priv;
 	ECal *client;
-
+	
 	priv = an->priv;
 
-	client = g_hash_table_lookup (priv->uri_client_hash, str_uri);
+	client = g_hash_table_lookup (priv->uri_client_hash[source_type], str_uri);
 	if (client) {
 		alarm_queue_remove_client (client);
-		g_hash_table_remove (priv->uri_client_hash, str_uri);
+		g_hash_table_remove (priv->uri_client_hash[source_type], str_uri);
 	}
 }
Index: gui/alarm-notify/alarm-notify.h
===================================================================
RCS file: /cvs/gnome/evolution/calendar/gui/alarm-notify/alarm-notify.h,v
retrieving revision 1.11
diff -u -r1.11 alarm-notify.h
--- gui/alarm-notify/alarm-notify.h	16 Aug 2004 09:50:21 -0000	1.11
+++ gui/alarm-notify/alarm-notify.h	27 Aug 2004 13:16:20 -0000
@@ -56,7 +56,7 @@
 AlarmNotify *alarm_notify_new (void);
 
 void alarm_notify_add_calendar (AlarmNotify *an, ECalSourceType source_type, ESource *source, gboolean load_afterwards);
-void alarm_notify_remove_calendar (AlarmNotify *an, const char *str_uri);
+void alarm_notify_remove_calendar (AlarmNotify *an, ECalSourceType source_type, const char *str_uri);
 
 
 


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