[evolution-groupwise] Do not use find_book_view to update status, instead use e_book_backend_foreach_view



commit 92085b14e4feb5b8f19eeb717232fa650ed64f84
Author: Chenthill Palanisamy <pchenthill novell com>
Date:   Thu Feb 23 12:33:55 2012 +0530

    Do not use find_book_view to update status, instead use e_book_backend_foreach_view

 src/addressbook/e-book-backend-groupwise.c |  124 ++++++----------------------
 1 files changed, 27 insertions(+), 97 deletions(-)
---
diff --git a/src/addressbook/e-book-backend-groupwise.c b/src/addressbook/e-book-backend-groupwise.c
index 24cc84c..78faa20 100644
--- a/src/addressbook/e-book-backend-groupwise.c
+++ b/src/addressbook/e-book-backend-groupwise.c
@@ -2466,36 +2466,17 @@ e_book_backend_groupwise_stop_book_view (EBookBackend *backend,
 	e_flag_clear (closure->running);
 }
 
-static void
+static gboolean
 book_view_notify_status (EDataBookView *view,
-                         const gchar *status)
+                         gpointer user_data)
 {
+	const gchar *status = (const gchar *) user_data;
+
 	if (!view)
-		return;
+		return TRUE;
 	e_data_book_view_notify_progress (view, -1, status);
-}
-
-static gboolean
-pick_view_cb (EDataBookView *view,
-              gpointer user_data)
-{
-	EDataBookView **pick = user_data;
-
-	g_return_val_if_fail (user_data != NULL, FALSE);
-
-	/* just always use the first book view */
-	*pick = view;
-	return view == NULL;
-}
-
-static EDataBookView *
-find_book_view (EBookBackendGroupwise *ebgw)
-{
-	EDataBookView *pick = NULL;
-
-	e_book_backend_foreach_view (E_BOOK_BACKEND (ebgw), pick_view_cb, &pick);
 
-	return pick;
+	return TRUE;
 }
 
 static void
@@ -2657,8 +2638,6 @@ build_cache (EBookBackendGroupwise *ebgw)
 	gboolean done = FALSE;
 	EBookBackendGroupwisePrivate *priv = ebgw->priv;
 	const gchar *position = E_GW_CURSOR_POSITION_START;
-	EDataBookView *book_view;
-	GroupwiseBackendSearchClosure *closure;
 	gchar *status_msg;
 	GTimeVal start, end;
 	GTimeVal tstart, tend;
@@ -2680,14 +2659,6 @@ build_cache (EBookBackendGroupwise *ebgw)
 		return NULL;
 	}
 
