[evolution-patches] Exchange patch for deleting folders



Hi,

There are three parts for this patch. One each for evolution, evolution-
data-server and evolution-exchange. All are related to the exchange
parts of the code there. The Changelog and the file names should
explain. I have also included the new 2 files that are part of this
patch.

Thanks
-- Sarfraaz
Index: ChangeLog
===================================================================
RCS file: /cvs/gnome/evolution-data-server/servers/exchange/ChangeLog,v
retrieving revision 1.19
diff -u -p -u -p -r1.19 ChangeLog
--- ChangeLog	16 Jul 2005 07:13:33 -0000	1.19
+++ ChangeLog	21 Jul 2005 07:18:25 -0000
@@ -1,3 +1,21 @@
+2005-07-21  Sarfraaz Ahmed <asarfraaz novell com>
+
+	* storage/Makefile.am : Add the separated esource handling code files.
+	* storage/e-source.[ch] : Added new
+	* storage/e-folder-exchange.c : Reinclude the esource creation code.
+	* storage/exchange-account.c : Add a new fresh_folder list. This has
+	the latest list of folders available for the account, excluding the
+	folders that were deleted in the current session.
+	(exchange_account_rescan_tree) : Add a scan for fetching any new
+	folders apart from scanning the existing folder properties.
+	(exchange_account_get_folders): First check for the fresh_folder list
+	if available and get the list from that.
+	* storage/exchange-hierarchy-favorites.c : Reinclude the esource
+	removal code.
+	* storage/exchange-hierarchy-foreign.c : Similar
+	* storage/exchange-hierarchy-gal.c : Similar
+	* storage/exchange-hierarchy-webdav.c : Similar
+
 2005-07-15  Arunprakash <arunp novell com>
 
 	* storage/exchange-account.c (exchange_account_connect) :  Update the 
Index: storage/Makefile.am
===================================================================
RCS file: /cvs/gnome/evolution-data-server/servers/exchange/storage/Makefile.am,v
retrieving revision 1.9
diff -u -p -u -p -r1.9 Makefile.am
--- storage/Makefile.am	14 Jul 2005 11:51:35 -0000	1.9
+++ storage/Makefile.am	21 Jul 2005 07:18:25 -0000
@@ -34,6 +34,8 @@ libexchange_storage_1_2_la_SOURCES =				
 	e-storage.h						\
 	exchange-account.c					\
 	exchange-account.h					\
+	exchange-esource.c					\
+	exchange-esource.h					\
 	exchange-folder-size.c					\
 	exchange-folder-size.h					\
 	exchange-hierarchy-favorites.c				\
Index: storage/e-folder-exchange.c
===================================================================
RCS file: /cvs/gnome/evolution-data-server/servers/exchange/storage/e-folder-exchange.c,v
retrieving revision 1.4
diff -u -p -u -p -r1.4 e-folder-exchange.c
--- storage/e-folder-exchange.c	7 Jul 2005 11:23:49 -0000	1.4
+++ storage/e-folder-exchange.c	21 Jul 2005 07:18:26 -0000
@@ -23,6 +23,7 @@
 
 #include "e-folder-exchange.h"
 #include "exchange-account.h"
+#include "exchange-esource.h"
 #include "exchange-hierarchy.h"
 #include "e2k-uri.h"
 #include "e2k-path.h"
@@ -183,8 +184,6 @@ e_folder_exchange_new (ExchangeHierarchy
 	efe->priv->path = e2k_uri_path (e_folder_get_physical_uri (ef));
 	efe->priv->outlook_class = g_strdup (outlook_class);
 
-#if 0
-SURF :
 	/* Add ESources */
 	if (hier->type == EXCHANGE_HIERARCHY_PERSONAL || 
 	    hier->type == EXCHANGE_HIERARCHY_FAVORITES) {
@@ -211,7 +210,6 @@ SURF :
 				     	    physical_uri);
 		}
 	}
-#endif	
 	return ef;
 }
 
