[evolution-groupwise] Adapt to EBookBackend API changes
- From: Milan Crha <mcrha src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [evolution-groupwise] Adapt to EBookBackend API changes
- Date: Mon, 10 Oct 2011 10:50:01 +0000 (UTC)
commit eccebbe8a4b93c2273d0e436cf954afef8f8a02c
Author: Milan Crha <mcrha redhat com>
Date: Mon Oct 10 12:49:49 2011 +0200
Adapt to EBookBackend API changes
src/addressbook/e-book-backend-groupwise.c | 84 +++++++++++++++++++---------
1 files changed, 58 insertions(+), 26 deletions(-)
---
diff --git a/src/addressbook/e-book-backend-groupwise.c b/src/addressbook/e-book-backend-groupwise.c
index 9e7a945..783939e 100644
--- a/src/addressbook/e-book-backend-groupwise.c
+++ b/src/addressbook/e-book-backend-groupwise.c
@@ -1215,11 +1215,11 @@ fill_contact_from_gw_item (EContact *contact,
}
static void
-e_book_backend_groupwise_create_contact (EBookBackend *backend,
- EDataBook *book,
- guint32 opid,
- GCancellable *cancellable,
- const gchar *vcard)
+e_book_backend_groupwise_create_contacts (EBookBackend *backend,
+ EDataBook *book,
+ guint32 opid,
+ GCancellable *cancellable,
+ const GSList *vcards)
{
EContact *contact;
EBookBackendGroupwise *egwb;
@@ -1236,19 +1236,30 @@ e_book_backend_groupwise_create_contact (EBookBackend *backend,
egwb = E_BOOK_BACKEND_GROUPWISE (backend);
if (!e_backend_get_online (E_BACKEND (backend))) {
- e_data_book_respond_create (book, opid, EDB_ERROR (REPOSITORY_OFFLINE), NULL);
+ e_data_book_respond_create_contacts (book, opid, EDB_ERROR (REPOSITORY_OFFLINE), NULL);
return;
}
if (egwb->priv->cnc == NULL) {
- e_data_book_respond_create (book, opid, EDB_ERROR (AUTHENTICATION_REQUIRED), NULL);
+ e_data_book_respond_create_contacts (book, opid, EDB_ERROR (AUTHENTICATION_REQUIRED), NULL);
return;
}
if (egwb->priv->is_readonly) {
- 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);
return;
}
- contact = e_contact_new_from_vcard (vcard);
+
+ /* 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) {
+ e_data_book_respond_create_contacts (book, opid,
+ EDB_ERROR_EX (NOT_SUPPORTED,
+ _("The backend does not support bulk additions")),
+ NULL);
+ return;
+ }
+
+ contact = e_contact_new_from_vcard (vcards->data);
item = e_gw_item_new_empty ();
e_gw_item_set_item_type (item, e_contact_get (contact, E_CONTACT_IS_LIST) ? E_GW_ITEM_TYPE_GROUP :E_GW_ITEM_TYPE_CONTACT);
e_gw_item_set_container_id (item, g_strdup (egwb->priv->container_id));
@@ -1277,14 +1288,19 @@ e_book_backend_groupwise_create_contact (EBookBackend *backend,
/* Make sure server has returned an id for the created contact */
if (status == E_GW_CONNECTION_STATUS_OK && id) {
+ GSList *added_contacts;
+
e_contact_set (contact, E_CONTACT_UID, id);
g_free (id);
e_book_backend_db_cache_add_contact (egwb->priv->file_db, contact);
egwb->priv->file_db->sync (egwb->priv->file_db, 0);
e_book_backend_summary_add_contact (egwb->priv->summary, contact);
- e_data_book_respond_create (book, opid, EDB_ERROR (SUCCESS), contact);
+
+ added_contacts = g_slist_append (NULL, contact);
+ e_data_book_respond_create_contacts (book, opid, EDB_ERROR (SUCCESS), added_contacts);
+ e_util_free_object_slist (added_contacts);
} else {
- e_data_book_respond_create (book, opid, EDB_ERROR_FAILED_STATUS (OTHER_ERROR, status), NULL);
+ e_data_book_respond_create_contacts (book, opid, EDB_ERROR_FAILED_STATUS (OTHER_ERROR, status), NULL);
}
g_object_unref (item);
}
@@ -1371,11 +1387,11 @@ set_changes_in_gw_item (EGwItem *new_item,
}
static void
-e_book_backend_groupwise_modify_contact (EBookBackend *backend,
- EDataBook *book,
- guint32 opid,
- GCancellable *cancellable,
- const gchar *vcard)
+e_book_backend_groupwise_modify_contacts (EBookBackend *backend,
+ EDataBook *book,
+ guint32 opid,
+ GCancellable *cancellable,
+ const GSList *vcards)
{
EContact *contact;
EBookBackendGroupwise *egwb;
@@ -1392,19 +1408,30 @@ e_book_backend_groupwise_modify_contact (EBookBackend *backend,
egwb = E_BOOK_BACKEND_GROUPWISE (backend);
if (!e_backend_get_online (E_BACKEND (backend))) {
- e_data_book_respond_modify (book, opid, EDB_ERROR (REPOSITORY_OFFLINE), NULL);
+ e_data_book_respond_modify_contacts (book, opid, EDB_ERROR (REPOSITORY_OFFLINE), NULL);
return;
}
if (egwb->priv->cnc == NULL) {
- e_data_book_respond_modify (book, opid, EDB_ERROR (AUTHENTICATION_REQUIRED), NULL);
+ e_data_book_respond_modify_contacts (book, opid, EDB_ERROR (AUTHENTICATION_REQUIRED), NULL);
return;
}
if (egwb->priv->is_readonly) {
- 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);
return;
}
- contact = e_contact_new_from_vcard (vcard);
+
+ /* 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) {
+ e_data_book_respond_modify_contacts (book, opid,
+ EDB_ERROR_EX (NOT_SUPPORTED,
+ _("The backend does not support bulk modifications")),
+ NULL);
+ return;
+ }
+
+ contact = e_contact_new_from_vcard (vcards->data);
new_item = e_gw_item_new_empty ();
for (i = 0; i < G_N_ELEMENTS (mappings); i++) {
@@ -1429,12 +1456,12 @@ e_book_backend_groupwise_modify_contact (EBookBackend *backend,
status = e_gw_connection_get_item (egwb->priv->cnc, egwb->priv->container_id, id, NULL, &old_item);
if (old_item == NULL) {
- e_data_book_respond_modify (book, opid, EDB_ERROR (CONTACT_NOT_FOUND), NULL);
+ e_data_book_respond_modify_contacts (book, opid, EDB_ERROR (CONTACT_NOT_FOUND), NULL);
return;
}
if (status != E_GW_CONNECTION_STATUS_OK) {
- e_data_book_respond_modify (book, opid, EDB_ERROR_FAILED_STATUS (OTHER_ERROR, status), NULL);
+ e_data_book_respond_modify_contacts (book, opid, EDB_ERROR_FAILED_STATUS (OTHER_ERROR, status), NULL);
return;
}
@@ -1446,14 +1473,19 @@ e_book_backend_groupwise_modify_contact (EBookBackend *backend,
e_gw_item_set_item_type (new_item, e_gw_item_get_item_type (old_item));
status = e_gw_connection_modify_item (egwb->priv->cnc, id, new_item);
if (status == E_GW_CONNECTION_STATUS_OK) {
- e_data_book_respond_modify (book, opid, EDB_ERROR (SUCCESS), contact);
+ GSList *modified_contacts;
+
e_book_backend_db_cache_remove_contact (egwb->priv->file_db, id);
e_book_backend_summary_remove_contact (egwb->priv->summary, id);
e_book_backend_db_cache_add_contact (egwb->priv->file_db, contact);
egwb->priv->file_db->sync (egwb->priv->file_db, 0);
e_book_backend_summary_add_contact (egwb->priv->summary, contact);
+
+ modified_contacts = g_slist_append (NULL, contact);
+ e_data_book_respond_modify_contacts (book, opid, EDB_ERROR (SUCCESS), modified_contacts);
+ e_util_free_object_slist (modified_contacts);
} else
- e_data_book_respond_modify (book, opid, EDB_ERROR_FAILED_STATUS (OTHER_ERROR, status), NULL);
+ e_data_book_respond_modify_contacts (book, opid, EDB_ERROR_FAILED_STATUS (OTHER_ERROR, status), NULL);
g_object_unref (new_item);
g_object_ref (old_item);
g_object_unref (contact);
@@ -3830,9 +3862,9 @@ e_book_backend_groupwise_class_init (EBookBackendGroupwiseClass *klass)
parent_class->open = e_book_backend_groupwise_open;
parent_class->get_backend_property = e_book_backend_groupwise_get_backend_property;
- parent_class->create_contact = e_book_backend_groupwise_create_contact;
+ parent_class->create_contacts = e_book_backend_groupwise_create_contacts;
parent_class->remove_contacts = e_book_backend_groupwise_remove_contacts;
- parent_class->modify_contact = e_book_backend_groupwise_modify_contact;
+ parent_class->modify_contacts = e_book_backend_groupwise_modify_contacts;
parent_class->get_contact = e_book_backend_groupwise_get_contact;
parent_class->get_contact_list = e_book_backend_groupwise_get_contact_list;
parent_class->start_book_view = e_book_backend_groupwise_start_book_view;
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]