[evolution-exchange] Adapt to EBookBackend API changes
- From: Milan Crha <mcrha src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [evolution-exchange] Adapt to EBookBackend API changes
- Date: Mon, 10 Oct 2011 10:38:29 +0000 (UTC)
commit bd7e665458192abc2673468ac694923261b09073
Author: Milan Crha <mcrha redhat com>
Date: Mon Oct 10 12:37:53 2011 +0200
Adapt to EBookBackend API changes
addressbook/e-book-backend-exchange.c | 342 +++++++++++++++++----------------
addressbook/e-book-backend-gal.c | 36 ++--
2 files changed, 198 insertions(+), 180 deletions(-)
---
diff --git a/addressbook/e-book-backend-exchange.c b/addressbook/e-book-backend-exchange.c
index 626881f..3aaac5c 100644
--- a/addressbook/e-book-backend-exchange.c
+++ b/addressbook/e-book-backend-exchange.c
@@ -1703,221 +1703,239 @@ merge_contact_lists (EBookBackendExchange *be,
}
static void
-e_book_backend_exchange_create_contact (EBookBackendSync *backend,
- EDataBook *book,
- GCancellable *cancellable,
- const gchar *vcard,
- EContact **contact,
- GError **perror)
+e_book_backend_exchange_create_contacts (EBookBackendSync *backend,
+ EDataBook *book,
+ GCancellable *cancellable,
+ const GSList *vcards,
+ GSList **added_contacts,
+ GError **perror)
{
EBookBackendExchange *be = E_BOOK_BACKEND_EXCHANGE (backend);
EBookBackendExchangePrivate *bepriv = be->priv;
E2kProperties *props = NULL;
- const gchar *name;
+ const gchar *name, *vcard;
+ EContact *contact;
E2kHTTPStatus status;
gchar *location = NULL;
- d(printf("ebbe_create_contact(%p, %p, %s)\n", backend, book, vcard));
+ d(printf("ebbe_create_contact(%p, %p, %s)\n", backend, book, (const gchar *) vcards->data));
+
+ *added_contacts = NULL;
LOCK (bepriv);
if (!e_backend_get_online (E_BACKEND (backend))) {
- *contact = NULL;
UNLOCK (bepriv);
g_propagate_error (perror, EDB_ERROR (REPOSITORY_OFFLINE));
- } else {
- *contact = e_contact_new_from_vcard (vcard);
+ return;
+ }
- /* figure out the right uri to be using */
- name = contact_name (*contact);
- if (!name)
- name = "No Subject";
+ /* We make the assumption that the vCard list we're passed is always exactly one element long, since we haven't specified "bulk-adds"
+ * in our static capability list. This is because there is no clean way to roll back changes in case of an error. */
+ if (vcards->next != NULL) {
+ UNLOCK (bepriv);
+ g_propagate_error (perror, EDB_ERROR_EX (NOT_SUPPORTED, _("The backend does not support bulk additions")));
+ return;
+ }
- if (!bepriv->connected || !bepriv->ctx || !bepriv->summary) {
- if (!e_book_backend_exchange_connect (be, perror)) {
- UNLOCK (bepriv);
- return;
- }
- }
+ vcard = vcards->data;
+ contact = e_contact_new_from_vcard (vcard);
+
+ /* figure out the right uri to be using */
+ name = contact_name (contact);
+ if (!name)
+ name = "No Subject";
- props = props_from_contact (be, *contact, NULL);
+ if (!bepriv->connected || !bepriv->ctx || !bepriv->summary) {
+ if (!e_book_backend_exchange_connect (be, perror)) {
+ UNLOCK (bepriv);
+ return;
+ }
+ }
- status = e_folder_exchange_proppatch_new (bepriv->folder, NULL, name,
- test_name, bepriv->summary,
- props, &location, NULL);
+ props = props_from_contact (be, contact, NULL);
- if (E2K_HTTP_STATUS_IS_SUCCESSFUL (status) && GPOINTER_TO_INT (e_contact_get (*contact, E_CONTACT_IS_LIST))) {
- e_contact_set (*contact, E_CONTACT_UID, location);
- e_contact_set (*contact, E_CONTACT_LIST_SHOW_ADDRESSES, GINT_TO_POINTER (TRUE));
- status = merge_contact_lists (be, location, *contact);
- } else if (E2K_HTTP_STATUS_IS_SUCCESSFUL (status)) {
- gchar *note;
- EContactPhoto *photo;
+ status = e_folder_exchange_proppatch_new (bepriv->folder, NULL, name,
+ test_name, bepriv->summary,
+ props, &location, NULL);
- e_contact_set (*contact, E_CONTACT_UID, location);
+ if (E2K_HTTP_STATUS_IS_SUCCESSFUL (status) && GPOINTER_TO_INT (e_contact_get (contact, E_CONTACT_IS_LIST))) {
+ e_contact_set (contact, E_CONTACT_UID, location);
+ e_contact_set (contact, E_CONTACT_LIST_SHOW_ADDRESSES, GINT_TO_POINTER (TRUE));
+ status = merge_contact_lists (be, location, contact);
+ } else if (E2K_HTTP_STATUS_IS_SUCCESSFUL (status)) {
+ gchar *note;
+ EContactPhoto *photo;
- note = e_contact_get (*contact, E_CONTACT_NOTE);
- photo = e_contact_get (*contact, E_CONTACT_PHOTO);
+ e_contact_set (contact, E_CONTACT_UID, location);
- if (note || photo) {
- /* Do the PUT request. */
- status = do_put (be, book, location,
- contact_name (*contact),
- note, photo);
- }
+ note = e_contact_get (contact, E_CONTACT_NOTE);
+ photo = e_contact_get (contact, E_CONTACT_PHOTO);
- if (note)
- g_free (note);
- if (photo)
- e_contact_photo_free (photo);
+ if (note || photo) {
+ /* Do the PUT request. */
+ status = do_put (be, book, location,
+ contact_name (contact),
+ note, photo);
}
- g_free (location);
- if (props)
- e2k_properties_free (props);
+ if (note)
+ g_free (note);
+ if (photo)
+ e_contact_photo_free (photo);
+ }
+
+ g_free (location);
+ if (props)
+ e2k_properties_free (props);
- if (E2K_HTTP_STATUS_IS_SUCCESSFUL (status)) {
- e_book_backend_summary_add_contact (bepriv->summary,
- *contact);
- e_book_backend_cache_add_contact (bepriv->cache, *contact);
- UNLOCK (bepriv);
- return;
- } else {
- g_object_unref (*contact);
- *contact = NULL;
- UNLOCK (bepriv);
- http_status_to_error (status, perror);
- return;
- }
+ if (E2K_HTTP_STATUS_IS_SUCCESSFUL (status)) {
+ e_book_backend_summary_add_contact (bepriv->summary, contact);
+ e_book_backend_cache_add_contact (bepriv->cache, contact);
+ *added_contacts = g_slist_append (NULL, contact);
+ } else {
+ g_object_unref (contact);
+ http_status_to_error (status, perror);
}
+
UNLOCK (bepriv);
}
static void
-e_book_backend_exchange_modify_contact (EBookBackendSync *backend,
- EDataBook *book,
- GCancellable *cancellable,
- const gchar *vcard,
- EContact **contact,
- GError **perror)
+e_book_backend_exchange_modify_contacts (EBookBackendSync *backend,
+ EDataBook *book,
+ GCancellable *cancellable,
+ const GSList *vcards,
+ GSList **contacts,
+ GError **perror)
{
EBookBackendExchange *be = E_BOOK_BACKEND_EXCHANGE (backend);
EBookBackendExchangePrivate *bepriv = be->priv;
EContact *old_contact;
- const gchar *uri;
+ const gchar *uri, *vcard;
E2kHTTPStatus status;
E2kResult *results;
gint nresults = 0;
E2kProperties *props;
+ EContact *contact;
- d(printf("ebbe_modify_contact(%p, %p, %s)\n", backend, book, vcard));
+ d(printf("ebbe_modify_contact(%p, %p, %s)\n", backend, book, (const gchar *) vcards->data));
+
+ *contacts = NULL;
if (!e_backend_get_online (E_BACKEND (backend))) {
- *contact = NULL;
g_propagate_error (perror, EDB_ERROR (REPOSITORY_OFFLINE));
- } else {
- *contact = e_contact_new_from_vcard (vcard);
- uri = e_contact_get_const (*contact, E_CONTACT_UID);
+ return;
+ }
- if (!bepriv->connected || !bepriv->ctx || !bepriv->summary) {
- if (!e_book_backend_exchange_connect (be, perror)) {
- return;
- }
- }
+ /* We make the assumption that the vCard list we're passed is always exactly one element long, since we haven't specified "bulk-modifies"
+ * in our static capability list. This is because there is no clean way to roll back changes in case of an error. */
+ if (vcards->next != NULL) {
+ g_propagate_error (perror, EDB_ERROR_EX (NOT_SUPPORTED, _("The backend does not support bulk modifications")));
+ return;
+ }
- status = e2k_context_propfind (bepriv->ctx, NULL, uri,
- field_names, n_field_names,
- &results, &nresults);
- if (status == E2K_HTTP_CANCELLED) {
- g_object_unref (book);
- g_object_unref (*contact);
- *contact = NULL;
- g_propagate_error (perror, EDB_ERROR_EX (OTHER_ERROR, _("Cancelled")));
+ vcard = vcards->data;
+ contact = e_contact_new_from_vcard (vcard);
+ uri = e_contact_get_const (contact, E_CONTACT_UID);
+
+ if (!bepriv->connected || !bepriv->ctx || !bepriv->summary) {
+ if (!e_book_backend_exchange_connect (be, perror)) {
+ g_object_unref (contact);
return;
}
+ }
- if (status == E2K_HTTP_MULTI_STATUS && nresults > 0)
- old_contact = e_contact_from_props (be, &results[0]);
- else
- old_contact = NULL;
+ status = e2k_context_propfind (bepriv->ctx, NULL, uri,
+ field_names, n_field_names,
+ &results, &nresults);
+ if (status == E2K_HTTP_CANCELLED) {
+ g_object_unref (book);
+ g_object_unref (contact);
+ g_propagate_error (perror, EDB_ERROR_EX (OTHER_ERROR, _("Cancelled")));
+ return;
+ }
- props = props_from_contact (be, *contact, old_contact);
- if (!props)
- status = E2K_HTTP_OK;
- else
- status = e2k_context_proppatch (bepriv->ctx, NULL, uri,
- props, FALSE, NULL);
-
- if (E2K_HTTP_STATUS_IS_SUCCESSFUL (status) && GPOINTER_TO_INT (e_contact_get (*contact, E_CONTACT_IS_LIST))) {
- status = merge_contact_lists (be, uri, *contact);
- } else if (E2K_HTTP_STATUS_IS_SUCCESSFUL (status)) {
- /* Do the PUT request if we need to. */
- gchar *old_note, *new_note;
- EContactPhoto *old_photo, *new_photo;
- gboolean changed = FALSE;
-
- old_note = e_contact_get (old_contact, E_CONTACT_NOTE);
- old_photo = e_contact_get (old_contact, E_CONTACT_PHOTO);
- new_note = e_contact_get (*contact, E_CONTACT_NOTE);
- new_photo = e_contact_get (*contact, E_CONTACT_PHOTO);
-
- if ((old_note && !new_note) ||
- (new_note && !old_note) ||
- (old_note && new_note &&
- strcmp (old_note, new_note) != 0))
- changed = TRUE;
- else if ((old_photo && !new_photo) || (new_photo && !old_photo))
- changed = TRUE;
- else if (old_photo && new_photo) {
- if ((old_photo->type == new_photo->type) &&
- old_photo->type == E_CONTACT_PHOTO_TYPE_INLINED) {
- changed = ((old_photo->data.inlined.length == new_photo->data.inlined.length)
- && !memcmp (old_photo->data.inlined.data,
- new_photo->data.inlined.data,
- old_photo->data.inlined.length));
- }
- else if ((old_photo->type == new_photo->type) &&
- old_photo->type == E_CONTACT_PHOTO_TYPE_URI) {
- changed = !strcmp (old_photo->data.uri, new_photo->data.uri);
- }
- }
+ if (status == E2K_HTTP_MULTI_STATUS && nresults > 0)
+ old_contact = e_contact_from_props (be, &results[0]);
+ else
+ old_contact = NULL;
- if (changed) {
- status = do_put (be, book, uri,
- contact_name (*contact),
- new_note, new_photo);
+ props = props_from_contact (be, contact, old_contact);
+ if (!props)
+ status = E2K_HTTP_OK;
+ else
+ status = e2k_context_proppatch (bepriv->ctx, NULL, uri,
+ props, FALSE, NULL);
+
+ if (E2K_HTTP_STATUS_IS_SUCCESSFUL (status) && GPOINTER_TO_INT (e_contact_get (contact, E_CONTACT_IS_LIST))) {
+ status = merge_contact_lists (be, uri, contact);
+ } else if (E2K_HTTP_STATUS_IS_SUCCESSFUL (status)) {
+ /* Do the PUT request if we need to. */
+ gchar *old_note, *new_note;
+ EContactPhoto *old_photo, *new_photo;
+ gboolean changed = FALSE;
+
+ old_note = e_contact_get (old_contact, E_CONTACT_NOTE);
+ old_photo = e_contact_get (old_contact, E_CONTACT_PHOTO);
+ new_note = e_contact_get (contact, E_CONTACT_NOTE);
+ new_photo = e_contact_get (contact, E_CONTACT_PHOTO);
+
+ if ((old_note && !new_note) ||
+ (new_note && !old_note) ||
+ (old_note && new_note &&
+ strcmp (old_note, new_note) != 0))
+ changed = TRUE;
+ else if ((old_photo && !new_photo) || (new_photo && !old_photo))
+ changed = TRUE;
+ else if (old_photo && new_photo) {
+ if ((old_photo->type == new_photo->type) &&
+ old_photo->type == E_CONTACT_PHOTO_TYPE_INLINED) {
+ changed = ((old_photo->data.inlined.length == new_photo->data.inlined.length)
+ && !memcmp (old_photo->data.inlined.data,
+ new_photo->data.inlined.data,
+ old_photo->data.inlined.length));
+ }
+ else if ((old_photo->type == new_photo->type) &&
+ old_photo->type == E_CONTACT_PHOTO_TYPE_URI) {
+ changed = !strcmp (old_photo->data.uri, new_photo->data.uri);
}
+ }
- g_free (old_note);
- g_free (new_note);
- if (old_photo)
- e_contact_photo_free (old_photo);
- if (new_photo)
- e_contact_photo_free (new_photo);
+ if (changed) {
+ status = do_put (be, book, uri,
+ contact_name (contact),
+ new_note, new_photo);
}
- if (old_contact)
- g_object_unref (old_contact);
+ g_free (old_note);
+ g_free (new_note);
+ if (old_photo)
+ e_contact_photo_free (old_photo);
+ if (new_photo)
+ e_contact_photo_free (new_photo);
+ }
- if (nresults)
- e2k_results_free (results, nresults);
+ if (old_contact)
+ g_object_unref (old_contact);
- if (E2K_HTTP_STATUS_IS_SUCCESSFUL (status)) {
- LOCK (bepriv);
- e_book_backend_summary_remove_contact (bepriv->summary,
- uri);
- e_book_backend_summary_add_contact (bepriv->summary,
- *contact);
- e_book_backend_cache_remove_contact (bepriv->cache, uri);
- e_book_backend_cache_add_contact (bepriv->cache, *contact);
- UNLOCK (bepriv);
- return;
- } else {
- g_object_unref (*contact);
- *contact = NULL;
- http_status_to_error (status, perror);
- return;
- }
+ if (nresults)
+ e2k_results_free (results, nresults);
+
+ if (E2K_HTTP_STATUS_IS_SUCCESSFUL (status)) {
+ LOCK (bepriv);
+ e_book_backend_summary_remove_contact (bepriv->summary, uri);
+ e_book_backend_summary_add_contact (bepriv->summary, contact);
+ e_book_backend_cache_remove_contact (bepriv->cache, uri);
+ e_book_backend_cache_add_contact (bepriv->cache, contact);
+ UNLOCK (bepriv);
+
+ *contacts = g_slist_append (NULL, contact);
+ return;
+ } else {
+ g_object_unref (contact);
+ http_status_to_error (status, perror);
+ return;
}
}
@@ -2820,9 +2838,9 @@ e_book_backend_exchange_class_init (EBookBackendExchangeClass *klass)
backend_class->authenticate_user = e_book_backend_exchange_authenticate_user;
sync_class->remove_sync = e_book_backend_exchange_remove;
- sync_class->create_contact_sync = e_book_backend_exchange_create_contact;
+ sync_class->create_contacts_sync = e_book_backend_exchange_create_contacts;
sync_class->remove_contacts_sync = e_book_backend_exchange_remove_contacts;
- sync_class->modify_contact_sync = e_book_backend_exchange_modify_contact;
+ sync_class->modify_contacts_sync = e_book_backend_exchange_modify_contacts;
sync_class->get_contact_sync = e_book_backend_exchange_get_contact;
sync_class->get_contact_list_sync = e_book_backend_exchange_get_contact_list;
sync_class->get_backend_property_sync = e_book_backend_exchange_get_backend_property;
diff --git a/addressbook/e-book-backend-gal.c b/addressbook/e-book-backend-gal.c
index d8e71ca..deecbf9 100644
--- a/addressbook/e-book-backend-gal.c
+++ b/addressbook/e-book-backend-gal.c
@@ -528,15 +528,15 @@ ldap_error_to_response (gint ldap_error)
static void
-create_contact (EBookBackend *backend,
- EDataBook *book,
- guint32 opid,
- GCancellable *cancellable,
- const gchar *vcard)
+create_contacts (EBookBackend *backend,
+ EDataBook *book,
+ guint32 opid,
+ GCancellable *cancellable,
+ const GSList *vcards)
{
- e_data_book_respond_create (book, opid,
- EDB_ERROR (PERMISSION_DENIED),
- NULL);
+ e_data_book_respond_create_contacts (book, opid,
+ EDB_ERROR (PERMISSION_DENIED),
+ NULL);
}
static void
@@ -552,15 +552,15 @@ remove_contacts (EBookBackend *backend,
}
static void
-modify_contact (EBookBackend *backend,
- EDataBook *book,
- guint32 opid,
- GCancellable *cancellable,
- const gchar *vcard)
+modify_contacts (EBookBackend *backend,
+ EDataBook *book,
+ guint32 opid,
+ GCancellable *cancellable,
+ const GSList *vcards)
{
- e_data_book_respond_modify (book, opid,
- EDB_ERROR (PERMISSION_DENIED),
- NULL);
+ e_data_book_respond_modify_contacts (book, opid,
+ EDB_ERROR (PERMISSION_DENIED),
+ NULL);
}
typedef struct {
@@ -3005,9 +3005,9 @@ e_book_backend_gal_class_init (EBookBackendGALClass *class)
backend_class->remove = gal_remove;
backend_class->get_backend_property = gal_get_backend_property;
- backend_class->create_contact = create_contact;
+ backend_class->create_contacts = create_contacts;
backend_class->remove_contacts = remove_contacts;
- backend_class->modify_contact = modify_contact;
+ backend_class->modify_contacts = modify_contacts;
backend_class->get_contact = get_contact;
backend_class->get_contact_list = get_contact_list;
backend_class->start_book_view = start_book_view;
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]