From 650499f47aa1b1872866b33bed545c9684ade6e2 Mon Sep 17 00:00:00 2001 From: Chenthill Palanisamy Date: Mon, 16 Jan 2006 09:40:41 +0000 Subject: [PATCH] e_source_list_is_gconf_updated () function is added in e-source-list.c to to be used in e_source_list_sync () --- ChangeLog | 9 ++++ libedataserver/e-source-list.c | 103 ++++++++++++++++++++++++++++++++++++++--- libedataserver/e-source-list.h | 2 + 3 files changed, 108 insertions(+), 6 deletions(-) diff --git a/ChangeLog b/ChangeLog index c850c24..7030878 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,12 @@ +2006-01-16 P S Chakravarthi + + * 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-16 Harish Krishnaswamy * configure.in : Add target for CALDAV calendar diff --git a/libedataserver/e-source-list.c b/libedataserver/e-source-list.c index f591796..241a177 100644 --- a/libedataserver/e-source-list.c +++ b/libedataserver/e-source-list.c @@ -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,105 @@ 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; + } + + } + + for (p = conf_list; p != NULL ; p = p->next) { + gconf_xml = (char *) p->data; + g_free (gconf_xml); + } + g_slist_free (conf_list); + + /* If there is mismatch return FALSE */ + if (!list_to_conf) + return FALSE; + + return TRUE; +} diff --git a/libedataserver/e-source-list.h b/libedataserver/e-source-list.h index ddbde02..25938b6 100644 --- a/libedataserver/e-source-list.h +++ b/libedataserver/e-source-list.h @@ -87,6 +87,8 @@ gboolean e_source_list_remove_source_by_uid (ESourceList *list, 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_ */ -- 2.7.4