@@ -932,8 +930,6 @@ e_folder_exchange_delete (EFolder *folde
 	const char *folder_type, *physical_uri;
 
 	g_return_val_if_fail (E_IS_FOLDER_EXCHANGE (folder), E2K_HTTP_MALFORMED);
-#if 0
-SURF :
 	/* remove ESources */
 	hier = e_folder_exchange_get_hierarchy (folder); 
 
@@ -961,7 +957,7 @@ SURF :
 					       physical_uri);
 		}
 	}
-#endif
+
 	return e2k_context_delete (E_FOLDER_EXCHANGE_CONTEXT (folder), op,
 				   E_FOLDER_EXCHANGE_URI (folder));
 }
Index: storage/exchange-account.c
===================================================================
RCS file: /cvs/gnome/evolution-data-server/servers/exchange/storage/exchange-account.c,v
retrieving revision 1.8
diff -u -p -u -p -r1.8 exchange-account.c
--- storage/exchange-account.c	16 Jul 2005 07:13:34 -0000	1.8
+++ storage/exchange-account.c	21 Jul 2005 07:18:27 -0000
@@ -71,7 +71,7 @@ struct _ExchangeAccountPrivate {
 	GPtrArray *hierarchies;
 	GHashTable *hierarchies_by_folder, *foreign_hierarchies;
 	ExchangeHierarchy *favorites_hierarchy;
-	GHashTable *folders;
+	GHashTable *folders, *fresh_folders;
 	char *uri_authority, *http_uri_schema;
 	gboolean uris_use_email, offline_sync;
 
@@ -154,6 +154,7 @@ init (GObject *object)
 	account->priv->hierarchies_by_folder = g_hash_table_new (NULL, NULL);
 	account->priv->foreign_hierarchies = g_hash_table_new (g_str_hash, g_str_equal);
 	account->priv->folders = g_hash_table_new (g_str_hash, g_str_equal);
+	account->priv->fresh_folders = NULL;
 	account->priv->discover_data_lock = g_mutex_new ();
 	account->priv->account_online = TRUE;
 	account->priv->nt_domain = NULL;
@@ -222,6 +223,12 @@ dispose (GObject *object)
 		account->priv->folders = NULL;
 	}
 
+	if (account->priv->fresh_folders) {
+		g_hash_table_foreach (account->priv->fresh_folders, free_folder, NULL);
+		g_hash_table_destroy (account->priv->fresh_folders);
+		account->priv->fresh_folders = NULL;
+	}
+
 	G_OBJECT_CLASS (parent_class)->dispose (object);
 }
 