-	book_view = find_book_view (ebgw);
-	if (book_view) {
-		closure = get_closure (book_view);
-		e_data_book_view_ref (book_view);
-		if (closure)
-			e_flag_set (closure->running);
-	}
-
 	while (!done) {
 
 		if (enable_debug)
@@ -2728,14 +2699,11 @@ build_cache (EBookBackendGroupwise *ebgw)
 			 * Also we should be using "percent" in notify_progress() instead of
 			 * forming the message like this.
 			 */
-			if (book_view) {
-				status_msg = g_strdup_printf (_("Downloading contacts (%d)... "),
-								 contact_num);
-				book_view_notify_status (book_view, status_msg);
-				e_data_book_view_notify_update (book_view, contact);
-
-				g_free (status_msg);
-			}
+			status_msg = g_strdup_printf (_("Downloading contacts (%d)... "),
+							 contact_num);
+			e_book_backend_foreach_view (E_BOOK_BACKEND (ebgw), book_view_notify_status, status_msg);
+			e_book_backend_notify_update (E_BOOK_BACKEND (ebgw), contact);
+			g_free (status_msg);
 
 			g_object_unref (contact);
 			g_object_unref (l->data);
@@ -2755,11 +2723,6 @@ build_cache (EBookBackendGroupwise *ebgw)
 
 	ebgw->priv->file_db->sync (ebgw->priv->file_db, 0);
 
-	if (book_view) {
-		e_data_book_view_notify_complete (book_view, NULL /* Success */);
-		e_data_book_view_unref (book_view);
-	}
-
 	e_gw_connection_destroy_cursor (priv->cnc, priv->container_id, cursor);
 
 	if (enable_debug) {
@@ -2823,8 +2786,6 @@ update_cache (EBookBackendGroupwise *ebgw)
 	const struct tm *tm;
 	struct stat buf;
 	gchar *cache_file_name;
-	EDataBookView *book_view;
-	GroupwiseBackendSearchClosure *closure;
 	GTimeVal start, end;
 	gulong diff;
 
@@ -2838,14 +2799,6 @@ update_cache (EBookBackendGroupwise *ebgw)
 		printf("updating cache for %s\n", ebgw->priv->book_name);
 	}
 
-	book_view = find_book_view (ebgw);
-	if (book_view) {
-		closure = get_closure (book_view);
-		e_data_book_view_ref (book_view);
-		if (closure)
-			e_flag_set (closure->running);
-	}
-
 	cache_file_name = e_book_backend_db_cache_get_filename (ebgw->priv->file_db);
 	g_stat (cache_file_name, &buf);
 	g_free (cache_file_name);
@@ -2859,8 +2812,6 @@ update_cache (EBookBackendGroupwise *ebgw)
 	status = e_gw_connection_get_items (ebgw->priv->cnc, ebgw->priv->container_id,
 					    "name email default members", filter, &gw_items);
 	if (status != E_GW_CONNECTION_STATUS_OK) {
-		if (book_view)
-			e_data_book_view_unref (book_view);
 		if (enable_debug)
 			printf("No connection with the server \n");
 		g_mutex_unlock (ebgw->priv->update_cache_mutex);
@@ -2878,12 +2829,11 @@ update_cache (EBookBackendGroupwise *ebgw)
 		id =  e_contact_get_const (contact, E_CONTACT_UID);
 
 		contact_num++;
-		if (book_view) {
-			status_msg = g_strdup_printf (_("Updating contacts cache (%d)... "),
-							 contact_num);
-			book_view_notify_status (book_view, status_msg);
-			g_free (status_msg);
-		}
+		
+		status_msg = g_strdup_printf (_("Updating contacts cache (%d)... "),
+				contact_num);
+		e_book_backend_foreach_view (E_BOOK_BACKEND (ebgw), book_view_notify_status, status_msg);
+		g_free (status_msg);
 
 		if (e_book_backend_db_cache_check_contact (ebgw->priv->file_db, id)) {
 			e_book_backend_db_cache_add_contact (ebgw->priv->file_db, contact);
@@ -2902,10 +2852,6 @@ update_cache (EBookBackendGroupwise *ebgw)
 
 	ebgw->priv->file_db->sync (ebgw->priv->file_db, 0);
 
-	if (book_view) {
-		e_data_book_view_notify_complete (book_view, NULL /* Success */);
-		e_data_book_view_unref (book_view);
-	}
 	g_object_unref (filter);
 	g_list_free (gw_items);
 
@@ -2930,8 +2876,6 @@ update_address_book_deltas (EBookBackendGroupwise *ebgw)
 	gboolean sync_required = FALSE;
 	GList *add_list = NULL, *delete_list = NULL;
 	EContact *contact;
-	EDataBookView *book_view;
-	GroupwiseBackendSearchClosure *closure;
 	EGwItem *item;
 	EBookBackendGroupwisePrivate *priv;
 
@@ -2996,14 +2940,6 @@ update_address_book_deltas (EBookBackendGroupwise *ebgw)
 	if (enable_debug)
 		g_get_current_time (&start);
 
-	book_view = find_book_view (ebgw);
-	if (book_view) {
-		closure = get_closure (book_view);
-		e_data_book_view_ref (book_view);
-		if (closure)
-			e_flag_set (closure->running);
-	}
-
 	/* update the cache */
 	sequence = g_strdup_printf ("%lf", cache_last_sequence +1);
 	count = g_strdup_printf ("%d", CURSOR_ITEM_LIMIT);
@@ -3059,12 +2995,11 @@ update_address_book_deltas (EBookBackendGroupwise *ebgw)
 				if (e_book_backend_db_cache_check_contact (ebgw->priv->file_db, id)) {
 					contact_num++;
 
-					if (book_view) {
-						status_msg = g_strdup_printf (_("Updating contacts cache (%d)... "),
-										 contact_num);
-						book_view_notify_status (book_view, status_msg);
-						g_free (status_msg);
-					}
+					status_msg = g_strdup_printf (_("Updating contacts cache (%d)... "),
+							contact_num);
+					e_book_backend_foreach_view (E_BOOK_BACKEND (ebgw), book_view_notify_status, status_msg);
+					g_free (status_msg);
+
 					e_book_backend_db_cache_remove_contact (ebgw->priv->file_db, id);
 					e_book_backend_summary_remove_contact (ebgw->priv->summary, id);
 				}
@@ -3106,12 +3041,12 @@ update_address_book_deltas (EBookBackendGroupwise *ebgw)
 				id =  e_contact_get_const (contact, E_CONTACT_UID);
 
 				contact_num++;
-				if (book_view) {
-					status_msg = g_strdup_printf (_("Updating contacts cache (%d)... "),
-									 contact_num);
-					book_view_notify_status (book_view, status_msg);
-					g_free (status_msg);
-				}
+				
+				status_msg = g_strdup_printf (_("Updating contacts cache (%d)... "),
+								contact_num);
+				e_book_backend_foreach_view (E_BOOK_BACKEND (ebgw), book_view_notify_status, status_msg);
+				g_free (status_msg);
+
 				if (e_book_backend_db_cache_check_contact (ebgw->priv->file_db, id)) {
 					if (enable_debug)
 						printf("contact already there\n");
@@ -3147,11 +3082,6 @@ update_address_book_deltas (EBookBackendGroupwise *ebgw)
 	if (sync_required)
 		ebgw->priv->file_db->sync (ebgw->priv->file_db, 0);
 
-	if (book_view) {
-		e_data_book_view_notify_complete (book_view, NULL /* Success */);
-		e_data_book_view_unref (book_view);
-	}
-
 	if (enable_debug) {
 		g_get_current_time (&end);
 		diff = end.tv_sec * 1000 + end.tv_usec / 1000;



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