[evolution-patches] Exchange connector: Fix for 73494 and 72100



Please consider this patch.
Removed some printfs .

Thanks,
Sushma.
Index: storage/exchange-folder-size.c
===================================================================
RCS file: /cvs/gnome/evolution-exchange/storage/exchange-folder-size.c,v
retrieving revision 1.8
diff -u -p -r1.8 exchange-folder-size.c
--- storage/exchange-folder-size.c	26 Feb 2005 08:44:02 -0000	1.8
+++ storage/exchange-folder-size.c	16 Mar 2005 08:28:52 -0000
@@ -60,12 +60,14 @@ enum {
         NUM_COLUMNS
 };
 
-static void
+static gboolean
 free_fsize_table (gpointer key, gpointer value, gpointer data)
 {
 	folder_info *f_info = (folder_info *) value;
-	g_free (f_info->folder_name);
+	if (f_info->folder_name)
+		g_free (f_info->folder_name);
 	g_free (f_info);
+	return TRUE;
 }
 
 static void
@@ -73,10 +75,12 @@ finalize (GObject *object)
 {
 	ExchangeFolderSize *fsize = EXCHANGE_FOLDER_SIZE (object);
 
+	g_hash_table_foreach_remove (fsize->priv->table, free_fsize_table, NULL);
 	g_hash_table_destroy (fsize->priv->table);
 	g_hash_table_destroy (fsize->priv->row_refs);
 	if (fsize->priv->model)
 		g_object_unref (fsize->priv->model);
+	g_free (fsize->priv);
 
 	G_OBJECT_CLASS (parent_class)->finalize (object);
 }
@@ -104,8 +108,7 @@ init (GObject *object)
 	ExchangeFolderSize *fsize = EXCHANGE_FOLDER_SIZE (object);
 
 	fsize->priv = g_new0 (ExchangeFolderSizePrivate, 1);
-	fsize->priv->table = g_hash_table_new_full (g_str_hash, g_str_equal,
-					NULL, (GDestroyNotify)free_fsize_table);
+	fsize->priv->table = g_hash_table_new (g_str_hash, g_str_equal);
         fsize->priv->model = gtk_list_store_new (NUM_COLUMNS, G_TYPE_STRING, G_TYPE_DOUBLE);
 	fsize->priv->row_refs = g_hash_table_new (g_str_hash, g_str_equal);
 }
@@ -180,6 +183,55 @@ exchange_folder_size_update (ExchangeFol
 
 		g_hash_table_insert (fsize->priv->row_refs, f_info->folder_name, row);
 	}
+}
+
+void
+exchange_folder_size_remove (ExchangeFolderSize *fsize, 
+				const char *folder_name)
+{
+	ExchangeFolderSizePrivate *priv;
+	GHashTable *folder_size_table;
+	folder_info *cached_info;
+	GtkTreeRowReference *row;
+	GtkTreeIter iter;
+	GtkTreePath *path;
+
+	g_return_if_fail (EXCHANGE_IS_FOLDER_SIZE (fsize));
+	g_return_if_fail (folder_name != NULL);
+
+	priv = fsize->priv;
+	folder_size_table = priv->table;
+
+	cached_info = g_hash_table_lookup (folder_size_table, folder_name);
+	if (cached_info)  {
+		row = g_hash_table_lookup (priv->row_refs, folder_name);
+		path = gtk_tree_row_reference_get_path (row);
+		g_hash_table_remove (folder_size_table, cached_info->folder_name);
+		if (gtk_tree_model_get_iter (GTK_TREE_MODEL (fsize->priv->model), &iter, path)) {
+			gtk_list_store_remove (fsize->priv->model, &iter);
+		}
+		gtk_tree_path_free (path);
+	}
+}
+
+gdouble
+exchange_folder_size_get (ExchangeFolderSize *fsize,
+			  const char *folder_name)
+{
+	ExchangeFolderSizePrivate *priv;
+	GHashTable *folder_size_table;
+	folder_info *cached_info;
+
+	g_return_val_if_fail (EXCHANGE_IS_FOLDER_SIZE (fsize), -1);
+	
+	priv = fsize->priv;
+	folder_size_table = priv->table;
+
+	cached_info = g_hash_table_lookup (folder_size_table, folder_name);
+	if (cached_info)  {
+		return cached_info->folder_size;
+	}
+	return -1;
 }
 
 static void