@@ -313,8 +320,19 @@ exchange_account_rescan_tree (ExchangeAc
 
 	g_return_if_fail (EXCHANGE_IS_ACCOUNT (account));
 
-	for (i = 0; i < account->priv->hierarchies->len; i++)
+	if (account->priv->fresh_folders) {
+		g_hash_table_foreach (account->priv->fresh_folders, free_folder, NULL);
+		g_hash_table_destroy (account->priv->fresh_folders);
+		account->priv->fresh_folders = NULL;
+	}
+	account->priv->fresh_folders = g_hash_table_new (g_str_hash, g_str_equal);
+
+	for (i = 0; i < account->priv->hierarchies->len; i++) {
+		exchange_hierarchy_scan_subtree (account->priv->hierarchies->pdata[i],
+						EXCHANGE_HIERARCHY (account->priv->hierarchies->pdata[i])->toplevel,
+						FALSE);
 		exchange_hierarchy_rescan (account->priv->hierarchies->pdata[i]);
+	}
 }
 
 /*
@@ -342,6 +360,14 @@ hierarchy_new_folder (ExchangeHierarchy 
 				     folder);
 		table_updated = 1;
 	}
+
+	if (account->priv->fresh_folders) {
+		g_object_ref (folder);
+		g_hash_table_insert (account->priv->fresh_folders,
+				     (char *)e_folder_exchange_get_path (folder),
+				     folder);
+	}	
+	
 	if (!g_hash_table_lookup (account->priv->folders, 
 				e_folder_get_physical_uri (folder))) {
 		/* Avoid dupilcations since the user could add a folder as
@@ -1822,7 +1848,10 @@ exchange_account_get_folders (ExchangeAc
 	g_return_val_if_fail (EXCHANGE_IS_ACCOUNT (account), NULL);
 
 	folders = g_ptr_array_new ();
-	g_hash_table_foreach (account->priv->folders, add_folder, folders);
+	if (account->priv->fresh_folders)
+		g_hash_table_foreach (account->priv->fresh_folders, add_folder, folders);
+	else
+		g_hash_table_foreach (account->priv->folders, add_folder, folders);
 
 	qsort (folders->pdata, folders->len,
 	       sizeof (EFolder *), folder_comparator);
Index: storage/exchange-hierarchy-favorites.c
===================================================================
RCS file: /cvs/gnome/evolution-data-server/servers/exchange/storage/exchange-hierarchy-favorites.c,v
retrieving revision 1.3
diff -u -p -u -p -r1.3 exchange-hierarchy-favorites.c
--- storage/exchange-hierarchy-favorites.c	28 Jun 2005 08:27:14 -0000	1.3
+++ storage/exchange-hierarchy-favorites.c	21 Jul 2005 07:18:27 -0000
@@ -27,12 +27,11 @@
 
 #include "exchange-hierarchy-favorites.h"
 #include "exchange-account.h"
-//#include "exchange-constants.h"
 #include "e-folder-exchange.h"
 #include "e2k-propnames.h"
 #include "e2k-uri.h"
 #include "e2k-utils.h"
-//#include "exchange-config-listener.h"
+#include "exchange-esource.h"
 
 #include <libedataserver/e-source-list.h>
 
@@ -217,8 +216,6 @@ remove_folder (ExchangeHierarchy *hier, 
 		exchange_hierarchy_removed_folder (hier, folder);
 	}
 
-#if 0
-SURF : Find a proper palce to fix this
 	/* Temp Fix for remove fav folders. see #59168 */
 	/* remove ESources */
 	folder_type = e_folder_get_type_string (folder);
@@ -240,7 +237,6 @@ SURF : Find a proper palce to fix this
 				       physical_uri);
 	}
 	
-#endif
 	return exchange_hierarchy_webdav_status_to_folder_result (status);
 }
 
Index: storage/exchange-hierarchy-foreign.c
===================================================================
RCS file: /cvs/gnome/evolution-data-server/servers/exchange/storage/exchange-hierarchy-foreign.c,v
retrieving revision 1.3
diff -u -p -u -p -r1.3 exchange-hierarchy-foreign.c
--- storage/exchange-hierarchy-foreign.c	14 Jul 2005 03:46:17 -0000	1.3
+++ storage/exchange-hierarchy-foreign.c	21 Jul 2005 07:18:27 -0000
@@ -31,7 +31,7 @@
 #include "e2k-propnames.h"
 #include "e2k-uri.h"
 #include "e2k-utils.h"
-//#include "exchange-config-listener.h"
+#include "exchange-esource.h"
 #include "exchange-types.h"
 #include "e2k-types.h"
 
