[evolution-patches] Exchange: Fix for bug 310433



Hello -

I am attaching the patch that fixes the bug 310433 (Rename of Calendar
and Task folders). This patch also has the related changes in the
addressbook. Please review.

Thanks -
Praveen.
Index: plugins/exchange-operations/ChangeLog
===================================================================
RCS file: /cvs/gnome/evolution/plugins/exchange-operations/ChangeLog,v
retrieving revision 1.25
diff -u -p -r1.25 ChangeLog
--- plugins/exchange-operations/ChangeLog	19 Jul 2005 09:36:43 -0000	1.25
+++ plugins/exchange-operations/ChangeLog	21 Jul 2005 10:23:41 -0000
@@ -1,3 +1,18 @@
+2005-07-21  Praveen Kumar <kpraveen novell com>
+
+	* exchange-calendar.c : Handling the rename of calendars. This
+	addresses the bug 310433
+	* exchange-config-listener.c (add_folder_esource) : Modified the way
+	of Exchange addressbook ESource URI handling to be the same way as 
+	calendar ESource URI handling
+	* exchange-contacts.c : Handling the rename of addressbooks. Also 
+	modified the way of Exchange addressbook ESource URI handling to be 
+	the same way as calendar ESource URI handling
+	* exchange-operations.c (exchange_operations_update_child_esources) :
+	Added new to handle the rename of the ESources of all child folders 
+	in the case of parent folder being renamed.
+	* exchange-operations.h : Added prototype for the new function
+	
 2005-07-19  Shakti Sen <shprasad novell com>
 
 	* exchange-permissions-dialog.c (display_role, get_widgets):
Index: plugins/exchange-operations/exchange-calendar.c
===================================================================
RCS file: /cvs/gnome/evolution/plugins/exchange-operations/exchange-calendar.c,v
retrieving revision 1.2
diff -u -p -r1.2 exchange-calendar.c
--- plugins/exchange-operations/exchange-calendar.c	14 Jul 2005 11:18:35 -0000	1.2
+++ plugins/exchange-operations/exchange-calendar.c	21 Jul 2005 10:23:41 -0000
@@ -43,6 +43,9 @@ enum {
 	NUM_COLS
 };
 
+gboolean calendar_src_exists=FALSE;
+gchar *calendar_old_source_uri=NULL;
+
 GPtrArray *e_exchange_calendar_get_calendars (ECalSourceType *ftype);
 void e_exchange_calendar_pcalendar_on_change (GtkTreeView *treeview, ESource *source);
 GtkWidget *e_exchange_calendar_pcalendar (EPlugin *epl, EConfigHookItemFactoryData *data);
