[evolution-data-server/openismus-work] Make EBookBackend notify changes with only the UID if UID 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] Make EBookBackend notify changes with only the UID if UID is the only requested field.
- Date: Fri, 17 Jun 2011 20:46:50 +0000 (UTC)
commit 30035bd6454893583955f293d957450d6ea8de89
Author: Tristan Van Berkom <tristan van berkom gmail com>
Date: Fri Jun 17 17:47:56 2011 +0900
Make EBookBackend notify changes with only the UID if UID is the only requested field.
Also extended the test-ebook-get-book-view-uid-only.c test case to test that
future changes also come with only the UID.
addressbook/libedata-book/e-book-backend.c | 27 +++-
.../ebook/test-ebook-get-book-view-uid-only.c | 188 ++++++++++++--------
2 files changed, 143 insertions(+), 72 deletions(-)
---
diff --git a/addressbook/libedata-book/e-book-backend.c b/addressbook/libedata-book/e-book-backend.c
index 7af0ae0..af0b9f2 100644
--- a/addressbook/libedata-book/e-book-backend.c
+++ b/addressbook/libedata-book/e-book-backend.c
@@ -9,6 +9,7 @@
#include <config.h>
#include <libedataserver/e-data-server-util.h>
+#include <string.h>
#include "e-data-book-view.h"
#include "e-data-book.h"
@@ -1063,9 +1064,31 @@ e_book_backend_foreach_view (EBookBackend *backend,
}
static void
-view_notify_update (EDataBookView *view, gpointer contact)
+view_notify_update (EDataBookView *view, gpointer data)
{
- e_data_book_view_notify_update (view, contact);
+ EContact *contact = data;
+ const gchar **requested_fields;
+ gboolean uid_only = FALSE;
+
+ /* If only the UID was requested, avoid digging everything else up */
+ requested_fields = e_data_book_view_get_requested_fields (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);
+
+ if (uid_only) {
+ /* Create a shallow version of the contacts for views that are
+ * only interested in the uid. */
+ EContact *shallow = e_contact_new ();
+ gchar *vcard;
+
+ e_contact_set (shallow, E_CONTACT_UID, e_contact_get_const (contact, E_CONTACT_UID));
+ vcard = e_vcard_to_string (E_VCARD (shallow), EVC_FORMAT_VCARD_30);
+ g_object_unref (shallow);
+
+ e_data_book_view_notify_update_vcard (view, vcard);
+ } else {
+ e_data_book_view_notify_update (view, contact);
+ }
}
/**
diff --git a/addressbook/tests/ebook/test-ebook-get-book-view-uid-only.c b/addressbook/tests/ebook/test-ebook-get-book-view-uid-only.c
index 5baa159..2043956 100644
--- a/addressbook/tests/ebook/test-ebook-get-book-view-uid-only.c
+++ b/addressbook/tests/ebook/test-ebook-get-book-view-uid-only.c
@@ -25,9 +25,100 @@
# define PRINT_TIMER(timer, activity)
#endif
+#define NOTIFICATION_WAIT 2000
+static gboolean loading_view;
static GMainLoop *loop;
+
+/****************************************************************
+ * Modify/Setup the EBook *
+ ****************************************************************/
+static void
+add_contact (EBook *book)
+{
+ EContact *contact = e_contact_new ();
+ EContact *final;
+ const gchar *uid;
+
+ e_contact_set (contact, E_CONTACT_FULL_NAME, "Micheal Jackson");
+
+ uid = ebook_test_utils_book_add_contact (book, contact);
+ final = ebook_test_utils_book_get_contact (book, uid);
+
+ /* verify the contact was added "successfully" (not thorough) */
+ g_assert (ebook_test_utils_contacts_are_equal_shallow (contact, final));
+}
+
+static void
+setup_book (EBook **book_out)
+{
+ EBook *book;
+ gint i, j;
+
+ book = ebook_test_utils_book_new_temp (NULL);
+ ebook_test_utils_book_open (book, FALSE);
+
+ for (i = 0; i < N_TEST_CONTACTS; i++)
+ {
+ EContact *contact = e_contact_new ();
+ EContact *final;
+ const gchar *uid;
+ gchar *name = g_strdup_printf ("Contact #%d", i + 1);
+ gchar *emails[5] = {
+ g_strdup_printf ("contact%d first email com", i),
+ g_strdup_printf ("contact%d second email com", i),
+ g_strdup_printf ("contact%d third email com", i),
+ g_strdup_printf ("contact%d fourth email com", i),
+ NULL
+ };
+
+ e_contact_set (contact, E_CONTACT_FULL_NAME, name);
+ e_contact_set (contact, E_CONTACT_NICKNAME, name);
+
+ /* Fill some emails */
+ for (j = E_CONTACT_EMAIL_1; j < (E_CONTACT_EMAIL_4 + 1); j++)
+ e_contact_set (contact, j, emails[j - E_CONTACT_EMAIL_1]);
+
+#if BEEFY_VCARDS
+ /* Fill some other random stuff */
+ for (j = E_CONTACT_IM_AIM_HOME_1; j < (E_CONTACT_IM_AIM_HOME_3 + 1); j++)
+ e_contact_set (contact, j, emails[j - E_CONTACT_IM_AIM_HOME_1]);
+ for (j = E_CONTACT_IM_AIM_WORK_1; j < (E_CONTACT_IM_AIM_WORK_3 + 1); j++)
+ e_contact_set (contact, j, emails[j - E_CONTACT_IM_AIM_WORK_1]);
+ for (j = E_CONTACT_IM_GROUPWISE_HOME_1; j < (E_CONTACT_IM_GROUPWISE_HOME_3 + 1); j++)
+ e_contact_set (contact, j, emails[j - E_CONTACT_IM_GROUPWISE_HOME_1]);
+ for (j = E_CONTACT_IM_GROUPWISE_WORK_1; j < (E_CONTACT_IM_GROUPWISE_WORK_3 + 1); j++)
+ e_contact_set (contact, j, emails[j - E_CONTACT_IM_GROUPWISE_WORK_1]);
+ for (j = E_CONTACT_IM_JABBER_HOME_1; j < (E_CONTACT_IM_JABBER_HOME_3 + 1); j++)
+ e_contact_set (contact, j, emails[j - E_CONTACT_IM_JABBER_HOME_1]);
+ for (j = E_CONTACT_IM_JABBER_WORK_1; j < (E_CONTACT_IM_JABBER_WORK_3 + 1); j++)
+ e_contact_set (contact, j, emails[j - E_CONTACT_IM_JABBER_WORK_1]);
+ for (j = E_CONTACT_IM_YAHOO_HOME_1; j < (E_CONTACT_IM_YAHOO_HOME_3 + 1); j++)
+ e_contact_set (contact, j, emails[j - E_CONTACT_IM_YAHOO_HOME_1]);
+ for (j = E_CONTACT_IM_YAHOO_WORK_1; j < (E_CONTACT_IM_YAHOO_WORK_3 + 1); j++)
+ e_contact_set (contact, j, emails[j - E_CONTACT_IM_YAHOO_WORK_1]);
+#endif
+
+ uid = ebook_test_utils_book_add_contact (book, contact);
+ final = ebook_test_utils_book_get_contact (book, uid);
+
+ /* verify the contact was added "successfully" (not thorough) */
+ g_assert (ebook_test_utils_contacts_are_equal_shallow (contact, contact));
+
+ g_free (name);
+ for (j = E_CONTACT_EMAIL_1; j < (E_CONTACT_EMAIL_4 + 1); j++)
+ g_free (emails[j - E_CONTACT_EMAIL_1]);
+
+ g_object_unref (contact);
+ }
+
+ *book_out = book;
+}
+
+/****************************************************************
+ * Handle EBookView notifications *
+ ****************************************************************/
#if !COMPARE_PERFORMANCE
static void
print_contact (EContact *contact)
@@ -50,6 +141,14 @@ print_contact (EContact *contact)
#endif
static void
+finish_test (EBookView *book_view)
+{
+ e_book_view_stop (book_view);
+ g_object_unref (book_view);
+ g_main_loop_quit (loop);
+}
+
+static void
contacts_added (EBookView *book_view, const GList *contacts)
{
GList *l;
@@ -70,6 +169,9 @@ contacts_added (EBookView *book_view, const GList *contacts)
else if (!uid_only && e_contact_get_const (contact, E_CONTACT_FULL_NAME) == NULL)
g_error ("expected contact name missing");
}
+
+ if (!loading_view)
+ finish_test (book_view);
}
static void
@@ -82,12 +184,23 @@ contacts_removed (EBookView *book_view, const GList *ids)
}
}
+static gboolean
+add_contact_timeout (EBookView *book_view)
+{
+ if (book_view)
+ g_error ("Timed out waiting for notification of added contact");
+
+ return FALSE;
+}
+
static void
view_complete (EBookView *book_view, EBookViewStatus status, const gchar *error_msg)
{
- e_book_view_stop (book_view);
- g_object_unref (book_view);
- g_main_loop_quit (loop);
+ /* Now add a contact and assert that we received notification */
+ loading_view = FALSE;
+ add_contact (e_book_view_get_book (book_view));
+
+ g_timeout_add (NOTIFICATION_WAIT, (GSourceFunc)add_contact_timeout, book_view);
}
static void
@@ -97,6 +210,8 @@ setup_and_start_view (EBookView *view)
g_signal_connect (view, "contacts_removed", G_CALLBACK (contacts_removed), NULL);
g_signal_connect (view, "view_complete", G_CALLBACK (view_complete), NULL);
+ loading_view = TRUE;
+
e_book_view_start (view);
}
@@ -110,72 +225,6 @@ get_book_view_cb (EBookTestClosure *closure)
setup_and_start_view (closure->view);
}
-static void
-setup_book (EBook **book_out)
-{
- EBook *book;
- gint i, j;
-
- book = ebook_test_utils_book_new_temp (NULL);
- ebook_test_utils_book_open (book, FALSE);
-
- for (i = 0; i < N_TEST_CONTACTS; i++)
- {
- EContact *contact = e_contact_new ();
- EContact *final;
- const gchar *uid;
- gchar *name = g_strdup_printf ("Contact #%d", i + 1);
- gchar *emails[5] = {
- g_strdup_printf ("contact%d first email com", i),
- g_strdup_printf ("contact%d second email com", i),
- g_strdup_printf ("contact%d third email com", i),
- g_strdup_printf ("contact%d fourth email com", i),
- NULL
- };
-
- e_contact_set (contact, E_CONTACT_FULL_NAME, name);
- e_contact_set (contact, E_CONTACT_NICKNAME, name);
-
- /* Fill some emails */
- for (j = E_CONTACT_EMAIL_1; j < (E_CONTACT_EMAIL_4 + 1); j++)
- e_contact_set (contact, j, emails[j - E_CONTACT_EMAIL_1]);
-
-#if BEEFY_VCARDS
- /* Fill some other random stuff */
- for (j = E_CONTACT_IM_AIM_HOME_1; j < (E_CONTACT_IM_AIM_HOME_3 + 1); j++)
- e_contact_set (contact, j, emails[j - E_CONTACT_IM_AIM_HOME_1]);
- for (j = E_CONTACT_IM_AIM_WORK_1; j < (E_CONTACT_IM_AIM_WORK_3 + 1); j++)
- e_contact_set (contact, j, emails[j - E_CONTACT_IM_AIM_WORK_1]);
- for (j = E_CONTACT_IM_GROUPWISE_HOME_1; j < (E_CONTACT_IM_GROUPWISE_HOME_3 + 1); j++)
- e_contact_set (contact, j, emails[j - E_CONTACT_IM_GROUPWISE_HOME_1]);
- for (j = E_CONTACT_IM_GROUPWISE_WORK_1; j < (E_CONTACT_IM_GROUPWISE_WORK_3 + 1); j++)
- e_contact_set (contact, j, emails[j - E_CONTACT_IM_GROUPWISE_WORK_1]);
- for (j = E_CONTACT_IM_JABBER_HOME_1; j < (E_CONTACT_IM_JABBER_HOME_3 + 1); j++)
- e_contact_set (contact, j, emails[j - E_CONTACT_IM_JABBER_HOME_1]);
- for (j = E_CONTACT_IM_JABBER_WORK_1; j < (E_CONTACT_IM_JABBER_WORK_3 + 1); j++)
- e_contact_set (contact, j, emails[j - E_CONTACT_IM_JABBER_WORK_1]);
- for (j = E_CONTACT_IM_YAHOO_HOME_1; j < (E_CONTACT_IM_YAHOO_HOME_3 + 1); j++)
- e_contact_set (contact, j, emails[j - E_CONTACT_IM_YAHOO_HOME_1]);
- for (j = E_CONTACT_IM_YAHOO_WORK_1; j < (E_CONTACT_IM_YAHOO_WORK_3 + 1); j++)
- e_contact_set (contact, j, emails[j - E_CONTACT_IM_YAHOO_WORK_1]);
-#endif
-
- uid = ebook_test_utils_book_add_contact (book, contact);
- final = ebook_test_utils_book_get_contact (book, uid);
-
- /* verify the contact was added "successfully" (not thorough) */
- g_assert (ebook_test_utils_contacts_are_equal_shallow (contact, final));
-
- g_free (name);
- for (j = E_CONTACT_EMAIL_1; j < (E_CONTACT_EMAIL_4 + 1); j++)
- g_free (emails[j - E_CONTACT_EMAIL_1]);
-
- g_object_unref (contact);
- }
-
- *book_out = book;
-}
-
gint
main (gint argc, gchar **argv)
{
@@ -208,7 +257,6 @@ main (gint argc, gchar **argv)
/*
* Sync version with uids only
*/
- //setup_book (&book);
query = e_book_query_any_field_contains ("");
ebook_test_utils_book_get_book_view (book, query, &requested_field, &view);
g_object_set_data (G_OBJECT (view), "uid-only", GINT_TO_POINTER (TRUE));
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]