@@ -341,8 +341,6 @@ create_folder (ExchangeHierarchy *hier, 
 static ExchangeAccountFolderResult
 remove_folder (ExchangeHierarchy *hier, EFolder *folder)
 {
-/* This should be moved to plugins */
-#if 0
 	const char *folder_type, *physical_uri;
 
 	/* Temp Fix for remove fav folders. see #59168 */
@@ -365,7 +363,6 @@ remove_folder (ExchangeHierarchy *hier, 
 				       EXCHANGE_CONTACTS_FOLDER,
 				       physical_uri);
 	}
-#endif
 	if (folder != hier->toplevel)
 		exchange_hierarchy_removed_folder (hier, folder);
 
@@ -429,9 +426,8 @@ exchange_hierarchy_foreign_add_folder (E
 	char *new_folder_name;
 
 	result =  create_internal (hier, hier->toplevel, folder_name, NULL, folder);
-#if 0
 	if (result == EXCHANGE_ACCOUNT_FOLDER_OK) {
-		// Add the esources
+		/* Add the esources */
 		folder_type = e_folder_get_type_string (*folder);
 		physical_uri = e_folder_get_physical_uri (*folder);
 		new_folder_name = g_strdup_printf("%s's %s", 
@@ -461,7 +457,6 @@ exchange_hierarchy_foreign_add_folder (E
 		}
 		g_free (new_folder_name);
 	}
-#endif
 	return result;
 }
 
Index: storage/exchange-hierarchy-gal.c
===================================================================
RCS file: /cvs/gnome/evolution-data-server/servers/exchange/storage/exchange-hierarchy-gal.c,v
retrieving revision 1.2
diff -u -p -u -p -r1.2 exchange-hierarchy-gal.c
--- storage/exchange-hierarchy-gal.c	10 Jun 2005 10:51:09 -0000	1.2
+++ storage/exchange-hierarchy-gal.c	21 Jul 2005 07:18:27 -0000
@@ -29,7 +29,7 @@
 #include "exchange-hierarchy-gal.h"
 #include "exchange-account.h"
 #include "e-folder-exchange.h"
-//#include "exchange-config-listener.h"
+#include "exchange-esource.h"
 
 #include <libedataserver/e-source-list.h>
 
@@ -59,12 +59,9 @@ exchange_hierarchy_gal_new (ExchangeAcco
 	exchange_hierarchy_construct (hier, account,
 				      EXCHANGE_HIERARCHY_GAL, toplevel,
 				      NULL, NULL, NULL);
-#if 0
-SURF :
 	/* Add ESource */
 	add_folder_esource (hier->account, EXCHANGE_CONTACTS_FOLDER, 
 		     	    hierarchy_name, physical_uri_prefix);
-#endif
 	
 	g_object_unref (toplevel);
 
Index: storage/exchange-hierarchy-webdav.c
===================================================================
RCS file: /cvs/gnome/evolution-data-server/servers/exchange/storage/exchange-hierarchy-webdav.c,v
retrieving revision 1.3
diff -u -p -u -p -r1.3 exchange-hierarchy-webdav.c
--- storage/exchange-hierarchy-webdav.c	7 Jul 2005 11:23:49 -0000	1.3
+++ storage/exchange-hierarchy-webdav.c	21 Jul 2005 07:18:27 -0000
@@ -28,15 +28,14 @@
 
 #include "exchange-hierarchy-webdav.h"
 #include "exchange-account.h"
-//#include "exchange-constants.h"
 #include "e-folder-exchange.h"
 #include "e2k-context.h"
 #include "e2k-propnames.h"
 #include "e2k-restriction.h"
 #include "e2k-uri.h"
 #include "e2k-utils.h"
-//#include "exchange-config-listener.h"
 #include "exchange-folder-size.h"
+#include "exchange-esource.h"
 
 #include <libedataserverui/e-passwords.h>
 #include "e2k-path.h"
@@ -385,7 +384,6 @@ xfer_folder (ExchangeHierarchy *hier, EF
 	const char *folder_type = NULL, *source_folder_name;
 	ExchangeAccountFolderResult ret_code;
 	int offline;
-	gdouble f_size;
 
 	exchange_account_is_offline (hier->account, &offline);
         if (offline != ONLINE_MODE)
@@ -444,8 +442,6 @@ xfer_folder (ExchangeHierarchy *hier, EF
 	}
 
 	/* Remove the ESource of the source folder, in case of rename/move */
-#if 0
-SURF :
 	if ((hier->type == EXCHANGE_HIERARCHY_PERSONAL || 
 	     hier->type == EXCHANGE_HIERARCHY_FAVORITES) && remove_source && 
 	     ret_code == EXCHANGE_ACCOUNT_FOLDER_OK) {
@@ -469,7 +465,6 @@ SURF :
 					       physical_uri);
 		}
 	}
-#endif
 	if (physical_uri)
 		g_free (physical_uri);
 	return ret_code;
@@ -642,7 +637,7 @@ exchange_hierarchy_webdav_parse_folder (
 	 */
 	permanenturl = e2k_properties_get_prop (result->props,
 						E2K_PR_EXCHANGE_PERMANENTURL);
-	// Check for errors
+	/* Check for errors */
 
 	folder = e_folder_webdav_new (EXCHANGE_HIERARCHY (hwd),
 				      result->href, parent,
Index: ChangeLog
===================================================================
RCS file: /cvs/gnome/evolution/plugins/exchange-operations/ChangeLog,v
retrieving revision 1.25
diff -u -p -u -p -r1.25 ChangeLog
--- ChangeLog	19 Jul 2005 09:36:43 -0000	1.25
+++ ChangeLog	21 Jul 2005 07:09:56 -0000
@@ -1,3 +1,13 @@
+2005-07-21  Sarfraaz Ahmed <asarfraaz novell com>
+
+	* exchange-calendar.c (e_exchange_calendar_get_calendars): Rescan the
+	tree before fetching the folder list.
+	* exchange-contacts.c (e_exchange_contacts_get_contacts): Similar
+	* exchange-config-listener.c (account_added): Dont add the sources here
+	now. Its now taken care while the folders are being created in e-d-s.
+	* exchange-folder.c (org_gnome_exchange_folder_subscription): Dont add
+	the esources here.
+
 2005-07-19  Shakti Sen <shprasad novell com>
 
 	* exchange-permissions-dialog.c (display_role, get_widgets):
Index: exchange-calendar.c
===================================================================
RCS file: /cvs/gnome/evolution/plugins/exchange-operations/exchange-calendar.c,v
retrieving revision 1.2
diff -u -p -u -p -r1.2 exchange-calendar.c
--- exchange-calendar.c	14 Jul 2005 11:18:35 -0000	1.2
+++ exchange-calendar.c	21 Jul 2005 07:09:56 -0000
@@ -84,6 +84,7 @@ e_exchange_calendar_get_calendars (ECalS
 
 	calendar_list = g_ptr_array_new ();
 
+	exchange_account_rescan_tree (account);
 	folder_array = exchange_account_get_folders (account);
 
 	for (i=0; i<folder_array->len; ++i) {
Index: exchange-config-listener.c
===================================================================
RCS file: /cvs/gnome/evolution/plugins/exchange-operations/exchange-config-listener.c,v
retrieving revision 1.6
diff -u -p -u -p -r1.6 exchange-config-listener.c
--- exchange-config-listener.c	11 Jul 2005 12:26:24 -0000	1.6
+++ exchange-config-listener.c	21 Jul 2005 07:09:57 -0000
@@ -874,7 +874,6 @@ account_added (EAccountList *account_lis
  	exchange_account_connect (exchange_account, NULL, &result);
 	if (result != EXCHANGE_ACCOUNT_CONNECT_SUCCESS)
 		exchange_operations_report_error (exchange_account, result);
-	add_new_sources (exchange_account);
 }
 
 struct account_update_data {
Index: exchange-contacts.c
===================================================================
RCS file: /cvs/gnome/evolution/plugins/exchange-operations/exchange-contacts.c,v
retrieving revision 1.1
diff -u -p -u -p -r1.1 exchange-contacts.c
--- exchange-contacts.c	1 Jul 2005 10:06:24 -0000	1.1
+++ exchange-contacts.c	21 Jul 2005 07:09:57 -0000
@@ -71,6 +71,7 @@ e_exchange_contacts_get_contacts (void) 
 	prefix_len = strlen (uri_prefix);
 
 	contacts_list = g_ptr_array_new ();
+	exchange_account_rescan_tree (account);
 	folder_array = exchange_account_get_folders (account);
 
 	for (i=0; i<folder_array->len; ++i) {
Index: exchange-folder.c
===================================================================
RCS file: /cvs/gnome/evolution/plugins/exchange-operations/exchange-folder.c,v
retrieving revision 1.3
diff -u -p -u -p -r1.3 exchange-folder.c
--- exchange-folder.c	14 Jul 2005 07:00:51 -0000	1.3
+++ exchange-folder.c	21 Jul 2005 07:09:57 -0000
@@ -388,7 +388,7 @@ org_gnome_exchange_folder_subscription (
 	if (!folder) {
 		return;
 	}
-
+#if 0
 	hier = e_folder_exchange_get_hierarchy (folder);
 	folder_display_name = g_strdup_printf ("%s's %s", hier->owner_name, folder_name);
 	folder_type = (gchar *) e_folder_get_type_string (folder);
@@ -405,9 +405,10 @@ org_gnome_exchange_folder_subscription (
 		 !(strcmp (folder_type, "contacts/public")) ||
 		 !(strcmp (folder_type, "contacts/ldap"))) {
 			add_folder_esource (account, EXCHANGE_CONTACTS_FOLDER, folder_display_name, physical_uri);
-}
+	}
 
-g_free (folder_display_name);
-exchange_account_open_folder (account, g_strdup_printf ("/%s", user_email_address));
+	g_free (folder_display_name);
+#endif
+	exchange_account_open_folder (account, g_strdup_printf ("/%s", user_email_address));
 }
 
Index: ChangeLog
===================================================================
RCS file: /cvs/gnome/evolution-exchange/ChangeLog,v
retrieving revision 1.356
diff -u -p -u -p -r1.356 ChangeLog
--- ChangeLog	20 Jul 2005 06:21:22 -0000	1.356
+++ ChangeLog	21 Jul 2005 07:13:01 -0000
@@ -1,3 +1,12 @@
+2005-07-21  Sarfraaz Ahmed <asarfraaz novell com>
+
+	* addressbook/e-book-backend-exchange.c 
+	(e_book_backend_exchange_remove): Implemented
+	* calendar/e-cal-backend-exchange.c (remove_calendar): Implemented
+	* storage/exchange-component.c (exchange_component_get_account_for_uri):
+	Do rescan once, if you cant get a folder at the first attempt. This is
+	for syncing any new folder creation that happened in the plugin.
+
 2005-07-19  Sarfraaz Ahmed <asarfraaz novell com>
 
 	* calendar/e-cal-backend-exchange.c (get_static_capabilities): Removed 
Index: addressbook/e-book-backend-exchange.c
===================================================================
RCS file: /cvs/gnome/evolution-exchange/addressbook/e-book-backend-exchange.c,v
retrieving revision 1.30
diff -u -p -u -p -r1.30 e-book-backend-exchange.c
--- addressbook/e-book-backend-exchange.c	23 Jun 2005 09:23:38 -0000	1.30
+++ addressbook/e-book-backend-exchange.c	21 Jul 2005 07:13:01 -0000
@@ -2239,9 +2239,15 @@ e_book_backend_exchange_load_source (EBo
 static EBookBackendSyncStatus
 e_book_backend_exchange_remove (EBookBackendSync *backend, EDataBook *book, guint32 opid)
 {
-	d(printf("ebbe_remove(%p, %p)\n", backend, book));
-	return GNOME_Evolution_Addressbook_PermissionDenied;
+	EBookBackendExchange *be = E_BOOK_BACKEND_EXCHANGE (backend);
+	EBookBackendExchangePrivate *bepriv = be->priv;
+	ExchangeAccountFolderResult result;
+	const char *uri;
 
+	d(printf("ebbe_remove(%p, %p)\n", backend, book));
+	uri = e_folder_exchange_get_internal_uri (bepriv->folder);
+	result = exchange_account_remove_folder (bepriv->account, uri);
+	return GNOME_Evolution_Addressbook_Success;
 	/* FIXME: Folder deletion from contacts view */
 #if 0 
 	EBookBackendExchange *be = E_BOOK_BACKEND_EXCHANGE (backend);
Index: calendar/e-cal-backend-exchange.c
===================================================================
RCS file: /cvs/gnome/evolution-exchange/calendar/e-cal-backend-exchange.c,v
retrieving revision 1.35
diff -u -p -u -p -r1.35 e-cal-backend-exchange.c
--- calendar/e-cal-backend-exchange.c	20 Jul 2005 06:21:23 -0000	1.35
+++ calendar/e-cal-backend-exchange.c	21 Jul 2005 07:13:01 -0000
@@ -322,7 +322,7 @@ open_calendar (ECalBackendSync *backend,
 	if (!cbex->account)
 		return GNOME_Evolution_Calendar_PermissionDenied;
 	if (!exchange_account_get_context (cbex->account))
-		return GNOME_Evolution_Calendar_RepositoryOffline;
+		return GNOME_Evolution_Calendar_RepositoryOffline; 
 
 	cbex->folder = exchange_account_get_folder (cbex->account, uristr);
 	if (!cbex->folder) {
@@ -364,20 +364,26 @@ static ECalBackendSyncStatus
 remove_calendar (ECalBackendSync *backend, EDataCal *cal)
 {
 	d(printf("ecbe_remove_calendar(%p, %p)\n", backend, cal));
-
-	//display_error_dialog("Can not perform this operation, Use Exchange component for folder operations\n");
-	return GNOME_Evolution_Calendar_PermissionDenied; /* Error code is not handled in Evolution */
+	ECalBackendExchange *cbex = E_CAL_BACKEND_EXCHANGE (backend);
+	ExchangeAccountFolderResult result;
+	const char *uri;
 
 	/* FIXME: Deleting calendar/tasks from respective views */
-#if 0
-	status = e_folder_exchange_delete (be->folder, NULL);
-	if (E2K_HTTP_STATUS_IS_SUCCESSFUL (status))
+	uri = e_folder_exchange_get_internal_uri (cbex->folder);
+	result = exchange_account_remove_folder (cbex->account, uri);
+	return GNOME_Evolution_Calendar_Success;
+
+	/* status = e_folder_exchange_delete (cbex->folder, NULL);
+	if (E2K_HTTP_STATUS_IS_SUCCESSFUL (status)) {
+		d(printf ("successfully removed\n"));
 		return GNOME_Evolution_Calendar_Success;
-	else if (status == E2K_HTTP_UNAUTHORIZED)
+	} else if (status == E2K_HTTP_UNAUTHORIZED) {
+		d(printf ("permission denied\n"));
 		return GNOME_Evolution_Calendar_PermissionDenied;
-	else
+	} else {
+		d(printf ("other error\n"));
 		return GNOME_Evolution_Calendar_OtherError;
-#endif
+	} */
 }
 
 static void
Index: storage/exchange-component.c
===================================================================
RCS file: /cvs/gnome/evolution-exchange/storage/exchange-component.c,v
retrieving revision 1.10
diff -u -p -u -p -r1.10 exchange-component.c
--- storage/exchange-component.c	12 Jul 2005 06:32:21 -0000	1.10
+++ storage/exchange-component.c	21 Jul 2005 07:13:01 -0000
@@ -361,8 +361,13 @@ exchange_component_get_account_for_uri (
 		if (!uri)
 			return baccount->account;
 
-		if (exchange_account_get_folder (baccount->account, uri))
+		if (exchange_account_get_folder (baccount->account, uri)) {
 			return baccount->account;
+		} else {
+			exchange_account_rescan_tree (baccount->account);
+			if (exchange_account_get_folder (baccount->account, uri))
+				return baccount->account;
+		}
 		/* FIXME : Handle multiple accounts */
 	}
 	return NULL;
/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */

/* Copyright (C) 2001-2004 Novell, Inc.
 *
 * This program is free software; you can redistribute it and/or
 * modify it under the terms of version 2 of the GNU General Public
 * License as published by the Free Software Foundation.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * General Public License for more details.
 *
 * You should have received a copy of the GNU General Public
 * License along with this program; if not, write to the
 * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
 * Boston, MA 02111-1307, USA.
 */

/* ExchangeConfigListener: a class that listens to the config database
 * and handles creating the ExchangeAccount object and making sure that
 * default folders are updated as needed.
 */

#ifdef HAVE_CONFIG_H
#include <config.h>
#endif

#include "exchange-esource.h"

#include <libedataserver/e-source.h>
#include <libedataserver/e-source-list.h>
#include <libedataserver/e-source-group.h>

#include <stdlib.h>
#include <string.h>

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 = NULL;

	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_URI_PREFIX));
		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_URI_PREFIX));
		is_contacts_folder = FALSE;
	}

	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_URI_PREFIX);
		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);
        		g_free (relative_uri);
			return;
		}
		if (is_contacts_folder)
			source = e_source_new_with_absolute_uri (folder_name,
								 physical_uri);
		else
			source = e_source_new (folder_name, 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_group_add_source (source_group, source, -1);
		e_source_list_sync (source_list, NULL);
		group_new = source_new = TRUE;
	}
	else {
                /* source group already exists*/
		if((source = e_source_group_peek_source_by_name (source_group, 
							folder_name)) == NULL) {
			printf("old group, new source\n");
			if (is_contacts_folder)
				source = e_source_new_with_absolute_uri (
						folder_name, physical_uri);
			else
        			source = e_source_new (folder_name, relative_uri);

			if (mode == OFFLINE_MODE)
				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 */
				if (mode == OFFLINE_MODE) 
					e_source_set_property (source, "offline_sync", "1");
			}
		}
	}

	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, 
					     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);
		}
		else if (folder_type == EXCHANGE_TASKS_FOLDER) {

			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_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);
}

