Re: [evolution-patches] [calendar-alarms] fixes 324889 and 324816



Index: ChangeLog
===================================================================
RCS file: /cvs/gnome/evolution/calendar/ChangeLog,v
retrieving revision 1.2917
diff -u -p -r1.2917 ChangeLog
--- ChangeLog	5 Jan 2006 07:53:20 -0000	1.2917
+++ ChangeLog	11 Jan 2006 09:46:58 -0000
@@ -1,3 +1,13 @@
+2006-01-11 P S Chakravarthi <pchakravarthi novell com>
+
+	Fixes #324816 #324889
+
+	* gui/alarm-notify/alarm-queue.c : menu_item_toggle_callback :
+	revised the code to use only e_source_group_add_source and 
+	e_source_group_remove_source alone to update gconf rather than
+	explicit updating of the gconf xml
+	[along with a patch in e-source-list.c]
+
 2006-01-05  Johnny Jacob  <johnnyjacob gmail com>
 
 	* gui/dialogs/event-page.c (init_widgets): Set alarm-dialog as
Index: gui/alarm-notify/alarm-queue.c
===================================================================
RCS file: /cvs/gnome/evolution/calendar/gui/alarm-notify/alarm-queue.c,v
retrieving revision 1.92
diff -u -p -r1.92 alarm-queue.c
--- gui/alarm-notify/alarm-queue.c	17 Dec 2005 13:48:18 -0000	1.92
+++ gui/alarm-notify/alarm-queue.c	11 Jan 2006 09:46:58 -0000
@@ -1029,7 +1029,7 @@ menu_item_toggle_callback (GtkToggleButt
 {
 	gboolean state = gtk_toggle_button_get_active (item);
 	ESource *source = e_source_copy ((ESource *) data);
-	GSList *groups, *p;
+	GSList *groups, *sel_groups, *p;
 
 	if (e_source_get_uri ((ESource *)data)) {
 		g_free (e_source_get_uri (source));
@@ -1040,45 +1040,50 @@ menu_item_toggle_callback (GtkToggleButt
 		const char *uid = e_source_peek_uid (source);
 		ESourceList *selected_cal = alarm_notify_get_selected_calendars (an);
 		ESourceList *all_cal;
-		ESourceGroup *sel_group = NULL;
-		const char *grp_name=NULL;
-		ESourceGroup *group;
-		ESource *del_source;		
+		ESourceGroup *group = NULL, *sel_group = NULL;
+		const char *grp_uid = NULL;
+		char * check_grp_uid = NULL;
+		ESource *source_got = NULL;		
+		gboolean found_grp = FALSE;
 
 		e_cal_get_sources (&all_cal, E_CAL_SOURCE_TYPE_EVENT, NULL);
 
 		alarm_notify_add_calendar (an, E_CAL_SOURCE_TYPE_EVENT, source, FALSE);
-		
-		/* Browse the list of calendars for the newly added calendar*/
+
+		/* Browse the list of all calendars for the newly added calendar*/
 		groups = e_source_list_peek_groups (all_cal);
 		for (p = groups; p != NULL; p = p->next) {
-			ESourceGroup *group = E_SOURCE_GROUP (p->data);
-			ESource *sel_source = e_source_group_peek_source_by_uid (group, uid);
+			group = E_SOURCE_GROUP (p->data);
+			source_got = e_source_group_peek_source_by_uid (group, uid);
 
-			if (sel_source) {
-				sel_group = group;
-				grp_name = e_source_group_peek_name (sel_group);
-				/* You have got the group name*/
+			if (source_got) {	/* You have got the group */
 				break;
-	}
-}
+			}
+		}
 
-		/* Add the source the the group name in the alarms calendar list*/
-		group = e_source_list_peek_group_by_name (selected_cal, grp_name);	
-		del_source = e_source_group_peek_source_by_uid (group, uid);
-		
-		if (!del_source) {
-			char *xml, *old_xml;
+		/* Ensure that the source is under some source group in all calendar list */
+		g_assert (group != NULL);
 
-			old_xml = e_source_group_to_xml (group);
-			e_source_group_add_source (group, source, -1);
-			xml = e_source_group_to_xml (group);
-			config_data_replace_string_list ("/apps/evolution/calendar/notify/calendars", old_xml, xml);
+		/* Get the group id from the above */
+		grp_uid =  e_source_group_peek_uid (group);
 
-			g_free (xml);
-			g_free (old_xml);
+		/* Look for the particular group in the original selected calendars list */
+		sel_groups = e_source_list_peek_groups (selected_cal);
+		for (p = sel_groups; p != NULL; p = p->next) {
+			sel_group = E_SOURCE_GROUP (p->data);
+			check_grp_uid = g_strdup ((const char *)e_source_group_peek_uid (sel_group));
+			if (!strcmp (grp_uid, check_grp_uid)) {
+				g_free (check_grp_uid);
+				found_grp = TRUE;
+				break;
+			}	
+			g_free (check_grp_uid);
 		}
 
+		g_assert (found_grp == TRUE);
+
+		e_source_group_add_source (sel_group, source, -1);
+
 		g_object_unref (all_cal);
 
 	} else {
@@ -1094,18 +1099,7 @@ menu_item_toggle_callback (GtkToggleButt
 		
 			del_source = e_source_group_peek_source_by_uid (group, uid);
 			if (del_source) {
-				char *xml, *old_xml;
-
-				old_xml = e_source_group_to_xml (group);
-
 				e_source_group_remove_source_by_uid (group, uid);
-				
-				xml = e_source_group_to_xml (group);
-
-				config_data_replace_string_list ("/apps/evolution/calendar/notify/calendars", old_xml, xml);
-
-				g_free (xml);
-				g_free (old_xml);
 				break;
 			}
 		}
Index: ChangeLog
===================================================================
RCS file: /cvs/gnome/evolution-data-server/ChangeLog,v
retrieving revision 1.355
diff -u -p -r1.355 ChangeLog
--- ChangeLog	10 Jan 2006 07:59:03 -0000	1.355
+++ ChangeLog	13 Jan 2006 05:50:40 -0000
@@ -1,3 +1,12 @@
+2006-01-11  P S Chakravarthi <pchakravarthi novell com>
+
+	* libedataserver/e-source-list.[ch] : added a function called
+	e_source_list_is_gconf_updated () which returns a boolean indicating
+	whether or not a given ESourceList instance is in sync with its
+	corresponding gconf xml or not.
+	e_source_list_sync () : added an if clause that uses the above
+	function before updating the gconf.
+
 2006-01-10  Simon Zheng  <simon zheng sun com>
 
 	* docs/reference/camel/camel-sections.txt:
Index: libedataserver/e-source-list.h
===================================================================
RCS file: /cvs/gnome/evolution-data-server/libedataserver/e-source-list.h,v
retrieving revision 1.8
diff -u -p -r1.8 e-source-list.h
--- libedataserver/e-source-list.h	31 Aug 2005 04:26:10 -0000	1.8
+++ libedataserver/e-source-list.h	13 Jan 2006 05:50:40 -0000
@@ -87,6 +87,8 @@ gboolean  e_source_list_remove_source_by
 gboolean  e_source_list_sync  (ESourceList  *list,
 			       GError      **error);
 
+gboolean e_source_list_is_gconf_updated (ESourceList *list);
+
 G_END_DECLS
 
 #endif /* _E_SOURCE_LIST_H_ */
Index: libedataserver/e-source-list.c
===================================================================
RCS file: /cvs/gnome/evolution-data-server/libedataserver/e-source-list.c,v
retrieving revision 1.14
diff -u -p -r1.14 e-source-list.c
--- libedataserver/e-source-list.c	17 Nov 2005 11:38:48 -0000	1.14
+++ libedataserver/e-source-list.c	13 Jan 2006 05:50:40 -0000
@@ -172,7 +172,7 @@ load_from_gconf (ESourceList *list)
 
 	/* FIXME if the order changes, the function doesn't notice.  */
 
-	if (changed)
+	if (changed) 
 		g_signal_emit (list, signals[CHANGED], 0);
 }
 
@@ -574,14 +574,104 @@ e_source_list_sync (ESourceList *list,
 		conf_list = g_slist_prepend (conf_list, e_source_group_to_xml (E_SOURCE_GROUP (p->data)));
 	conf_list = g_slist_reverse (conf_list);
 
-	retval = gconf_client_set_list (list->priv->gconf_client,
-					list->priv->gconf_path,
-					GCONF_VALUE_STRING,
-					conf_list,
-					error);
+	if (!e_source_list_is_gconf_updated (list))
+		retval = gconf_client_set_list (list->priv->gconf_client,
+						list->priv->gconf_path,
+						GCONF_VALUE_STRING,
+						conf_list,
+						error);
+	else
+		retval = TRUE;
 
 	g_slist_foreach (conf_list, (GFunc) g_free, NULL);
 	g_slist_free (conf_list);
 
 	return retval;
+}
+
+gboolean
+e_source_list_is_gconf_updated (ESourceList *list)
+{
+	char *source_group_xml = NULL;
+	char *gconf_xml = NULL;
+	char *group_uid = NULL;
+	GSList *conf_list = NULL, *temp = NULL, *p = NULL;
+	xmlDocPtr xmldoc;
+	ESourceGroup *group = NULL;
+	GSList *groups = NULL;	
+	gboolean conf_to_list = TRUE, list_to_conf = TRUE;
+	
+	g_return_val_if_fail (list != NULL, FALSE);
+
+	conf_list = gconf_client_get_list (list->priv->gconf_client,
+					   list->priv->gconf_path,
+					   GCONF_VALUE_STRING, NULL);
+
+	/* From conf to list */
+
+	for (temp = conf_list; temp != NULL; temp = temp->next) {
+		gconf_xml = (char *)temp->data;
+		xmldoc = xmlParseDoc ((const xmlChar *)gconf_xml);
+
+		group_uid = e_source_group_uid_from_xmldoc (xmldoc);
+		group = e_source_list_peek_group_by_uid (list, group_uid);
+
+		if (group) {
+			source_group_xml = e_source_group_to_xml (group);
+			if (!strcmp (gconf_xml, source_group_xml))
+				continue;
+			else {
+				conf_to_list  = FALSE;
+				break;
+			}
+		} else {
+			conf_to_list = FALSE;	
+			break;
+		}
+	}
+
+	/* If there is mismatch, free the conf_list and return FALSE */
+	if (!conf_to_list) {
+		for (p = conf_list; p != NULL ; p = p->next) {
+			gconf_xml = (char *) p->data;
+			g_free (gconf_xml);
+		}
+		g_slist_free (conf_list);
+		return FALSE;
+	}
+	
+	groups = e_source_list_peek_groups (list);
+	
+	/* From list to conf */	
+
+	for (p = groups ; p != NULL; p = p->next) {
+		group = E_SOURCE_GROUP (p->data);
+		source_group_xml = e_source_group_to_xml (group);
+
+		for (temp = conf_list; temp != NULL; temp = temp->next) {
+			gconf_xml = (char *)temp->data;
+			if (strcmp (gconf_xml, source_group_xml))
+				continue;
+			else
+				break; 
+		}
+
+		if (!temp) {
+			list_to_conf = FALSE;
+			break;
+		}
+
+	}
+
+	/* If there is mismatch, free the conf_list and return FALSE */
+	if (!list_to_conf) {
+		for (p = conf_list; p != NULL ; p = p->next) {
+			gconf_xml = (char *) p->data;
+			g_free (gconf_xml);
+		}
+		g_slist_free (conf_list);
+		return FALSE;
+	}
+	
+	return TRUE;
 }


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