diff options
| author | Christophe Dumez <christophe.dumez@intel.com> | 2011-10-05 16:22:31 +0300 |
|---|---|---|
| committer | Christophe Dumez <christophe.dumez@intel.com> | 2011-10-10 13:12:38 +0300 |
| commit | fbb03706a9f1b625f65d25a59d3fe50dc277058b (patch) | |
| tree | 6ad4861d2d41c95465c021de0a73507c272cd9c4 /addressbook/libedata-book | |
| parent | 7bb77327298819f7845602bfa643281a0cba4e21 (diff) | |
| download | evolution-data-server-fbb03706a9f1b625f65d25a59d3fe50dc277058b.tar.gz | |
e-book-client: Add bulk contact modification methods.
This reduces the number of DBus round-trips and enables
optimizations in the backend.
This patch also makes use of Berkeley DB transactions in the file
backend.
Diffstat (limited to 'addressbook/libedata-book')
| -rw-r--r-- | addressbook/libedata-book/e-book-backend-sync.c | 39 | ||||
| -rw-r--r-- | addressbook/libedata-book/e-book-backend-sync.h | 4 | ||||
| -rw-r--r-- | addressbook/libedata-book/e-book-backend.c | 24 | ||||
| -rw-r--r-- | addressbook/libedata-book/e-book-backend.h | 4 | ||||
| -rw-r--r-- | addressbook/libedata-book/e-data-book.c | 51 | ||||
| -rw-r--r-- | addressbook/libedata-book/e-data-book.h | 2 |
6 files changed, 63 insertions, 61 deletions
diff --git a/addressbook/libedata-book/e-book-backend-sync.c b/addressbook/libedata-book/e-book-backend-sync.c index 7ee5635df..579b1237e 100644 --- a/addressbook/libedata-book/e-book-backend-sync.c +++ b/addressbook/libedata-book/e-book-backend-sync.c @@ -235,32 +235,32 @@ e_book_backend_sync_remove_contacts (EBookBackendSync *backend, } /** - * e_book_backend_sync_modify_contact: + * e_book_backend_sync_modify_contacts: * @backend: an #EBookBackendSync * @book: an #EDataBook * @cancellable: a #GCancellable for the operation - * @vcard: the string representation of a contact - * @contact: a pointer to a location to store the resulting #EContact + * @vcards: the string representations of contacts + * @contacts: a pointer to a location to store the resulting #EContact objects * @error: #GError to set, when something fails * - * Modifies the contact specified by the ID embedded in @vcard, to - * reflect the full contents of @vcard. + * Modifies the contacts specified by the IDs embedded in @vcards, to + * reflect the full contents of @vcards. **/ void -e_book_backend_sync_modify_contact (EBookBackendSync *backend, +e_book_backend_sync_modify_contacts (EBookBackendSync *backend, EDataBook *book, GCancellable *cancellable, - const gchar *vcard, - EContact **contact, + const GSList *vcards, + GSList **contacts, GError **error) { e_return_data_book_error_if_fail (E_IS_BOOK_BACKEND_SYNC (backend), E_DATA_BOOK_STATUS_INVALID_ARG); e_return_data_book_error_if_fail (E_IS_DATA_BOOK (book), E_DATA_BOOK_STATUS_INVALID_ARG); - e_return_data_book_error_if_fail (vcard, E_DATA_BOOK_STATUS_INVALID_ARG); - e_return_data_book_error_if_fail (contact, E_DATA_BOOK_STATUS_INVALID_ARG); - e_return_data_book_error_if_fail (E_BOOK_BACKEND_SYNC_GET_CLASS (backend)->modify_contact_sync, E_DATA_BOOK_STATUS_NOT_SUPPORTED); + e_return_data_book_error_if_fail (vcards, E_DATA_BOOK_STATUS_INVALID_ARG); + e_return_data_book_error_if_fail (contacts, E_DATA_BOOK_STATUS_INVALID_ARG); + e_return_data_book_error_if_fail (E_BOOK_BACKEND_SYNC_GET_CLASS (backend)->modify_contacts_sync, E_DATA_BOOK_STATUS_NOT_SUPPORTED); - (* E_BOOK_BACKEND_SYNC_GET_CLASS (backend)->modify_contact_sync) (backend, book, cancellable, vcard, contact, error); + (* E_BOOK_BACKEND_SYNC_GET_CLASS (backend)->modify_contacts_sync) (backend, book, cancellable, vcards, contacts, error); } /** @@ -519,21 +519,20 @@ book_backend_remove_contacts (EBookBackend *backend, } static void -book_backend_modify_contact (EBookBackend *backend, +book_backend_modify_contacts (EBookBackend *backend, EDataBook *book, guint32 opid, GCancellable *cancellable, - const gchar *vcard) + const GSList *vcards) { GError *error = NULL; - EContact *contact = NULL; + GSList *modified_contacts = NULL; - e_book_backend_sync_modify_contact (E_BOOK_BACKEND_SYNC (backend), book, cancellable, vcard, &contact, &error); + e_book_backend_sync_modify_contacts (E_BOOK_BACKEND_SYNC (backend), book, cancellable, vcards, &modified_contacts, &error); - e_data_book_respond_modify (book, opid, error, contact); + e_data_book_respond_modify_contacts (book, opid, error, modified_contacts); - if (contact) - g_object_unref (contact); + e_util_free_object_slist (modified_contacts); } static void @@ -670,7 +669,7 @@ e_book_backend_sync_class_init (EBookBackendSyncClass *klass) backend_class->set_backend_property = book_backend_set_backend_property; backend_class->create_contacts = book_backend_create_contacts; backend_class->remove_contacts = book_backend_remove_contacts; - backend_class->modify_contact = book_backend_modify_contact; + backend_class->modify_contacts = book_backend_modify_contacts; backend_class->get_contact = book_backend_get_contact; backend_class->get_contact_list = book_backend_get_contact_list; backend_class->get_contact_list_uids = book_backend_get_contact_list_uids; diff --git a/addressbook/libedata-book/e-book-backend-sync.h b/addressbook/libedata-book/e-book-backend-sync.h index 621cdb3e3..de2762442 100644 --- a/addressbook/libedata-book/e-book-backend-sync.h +++ b/addressbook/libedata-book/e-book-backend-sync.h @@ -35,7 +35,7 @@ struct _EBookBackendSyncClass { gboolean (*set_backend_property_sync) (EBookBackendSync *backend, EDataBook *book, GCancellable *cancellable, const gchar *prop_name, const gchar *prop_value, GError **error); void (*create_contacts_sync) (EBookBackendSync *backend, EDataBook *book, GCancellable *cancellable, const GSList *vcards, GSList **added_contacts, GError **error); void (*remove_contacts_sync) (EBookBackendSync *backend, EDataBook *book, GCancellable *cancellable, const GSList *id_list, GSList **removed_ids, GError **error); - void (*modify_contact_sync) (EBookBackendSync *backend, EDataBook *book, GCancellable *cancellable, const gchar *vcard, EContact **contact, GError **error); + void (*modify_contacts_sync) (EBookBackendSync *backend, EDataBook *book, GCancellable *cancellable, const GSList *vcards, GSList **modified_contacts, GError **error); void (*get_contact_sync) (EBookBackendSync *backend, EDataBook *book, GCancellable *cancellable, const gchar *id, gchar **vcard, GError **error); void (*get_contact_list_sync) (EBookBackendSync *backend, EDataBook *book, GCancellable *cancellable, const gchar *query, GSList **contacts, GError **error); void (*get_contact_list_uids_sync) (EBookBackendSync *backend, EDataBook *book, GCancellable *cancellable, const gchar *query, GSList **contacts_uids, GError **error); @@ -54,7 +54,7 @@ gboolean e_book_backend_sync_get_backend_property (EBookBackendSync *backend, ED gboolean e_book_backend_sync_set_backend_property (EBookBackendSync *backend, EDataBook *book, GCancellable *cancellable, const gchar *prop_name, const gchar *prop_value, GError **error); void e_book_backend_sync_create_contacts (EBookBackendSync *backend, EDataBook *book, GCancellable *cancellable, const GSList *vcards, GSList **added_contacts, GError **error); void e_book_backend_sync_remove_contacts (EBookBackendSync *backend, EDataBook *book, GCancellable *cancellable, const GSList *id_list, GSList **removed_ids, GError **error); -void e_book_backend_sync_modify_contact (EBookBackendSync *backend, EDataBook *book, GCancellable *cancellable, const gchar *vcard, EContact **contact, GError **error); +void e_book_backend_sync_modify_contacts (EBookBackendSync *backend, EDataBook *book, GCancellable *cancellable, const GSList *vcards, GSList **modified_contacts, GError **error); void e_book_backend_sync_get_contact (EBookBackendSync *backend, EDataBook *book, GCancellable *cancellable, const gchar *id, gchar **vcard, GError **error); void e_book_backend_sync_get_contact_list (EBookBackendSync *backend, EDataBook *book, GCancellable *cancellable, const gchar *query, GSList **contacts, GError **error); void e_book_backend_sync_get_contact_list_uids (EBookBackendSync *backend, EDataBook *book, GCancellable *cancellable, const gchar *query, GSList **contacts_uids, GError **error); diff --git a/addressbook/libedata-book/e-book-backend.c b/addressbook/libedata-book/e-book-backend.c index 5b691940b..0ef4fc5d1 100644 --- a/addressbook/libedata-book/e-book-backend.c +++ b/addressbook/libedata-book/e-book-backend.c @@ -493,35 +493,35 @@ e_book_backend_remove_contacts (EBookBackend *backend, } /** - * e_book_backend_modify_contact: + * e_book_backend_modify_contacts: * @backend: an #EBookBackend * @book: an #EDataBook * @opid: the ID to use for this operation * @cancellable: a #GCancellable for the operation - * @vcard: the VCard to update + * @vcards: the VCards to update * - * Executes a 'modify contact' request specified by @opid on @book + * Executes a 'modify contacts' request specified by @opid on @book * using @backend. - * This might be finished with e_data_book_respond_modify(). + * This might be finished with e_data_book_respond_modify_contacts(). **/ void -e_book_backend_modify_contact (EBookBackend *backend, +e_book_backend_modify_contacts (EBookBackend *backend, EDataBook *book, guint32 opid, GCancellable *cancellable, - const gchar *vcard) + const GSList *vcards) { g_return_if_fail (E_IS_BOOK_BACKEND (backend)); g_return_if_fail (E_IS_DATA_BOOK (book)); - g_return_if_fail (vcard); - g_return_if_fail (E_BOOK_BACKEND_GET_CLASS (backend)->modify_contact); + g_return_if_fail (vcards); + g_return_if_fail (E_BOOK_BACKEND_GET_CLASS (backend)->modify_contacts); if (e_book_backend_is_opening (backend)) - e_data_book_respond_modify (book, opid, EDB_OPENING_ERROR, NULL); + e_data_book_respond_modify_contacts (book, opid, EDB_OPENING_ERROR, NULL); else if (!e_book_backend_is_opened (backend)) - e_data_book_respond_modify (book, opid, EDB_NOT_OPENED_ERROR, NULL); + e_data_book_respond_modify_contacts (book, opid, EDB_NOT_OPENED_ERROR, NULL); else - (* E_BOOK_BACKEND_GET_CLASS (backend)->modify_contact) (backend, book, opid, cancellable, vcard); + (* E_BOOK_BACKEND_GET_CLASS (backend)->modify_contacts) (backend, book, opid, cancellable, vcards); } /** @@ -1017,7 +1017,7 @@ e_book_backend_sync (EBookBackend *backend) * Notifies all of @backend's book views about the new or modified * contacts @contact. * - * e_data_book_respond_create() and e_data_book_respond_modify() call this + * e_data_book_respond_create_contacts() and e_data_book_respond_modify_contacts() call this * function for you. You only need to call this from your backend if * contacts are created or modified by another (non-PAS-using) client. **/ diff --git a/addressbook/libedata-book/e-book-backend.h b/addressbook/libedata-book/e-book-backend.h index 7e047d97c..214aa4c65 100644 --- a/addressbook/libedata-book/e-book-backend.h +++ b/addressbook/libedata-book/e-book-backend.h @@ -142,7 +142,7 @@ struct _EBookBackendClass { void (* refresh) (EBookBackend *backend, EDataBook *book, guint32 opid, GCancellable *cancellable); void (* create_contacts) (EBookBackend *backend, EDataBook *book, guint32 opid, GCancellable *cancellable, const GSList *vcards); void (* remove_contacts) (EBookBackend *backend, EDataBook *book, guint32 opid, GCancellable *cancellable, const GSList *id_list); - void (* modify_contact) (EBookBackend *backend, EDataBook *book, guint32 opid, GCancellable *cancellable, const gchar *vcard); + void (* modify_contacts) (EBookBackend *backend, EDataBook *book, guint32 opid, GCancellable *cancellable, const GSList *vcards); void (* get_contact) (EBookBackend *backend, EDataBook *book, guint32 opid, GCancellable *cancellable, const gchar *id); void (* get_contact_list) (EBookBackend *backend, EDataBook *book, guint32 opid, GCancellable *cancellable, const gchar *query); void (* get_contact_list_uids) (EBookBackend *backend, EDataBook *book, guint32 opid, GCancellable *cancellable, const gchar *query); @@ -179,7 +179,7 @@ void e_book_backend_remove (EBookBackend *backend, EDataBook *book, guint32 op void e_book_backend_refresh (EBookBackend *backend, EDataBook *book, guint32 opid, GCancellable *cancellable); void e_book_backend_create_contacts (EBookBackend *backend, EDataBook *book, guint32 opid, GCancellable *cancellable, const GSList *vcards); void e_book_backend_remove_contacts (EBookBackend *backend, EDataBook *book, guint32 opid, GCancellable *cancellable, const GSList *id_list); -void e_book_backend_modify_contact (EBookBackend *backend, EDataBook *book, guint32 opid, GCancellable *cancellable, const gchar *vcard); +void e_book_backend_modify_contacts (EBookBackend *backend, EDataBook *book, guint32 opid, GCancellable *cancellable, const GSList *vcards); void e_book_backend_get_contact (EBookBackend *backend, EDataBook *book, guint32 opid, GCancellable *cancellable, const gchar *id); void e_book_backend_get_contact_list (EBookBackend *backend, EDataBook *book, guint32 opid, GCancellable *cancellable, const gchar *query); void e_book_backend_get_contact_list_uids (EBookBackend *backend, EDataBook *book, guint32 opid, GCancellable *cancellable, const gchar *query); diff --git a/addressbook/libedata-book/e-data-book.c b/addressbook/libedata-book/e-data-book.c index 3c0b5d266..fa7223159 100644 --- a/addressbook/libedata-book/e-data-book.c +++ b/addressbook/libedata-book/e-data-book.c @@ -68,7 +68,7 @@ typedef enum { OP_AUTHENTICATE, OP_ADD_CONTACTS, OP_REMOVE_CONTACTS, - OP_MODIFY_CONTACT, + OP_MODIFY_CONTACTS, OP_GET_BACKEND_PROPERTY, OP_SET_BACKEND_PROPERTY, OP_GET_VIEW, @@ -93,9 +93,8 @@ typedef struct { /* OP_REMOVE_CONTACTS */ GSList *ids; /* OP_ADD_CONTACT */ + /* OP_MODIFY_CONTACTS */ GSList *vcards; - /* OP_MODIFY_CONTACT */ - gchar *vcard; /* OP_GET_VIEW */ /* OP_GET_CONTACTS */ /* OP_GET_CONTACTS_UIDS */ @@ -170,9 +169,9 @@ operation_thread (gpointer data, e_book_backend_get_contact_list_uids (backend, op->book, op->id, op->cancellable, op->d.query); g_free (op->d.query); break; - case OP_MODIFY_CONTACT: - e_book_backend_modify_contact (backend, op->book, op->id, op->cancellable, op->d.vcard); - g_free (op->d.vcard); + case OP_MODIFY_CONTACTS: + e_book_backend_modify_contacts (backend, op->book, op->id, op->cancellable, op->d.vcards); + e_util_free_string_slist (op->d.vcards); break; case OP_REMOVE_CONTACTS: e_book_backend_remove_contacts (backend, op->book, op->id, op->cancellable, op->d.ids); @@ -639,25 +638,25 @@ impl_Book_add_contacts (EGdbusBook *object, } static gboolean -impl_Book_modify_contact (EGdbusBook *object, - GDBusMethodInvocation *invocation, - const gchar *in_vcard, - EDataBook *book) +impl_Book_modify_contacts (EGdbusBook *object, + GDBusMethodInvocation *invocation, + const gchar * const *in_vcards, + EDataBook *book) { OperationData *op; - if (in_vcard == NULL) { + if (in_vcards == NULL || !*in_vcards) { GError *error = e_data_book_create_error (E_DATA_BOOK_STATUS_INVALID_QUERY, NULL); /* Translators: This is prefix to a detailed error message */ - data_book_return_error (invocation, error, _("Cannot modify contact: ")); + data_book_return_error (invocation, error, _("Cannot modify contacts: ")); g_error_free (error); return TRUE; } - op = op_new (OP_MODIFY_CONTACT, book); - op->d.vcard = g_strdup (in_vcard); + op = op_new (OP_MODIFY_CONTACTS, book); + op->d.vcards = e_util_strv_to_slist (in_vcards); - e_gdbus_book_complete_modify_contact (book->priv->gdbus_object, invocation, op->id); + e_gdbus_book_complete_modify_contacts (book->priv->gdbus_object, invocation, op->id); e_operation_pool_push (ops_pool, op); return TRUE; @@ -1051,22 +1050,26 @@ e_data_book_respond_create_contacts (EDataBook *book, } void -e_data_book_respond_modify (EDataBook *book, - guint32 opid, - GError *error, - const EContact *contact) +e_data_book_respond_modify_contacts (EDataBook *book, + guint32 opid, + GError *error, + const GSList *contacts) { op_complete (book, opid); /* Translators: This is prefix to a detailed error message */ - g_prefix_error (&error, "%s", _("Cannot modify contact: ")); + g_prefix_error (&error, "%s", _("Cannot modify contacts: ")); - e_gdbus_book_emit_modify_contact_done (book->priv->gdbus_object, opid, error); + e_gdbus_book_emit_modify_contacts_done (book->priv->gdbus_object, opid, error); if (error) { g_error_free (error); } else { - e_book_backend_notify_update (e_data_book_get_backend (book), contact); + const GSList *l; + + for (l = contacts; l != NULL; l = l->next) + e_book_backend_notify_update (e_data_book_get_backend (book), l->data); + e_book_backend_notify_complete (e_data_book_get_backend (book)); } } @@ -1396,8 +1399,8 @@ e_data_book_init (EDataBook *ebook) gdbus_object, "handle-remove-contacts", G_CALLBACK (impl_Book_remove_contacts), ebook); g_signal_connect ( - gdbus_object, "handle-modify-contact", - G_CALLBACK (impl_Book_modify_contact), ebook); + gdbus_object, "handle-modify-contacts", + G_CALLBACK (impl_Book_modify_contacts), ebook); g_signal_connect ( gdbus_object, "handle-get-backend-property", G_CALLBACK (impl_Book_get_backend_property), ebook); diff --git a/addressbook/libedata-book/e-data-book.h b/addressbook/libedata-book/e-data-book.h index 0b900c536..2bd6d6554 100644 --- a/addressbook/libedata-book/e-data-book.h +++ b/addressbook/libedata-book/e-data-book.h @@ -138,7 +138,7 @@ void e_data_book_respond_get_backend_property (EDataBook *book, guint32 opid, G void e_data_book_respond_set_backend_property (EDataBook *book, guint32 opid, GError *error); void e_data_book_respond_create_contacts (EDataBook *book, guint32 opid, GError *error, const GSList *contacts); void e_data_book_respond_remove_contacts (EDataBook *book, guint32 opid, GError *error, const GSList *ids); -void e_data_book_respond_modify (EDataBook *book, guint32 opid, GError *error, const EContact *contact); +void e_data_book_respond_modify_contacts (EDataBook *book, guint32 opid, GError *error, const GSList *contacts); void e_data_book_respond_get_contact (EDataBook *book, guint32 opid, GError *error, const gchar *vcard); void e_data_book_respond_get_contact_list (EDataBook *book, guint32 opid, GError *error, const GSList *cards); void e_data_book_respond_get_contact_list_uids (EDataBook *book, guint32 opid, GError *error, const GSList *uids); |
