[evolution-couchdb] Notify Evolution of modified contacts from the documents stored in the database, not the original on
- From: Rodrigo Moya <rodrigo src gnome org>
- To: svn-commits-list gnome org
- Cc:
- Subject: [evolution-couchdb] Notify Evolution of modified contacts from the documents stored in the database, not the original on
- Date: Mon, 26 Oct 2009 17:39:21 +0000 (UTC)
commit 01c2aaf35ac9c625152f76285f08333ce3192fb8
Author: Rodrigo Moya <rodrigo gnome-db org>
Date: Mon Oct 26 18:39:08 2009 +0100
Notify Evolution of modified contacts from the documents stored in the database, not the original ones from Evolution
addressbook/e-book-backend-couchdb.c | 50 ++++++++++++++++++++++-----------
1 files changed, 33 insertions(+), 17 deletions(-)
---
diff --git a/addressbook/e-book-backend-couchdb.c b/addressbook/e-book-backend-couchdb.c
index 834df63..9bf32eb 100644
--- a/addressbook/e-book-backend-couchdb.c
+++ b/addressbook/e-book-backend-couchdb.c
@@ -908,7 +908,7 @@ e_book_backend_couchdb_load_source (EBookBackend *backend,
uri = g_strdup_printf ("http://127.0.0.1:%d", port);
/* Get OAuth tokens from GnomeKeyring */
- attrs = gnome_keyring_attribute_list_new();
+ attrs = gnome_keyring_attribute_list_new ();
gnome_keyring_attribute_list_append_string (attrs, "desktopcouch", "oauth");
result = gnome_keyring_find_items_sync (GNOME_KEYRING_ITEM_GENERIC_SECRET,
@@ -1026,15 +1026,40 @@ e_book_backend_couchdb_get_static_capabilities (EBookBackend *backend)
return g_strdup ("local,do-initial-query,bulk-removes,contact-lists");
}
+static EContact *
+put_document (EBookBackendCouchDB *couchdb_backend, CouchDBDocument *document)
+{
+ GError *error = NULL;
+
+ if (couchdb_document_put (document, couchdb_backend->dbname, &error)) {
+ EContact *new_contact;
+ char *vcard_str;
+
+ /* couchdb_document_put sets the ID for new documents, so need to send that back */
+ vcard_str = vcard_from_couch_document (document);
+ new_contact = e_contact_new_from_vcard (vcard_str);
+
+ g_free (vcard_str);
+
+ return new_contact;
+ } else {
+ if (error != NULL) {
+ g_warning ("Could not PUT document: %s\n", error->message);
+ g_error_free (error);
+ }
+ }
+
+ return NULL;
+}
+
static void
e_book_backend_couchdb_create_contact (EBookBackend *backend,
EDataBook *book,
guint32 opid,
const char *vcard)
{
- EContact *contact;
+ EContact *contact, *new_contact;
CouchDBDocument *document;
- GError *error = NULL;
EBookBackendCouchDB *couchdb_backend = E_BOOK_BACKEND_COUCHDB (backend);
contact = e_contact_new_from_vcard (vcard);
@@ -1051,17 +1076,8 @@ e_book_backend_couchdb_create_contact (EBookBackend *backend,
}
/* save the contact into the DB */
- if (couchdb_document_put (document, couchdb_backend->dbname, &error)) {
- EContact *new_contact;
- char *vcard_str;
-
- /* couchdb_document_put sets the ID for new documents, so need to send that back */
- vcard_str = vcard_from_couch_document (document);
- new_contact = e_contact_new_from_vcard (vcard_str);
-
+ if ((new_contact = put_document (couchdb_backend, document)) != NULL) {
e_data_book_respond_create (book, opid, GNOME_Evolution_Addressbook_Success, new_contact);
-
- g_free (vcard_str);
g_object_unref (new_contact);
} else
e_data_book_respond_create (book, opid, GNOME_Evolution_Addressbook_OtherError, NULL);
@@ -1120,9 +1136,8 @@ e_book_backend_couchdb_modify_contact (EBookBackend *backend,
guint32 opid,
const char *vcard)
{
- EContact *contact;
+ EContact *contact, *new_contact;
CouchDBDocument *document;
- GError *error = NULL;
EBookBackendCouchDB *couchdb_backend = E_BOOK_BACKEND_COUCHDB (backend);
contact = e_contact_new_from_vcard (vcard);
@@ -1139,8 +1154,9 @@ e_book_backend_couchdb_modify_contact (EBookBackend *backend,
}
/* save the contact into the DB */
- if (couchdb_document_put (document, couchdb_backend->dbname, &error)) {
- e_data_book_respond_modify (book, opid, GNOME_Evolution_Addressbook_Success, contact);
+ if ((new_contact = put_document (couchdb_backend, document)) != NULL) {
+ e_data_book_respond_modify (book, opid, GNOME_Evolution_Addressbook_Success, new_contact);
+ g_object_unref (new_contact);
} else
e_data_book_respond_modify (book, opid, GNOME_Evolution_Addressbook_OtherError, NULL);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]