Index: storage/exchange-folder-size.h
===================================================================
RCS file: /cvs/gnome/evolution-exchange/storage/exchange-folder-size.h,v
retrieving revision 1.3
diff -u -p -r1.3 exchange-folder-size.h
--- storage/exchange-folder-size.h	26 Feb 2005 08:44:02 -0000	1.3
+++ storage/exchange-folder-size.h	16 Mar 2005 08:28:59 -0000
@@ -42,6 +42,9 @@ ExchangeFolderSize *exchange_folder_size
 void exchange_folder_size_update (ExchangeFolderSize *fsize,
 						const char *folder_name,
 						gdouble folder_size);
+void exchange_folder_size_remove (ExchangeFolderSize *fsize, const char *folder_name);
+
+gdouble exchange_folder_size_get (ExchangeFolderSize *fsize, const char *folder_name);
 
 void exchange_folder_size_display (EFolder *folder, GtkWidget *parent);
 
Index: storage/exchange-hierarchy-webdav.c
===================================================================
RCS file: /cvs/gnome/evolution-exchange/storage/exchange-hierarchy-webdav.c,v
retrieving revision 1.27
diff -u -p -r1.27 exchange-hierarchy-webdav.c
--- storage/exchange-hierarchy-webdav.c	9 Mar 2005 07:50:40 -0000	1.27
+++ storage/exchange-hierarchy-webdav.c	16 Mar 2005 08:29:12 -0000
@@ -185,6 +185,7 @@ hierarchy_new_folder (ExchangeHierarchy 
 {
 	const char *internal_uri ;
 	char *mf_path;
+	char *internal_uri_temp;
 	
 	g_return_if_fail (E_IS_FOLDER (folder));
 	internal_uri = e_folder_exchange_get_internal_uri (folder);
@@ -196,8 +197,18 @@ hierarchy_new_folder (ExchangeHierarchy 
 				(char *)e2k_uri_path (internal_uri)))
 		return;
 
+	/* FIXME: 
+	 * In case of create_folder internal uri is not ending with the slash than 
+	 * rescan tries to read from hash with the uri ending with slash
+	 */
+	if (*(internal_uri + (strlen(internal_uri) -1)) != '/') {
+		internal_uri_temp = g_strdup_printf("%s/", internal_uri);
+	}
+	else 
+		internal_uri_temp = g_strdup (internal_uri);
 	g_hash_table_insert (EXCHANGE_HIERARCHY_WEBDAV (hier)->priv->folders_by_internal_path,
-			     (char *)e2k_uri_path (internal_uri), folder);
+			     (char *)e2k_uri_path (internal_uri_temp), folder);
+	g_free (internal_uri_temp);
 
 	mf_path = e_folder_exchange_get_storage_file (folder, "connector-metadata.xml");
 	e_folder_exchange_save_to_file (folder, mf_path);
@@ -329,6 +340,11 @@ create_folder (ExchangeHierarchy *hier, 
 		g_free (permanent_url);
 		exchange_hierarchy_new_folder (hier, dest);
 		g_object_unref (dest);
+
+		/* update the folder size table, new folder, initialize the size to 0 */ 
+		exchange_folder_size_update (
+				EXCHANGE_HIERARCHY_WEBDAV (hier)->priv->foldersize,
+				name, 0);
 		return EXCHANGE_ACCOUNT_FOLDER_OK;
 	}
 
