[evolution-couchdb] Implemented create_contact backend method



commit 5f74f84dc7389e5d8252c67d905b37395d2e035c
Author: Rodrigo Moya <rodrigo gnome-db org>
Date:   Mon Jun 22 17:50:00 2009 +0200

    Implemented create_contact backend method

 addressbook/e-book-backend-couchdb.c |   45 ++++++++++++++++++++++++++++++++-
 1 files changed, 43 insertions(+), 2 deletions(-)
---
diff --git a/addressbook/e-book-backend-couchdb.c b/addressbook/e-book-backend-couchdb.c
index 59211ae..70e1c2f 100644
--- a/addressbook/e-book-backend-couchdb.c
+++ b/addressbook/e-book-backend-couchdb.c
@@ -225,10 +225,51 @@ e_book_backend_couchdb_create_contact (EBookBackend *backend,
 				       guint32 opid,
 				       const char *vcard)
 {
+	EContact *contact;
+	CouchDBDocument *document;
+	EContactDate *dt;
+	char *uid;
+	GError *error = NULL;
 	EBookBackendCouchDB *couchdb_backend = E_BOOK_BACKEND_COUCHDB (backend);
+	static guint uid_count = 0;
 
-	/* FIXME */
-	e_data_book_respond_create(book, opid, GNOME_Evolution_Addressbook_OtherError, NULL);
+	contact = e_contact_new_from_vcard (vcard);
+	if (!contact) {
+		e_data_book_respond_create (book, opid, GNOME_Evolution_Addressbook_OtherError, NULL);
+		return;
+	}
+
+	uid = g_strdup_printf ("%08lX%08X", time (NULL), uid_count++);
+	e_contact_set (contact, E_CONTACT_UID, uid);
+	g_free (uid);
+
+	/* create the CouchDBDocument to put on the database */
+	document = couchdb_document_new (couchdb_backend->couchdb);
+	couchdb_document_set_id (document, (const char *) e_contact_get (contact, E_CONTACT_UID));
+
+	couchdb_document_contact_set_first_name (document, (const char *) e_contact_get (contact, E_CONTACT_GIVEN_NAME));
+	couchdb_document_contact_set_last_name (document, (const char *) e_contact_get (contact, E_CONTACT_FAMILY_NAME));
+	/* FIXME: email_addresses */
+	/* FIXME: phone numbers */
+	/* FIXME: addresses */
+
+	dt = (EContactDate *) e_contact_get (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);
+	}
+
+	/* save the contact into the DB */
+	if (couchdb_document_put (document, &error))
+		e_data_book_respond_create (book, opid, GNOME_Evolution_Addressbook_Success, contact);
+	else
+		e_data_book_respond_create (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]