[evolution-data-server/openismus-work-master: 11/11] Updated local addressbook backend for new sqlitedb apis.



commit f5aaa4fe82ec8051d1abc1fd617f112e92868e3d
Author: Tristan Van Berkom <tristan van berkom gmail com>
Date:   Sat Aug 6 19:25:50 2011 -0400

    Updated local addressbook backend for new sqlitedb apis.
    
    Now leverage the sqlitedb object better, save processing
    and return correct information according to the apis.
    
    Bug https://bugzilla.gnome.org/show_bug.cgi?id=656058.

 addressbook/backends/file/e-book-backend-file.c |   78 +++++++++++++++++++----
 1 files changed, 65 insertions(+), 13 deletions(-)
---
diff --git a/addressbook/backends/file/e-book-backend-file.c b/addressbook/backends/file/e-book-backend-file.c
index d545532..9647f00 100644
--- a/addressbook/backends/file/e-book-backend-file.c
+++ b/addressbook/backends/file/e-book-backend-file.c
@@ -1103,6 +1103,8 @@ e_book_backend_file_get_contact_list (EBookBackendSync *backend,
 	const gchar *search = query;
 	GSList *contact_list = NULL, *l;
 	GSList *summary_list = NULL;
+	gboolean searched_summary = FALSE;
+	gboolean complete_vcards  = FALSE;
 
 	d(printf ("e_book_backend_file_get_contact_list (%s)\n", search));
 
@@ -1113,15 +1115,32 @@ e_book_backend_file_get_contact_list (EBookBackendSync *backend,
 
 	summary_list = e_book_backend_sqlitedb_search (bf->priv->sqlitedb,
 						       SQLITEDB_FOLDER_ID,
-						       search, NULL, NULL);
+						       search, NULL,
+						       &searched_summary,
+						       &complete_vcards, NULL);
 
 	if (summary_list) {
 
 		for (l = summary_list; l; l = l->next) {
 			EbSdbSearchData *data = l->data;
 
-			contact_list = g_slist_prepend (contact_list, data->vcard);
-			data->vcard  = NULL;
+			if (complete_vcards) {
+				contact_list = g_slist_prepend (contact_list, data->vcard);
+				data->vcard  = NULL;
+			} else {
+				/* In this case the sqlitedb helped us with the query, but
+				 * the return information is incomplete so we need to load it up.
+				 */
+				gchar *vcard;
+
+				vcard = load_vcard (bf, data->uid, perror);
+
+				/* Break out on the first BDB error */
+				if (!vcard)
+					break;
+
+				contact_list = g_slist_prepend (contact_list, vcard);
+			}
 		}
 
 		g_slist_foreach (summary_list, (GFunc)e_book_backend_sqlitedb_search_data_free, NULL);
@@ -1207,6 +1226,7 @@ e_book_backend_file_get_contact_list_uids (EBookBackendSync *backend,
 	gboolean search_needed;
 	const gchar *search = query;
 	GSList *uids = NULL;
+	gboolean searched = FALSE;
 
 	d(printf ("e_book_backend_file_get_contact_list (%s)\n", search));
 
@@ -1217,9 +1237,9 @@ e_book_backend_file_get_contact_list_uids (EBookBackendSync *backend,
 
 	uids = e_book_backend_sqlitedb_search_uids (bf->priv->sqlitedb,
 						    SQLITEDB_FOLDER_ID,
-						    search, NULL);
+						    search, &searched, NULL);
 
-	if (!uids) {
+	if (!searched) {
 		search_needed = TRUE;
 		if (!strcmp (search, "(contains \"x-evolution-any-field\" \"\")"))
 			search_needed = FALSE;
@@ -1340,6 +1360,8 @@ book_view_thread (gpointer data)
 	gboolean allcontacts;
 	GSList *summary_list, *l;
 	GHashTable *fields_of_interest;
+	gboolean searched = FALSE;
+	gboolean complete_vcards = FALSE;
 
 	g_return_val_if_fail (E_IS_DATA_BOOK_VIEW (data), NULL);
 
@@ -1380,14 +1402,37 @@ book_view_thread (gpointer data)
 
 	summary_list = e_book_backend_sqlitedb_search (bf->priv->sqlitedb,
 						       SQLITEDB_FOLDER_ID,
-						       query, fields_of_interest, NULL);
-	if (summary_list) {
+						       query, fields_of_interest, 
+						       &searched, &complete_vcards, NULL);
+
+	if (searched) {
 
 		for (l = summary_list; l; l = l->next) {
 			EbSdbSearchData *data = l->data;
+			gchar *vcard = NULL;
+
+			if (complete_vcards) {
+				vcard = data->vcard;
+				data->vcard = NULL;
+			} else {
+				GError *error = NULL;
 
-			notify_update_vcard (book_view, TRUE, data->uid, data->vcard);
-			data->vcard = NULL;
+				/* The sqlitedb summary did not satisfy 'fields-of-interest',
+				 * load the complete vcard here. */
+				vcard = load_vcard (bf, data->uid, &error);
+
+				if (error) {
+					g_warning ("Error loading contact %s: %s",
+						   data->uid, error->message);
+					g_error_free (error);
+				}
+
+				if (!vcard)
+					continue;
+
+			}
+
+			notify_update_vcard (book_view, TRUE, data->uid, vcard);
 		}
 
 		g_slist_foreach (summary_list, (GFunc)e_book_backend_sqlitedb_search_data_free, NULL);
@@ -2045,19 +2090,26 @@ view_notify_update (EDataBookView *view, gpointer data)
 	NotifyData *ndata    = data;
 	GHashTable *fields   = e_data_book_view_get_fields_of_interest (view);
 	gboolean    notified = FALSE;
+	gboolean    complete = FALSE;
 
-	if (e_book_backend_sqlitedb_is_summary_query (e_data_book_view_get_card_query (view), fields)) {
+	if (e_book_backend_sqlitedb_is_summary_query (e_data_book_view_get_card_query (view)) &&
+	    e_book_backend_sqlitedb_is_summary_fields (fields)) {
 
 		const gchar *uid = e_contact_get_const (ndata->contact, E_CONTACT_UID);
 		gchar       *vcard;
 
 		vcard = e_book_backend_sqlitedb_get_vcard_string (ndata->bf->priv->sqlitedb,
 								  SQLITEDB_FOLDER_ID, uid,
-								  fields, NULL);
+								  fields, &complete, NULL);
 
 		if (vcard) {
-			e_data_book_view_notify_update_prefiltered_vcard (view, uid, vcard);
-			notified = TRUE;
+
+			if (complete) {
+				e_data_book_view_notify_update_prefiltered_vcard (view, uid, vcard);
+				notified = TRUE;
+			} else {
+				g_free (vcard);
+			}
 		}
 	}
 



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