@@ -141,7 +144,6 @@ e_exchange_calendar_pcalendar (EPlugin *
 	gchar *ruri;
 	gchar *account_name;
         gchar *uri_text;
-	gboolean src_exists = TRUE;
 	int row, i;
 
 	if (!hidden)
@@ -166,8 +168,13 @@ e_exchange_calendar_pcalendar (EPlugin *
 	e_uri_free (uri);
 	g_free (uri_text);
 
-	if (!strlen (e_source_peek_relative_uri (t->source))) {
-		src_exists = FALSE;
+	if (strlen (e_source_peek_relative_uri (t->source))) {
+		calendar_src_exists = TRUE;
+		g_free (calendar_old_source_uri);
+		calendar_old_source_uri = g_strdup (e_source_peek_relative_uri (t->source));
+	}
+	else {
+		calendar_src_exists = FALSE;
 	}
 	
 	parent = data->parent;
@@ -210,7 +217,7 @@ e_exchange_calendar_pcalendar (EPlugin *
 	gtk_table_attach (GTK_TABLE (parent), scrw_pcalendar, 0, 2, row+1, row+2, GTK_EXPAND|GTK_FILL, 0, 0, 0);
 	gtk_widget_show_all (scrw_pcalendar);
   
-	if (src_exists) {
+	if (calendar_src_exists) {
 		gchar *uri_prefix, *sruri, *tmpruri;
 		int prefix_len;
 		GtkTreeSelection *selection;
@@ -259,7 +266,7 @@ e_exchange_calendar_commit (EPlugin *epl
 {
 	ECalConfigTargetSource *t = (ECalConfigTargetSource *) target;
 	ESource *source = t->source;
-	gchar *uri_text, *gruri, *gname, *ruri, *ftype, *path, *path_prefix;
+	gchar *uri_text, *gruri, *gname, *ruri, *ftype, *path, *path_prefix, *oldpath=NULL;
 	int prefix_len;
 
 	ExchangeAccount *account;
@@ -290,11 +297,35 @@ e_exchange_calendar_commit (EPlugin *epl
 
 	gname = (gchar*) e_source_peek_name (source);
 	gruri = (gchar*) e_source_peek_relative_uri (source);
-	ruri = g_strconcat (gruri, "/", gname, NULL);
+	if (calendar_src_exists) {
+		gchar *tmpruri, *tmpdelimit;
+		tmpruri = g_strdup (gruri);
+		tmpdelimit = g_strrstr (tmpruri, "/");
+		tmpdelimit[0]='\0';
+		ruri = g_strconcat (tmpruri, "/", gname, NULL);
+		g_free (tmpruri);
+	}
+	else {
+		ruri = g_strconcat (gruri, "/", gname, NULL);
+	}
 	e_source_set_relative_uri (source, ruri);
-	path = g_strdup_printf ("/%s", ruri+prefix_len);
 
-	result = exchange_account_create_folder (account, path, ftype);
+	path = g_strdup_printf ("/%s", ruri+prefix_len);
+	
+	if (!calendar_src_exists) {
+		/* Create the new folder */
+		result = exchange_account_create_folder (account, path, ftype);
+	}
+	else if (strcmp (e_source_peek_relative_uri (source), calendar_old_source_uri)) {
+		/* Rename the folder */
+		oldpath = g_strdup_printf ("/%s", calendar_old_source_uri+prefix_len);
+		result = exchange_account_xfer_folder (account, oldpath, path, TRUE);
+		exchange_operations_update_child_esources (source, calendar_old_source_uri, ruri);
+	}
+	else {
+		/* Nothing happened specific to exchange; just return */
+		return;
+	}
 
 	switch (result) {
 		/* TODO: Modify all these error messages using e_error */
@@ -328,4 +359,7 @@ e_exchange_calendar_commit (EPlugin *epl
 	g_free (ruri);
 	g_free (path);
 	g_free (ftype);
+	g_free (oldpath);
+	g_free (calendar_old_source_uri);
+	calendar_old_source_uri = NULL;
 }
Index: plugins/exchange-operations/exchange-config-listener.c
===================================================================
RCS file: /cvs/gnome/evolution/plugins/exchange-operations/exchange-config-listener.c,v
retrieving revision 1.6
diff -u -p -r1.6 exchange-config-listener.c
--- plugins/exchange-operations/exchange-config-listener.c	11 Jul 2005 12:26:24 -0000	1.6
+++ plugins/exchange-operations/exchange-config-listener.c	21 Jul 2005 10:23:42 -0000
@@ -378,6 +378,10 @@ add_folder_esource (ExchangeAccount *acc
 	if (folder_type == EXCHANGE_CONTACTS_FOLDER) {
 		source_list = e_source_list_new_for_gconf ( client, 
 							CONF_KEY_CONTACTS);
+		/* Modify the URI handling of Contacts to the same way as calendar and tasks */
+		if (!g_str_has_prefix (physical_uri, "gal://")) {
+			relative_uri = g_strdup (physical_uri + strlen (EXCHANGE_URI_PREFIX));
+		}
 	}
 	else if (folder_type == EXCHANGE_CALENDAR_FOLDER) {
 		source_list = e_source_list_new_for_gconf ( client, 
@@ -405,7 +409,7 @@ add_folder_esource (ExchangeAccount *acc
         		g_free (relative_uri);
 			return;
 		}
-		if (is_contacts_folder)
+		if (is_contacts_folder && g_str_has_prefix (physical_uri, "gal://"))
 			source = e_source_new_with_absolute_uri (folder_name,
 								 physical_uri);
 		else
@@ -428,7 +432,7 @@ add_folder_esource (ExchangeAccount *acc
 		if((source = e_source_group_peek_source_by_name (source_group, 
 							folder_name)) == NULL) {
 			printf("old group, new source\n");
-			if (is_contacts_folder)
+			if (is_contacts_folder && g_str_has_prefix (physical_uri, "gal://"))
 				source = e_source_new_with_absolute_uri (
 						folder_name, physical_uri);
 			else
Index: plugins/exchange-operations/exchange-contacts.c
===================================================================
RCS file: /cvs/gnome/evolution/plugins/exchange-operations/exchange-contacts.c,v
retrieving revision 1.1
diff -u -p -r1.1 exchange-contacts.c
--- plugins/exchange-operations/exchange-contacts.c	1 Jul 2005 10:06:24 -0000	1.1
+++ plugins/exchange-operations/exchange-contacts.c	21 Jul 2005 10:23:42 -0000
@@ -45,7 +45,9 @@ enum {
 	NUM_COLS
 };
 
-gchar *contacts_uri=NULL;
+gboolean contacts_src_exists=FALSE;
+gchar *contacts_old_src_uri=NULL;
+
 
 GPtrArray *e_exchange_contacts_get_contacts (void);
 void e_exchange_contacts_pcontacts_on_change (GtkTreeView *treeview, ESource *source);
@@ -106,14 +108,9 @@ e_exchange_contacts_pcontacts_on_change 
 	gchar *ruri;
 	
 	gtk_tree_model_get (model, &iter, CONTACTSRURI_COL, &ruri, -1);
-	es_ruri = g_strconcat ("exchange://", account->account_filename, "/", ruri, NULL);
+	es_ruri = g_strconcat (account->account_filename, "/", ruri, NULL);
 	e_source_set_relative_uri (source, es_ruri);
-	/*
-	if (contacts_uri) {
-		g_free (contacts_uri);
-	}
-	contacts_uri = g_strdup (es_ruri);
-	*/
+
 	g_free (ruri);
 	g_free (es_ruri);
 } 
@@ -130,18 +127,12 @@ e_exchange_contacts_pcontacts (EPlugin *
 	ExchangeAccount *account;
 
 	int i;
-	gboolean src_exists=FALSE;
 
 	EABConfigTargetSource *t = (EABConfigTargetSource *) data->target;
 	ESource *source = t->source;
 
 	if (data->old) {
-		/* FIXME: Review this */
-		/*
-		gtk_widget_destroy (lbl_pcontacts);
-		gtk_widget_destroy (scrw_pcontacts);
-		gtk_widget_destroy (tv_pcontacts);
-		*/
+		gtk_widget_destroy (vb_pcontacts);
 	}
 
         uri_text = e_source_get_uri (source);
@@ -152,17 +143,14 @@ e_exchange_contacts_pcontacts (EPlugin *
 
 	g_free (uri_text);
 
-	if (e_source_peek_absolute_uri (source)) {
-		src_exists = TRUE;
+	if (strcmp (e_source_peek_relative_uri (source), e_source_peek_uid (source))) {
+		contacts_src_exists = TRUE;
+		g_free (contacts_old_src_uri);
+		contacts_old_src_uri = g_strdup (e_source_peek_relative_uri (source));
 	}
 	else {
+		contacts_src_exists = FALSE;
 		e_source_set_relative_uri (source, ""); /* FIXME: Nasty hack */
-		/*
-		if (contacts_uri) {
-			g_free (contacts_uri);
-			contacts_uri = NULL;
-		}
-		*/
 	}
 
 	account = exchange_operations_get_exchange_account ();
@@ -205,16 +193,15 @@ e_exchange_contacts_pcontacts (EPlugin *
 	gtk_box_pack_start (GTK_BOX (vb_pcontacts), scrw_pcontacts, FALSE, FALSE, 0);
 	gtk_widget_show_all (vb_pcontacts);
 	
-	if (src_exists) {
+	if (contacts_src_exists) {
 		gchar *uri_prefix, *sruri, *tmpruri;
 		int prefix_len;
 		GtkTreeSelection *selection;
 
-		uri_prefix = g_strconcat ("exchange://", account->account_filename, "/", NULL);
+		tmpruri = (gchar*)e_source_peek_relative_uri (t->source);
+		uri_prefix = g_strconcat (account->account_filename, "/", NULL);
 		prefix_len = strlen (uri_prefix);
 		
-		tmpruri = (gchar*)e_source_peek_absolute_uri (t->source);
-
 		if (g_str_has_prefix (tmpruri, uri_prefix)) {
 			sruri = g_strdup (tmpruri+prefix_len);
 		}
@@ -243,7 +230,6 @@ e_exchange_contacts_check (EPlugin *epl,
 
 	if (!strncmp (e_source_group_peek_base_uri (group), "exchange", 8)) {
 		if (!strlen (e_source_peek_relative_uri (t->source))) {
-			//if (!contacts_uri) {
 			return FALSE;
 		}
 	}
@@ -256,7 +242,7 @@ e_exchange_contacts_commit (EPlugin *epl
 {
 	EABConfigTargetSource *t = (EABConfigTargetSource *) target;
 	ESource *source = t->source;
-	gchar *uri_text, *gname, *gruri, *ruri, *path, *path_prefix;
+	gchar *uri_text, *gname, *gruri, *ruri, *path, *path_prefix, *oldpath=NULL;
 	int prefix_len;
 
 	ExchangeAccount *account;
@@ -267,29 +253,44 @@ e_exchange_contacts_commit (EPlugin *epl
 		g_free (uri_text);
 		return ;
 	}	
-	
 	g_free (uri_text);
-	
+
 	account = exchange_operations_get_exchange_account ();
-	path_prefix = g_strconcat ("exchange://", account->account_filename, "/", NULL);
+	path_prefix = g_strconcat (account->account_filename, "/", NULL);
 	prefix_len = strlen (path_prefix);
+	g_free (path_prefix);
 
 	gname = (gchar*) e_source_peek_name (source);
 	gruri = (gchar*) e_source_peek_relative_uri (source);
-	ruri = g_strconcat (gruri, "/", gname, NULL);
-	//ruri = g_strconcat (contacts_uri, "/", gname, NULL);
-
-	g_print ("Setting absolute URI to %s\n", ruri);
-
-	e_source_set_absolute_uri (source, ruri);
-
-	g_print ("Read absolute URI as %s\n", e_source_peek_absolute_uri(source));
-
-	/* FIXME: This creates some problem. Identify the cause */
-	//e_source_set_relative_uri (source, ""); /* FIXME: Nasty hack */
+	if (contacts_src_exists) {
+		gchar *tmpruri, *tmpdelimit;
+		tmpruri = g_strdup (gruri);
+		tmpdelimit = g_strrstr (tmpruri, "/");
+		tmpdelimit[0]='\0';
+		ruri = g_strconcat (tmpruri, "/", gname, NULL);
+		g_free (tmpruri);
+	}
+	else {
+		ruri = g_strconcat (gruri, "/", gname, NULL);
+	}
+	e_source_set_relative_uri (source, ruri);
 
 	path = g_strdup_printf ("/%s", ruri+prefix_len);
-	result = exchange_account_create_folder (account, path, "contacts");
+	
+	if (!contacts_src_exists) {
+		/* Create the new folder */
+		result = exchange_account_create_folder (account, path, "contacts");
+	}
+	else if (strcmp (e_source_peek_relative_uri (source), contacts_old_src_uri)) {
+		/* Rename the folder */
+		oldpath = g_strdup_printf ("/%s", contacts_old_src_uri+prefix_len);
+		result = exchange_account_xfer_folder (account, oldpath, path, TRUE);
+		exchange_operations_update_child_esources (source, contacts_old_src_uri, ruri);
+	}
+	else {
+		/* Nothing happened specific to exchange; just return */
+		return;
+	}
 
 	switch (result) {
 		/* TODO: Modify all these error messages using e_error */
@@ -318,10 +319,9 @@ e_exchange_contacts_commit (EPlugin *epl
 		g_print ("Generic error\n");
 		break;
 	}
-	/*
-	g_free (contacts_uri);
-	contacts_uri = NULL;
-	*/
 	g_free (ruri);
 	g_free (path);
+	g_free (oldpath);
+	g_free (contacts_old_src_uri);
+	contacts_old_src_uri = NULL;
 }
Index: plugins/exchange-operations/exchange-operations.c
===================================================================
RCS file: /cvs/gnome/evolution/plugins/exchange-operations/exchange-operations.c,v
retrieving revision 1.5
diff -u -p -r1.5 exchange-operations.c
--- plugins/exchange-operations/exchange-operations.c	14 Jul 2005 07:00:51 -0000	1.5
+++ plugins/exchange-operations/exchange-operations.c	21 Jul 2005 10:23:42 -0000
@@ -218,3 +218,24 @@ exchange_operations_report_error (Exchan
 	g_free (error_string);
 }
 
+void exchange_operations_update_child_esources (ESource *source, const gchar *old_path, const gchar *new_path)
+{
+	ESourceGroup *group;
+	GSList *sources, *tsource;
+	group = e_source_peek_group (source);
+	sources = e_source_group_peek_sources (group);
+	for (tsource = sources; tsource != NULL; tsource = tsource->next) {
+		gchar *ruri;
+		ruri = e_source_peek_relative_uri (tsource->data);
+		if (g_strrstr (ruri, old_path)) {
+			/* This ESource points to one of the child folders */
+			gchar **tmpv, *truri;
+			/* A nasty search and replace */
+		  	tmpv = g_strsplit (ruri, old_path, -1);
+			truri = g_strjoinv (new_path, tmpv);
+			e_source_set_relative_uri (tsource->data, truri);
+			g_strfreev (tmpv);
+			g_free (truri);	
+		}
+	}
+}
Index: plugins/exchange-operations/exchange-operations.h
===================================================================
RCS file: /cvs/gnome/evolution/plugins/exchange-operations/exchange-operations.h,v
retrieving revision 1.3
diff -u -p -r1.3 exchange-operations.h
--- plugins/exchange-operations/exchange-operations.h	11 Jul 2005 07:16:42 -0000	1.3
+++ plugins/exchange-operations/exchange-operations.h	21 Jul 2005 10:23:42 -0000
@@ -46,6 +46,8 @@ void exchange_operations_cta_select_node
 
 void exchange_operations_report_error (ExchangeAccount *account, ExchangeAccountResult result);
 
+void exchange_operations_update_child_esources (ESource *source, const gchar *old_path, const gchar *new_path);
+
 #ifdef __cplusplus
 }
 #endif /* __cplusplus */


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