@@ -360,6 +376,10 @@ remove_folder (ExchangeHierarchy *hier, 
 	status = e_folder_exchange_delete (folder, NULL);
 	if (E2K_HTTP_STATUS_IS_SUCCESSFUL (status)) {
 		exchange_hierarchy_removed_folder (hier, folder);
+
+		/* update the folder size info */
+		exchange_folder_size_remove (EXCHANGE_HIERARCHY_WEBDAV (hier)->priv->foldersize,
+					e_folder_get_name(folder));
 		return EXCHANGE_ACCOUNT_FOLDER_OK;
 	} else
 		return EXCHANGE_ACCOUNT_FOLDER_GENERIC_ERROR;
@@ -372,12 +392,13 @@ xfer_folder (ExchangeHierarchy *hier, EF
 {
 	E2kHTTPStatus status;
 	EFolder *dest;
-	char *permanent_url = NULL, *physical_uri;
+	char *permanent_url = NULL, *physical_uri, *source_parent;
 	ESourceList *cal_source_list, *task_source_list, *cont_source_list;
-	const char *folder_type = NULL;
+	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)
                 return EXCHANGE_ACCOUNT_FOLDER_OFFLINE;
@@ -406,6 +427,26 @@ xfer_folder (ExchangeHierarchy *hier, EF
 		physical_uri = (char *) e_folder_get_physical_uri (source);
 		g_object_unref (dest);
 		ret_code = EXCHANGE_ACCOUNT_FOLDER_OK;
+
+		/* Find if folder movement or rename.  
+		 * update folder size in case of rename.
+		 */
+
+		source_folder_name = strrchr (physical_uri + 1, '/');
+		source_parent = g_strndup (physical_uri, 
+					   source_folder_name - physical_uri); 
+		if (!strcmp (e_folder_get_physical_uri (dest_parent), source_parent)) {
+			/* rename - remove folder entry from hash, and 
+			 * update the hash table with new name 
+			 */
+			f_size = exchange_folder_size_get (EXCHANGE_HIERARCHY_WEBDAV (hier)->priv->foldersize,
+							   source_folder_name+1);
+			exchange_folder_size_remove (EXCHANGE_HIERARCHY_WEBDAV (hier)->priv->foldersize,
+						     source_folder_name+1);
+			exchange_folder_size_update (EXCHANGE_HIERARCHY_WEBDAV (hier)->priv->foldersize,
+						     dest_name, f_size);
+		}
+		g_free (source_parent);
 	} else {
 		physical_uri = e2k_uri_concat (
 				e_folder_get_physical_uri (dest_parent), 
@@ -479,8 +520,9 @@ add_href (gpointer path, gpointer folder
 	g_ptr_array_add (hrefs, path);
 }
 
+/* E2K_PR_EXCHANGE_FOLDER_SIZE also can be used for reading folder size */
 static const char *rescan_props[] = {
-	E2K_PR_EXCHANGE_FOLDER_SIZE,
+	PR_MESSAGE_SIZE_EXTENDED,
 	E2K_PR_HTTPMAIL_UNREAD_COUNT
 };
 static const int n_rescan_props = sizeof (rescan_props) / sizeof (rescan_props[0]);
@@ -535,16 +577,15 @@ rescan (ExchangeHierarchy *hier)
 			e_folder_set_unread_count (folder, unread);
 
 		folder_size = e2k_properties_get_prop (result->props,
-						E2K_PR_EXCHANGE_FOLDER_SIZE);
-		if (folder_size && personal) {
-			if (e_folder_exchange_get_permanent_uri (folder)) {
-				folder_name = e_folder_get_name (folder);
-				fsize_d = g_ascii_strtod (folder_size, NULL)/1024;
-				exchange_folder_size_update (hwd->priv->foldersize, 
-							folder_name, fsize_d);
+						PR_MESSAGE_SIZE_EXTENDED);
+		if (folder_size) {
+			folder_name = e_folder_get_name (folder);
+			fsize_d = g_ascii_strtod (folder_size, NULL)/1024;
+			exchange_folder_size_update (hwd->priv->foldersize, 
+						folder_name, fsize_d);
+			if (personal)
 				hwd->priv->total_folder_size = 
 					hwd->priv->total_folder_size + fsize_d;
-			}
 		}
 	}
 	e2k_result_iter_free (iter);
@@ -587,10 +628,9 @@ exchange_hierarchy_webdav_parse_folder (
 {
 	EFolder *folder;
 	ExchangeFolderType *folder_type;
-	const char *name, *prop, *outlook_class, *permanenturl, *folder_size;
+	const char *name, *prop, *outlook_class, *permanenturl;
 	int unread;
 	gboolean hassubs;
-	gdouble fsize_d;
 
 	g_return_val_if_fail (EXCHANGE_IS_HIERARCHY_WEBDAV (hwd), NULL);
 	g_return_val_if_fail (E_IS_FOLDER (parent), NULL);
@@ -628,11 +668,17 @@ exchange_hierarchy_webdav_parse_folder (
 	if (!outlook_class)
 		outlook_class = folder_type->contentclass;
 
+	/*
+	 * The permanenturl Field provides a unique identifier for an item 
+	 * across the *store* and will not change as long as the item remains 
+	 * in the same folder. The permanenturl Field contains the ID of the 
+	 * parent folder of the item, which changes when the item is moved to a 
+	 * different folder or deleted. Changing a field on an item will not 
+	 * change the permanenturl Field and neither will adding more items to
+	 * the folder with the same display name or message subject.
+	 */
 	permanenturl = e2k_properties_get_prop (result->props,
 						E2K_PR_EXCHANGE_PERMANENTURL);
-
-	folder_size = e2k_properties_get_prop (result->props,
-						E2K_PR_EXCHANGE_FOLDER_SIZE);
 	// Check for errors
 
 	folder = e_folder_webdav_new (EXCHANGE_HIERARCHY (hwd),
@@ -645,13 +691,10 @@ exchange_hierarchy_webdav_parse_folder (
 	if (hassubs)
 		e_folder_exchange_set_has_subfolders (folder, TRUE);
 	if (permanenturl) {
+		/* Favorite folders and subscribed folders will not have 
+		 * permanenturl 
+		 */
 		e_folder_exchange_set_permanent_uri (folder, permanenturl);
-		/* FIXME : Find a better way of doing this */
-		fsize_d = g_ascii_strtod (folder_size, NULL)/1024 ;
-		exchange_folder_size_update (hwd->priv->foldersize, 
-						name, fsize_d);
-		hwd->priv->total_folder_size = 
-				hwd->priv->total_folder_size + fsize_d;
 	}
 
 	return folder;
@@ -669,7 +712,7 @@ static const char *folder_props[] = {
 	E2K_PR_HTTPMAIL_UNREAD_COUNT,
 	E2K_PR_DAV_DISPLAY_NAME,
 	E2K_PR_EXCHANGE_PERMANENTURL,
-	E2K_PR_EXCHANGE_FOLDER_SIZE,
+	PR_MESSAGE_SIZE_EXTENDED,
 	E2K_PR_DAV_HAS_SUBS
 };
 static const int n_folder_props = sizeof (folder_props) / sizeof (folder_props[0]);
@@ -686,7 +729,10 @@ scan_subtree (ExchangeHierarchy *hier, E
 	EFolder *folder, *tmp;
 	GPtrArray *folders;
 	int i;
-	
+	gdouble fsize_d;
+	const char *name, *folder_size;
+	gboolean personal = ( EXCHANGE_HIERARCHY (hwd)->type == EXCHANGE_HIERARCHY_PERSONAL );
+
 	if (offline) {
 		folders = g_ptr_array_new ();
 		exchange_hierarchy_webdav_offline_scan_subtree (EXCHANGE_HIERARCHY (hier), add_folders, folders);
@@ -721,6 +767,22 @@ scan_subtree (ExchangeHierarchy *hier, E
 			subtrees = g_slist_prepend (subtrees, folder);
 		}
 		exchange_hierarchy_new_folder (hier, folder);
+
+		/* Check the folder size here */
+		name = e2k_properties_get_prop (result->props,
+							E2K_PR_DAV_DISPLAY_NAME);
+		folder_size = e2k_properties_get_prop (result->props,
+							PR_MESSAGE_SIZE_EXTENDED);
+
+		/* FIXME : Find a better way of doing this */
+		fsize_d = g_ascii_strtod (folder_size, NULL)/1024 ;
+		exchange_folder_size_update (hwd->priv->foldersize, 
+						name, fsize_d);
+		if (personal) {
+			/* calculate mail box size only for personal folders */
+			hwd->priv->total_folder_size = 
+				hwd->priv->total_folder_size + fsize_d;
+		}
 	}
 	status = e2k_result_iter_free (iter);
 


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