[evolution-patches] Exchange connector



Hi,

Re-organized the code for adding and removing e-sources.
This should fix the problem of e-sources not getting removed
while disabled account is removed.

Please review.

-Sushma.
Index: storage/exchange-config-listener.c
===================================================================
RCS file: /cvs/gnome/evolution-exchange/storage/exchange-config-listener.c,v
retrieving revision 1.17
diff -u -p -r1.17 exchange-config-listener.c
--- storage/exchange-config-listener.c	29 Mar 2005 06:15:33 -0000	1.17
+++ storage/exchange-config-listener.c	2 Apr 2005 06:50:09 -0000
@@ -53,6 +53,11 @@ struct _ExchangeConfigListenerPrivate {
 	ExchangeAccount *exchange_account;
 };
 
+typedef struct {
+	const char *name;
+	const char *uri;
+	int type;
+}FolderInfo;
 
 enum {
 	EXCHANGE_ACCOUNT_CREATED,
@@ -64,8 +69,8 @@ static guint signals [LAST_SIGNAL] = { 0
 
 #define PARENT_TYPE E_TYPE_ACCOUNT_LIST
 
-#define conf_key_selected_cal_sources "/apps/evolution/calendar/display/selected_calendars"
-#define conf_key_selected_tasks_sources "/apps/evolution/calendar/tasks/selected_tasks"
+#define CONF_KEY_SELECTED_CAL_SOURCES "/apps/evolution/calendar/display/selected_calendars"
+#define CONF_KEY_SELECTED_TASKS_SOURCES "/apps/evolution/calendar/tasks/selected_tasks"
 
 static EAccountListClass *parent_class = NULL;
 
@@ -219,36 +224,164 @@ is_active_exchange_account (EAccount *ac
 	return (strncmp (account->source->url, "exchange://", 11) == 0);
 }
 
-void
-add_esource (ExchangeAccount *account, 
-	     FolderType folder_type, 
-	     const char *folder_name, 
-	     const char *physical_uri,
-	     ESourceList **source_list)
+static void
+add_account_esources (ExchangeAccount *account,
+		      GSList *folders)
 {
 	ESource *source = NULL;
-	ESourceGroup *source_group;
+	ESourceGroup *cal_source_group = NULL;
+	ESourceGroup *tasks_source_group = NULL;
+	ESourceGroup *contacts_source_group = NULL;
 	char *relative_uri = NULL;
-	GSList *ids, *temp_ids;
+	GSList *ids;
 	GConfClient *client;
-	gboolean is_contacts_folder = TRUE;
-	const char *offline = NULL;
 	int mode;
+	ESourceList *cal_source_list, *tasks_source_list, *contacts_source_list;
+	FolderInfo *folder=NULL;
 
 	client = gconf_client_get_default ();
 
+	cal_source_list = e_source_list_new_for_gconf ( client, CONF_KEY_CAL);
+	tasks_source_list = e_source_list_new_for_gconf ( client, CONF_KEY_TASKS);
+	contacts_source_list = e_source_list_new_for_gconf ( client, CONF_KEY_CONTACTS);
+
 	exchange_account_is_offline_sync_set (account, &mode);
 
-	if (folder_type != EXCHANGE_CONTACTS_FOLDER) {
+	/* For each component create a source group */ 
+
+	cal_source_group = e_source_group_new (account->account_name,
+					   	"exchange://");
+	tasks_source_group = e_source_group_new (account->account_name, 
+					   	"exchange://");
+	contacts_source_group = e_source_group_new (account->account_name, 
+					   	"exchange://");
+
+	if (!e_source_list_add_group (contacts_source_list, contacts_source_group, -1) ||
+	    !e_source_list_add_group (cal_source_list, cal_source_group, -1) ||
+	    !e_source_list_add_group (tasks_source_list, tasks_source_group, -1)) {
+		goto done;
+	}
+	for ( ; folders != NULL ; folders = g_slist_next (folders)) {
+		/* Create source for each folder and add to the group */
+
+		folder = folders->data;
+		if (folder->type == EXCHANGE_CONTACTS_FOLDER) {
+			source = e_source_new_with_absolute_uri (folder->name,
+								 folder->uri);
+			e_source_group_add_source (contacts_source_group, 
+						   source, -1);
+			g_object_unref (source);
+		}
+		else if (folder->type == EXCHANGE_CALENDAR_FOLDER){
+			relative_uri = g_strdup (folder->uri + 
+						 strlen ("exchange://"));
+			source = e_source_new (folder->name, relative_uri);
+			e_source_group_add_source (cal_source_group, 
+						   source, -1);
+
+			ids = gconf_client_get_list (client,
+					     CONF_KEY_SELECTED_CAL_SOURCES, 
+					     GCONF_VALUE_STRING, NULL);
+			ids = g_slist_append (ids, 
+					g_strdup (e_source_peek_uid (source)));
+			gconf_client_set_list (client,
+				       CONF_KEY_SELECTED_CAL_SOURCES, 
+				       GCONF_VALUE_STRING, ids, NULL);
+			g_slist_foreach (ids, (GFunc) g_free, NULL);
+			g_slist_free (ids);
+			g_object_unref (source);
+			g_free (relative_uri);
+	
+		}
+		else if (folder->type == EXCHANGE_TASKS_FOLDER){
+			relative_uri = g_strdup (folder->uri + 
+						 strlen ("exchange://"));
+			source = e_source_new (folder->name, relative_uri);
+			e_source_group_add_source (tasks_source_group, 
+						   source, -1);
+
+			ids = gconf_client_get_list (client, 
+					     CONF_KEY_SELECTED_TASKS_SOURCES, 
+					     GCONF_VALUE_STRING, NULL);
+
+			ids = g_slist_append (ids, 
+					g_strdup (e_source_peek_uid (source)));
+			gconf_client_set_list (client,  
+				       CONF_KEY_SELECTED_TASKS_SOURCES, 
+				       GCONF_VALUE_STRING, ids, NULL);
+			g_slist_foreach (ids, (GFunc) g_free, NULL);
+			g_slist_free (ids);
+			g_object_unref (source);
+			g_free (relative_uri);
+		}
+
+		if (mode == OFFLINE_MODE) {
+			/* If account is marked for offline sync during account
+			 * creation, mark all the folders for offline sync 
+			 */
+			e_source_set_property (source, "offline_sync", "1");
+		}
+	}
+		
+	e_source_list_sync (cal_source_list, NULL);
+	e_source_list_sync (tasks_source_list, NULL);
+	e_source_list_sync (contacts_source_list, NULL);
+
+done:
+	g_object_unref (cal_source_group);
+	g_object_unref (tasks_source_group);
+	g_object_unref (contacts_source_group);
+
+	g_object_unref (cal_source_list);
+	g_object_unref (tasks_source_list);
+	g_object_unref (contacts_source_list);
+
+	g_object_unref (client);
+}
+
+void
+add_folder_esource (ExchangeAccount *account, 
+	     	    FolderType folder_type, 
+	     	    const char *folder_name, 
+	     	    const char *physical_uri)
+{
+	ESource *source = NULL;
+	ESourceGroup *source_group = NULL;
+	char *relative_uri = NULL;
+	GSList *ids;
+	GConfClient *client;
+	gboolean is_contacts_folder = TRUE, group_new = FALSE, source_new = FALSE;
+	const char *offline = NULL;
+	int mode;
+	ESourceList *source_list;
+
+	client = gconf_client_get_default ();
+
+	if (folder_type == EXCHANGE_CONTACTS_FOLDER) {
+		source_list = e_source_list_new_for_gconf ( client, 
+							CONF_KEY_CONTACTS);
+	}
+	else if (folder_type == EXCHANGE_CALENDAR_FOLDER) {
+		source_list = e_source_list_new_for_gconf ( client, 
+							CONF_KEY_CAL);
+		relative_uri = g_strdup (physical_uri + strlen ("exchange://"));
+		is_contacts_folder = FALSE;
+	}
+	else if (folder_type == EXCHANGE_TASKS_FOLDER) {
+		source_list = e_source_list_new_for_gconf ( client,
+							CONF_KEY_TASKS);
 		relative_uri = g_strdup (physical_uri + strlen ("exchange://"));
 		is_contacts_folder = FALSE;
 	}
 
-        if ((source_group = e_source_list_peek_group_by_name (*source_list, 
-					account->account_name)) == NULL){
+	exchange_account_is_offline_sync_set (account, &mode);
+
+        if ((source_group = e_source_list_peek_group_by_name (source_list, 
+					account->account_name)) == NULL) {
 		source_group = e_source_group_new (account->account_name, 
 						   "exchange://");
-		if (!e_source_list_add_group (*source_list, source_group, -1)) {
+		if (!e_source_list_add_group (source_list, source_group, -1)) {
+			g_object_unref (source_list);
 			g_object_unref (source_group);
 			g_object_unref (client);
 			if (relative_uri)
@@ -267,16 +400,15 @@ add_esource (ExchangeAccount *account, 
 			 */
 			e_source_set_property (source, "offline_sync", "1");
 		}
-
 		e_source_group_add_source (source_group, source, -1);
-
-		g_object_unref (source_group);
+		e_source_list_sync (source_list, NULL);
+		group_new = source_new = TRUE;
 	}
 	else {
-                /* group already exists*/
-		/* FIXME - is this check needed ?*/
+                /* source group already exists*/
 		if((source = e_source_group_peek_source_by_name (source_group, 
-							folder_name)) == NULL){
+							folder_name)) == NULL) {
+			printf("old group, new source\n");
 			if (is_contacts_folder)
 				source = e_source_new_with_absolute_uri (
 						folder_name, physical_uri);
@@ -287,7 +419,10 @@ add_esource (ExchangeAccount *account, 
 				e_source_set_property (source, "offline_sync", "1");
 
 			e_source_group_add_source (source_group, source, -1);
+			source_new = TRUE;
+			e_source_list_sync (source_list, NULL);
 		} else {
+			/* source group and source both already exist */
 			offline = e_source_get_property (source, "offline_sync");
 			if (!offline) {
 				/* Folder doesn't have any offline property set */
@@ -299,118 +434,201 @@ add_esource (ExchangeAccount *account, 
 
 	if (source && !is_contacts_folder) {
 
+		/* Select the folder created */
 		if (folder_type == EXCHANGE_CALENDAR_FOLDER) {
 			ids = gconf_client_get_list (client,
-					     conf_key_selected_cal_sources, 
+					     CONF_KEY_SELECTED_CAL_SOURCES, 
 					     GCONF_VALUE_STRING, NULL);
 			ids = g_slist_append (ids, 
 					g_strdup (e_source_peek_uid (source)));
 			gconf_client_set_list (client,
-				       conf_key_selected_cal_sources, 
+				       CONF_KEY_SELECTED_CAL_SOURCES, 
 				       GCONF_VALUE_STRING, ids, NULL);
-			temp_ids  = ids;
-			for (; temp_ids != NULL; temp_ids = g_slist_next (temp_ids))
-				g_free (temp_ids->data);
+			g_slist_foreach (ids, (GFunc) g_free, NULL);
 			g_slist_free (ids);
 		}
 		else if (folder_type == EXCHANGE_TASKS_FOLDER) {
 
 			ids = gconf_client_get_list (client, 
-					     conf_key_selected_tasks_sources, 
+					     CONF_KEY_SELECTED_TASKS_SOURCES, 
 					     GCONF_VALUE_STRING, NULL);
 
 			ids = g_slist_append (ids, 
 					g_strdup (e_source_peek_uid (source)));
 			gconf_client_set_list (client,  
-				       conf_key_selected_tasks_sources, 
+				       CONF_KEY_SELECTED_TASKS_SOURCES, 
 				       GCONF_VALUE_STRING, ids, NULL);
-			temp_ids  = ids;
-			for (; temp_ids != NULL; temp_ids = g_slist_next (temp_ids))
-				g_free (temp_ids->data);
+			g_slist_foreach (ids, (GFunc) g_free, NULL);
 			g_slist_free (ids);
 		}
 	}
 
-	if (relative_uri)
-		g_free (relative_uri);
-	if (source)
+	g_free (relative_uri);
+
+	if (source_new) 
 		g_object_unref (source);
+	if (group_new)
+		g_object_unref (source_group);
+	g_object_unref (source_list);
 	g_object_unref (client);
 }
 
 static void
 add_sources (ExchangeAccount *account)
 {
-	const char *folder_name, *folder_type, *physical_uri;
 	GPtrArray *exchange_folders;
-	EFolder *folder;
-	ESourceList *cal_source_list, *task_source_list, *cont_source_list;
-	int i;
 
 	exchange_folders = exchange_account_get_folders (account);                                                                                 
-        if (exchange_folders) {
-		cal_source_list = e_source_list_new_for_gconf ( 
-					gconf_client_get_default (), 
-					CONF_KEY_CAL);
-		task_source_list = e_source_list_new_for_gconf ( 
-					gconf_client_get_default (), 
-					CONF_KEY_TASKS);
-		cont_source_list = e_source_list_new_for_gconf (
-					gconf_client_get_default (), 
-					CONF_KEY_CONTACTS);
+        if (exchange_folders && exchange_folders->len > 0) {
+		int i;
+		const char *folder_type;
+		EFolder *folder;
+		GSList *folders = NULL;
 
 		for (i = 0; i < exchange_folders->len; i++) {
+			FolderInfo *folder_info = g_new0 (FolderInfo, 1);
+
 			folder = exchange_folders->pdata[i];
-			folder_name = e_folder_get_name (folder);
 			folder_type = e_folder_get_type_string (folder);
-			physical_uri = e_folder_get_physical_uri (folder);
 
 			if (!(strcmp (folder_type, "calendar")) ||
 			    !(strcmp (folder_type, "calendar/public"))) {
-        			add_esource (account, 
-					     EXCHANGE_CALENDAR_FOLDER, 
-					     folder_name, 
-					     physical_uri,
-					     &cal_source_list);
+				folder_info->name = e_folder_get_name (folder);
+				folder_info->uri = e_folder_get_physical_uri (folder); 
+				folder_info->type = EXCHANGE_CALENDAR_FOLDER;
+				folders = g_slist_append (folders, folder_info);
 				continue;
 			}
 			else if (!(strcmp (folder_type, "tasks")) ||
 			    	 !(strcmp (folder_type, "tasks/public"))) {
-        				add_esource (account, 
-					     EXCHANGE_TASKS_FOLDER, 
-					     folder_name, 
-					     physical_uri,
-					     &task_source_list);
+				folder_info->name = e_folder_get_name (folder);
+				folder_info->uri = e_folder_get_physical_uri (folder); 
+				folder_info->type = EXCHANGE_TASKS_FOLDER;
+				folders = g_slist_append (folders, folder_info);
 				continue;
 			}
 			else if (!(strcmp (folder_type, "contacts")) ||
 			    	 !(strcmp (folder_type, "contacts/public")) ||
 			    	 !(strcmp (folder_type, "contacts/ldap"))) {
-					add_esource (account, 
-					     EXCHANGE_CONTACTS_FOLDER, 
-					     folder_name, 
-					     physical_uri,
-					     &cont_source_list);
+				folder_info->name = e_folder_get_name (folder);
+				folder_info->uri = e_folder_get_physical_uri (folder); 
+				folder_info->type = EXCHANGE_CONTACTS_FOLDER;
+				folders = g_slist_append (folders, folder_info);
 				continue;
 			}
+			else
+				g_free (folder_info);
 			continue;
 		}
-		e_source_list_sync (cal_source_list, NULL);
-		g_object_unref (cal_source_list);
-		e_source_list_sync (task_source_list, NULL);
-		g_object_unref (task_source_list);
-		e_source_list_sync (cont_source_list, NULL);
-		g_object_unref (cont_source_list);
-		g_ptr_array_free (exchange_folders, TRUE);
+		/* Add e-sources for all the folders */
+		add_account_esources (account, folders);
+		g_slist_foreach (folders, (GFunc) g_free, NULL);
+		g_slist_free (folders);
         }
 }
 
+static void 
+remove_account_esource (ExchangeAccount *account, 
+		        FolderType folder_type)
+{
+	ESourceGroup *group;
+	ESource *source = NULL;
+	GSList *groups;
+	GSList *sources;
+	GSList *ids, *node_to_be_deleted;
+	gboolean found_group;
+	const char *source_uid;
+	GConfClient *client;
+	ESourceList *source_list;
+
+	/* Remove the ESource group, to remove all the folders in a component */
+
+	client = gconf_client_get_default ();
+
+	if (folder_type == EXCHANGE_CONTACTS_FOLDER)
+		source_list = e_source_list_new_for_gconf ( client, 
+							CONF_KEY_CONTACTS);
+	else if (folder_type == EXCHANGE_CALENDAR_FOLDER)
+		source_list = e_source_list_new_for_gconf ( client, 
+							CONF_KEY_CAL);
+	else if (folder_type == EXCHANGE_TASKS_FOLDER)
+		source_list = e_source_list_new_for_gconf ( client,
+							CONF_KEY_TASKS);
+
+	groups = e_source_list_peek_groups (source_list);
+	found_group = FALSE;
+
+	for ( ; groups != NULL && !found_group; groups = g_slist_next (groups)) {
+		group = E_SOURCE_GROUP (groups->data);
+
+		if (strcmp (e_source_group_peek_name (group), account->account_name) == 0
+                    &&
+                    strcmp (e_source_group_peek_base_uri (group), "exchange://" ) == 0) {
+			sources = e_source_group_peek_sources (group);
+
+			for( ; sources != NULL; sources = g_slist_next (sources)) {
+				source = E_SOURCE (sources->data);
+				source_uid = e_source_peek_uid (source);
+
+				/* Remove from the selected folders */
+				if (folder_type == EXCHANGE_CALENDAR_FOLDER) {
+					ids = gconf_client_get_list (
+							client, 
+							CONF_KEY_SELECTED_CAL_SOURCES , 
+							GCONF_VALUE_STRING, NULL);
+					if (ids) {
+						node_to_be_deleted = g_slist_find_custom (
+									ids, 
+									source_uid, 
+									(GCompareFunc) strcmp);
+						if (node_to_be_deleted) {
+							g_free (node_to_be_deleted->data);
+							ids = g_slist_delete_link (ids, 
+									node_to_be_deleted);
+							gconf_client_set_list (client, 
+								CONF_KEY_SELECTED_CAL_SOURCES,
+								GCONF_VALUE_STRING, ids, NULL);
+						}
+						g_slist_foreach (ids, (GFunc) g_free, NULL);
+						g_slist_free (ids);
+					}
+				}
+				else if (folder_type == EXCHANGE_TASKS_FOLDER) {
+					ids = gconf_client_get_list (client, 
+								CONF_KEY_SELECTED_TASKS_SOURCES , 
+								GCONF_VALUE_STRING, NULL);
+					if (ids) {
+						node_to_be_deleted = g_slist_find_custom (
+									ids,
+									source_uid, 
+									(GCompareFunc) strcmp);
+						if (node_to_be_deleted) {
+							g_free (node_to_be_deleted->data);
+							ids = g_slist_delete_link (ids, 
+									node_to_be_deleted);
+							gconf_client_set_list (client, 
+								CONF_KEY_SELECTED_TASKS_SOURCES,
+								GCONF_VALUE_STRING, ids, NULL);
+						}
+						g_slist_foreach (ids, (GFunc) g_free, NULL);
+						g_slist_free (ids);
+					}
+				}
+				e_source_list_remove_group (source_list, group);
+				e_source_list_sync (source_list, NULL);
+				found_group = TRUE;
+				break;
+			}
+		}
+	}
+	g_object_unref (source_list);
+	g_object_unref (client);
+}
+
 void 
-remove_esource (ExchangeAccount *account, 
-		FolderType folder_type, 
-		const char *physical_uri,
-		ESourceList **source_list,
-		gboolean is_account)
+remove_folder_esource (ExchangeAccount *account, 
+		       FolderType folder_type, 
+		       const char *physical_uri)
 {
 	ESourceGroup *group;
 	ESource *source;
@@ -421,15 +639,29 @@ remove_esource (ExchangeAccount *account
 	const char *source_uid;
 	GSList *ids, *temp_ids, *node_to_be_deleted;
 	GConfClient *client;
+	ESourceList *source_list;
 
 	client = gconf_client_get_default ();
 
-	if (folder_type != EXCHANGE_CONTACTS_FOLDER) {
+	/* Remove ESource for a given folder */
+	if (folder_type == EXCHANGE_CONTACTS_FOLDER) {
+		source_list = e_source_list_new_for_gconf ( client, 
+							CONF_KEY_CONTACTS);
+	}
+	else if (folder_type == EXCHANGE_CALENDAR_FOLDER) {
+		source_list = e_source_list_new_for_gconf ( client, 
+							CONF_KEY_CAL);
+		relative_uri = g_strdup (physical_uri + strlen ("exchange://"));
+		is_contacts_folder = FALSE;
+	}
+	else if (folder_type == EXCHANGE_TASKS_FOLDER) {
+		source_list = e_source_list_new_for_gconf ( client,
+							CONF_KEY_TASKS);
 		relative_uri = g_strdup (physical_uri + strlen ("exchange://"));
 		is_contacts_folder = FALSE;
 	}
 
-	groups = e_source_list_peek_groups (*source_list);
+	groups = e_source_list_peek_groups (source_list);
 	found_group = FALSE;
 
 	for ( ; groups != NULL && !found_group; groups = g_slist_next (groups)) {
@@ -442,7 +674,7 @@ remove_esource (ExchangeAccount *account
 			sources = e_source_group_peek_sources (group);
 
 			for( ; sources != NULL; sources = g_slist_next (sources)) {
-
+				
 				source = E_SOURCE (sources->data);
 
 				if (((!is_contacts_folder &&
@@ -453,28 +685,22 @@ remove_esource (ExchangeAccount *account
 					      physical_uri) == 0)) {
 
 					source_uid = e_source_peek_uid (source);
-					if (is_account) {
-						/* Account Deleted - Remove the group */
-						e_source_list_remove_group (
-								*source_list, 
-								group);
-					}
-					else {
-						/* Folder Deleted - Remove only the source */
-						/*
-						e_source_group_remove_source_by_uid (
-									group, 
-									source_uid);
-						*/
-						e_source_group_remove_source (
-									group,
-									source);
-					}
+					/* Folder Deleted - Remove only the source */
+					/*
+					e_source_group_remove_source_by_uid (
+								group, 
+								source_uid);
+					*/
+					e_source_group_remove_source (
+								group,
+								source);
+					e_source_list_sync (source_list, NULL);
 					if (!is_contacts_folder) {
-						if (is_account || folder_type == EXCHANGE_CALENDAR_FOLDER) {
+						/* Remove from the selected folders */
+						if (folder_type == EXCHANGE_CALENDAR_FOLDER) {
 							ids = gconf_client_get_list (
 									client, 
-									conf_key_selected_cal_sources , 
+									CONF_KEY_SELECTED_CAL_SOURCES, 
 									GCONF_VALUE_STRING, NULL);
 							if (ids) {
 								node_to_be_deleted = g_slist_find_custom (ids, 
@@ -491,10 +717,10 @@ remove_esource (ExchangeAccount *account
 							g_free (temp_ids->data);
 							g_slist_free (ids);
 						}
-						else if (is_account || folder_type == EXCHANGE_TASKS_FOLDER) {
+						else if (folder_type == EXCHANGE_TASKS_FOLDER) {
 							ids = gconf_client_get_list (client, 
-										conf_key_selected_tasks_sources , 
-										GCONF_VALUE_STRING, NULL);
+									CONF_KEY_SELECTED_TASKS_SOURCES, 
+									GCONF_VALUE_STRING, NULL);
 							if (ids) {
 								node_to_be_deleted = g_slist_find_custom (ids, 
 											source_uid, 
@@ -517,75 +743,20 @@ remove_esource (ExchangeAccount *account
                         }
                 }
         }
+	g_object_unref (source_list);
 	if (relative_uri)
         	g_free (relative_uri);
 	g_object_unref (client);
 }
 
 static void
-remove_sources(ExchangeAccount *account)
+remove_account_esources (ExchangeAccount *account)
 {
-	const char *physical_uri, *folder_type;
-	EFolder *folder; 
-	ESourceList *cal_source_list, *task_source_list, *cont_source_list;
-	GPtrArray *exchange_folders;
-	int i;
+	/* Remove ESources for all the folders in all the components */
 
-	exchange_folders = exchange_account_get_folders (account);
-	if (exchange_folders) {
-		cal_source_list = e_source_list_new_for_gconf ( 
-					gconf_client_get_default (), 
-					CONF_KEY_CAL);
-		task_source_list = e_source_list_new_for_gconf ( 
-					gconf_client_get_default (), 
-					CONF_KEY_TASKS);
-		cont_source_list = e_source_list_new_for_gconf (
-					gconf_client_get_default (), 
-					CONF_KEY_CONTACTS);
-
-		for (i = 0; i < exchange_folders->len; i++) {
-			folder = exchange_folders->pdata[i];
-			folder_type = e_folder_get_type_string (folder);
-			physical_uri = e_folder_get_physical_uri (folder);
-
-			if (!strcmp (folder_type, "calendar") ||
-			    !strcmp (folder_type, "calendar/public")) {
-        			remove_esource (account, 
-						EXCHANGE_CALENDAR_FOLDER, 
-						physical_uri,
-						&cal_source_list,
-						TRUE);
-				continue;
-			}
-			else if (!strcmp (folder_type, "tasks") || 
-			         !strcmp (folder_type, "tasks/public")) {
-        				remove_esource (account, 
-						EXCHANGE_TASKS_FOLDER, 
-						physical_uri,
-						&task_source_list,
-						TRUE);
-				continue;
-			}
-			else if (!strcmp (folder_type, "contacts") ||
-			         !strcmp (folder_type, "contacts/public") |
-			         !strcmp (folder_type, "contacts/ldap")) {
-        				remove_esource (account, 
-						EXCHANGE_CONTACTS_FOLDER, 
-						physical_uri,
-						&cont_source_list,
-						TRUE);
-				continue;
-			}
-			continue;
-		}
-		e_source_list_sync (cal_source_list, NULL);
-		g_object_unref (cal_source_list);
-		e_source_list_sync (task_source_list, NULL);
-		g_object_unref (task_source_list);
-		e_source_list_sync (cont_source_list, NULL);
-		g_object_unref (cont_source_list);
-        	g_ptr_array_free (exchange_folders, TRUE);
-        }
+	remove_account_esource (account, EXCHANGE_CALENDAR_FOLDER);
+	remove_account_esource (account, EXCHANGE_TASKS_FOLDER);
+	remove_account_esource (account, EXCHANGE_CONTACTS_FOLDER);
 }
 
 static void
@@ -658,7 +829,7 @@ requires_relogin (char *current_url, cha
 {
 	E2kUri *current_uri, *new_uri;
 	const char *current_param_val, *new_param_val;
-	const char *params [] = { "owa_url", "ad_server" };
+	const char *params [] = { "owa_url", "ad_server", "use_ssl" };
 	const int n_params = G_N_ELEMENTS (params);
 	int i;
 	gboolean relogin = FALSE;
@@ -667,7 +838,8 @@ requires_relogin (char *current_url, cha
 	new_uri = e2k_uri_new (new_url);
 
 	if (strcmp (current_uri->user, new_uri->user) ||
-	    strcmp (current_uri->host, new_uri->host)) {
+	    strcmp (current_uri->host, new_uri->host) ||
+	    strcmp (current_uri->authmech, new_uri->authmech)) {
 		relogin = TRUE;
 		goto end;
 	}
@@ -755,8 +927,11 @@ account_changed (EAccountList *account_l
 	 * could be due to change in hostname or some parameter value, 
 	 * remove old e-sources 
 	 */
-	if (strcmp (config_listener->priv->configured_uri, account->source->url)) { 
-		remove_sources (priv->exchange_account);
+	if (strcmp (config_listener->priv->configured_uri, account->source->url)) {
+		/* This condition will be true always as order of parameters in 
+		 * configured_uri and source->url will not match
+		 */
+		remove_account_esources (priv->exchange_account);
 
 		/* Ask user to authenticate at next login if username, hostname,
 		 * OWA URL or GC server values are changed. 
@@ -774,7 +949,7 @@ account_changed (EAccountList *account_l
 		}
 	}
 	else if (strcmp (config_listener->priv->configured_name, account->name))
-		remove_sources (priv->exchange_account);
+		remove_account_esources (priv->exchange_account);
 
 	/* Nope. Let the user know we're ignoring him. */
 	e_notice (NULL, GTK_MESSAGE_WARNING,
@@ -800,8 +975,8 @@ account_removed (EAccountList *account_l
 	if (account != priv->configured_account)
 		return;
 
-	/* Remove ESources */
-	remove_sources(priv->exchange_account);
+	/* Remove all ESources */
+	remove_account_esources (priv->exchange_account);
 
 	exchange_account_forget_password (priv->exchange_account);
 
Index: storage/exchange-config-listener.h
===================================================================
RCS file: /cvs/gnome/evolution-exchange/storage/exchange-config-listener.h,v
retrieving revision 1.5
diff -u -p -r1.5 exchange-config-listener.h
--- storage/exchange-config-listener.h	27 Jan 2005 12:11:39 -0000	1.5
+++ storage/exchange-config-listener.h	2 Apr 2005 06:50:46 -0000
@@ -51,8 +51,8 @@ ExchangeConfigListener *exchange_config_
 
 GSList                 *exchange_config_listener_get_accounts (ExchangeConfigListener *config_listener);
 
-void 			add_esource (ExchangeAccount *account, FolderType folder_type, const char *folder_name, const char *physical_uri, ESourceList **source_list);
-void 			remove_esource (ExchangeAccount *account, FolderType folder_type, const char *physical_uri, ESourceList **source_list, gboolean is_account);
+void 			add_folder_esource (ExchangeAccount *account, FolderType folder_type, const char *folder_name, const char *physical_uri);
+void 			remove_folder_esource (ExchangeAccount *account, FolderType folder_type, const char *physical_uri);
 
 #ifdef __cplusplus
 }
Index: storage/e-folder-exchange.c
===================================================================
RCS file: /cvs/gnome/evolution-exchange/storage/e-folder-exchange.c,v
retrieving revision 1.11
diff -u -p -r1.11 e-folder-exchange.c
--- storage/e-folder-exchange.c	27 Jan 2005 12:11:39 -0000	1.11
+++ storage/e-folder-exchange.c	2 Apr 2005 06:52:00 -0000
@@ -122,7 +122,6 @@ e_folder_exchange_new (ExchangeHierarchy
 {
 	EFolderExchange *efe;
 	EFolder *ef;
-	ESourceList *cal_source_list, *task_source_list, *cont_source_list;
 
 	g_return_val_if_fail (EXCHANGE_IS_HIERARCHY (hier), NULL);
 	g_return_val_if_fail (name != NULL, NULL);
@@ -145,45 +144,27 @@ e_folder_exchange_new (ExchangeHierarchy
 	/* Add ESources */
 	if (hier->type == EXCHANGE_HIERARCHY_PERSONAL || 
 	    hier->type == EXCHANGE_HIERARCHY_FAVORITES) {
-	
+		
 		if ((strcmp (type, "calendar") == 0) ||
 		    (strcmp (type, "calendar/public") == 0)) {
-			cal_source_list = e_source_list_new_for_gconf ( 
-						gconf_client_get_default (), 
-						CONF_KEY_CAL);
-			add_esource (hier->account, 
-				     EXCHANGE_CALENDAR_FOLDER, 
-				     name, 
-				     physical_uri, 
-				     &cal_source_list);
-			e_source_list_sync (cal_source_list, NULL);
-			g_object_unref (cal_source_list);
+			add_folder_esource (hier->account, 
+				     	    EXCHANGE_CALENDAR_FOLDER, 
+				     	    name, 
+				     	    physical_uri);
 		}
 		else if ((strcmp (type, "tasks") == 0) ||
 			 (strcmp (type, "tasks/public") == 0)) {
-			task_source_list = e_source_list_new_for_gconf ( 
-						gconf_client_get_default (), 
-						CONF_KEY_TASKS);
-			add_esource (hier->account, 
-				     EXCHANGE_TASKS_FOLDER, 
-				     name, 
-				     physical_uri, 
-				     &task_source_list);
-			e_source_list_sync (task_source_list, NULL);
-			g_object_unref (task_source_list);
+			add_folder_esource (hier->account, 
+				     	    EXCHANGE_TASKS_FOLDER, 
+				     	    name, 
+				     	    physical_uri);
 		}
 		else if ((strcmp (type, "contacts") == 0) ||
 			 (strcmp (type, "contacts/public") == 0)) {
-			cont_source_list = e_source_list_new_for_gconf ( 
-						gconf_client_get_default (), 
-						CONF_KEY_CONTACTS);
-			add_esource (hier->account, 
-				     EXCHANGE_CONTACTS_FOLDER, 
-				     name, 
-				     physical_uri, 
-				     &cont_source_list);
-			e_source_list_sync (cont_source_list, NULL);
-			g_object_unref (cont_source_list);
+			add_folder_esource (hier->account, 
+				     	    EXCHANGE_CONTACTS_FOLDER, 
+				     	    name, 
+				     	    physical_uri);
 		}
 	}
 	
@@ -887,7 +868,6 @@ E2kHTTPStatus
 e_folder_exchange_delete (EFolder *folder, E2kOperation *op)
 {
 	ExchangeHierarchy *hier;
-	ESourceList *cal_source_list, *task_source_list, *cont_source_list;
 	const char *folder_type, *physical_uri;
 
 	g_return_val_if_fail (E_IS_FOLDER_EXCHANGE (folder), E2K_HTTP_MALFORMED);
@@ -902,42 +882,21 @@ e_folder_exchange_delete (EFolder *folde
 
 		if ((strcmp (folder_type, "calendar") == 0) ||
 		    (strcmp (folder_type, "calendar/public") == 0)) {
-			cal_source_list = e_source_list_new_for_gconf (
-						gconf_client_get_default (),
-						CONF_KEY_CAL);
-			remove_esource (hier->account, 
-					EXCHANGE_CALENDAR_FOLDER,
-					physical_uri,
-					&cal_source_list,
-					FALSE);
-			e_source_list_sync (cal_source_list, NULL);
-			g_object_unref (cal_source_list);
+			remove_folder_esource (hier->account, 
+					       EXCHANGE_CALENDAR_FOLDER,
+					       physical_uri);
 		}
 		else if ((strcmp (folder_type, "tasks") == 0) ||
 			 (strcmp (folder_type, "tasks/public") == 0)) {
-			task_source_list = e_source_list_new_for_gconf (
-						gconf_client_get_default (),
-						CONF_KEY_TASKS);
-			remove_esource (hier->account,
-					EXCHANGE_TASKS_FOLDER,
-					physical_uri,
-					&task_source_list,
-					FALSE);
-			e_source_list_sync (task_source_list, NULL);
-			g_object_unref (task_source_list);
+			remove_folder_esource (hier->account,
+					       EXCHANGE_TASKS_FOLDER,
+					       physical_uri);
 		}
 		else if ((strcmp (folder_type, "contacts") == 0) ||
 			 (strcmp (folder_type, "contacts/public") == 0)) { 
-			cont_source_list = e_source_list_new_for_gconf (
-						gconf_client_get_default (),
-						CONF_KEY_CONTACTS);
-			remove_esource (hier->account,
-					EXCHANGE_CONTACTS_FOLDER,
-					physical_uri,
-					&cont_source_list,
-					FALSE);
-			e_source_list_sync (cont_source_list, NULL);
-			g_object_unref (cont_source_list);
+			remove_folder_esource (hier->account,
+					       EXCHANGE_CONTACTS_FOLDER,
+					       physical_uri);
 		}
 	}
 
Index: storage/exchange-hierarchy-gal.c
===================================================================
RCS file: /cvs/gnome/evolution-exchange/storage/exchange-hierarchy-gal.c,v
retrieving revision 1.5
diff -u -p -r1.5 exchange-hierarchy-gal.c
--- storage/exchange-hierarchy-gal.c	27 Jan 2005 12:11:39 -0000	1.5
+++ storage/exchange-hierarchy-gal.c	2 Apr 2005 06:53:05 -0000
@@ -45,7 +45,6 @@ exchange_hierarchy_gal_new (ExchangeAcco
 {
 	ExchangeHierarchy *hier;
 	EFolder *toplevel;
-	ESourceList *cont_source_list;
 
 	g_return_val_if_fail (EXCHANGE_IS_ACCOUNT (account), NULL);
 	g_return_val_if_fail (hierarchy_name != NULL, NULL);
@@ -61,13 +60,8 @@ exchange_hierarchy_gal_new (ExchangeAcco
 				      EXCHANGE_HIERARCHY_GAL, toplevel,
 				      NULL, NULL, NULL);
 	/* Add ESource */
-	cont_source_list = e_source_list_new_for_gconf (
-						gconf_client_get_default (),
-						CONF_KEY_CONTACTS);
-	add_esource (hier->account, EXCHANGE_CONTACTS_FOLDER, hierarchy_name, 
-		    physical_uri_prefix, &cont_source_list);
-	e_source_list_sync (cont_source_list, NULL);
-	g_object_unref (cont_source_list);	
+	add_folder_esource (hier->account, EXCHANGE_CONTACTS_FOLDER, 
+		     	    hierarchy_name, physical_uri_prefix);
 	
 	g_object_unref (toplevel);
 
Index: storage/exchange-hierarchy-webdav.c
===================================================================
RCS file: /cvs/gnome/evolution-exchange/storage/exchange-hierarchy-webdav.c,v
retrieving revision 1.28
diff -u -p -r1.28 exchange-hierarchy-webdav.c
--- storage/exchange-hierarchy-webdav.c	29 Mar 2005 07:54:13 -0000	1.28
+++ storage/exchange-hierarchy-webdav.c	2 Apr 2005 06:54:13 -0000
@@ -392,7 +392,6 @@ xfer_folder (ExchangeHierarchy *hier, EF
 	E2kHTTPStatus status;
 	EFolder *dest;
 	char *permanent_url = NULL, *physical_uri, *source_parent;
-	ESourceList *cal_source_list, *task_source_list, *cont_source_list;
 	const char *folder_type = NULL, *source_folder_name;
 	ExchangeAccountFolderResult ret_code;
 	int offline;
@@ -470,36 +469,21 @@ xfer_folder (ExchangeHierarchy *hier, EF
 		
 		if ((strcmp (folder_type, "calendar") == 0) ||
 		    (strcmp (folder_type, "calendar/public") == 0)) {
-			cal_source_list = e_source_list_new_for_gconf (
-						gconf_client_get_default (),
-						CONF_KEY_CAL);
-			remove_esource (hier->account, EXCHANGE_CALENDAR_FOLDER,
-					physical_uri, &cal_source_list,
-					FALSE);
-			e_source_list_sync (cal_source_list, NULL);
-			g_object_unref (cal_source_list);
+			remove_folder_esource (hier->account, 
+					       EXCHANGE_CALENDAR_FOLDER,
+					       physical_uri);
 		}
 		else if ((strcmp (folder_type, "tasks") == 0) ||
 			 (strcmp (folder_type, "tasks/public") == 0)){
-			task_source_list = e_source_list_new_for_gconf (
-						gconf_client_get_default (),
-						CONF_KEY_TASKS);
-			remove_esource (hier->account, EXCHANGE_TASKS_FOLDER,
-					physical_uri, &task_source_list,
-					FALSE);
-			e_source_list_sync (task_source_list, NULL);
-			g_object_unref (task_source_list);
+			remove_folder_esource (hier->account, 
+					       EXCHANGE_TASKS_FOLDER,
+					       physical_uri);
 		}
 		else if ((strcmp (folder_type, "contacts") == 0) ||
 			 (strcmp (folder_type, "contacts/public") == 0)) {
-			cont_source_list = e_source_list_new_for_gconf (
-						gconf_client_get_default (),
-						CONF_KEY_CONTACTS);
-			remove_esource (hier->account, EXCHANGE_CONTACTS_FOLDER,
-					physical_uri, &cont_source_list, 
-					FALSE);
-			e_source_list_sync (cont_source_list, NULL);
-			g_object_unref (cont_source_list);
+			remove_folder_esource (hier->account, 
+					       EXCHANGE_CONTACTS_FOLDER,
+					       physical_uri);
 		}
 	}
 	if (physical_uri)
Index: storage/exchange-hierarchy-favorites.c
===================================================================
RCS file: /cvs/gnome/evolution-exchange/storage/exchange-hierarchy-favorites.c,v
retrieving revision 1.14
diff -u -p -r1.14 exchange-hierarchy-favorites.c
--- storage/exchange-hierarchy-favorites.c	26 Feb 2005 14:19:16 -0000	1.14
+++ storage/exchange-hierarchy-favorites.c	2 Apr 2005 06:55:34 -0000
@@ -177,7 +177,6 @@ remove_folder (ExchangeHierarchy *hier, 
 		EXCHANGE_HIERARCHY_FAVORITES (hier);
 	const char *folder_uri, *shortcut_uri;
 	E2kHTTPStatus status;
-	ESourceList *cal_source_list, *task_source_list, *cont_source_list;
 	const char *folder_type, *physical_uri;
 
 	folder_uri = e_folder_exchange_get_internal_uri (folder);
@@ -200,31 +199,19 @@ remove_folder (ExchangeHierarchy *hier, 
 	physical_uri = e_folder_get_physical_uri (folder);
 
 	if (strcmp (folder_type, "calendar") == 0) {
-		cal_source_list = e_source_list_new_for_gconf (
-					gconf_client_get_default (),
-					CONF_KEY_CAL);
-		remove_esource (hier->account, EXCHANGE_CALENDAR_FOLDER, 
-				physical_uri, &cal_source_list, FALSE);
-		e_source_list_sync (cal_source_list, NULL);
-		g_object_unref (cal_source_list);
+		remove_folder_esource (hier->account,
+				       EXCHANGE_CALENDAR_FOLDER,
+				       physical_uri);
 	}
 	else if (strcmp (folder_type, "tasks") == 0) {
-		task_source_list = e_source_list_new_for_gconf (
-					gconf_client_get_default (),
-					CONF_KEY_TASKS);
-		remove_esource (hier->account, EXCHANGE_TASKS_FOLDER, 
-				physical_uri, &task_source_list, FALSE);
-		e_source_list_sync (task_source_list, NULL);
-		g_object_unref (task_source_list);
+		remove_folder_esource (hier->account,
+				       EXCHANGE_TASKS_FOLDER,
+				       physical_uri);
 	}
 	else if (strcmp (folder_type, "contacts") == 0) {
-		cont_source_list = e_source_list_new_for_gconf (
-					gconf_client_get_default (),
-					CONF_KEY_CONTACTS);
-		remove_esource (hier->account, EXCHANGE_CONTACTS_FOLDER, 
-				physical_uri, &cont_source_list, FALSE);
-		e_source_list_sync (cont_source_list, NULL);
-		g_object_unref (cont_source_list);
+		remove_folder_esource (hier->account,
+				       EXCHANGE_CONTACTS_FOLDER,
+				       physical_uri);
 	}
 	
 	return exchange_hierarchy_webdav_status_to_folder_result (status);
Index: storage/exchange-hierarchy-foreign.c
===================================================================
RCS file: /cvs/gnome/evolution-exchange/storage/exchange-hierarchy-foreign.c,v
retrieving revision 1.11
diff -u -p -r1.11 exchange-hierarchy-foreign.c
--- storage/exchange-hierarchy-foreign.c	4 Feb 2005 11:29:45 -0000	1.11
+++ storage/exchange-hierarchy-foreign.c	2 Apr 2005 06:56:28 -0000
@@ -336,7 +336,6 @@ create_folder (ExchangeHierarchy *hier, 
 static ExchangeAccountFolderResult
 remove_folder (ExchangeHierarchy *hier, EFolder *folder)
 {
-	ESourceList *cal_source_list, *task_source_list, *cont_source_list;
 	const char *folder_type, *physical_uri;
 
 	/* Temp Fix for remove fav folders. see #59168 */
@@ -345,31 +344,19 @@ remove_folder (ExchangeHierarchy *hier, 
         physical_uri = e_folder_get_physical_uri (folder);
 
         if (strcmp (folder_type, "calendar") == 0) {
-                cal_source_list = e_source_list_new_for_gconf (
-                                        gconf_client_get_default (),
-                                        CONF_KEY_CAL);
-                remove_esource (hier->account, EXCHANGE_CALENDAR_FOLDER, 
-				physical_uri, &cal_source_list, FALSE);
-                e_source_list_sync (cal_source_list, NULL);
-                g_object_unref (cal_source_list);
+                remove_folder_esource (hier->account,
+				       EXCHANGE_CALENDAR_FOLDER,
+				       physical_uri);
         }
         else if (strcmp (folder_type, "tasks") == 0) {
-                task_source_list = e_source_list_new_for_gconf (
-                                        gconf_client_get_default (),
-                                        CONF_KEY_TASKS);
-                remove_esource (hier->account, EXCHANGE_TASKS_FOLDER, 
-				physical_uri, &task_source_list, FALSE);
-                e_source_list_sync (task_source_list, NULL);
-                g_object_unref (task_source_list);
+                remove_folder_esource (hier->account,
+				       EXCHANGE_TASKS_FOLDER,
+				       physical_uri);
         }
         else if (strcmp (folder_type, "contacts") == 0) {
-                cont_source_list = e_source_list_new_for_gconf (
-                                        gconf_client_get_default (),
-                                        CONF_KEY_CONTACTS);
-                remove_esource (hier->account, EXCHANGE_CONTACTS_FOLDER, 
-				physical_uri, &cont_source_list, FALSE);
-                e_source_list_sync (cont_source_list, NULL);
-                g_object_unref (cont_source_list);
+                remove_folder_esource (hier->account,
+				       EXCHANGE_CONTACTS_FOLDER,
+				       physical_uri);
 	}
 
 	if (folder != hier->toplevel)
@@ -433,7 +420,6 @@ exchange_hierarchy_foreign_add_folder (E
 	const char *folder_type = NULL;
 	const char *physical_uri = NULL;
 	char *new_folder_name;
-	ESourceList *cal_source_list, *task_source_list, *cont_source_list;
 
 	result =  create_internal (hier, hier->toplevel, folder_name, NULL, folder);
 
@@ -446,46 +432,25 @@ exchange_hierarchy_foreign_add_folder (E
 
 		if (!(strcmp (folder_type, "calendar")) ||
 		!(strcmp (folder_type, "calendar/public"))) {
-			cal_source_list = e_source_list_new_for_gconf (
-						gconf_client_get_default (),
-						CONF_KEY_CAL);
-			add_esource (hier->account,
-				     EXCHANGE_CALENDAR_FOLDER,
-				     new_folder_name,
-				     physical_uri,
-				     &cal_source_list);
-			e_source_list_sync (cal_source_list, NULL);
-			g_object_unref (cal_source_list);
-
+			add_folder_esource (hier->account,
+				     	    EXCHANGE_CALENDAR_FOLDER,
+				     	    new_folder_name,
+				    	    physical_uri);
 		}
 		else if (!(strcmp (folder_type, "tasks")) ||
 			 !(strcmp (folder_type, "tasks/public"))) {
-				task_source_list = e_source_list_new_for_gconf (
-						gconf_client_get_default (),
-						CONF_KEY_TASKS);
-				add_esource (hier->account,
-				     EXCHANGE_TASKS_FOLDER,
-				     new_folder_name,
-				     physical_uri,
-				     &task_source_list);
-				e_source_list_sync (task_source_list, NULL);
-				g_object_unref (task_source_list);
-
+				add_folder_esource (hier->account,
+				     		    EXCHANGE_TASKS_FOLDER,
+				     		    new_folder_name,
+				     		    physical_uri);
 		}
 		else if (!(strcmp (folder_type, "contacts")) ||
 			 !(strcmp (folder_type, "contacts/public")) ||
 			 !(strcmp (folder_type, "contacts/ldap"))) {
-				cont_source_list = e_source_list_new_for_gconf (
-						gconf_client_get_default (),
-						CONF_KEY_CONTACTS);
-
-				add_esource (hier->account,
-				     EXCHANGE_CONTACTS_FOLDER,
-				     new_folder_name,
-				     physical_uri,
-				     &cont_source_list);
-				e_source_list_sync (cont_source_list, NULL);
-				g_object_unref (cont_source_list);
+				add_folder_esource (hier->account,
+				     		    EXCHANGE_CONTACTS_FOLDER,
+				     		    new_folder_name,
+				     		    physical_uri);
 		}
 		g_free (new_folder_name);
 	}


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