void 
remove_folder_esource (ExchangeAccount *account, 
		       FolderType folder_type, 
		       const char *physical_uri)
{
	ESourceGroup *group;
	ESource *source;
	GSList *groups;
	GSList *sources;
	gboolean found_group, is_contacts_folder = TRUE;
	char *relative_uri = NULL;
	const char *source_uid;
	GSList *ids, *temp_ids, *node_to_be_deleted;
	GConfClient *client;
	ESourceList *source_list = NULL;

	client = gconf_client_get_default ();

	/* 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_URI_PREFIX));
		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_URI_PREFIX));
		is_contacts_folder = FALSE;
	}

	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_URI_PREFIX) == 0) {

			sources = e_source_group_peek_sources (group);

			for( ; sources != NULL; sources = g_slist_next (sources)) {
				
				source = E_SOURCE (sources->data);

				if (((!is_contacts_folder &&
				      strcmp (e_source_peek_relative_uri (source),
					      relative_uri) == 0)) ||
				      (is_contacts_folder && 
				       strcmp (e_source_peek_absolute_uri (source),
					      physical_uri) == 0)) {

					source_uid = e_source_peek_uid (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) {
						/* 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);
								}
							}
							temp_ids  = ids;
							for (; temp_ids != NULL; temp_ids = g_slist_next (temp_ids))
							g_free (temp_ids->data);
							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);
								}
							}
							temp_ids  = ids;
							for (; temp_ids != NULL; temp_ids = g_slist_next (temp_ids))
								g_free (temp_ids->data);
							g_slist_free (ids);
						}
					}
                                        found_group = TRUE;
                                        break;
                                }
                        }
                }
        }
	g_object_unref (source_list);
        g_free (relative_uri);
	g_object_unref (client);
}
/* -*- Mode: C; indent-tabs-mode: t; c-basic-offset: 8; tab-width: 8 -*- */
/* Copyright (C) 2001-2004 Novell, Inc. */

#ifndef __EXCHANGE_ESOURCE_H__
#define __EXCHANGE_ESOURCE_H__

#include "exchange-constants.h"
#include "exchange-account.h"

#ifdef __cplusplus
extern "C" {
#pragma }
#endif /* __cplusplus */

#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_CAL "/apps/evolution/calendar/sources"
#define CONF_KEY_TASKS "/apps/evolution/tasks/sources"
#define CONF_KEY_CONTACTS "/apps/evolution/addressbook/sources"
#define EXCHANGE_URI_PREFIX "exchange://"

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
}
#endif /* __cplusplus */

#endif /* __EXCHANGE_ESOURCE_H__ */


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