[evolution-data-server/openismus-work] Report shallow vcards with only the UID if the UID field is the only 'requested_field'
- From: Tristan Van Berkom <tvb src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [evolution-data-server/openismus-work] Report shallow vcards with only the UID if the UID field is the only 'requested_field'
- Date: Sun, 12 Jun 2011 21:53:23 +0000 (UTC)
commit 1b7e19c4c6c85962357c8f1060466c9ad4fc3363
Author: Tristan Van Berkom <tristan van berkom gmail com>
Date: Sun Jun 12 16:45:48 2011 +0900
Report shallow vcards with only the UID if the UID field is the only 'requested_field'
This is an initial implementation and could be optimized, currently we
loop through and fetch the data from the db in the same way and then
decide to construct a vcard from the id string.
addressbook/backends/file/e-book-backend-file.c | 48 ++++++++++++++++++++---
1 files changed, 42 insertions(+), 6 deletions(-)
---
diff --git a/addressbook/backends/file/e-book-backend-file.c b/addressbook/backends/file/e-book-backend-file.c
index 1b7c7d7..af759f7 100644
--- a/addressbook/backends/file/e-book-backend-file.c
+++ b/addressbook/backends/file/e-book-backend-file.c
@@ -539,6 +539,36 @@ get_closure (EDataBookView *book_view)
return g_object_get_data (G_OBJECT (book_view), "EBookBackendFile.BookView::closure");
}
+static void
+notify_update_vcard (EDataBookView *book_view,
+ gboolean uid_only,
+ gboolean prefiltered,
+ const gchar *id,
+ const gchar *vcard)
+{
+ gchar *final_vcard;
+
+ if (uid_only) {
+ /* Create a shallow version of the contacts for views that are
+ * only interested in the uid. */
+ EContact *shallow = e_contact_new ();
+
+ e_contact_set (shallow, E_CONTACT_UID, id);
+ final_vcard = e_vcard_to_string (E_VCARD (shallow), EVC_FORMAT_VCARD_30);
+ g_object_unref (shallow);
+ } else {
+ final_vcard = (gchar *)vcard;
+ }
+
+ if (prefiltered)
+ e_data_book_view_notify_update_prefiltered_vcard (book_view, id, final_vcard);
+ else
+ e_data_book_view_notify_update_vcard (book_view, final_vcard);
+
+ if (final_vcard != (gchar *)vcard)
+ g_free (final_vcard);
+}
+
static gpointer
book_view_thread (gpointer data)
{
@@ -546,10 +576,11 @@ book_view_thread (gpointer data)
FileBackendSearchClosure *closure;
EBookBackendFile *bf;
const gchar *query;
+ const gchar **requested_fields;
DB *db;
DBT id_dbt, vcard_dbt;
gint db_error;
- gboolean allcontacts;
+ gboolean allcontacts, uid_only;
g_return_val_if_fail (E_IS_DATA_BOOK_VIEW (data), NULL);
@@ -578,6 +609,13 @@ book_view_thread (gpointer data)
allcontacts = FALSE;
}
+ /* If only the UID was requested, avoid digging everything else up */
+ requested_fields = e_data_book_view_get_requested_fields (book_view);
+ if (requested_fields && requested_fields[0] != NULL && requested_fields[1] == NULL)
+ uid_only = (strcmp (e_contact_field_name (E_CONTACT_UID), requested_fields[0]) == 0);
+ else
+ uid_only = FALSE;
+
d(printf ("signalling parent thread\n"));
e_flag_set (closure->running);
@@ -602,7 +640,7 @@ book_view_thread (gpointer data)
db_error = db->get (db, NULL, &id_dbt, &vcard_dbt, 0);
if (db_error == 0) {
- e_data_book_view_notify_update_prefiltered_vcard (book_view, id, vcard_dbt.data);
+ notify_update_vcard (book_view, uid_only, TRUE, id, vcard_dbt.data);
}
else {
g_warning (G_STRLOC ": db->get failed with %s", db_strerror (db_error));
@@ -630,10 +668,8 @@ book_view_thread (gpointer data)
/* don't include the version in the list of cards */
if (strcmp (id_dbt.data, E_BOOK_BACKEND_FILE_VERSION_NAME)) {
- if (allcontacts)
- e_data_book_view_notify_update_prefiltered_vcard (book_view, id_dbt.data, vcard_dbt.data);
- else
- e_data_book_view_notify_update_vcard (book_view, vcard_dbt.data);
+ notify_update_vcard (book_view, uid_only, allcontacts,
+ id_dbt.data, vcard_dbt.data);
} else {
g_free (vcard_dbt.data);
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]