[evolution-couchdb] Moved CouchDBDocument creation code to couch_document_from_contact function.
- From: Rodrigo Moya <rodrigo src gnome org>
- To: svn-commits-list gnome org
- Subject: [evolution-couchdb] Moved CouchDBDocument creation code to couch_document_from_contact function.
- Date: Wed, 24 Jun 2009 15:26:23 +0000 (UTC)
commit 2271e3e5447b275ba3dec452cab5d97091eaf383
Author: Rodrigo Moya <rodrigo gnome-db org>
Date: Wed Jun 24 16:36:50 2009 +0200
Moved CouchDBDocument creation code to couch_document_from_contact function.
Added missing e_book_backend_couchdb_modify_contact implementation.
addressbook/e-book-backend-couchdb.c | 197 ++++++++++++++++++++--------------
1 files changed, 118 insertions(+), 79 deletions(-)
---
diff --git a/addressbook/e-book-backend-couchdb.c b/addressbook/e-book-backend-couchdb.c
index 8178562..4b79713 100644
--- a/addressbook/e-book-backend-couchdb.c
+++ b/addressbook/e-book-backend-couchdb.c
@@ -155,6 +155,89 @@ vcard_from_couch_document (CouchDBDocument *document)
return str;
}
+static CouchDBDocument *
+couch_document_from_contact (EBookBackendCouchDB *couchdb_backend, EContact *contact)
+{
+ EContactDate *dt;
+ GSList *list;
+ gint i;
+ const char *str;
+ CouchDBDocument *document;
+
+ /* create the CouchDBDocument to put on the database */
+ document = couchdb_document_new (couchdb_backend->couchdb);
+
+ couchdb_document_contact_set_first_name (document, (const char *) e_contact_get_const (contact, E_CONTACT_GIVEN_NAME));
+ couchdb_document_contact_set_last_name (document, (const char *) e_contact_get_const (contact, E_CONTACT_FAMILY_NAME));
+
+ /* email addresses */
+ list = NULL;
+ for (i = E_CONTACT_FIRST_EMAIL_ID; i <= E_CONTACT_LAST_EMAIL_ID; i++) {
+ const gchar *email;
+
+ email = e_contact_get_const (contact, i);
+ if (email) {
+ CouchDBStructField *sf;
+
+ sf = couchdb_document_contact_email_new (email, /* FIXME */ NULL);
+ list = g_slist_append (list, sf);
+ }
+ }
+
+ if (list) {
+ couchdb_document_contact_set_email_addresses (document, list);
+
+ g_slist_foreach (list, (GFunc) couchdb_struct_field_unref, NULL);
+ g_slist_free (list);
+ }
+
+ /* phone numbers */
+ list = NULL;
+ str = e_contact_get_const (contact, E_CONTACT_PHONE_HOME);
+ if (str) {
+ CouchDBStructField *sf;
+
+ sf = couchdb_document_contact_phone_new (str, "home", /* FIXME */ 0);
+ list = g_slist_append (list, sf);
+ }
+
+ str = e_contact_get_const (contact, E_CONTACT_PHONE_BUSINESS);
+ if (str) {
+ CouchDBStructField *sf;
+
+ sf = couchdb_document_contact_phone_new (str, "work", /* FIXME */ 0);
+ list = g_slist_append (list, sf);
+ }
+
+ str = e_contact_get_const (contact, E_CONTACT_PHONE_OTHER);
+ if (str) {
+ CouchDBStructField *sf;
+
+ sf = couchdb_document_contact_phone_new (str, "other", /* FIXME */ 0);
+ list = g_slist_append (list, sf);
+ }
+
+ if (list) {
+ couchdb_document_contact_set_phone_numbers (document, list);
+
+ g_slist_foreach (list, (GFunc) couchdb_struct_field_unref, NULL);
+ g_slist_free (list);
+ }
+
+ /* FIXME: addresses */
+
+ /* birth date */
+ dt = (EContactDate *) e_contact_get_const (contact, E_CONTACT_BIRTH_DATE);
+ if (dt) {
+ char *dt_str = e_contact_date_to_string (dt);
+ couchdb_document_contact_set_birth_date (document, (const char *) dt_str);
+
+ g_free (dt_str);
+ }
+
+ return document;
+}
+
static GNOME_Evolution_Addressbook_CallStatus
e_book_backend_couchdb_load_source (EBookBackend *backend,
ESource *source,
@@ -228,13 +311,8 @@ e_book_backend_couchdb_create_contact (EBookBackend *backend,
{
EContact *contact;
CouchDBDocument *document;
- EContactDate *dt;
GError *error = NULL;
- GSList *list;
- gint i;
- const char *str;
EBookBackendCouchDB *couchdb_backend = E_BOOK_BACKEND_COUCHDB (backend);
- static guint uid_count = 0;
contact = e_contact_new_from_vcard (vcard);
if (!contact) {
@@ -242,75 +320,11 @@ e_book_backend_couchdb_create_contact (EBookBackend *backend,
return;
}
- /* create the CouchDBDocument to put on the database */
- document = couchdb_document_new (couchdb_backend->couchdb);
-
- couchdb_document_contact_set_first_name (document, (const char *) e_contact_get_const (contact, E_CONTACT_GIVEN_NAME));
- couchdb_document_contact_set_last_name (document, (const char *) e_contact_get_const (contact, E_CONTACT_FAMILY_NAME));
-
- /* email addresses */
- list = NULL;
- for (i = E_CONTACT_FIRST_EMAIL_ID; i <= E_CONTACT_LAST_EMAIL_ID; i++) {
- const gchar *email;
-
- email = e_contact_get_const (contact, i);
- if (email) {
- CouchDBStructField *sf;
-
- sf = couchdb_document_contact_email_new (email, /* FIXME */ NULL);
- list = g_slist_append (list, sf);
- }
- }
-
- if (list) {
- couchdb_document_contact_set_email_addresses (document, list);
-
- g_slist_foreach (list, (GFunc) couchdb_struct_field_unref, NULL);
- g_slist_free (list);
- }
-
- /* phone numbers */
- list = NULL;
- str = e_contact_get_const (contact, E_CONTACT_PHONE_HOME);
- if (str) {
- CouchDBStructField *sf;
-
- sf = couchdb_document_contact_phone_new (str, "home", /* FIXME */ 0);
- list = g_slist_append (list, sf);
- }
-
- str = e_contact_get_const (contact, E_CONTACT_PHONE_BUSINESS);
- if (str) {
- CouchDBStructField *sf;
-
- sf = couchdb_document_contact_phone_new (str, "work", /* FIXME */ 0);
- list = g_slist_append (list, sf);
- }
-
- str = e_contact_get_const (contact, E_CONTACT_PHONE_OTHER);
- if (str) {
- CouchDBStructField *sf;
-
- sf = couchdb_document_contact_phone_new (str, "other", /* FIXME */ 0);
- list = g_slist_append (list, sf);
- }
-
- if (list) {
- couchdb_document_contact_set_phone_numbers (document, list);
-
- g_slist_foreach (list, (GFunc) couchdb_struct_field_unref, NULL);
- g_slist_free (list);
- }
-
- /* FIXME: addresses */
-
- /* birth date */
- dt = (EContactDate *) e_contact_get_const (contact, E_CONTACT_BIRTH_DATE);
- if (dt) {
- char *dt_str = e_contact_date_to_string (dt);
- couchdb_document_contact_set_birth_date (document, (const char *) dt_str);
-
- g_free (dt_str);
+ document = couch_document_from_contact (couchdb_backend, contact);
+ if (!document) {
+ e_data_book_respond_create (book, opid, GNOME_Evolution_Addressbook_OtherError, NULL);
+ g_object_unref (G_OBJECT (document));
+ return;
}
/* save the contact into the DB */
@@ -337,12 +351,37 @@ e_book_backend_couchdb_remove_contacts (EBookBackend *backend,
static void
e_book_backend_couchdb_modify_contact (EBookBackend *backend,
- EDataBook *book,
- guint32 opid,
- const char *vcard)
+ EDataBook *book,
+ guint32 opid,
+ const char *vcard)
{
- /* FIXME */
- e_data_book_respond_modify (book, opid, GNOME_Evolution_Addressbook_OtherError, NULL);
+ EContact *contact;
+ CouchDBDocument *document;
+ GError *error = NULL;
+ EBookBackendCouchDB *couchdb_backend = E_BOOK_BACKEND_COUCHDB (backend);
+
+ contact = e_contact_new_from_vcard (vcard);
+ if (!contact) {
+ e_data_book_respond_modify (book, opid, GNOME_Evolution_Addressbook_OtherError, NULL);
+ return;
+ }
+
+ document = couch_document_from_contact (couchdb_backend, contact);
+ if (!document) {
+ e_data_book_respond_modify (book, opid, GNOME_Evolution_Addressbook_OtherError, NULL);
+ g_object_unref (G_OBJECT (document));
+ return;
+ }
+
+ /* 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);
+ } else
+ e_data_book_respond_modify (book, opid, GNOME_Evolution_Addressbook_OtherError, NULL);
+
+ /* free memory */
+ g_object_unref (G_OBJECT (contact));
+ g_object_unref (G_OBJECT (document));
}
static void
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]