[evolution-data-server] EBookBackend: Make get_contact_list_uids_sync() optional.



commit ae4172593484e9d1f95976c5e372421db3e7df4d
Author: Matthew Barnes <mbarnes redhat com>
Date:   Sat Apr 6 12:59:39 2013 -0400

    EBookBackend: Make get_contact_list_uids_sync() optional.
    
    This method is now optional.  By default, get_contact_list_uids_sync()
    simply calls get_contact_list_sync() and extracts UID strings from the
    matched EContacts.  Subclasses may override this if they can implement
    it more efficiently.

 addressbook/libedata-book/e-book-backend.c |   35 ++++++++++++++++++++++++++++
 addressbook/libedata-book/e-book-backend.h |    5 ++++
 2 files changed, 40 insertions(+), 0 deletions(-)
---
diff --git a/addressbook/libedata-book/e-book-backend.c b/addressbook/libedata-book/e-book-backend.c
index 39df4a3..fe03891 100644
--- a/addressbook/libedata-book/e-book-backend.c
+++ b/addressbook/libedata-book/e-book-backend.c
@@ -485,6 +485,40 @@ book_backend_get_backend_property (EBookBackend *backend,
        return prop_value;
 }
 
+static gboolean
+book_backend_get_contact_list_uids_sync (EBookBackend *backend,
+                                         const gchar *query,
+                                         GQueue *out_uids,
+                                         GCancellable *cancellable,
+                                         GError **error)
+{
+       EBookBackendClass *class;
+       GQueue queue = G_QUEUE_INIT;
+       gboolean success;
+
+       class = E_BOOK_BACKEND_GET_CLASS (backend);
+       g_return_val_if_fail (class->get_contact_list_sync != NULL, FALSE);
+
+       success = class->get_contact_list_sync (
+               backend, query, &queue, cancellable, error);
+
+       if (success) {
+               while (!g_queue_is_empty (&queue)) {
+                       EContact *contact;
+                       gchar *uid;
+
+                       contact = g_queue_pop_head (&queue);
+                       uid = e_contact_get (contact, E_CONTACT_UID);
+                       g_queue_push_tail (out_uids, uid);
+                       g_object_unref (contact);
+               }
+       }
+
+       g_warn_if_fail (g_queue_is_empty (&queue));
+
+       return success;
+}
+
 static void
 book_backend_notify_update (EBookBackend *backend,
                             const EContact *contact)
@@ -520,6 +554,7 @@ e_book_backend_class_init (EBookBackendClass *class)
        backend_class->authenticate_sync = book_backend_authenticate_sync;
 
        class->get_backend_property = book_backend_get_backend_property;
+       class->get_contact_list_uids_sync = book_backend_get_contact_list_uids_sync;
        class->notify_update = book_backend_notify_update;
 
        g_object_class_install_property (
diff --git a/addressbook/libedata-book/e-book-backend.h b/addressbook/libedata-book/e-book-backend.h
index d7a3857..a4668d1 100644
--- a/addressbook/libedata-book/e-book-backend.h
+++ b/addressbook/libedata-book/e-book-backend.h
@@ -141,6 +141,11 @@ struct _EBookBackendClass {
                                                 GQueue *out_contacts,
                                                 GCancellable *cancellable,
                                                 GError **error);
+
+       /* This method is optional.  By default, it simply calls
+        * get_contact_list_sync() and extracts UID strings from
+        * the matched EContacts.  Backends may override this if
+        * they can implement it more efficiently. */
        gboolean        (*get_contact_list_uids_sync)
                                                (EBookBackend *backend,
                                                 const gchar *query,


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