[evolution-couchdb] Added code to retrieve email addresses



commit 26b315a4d1be7a9b484d3a4d463c36210e29e122
Author: Rodrigo Moya <rodrigo gnome-db org>
Date:   Fri Jun 19 17:25:19 2009 +0200

    Added code to retrieve email addresses

 addressbook/e-book-backend-couchdb.c |   35 ++++++++++++++++++++++++++++++++-
 addressbook/e-book-backend-couchdb.h |    1 +
 2 files changed, 34 insertions(+), 2 deletions(-)
---
diff --git a/addressbook/e-book-backend-couchdb.c b/addressbook/e-book-backend-couchdb.c
index 863b16b..c6e1846 100644
--- a/addressbook/e-book-backend-couchdb.c
+++ b/addressbook/e-book-backend-couchdb.c
@@ -31,6 +31,7 @@ vcard_from_couch_document (CouchDBDocument *document)
 	EContact *contact;
 	char *str;
 	GSList *list, *sl;
+	GList *attr_list;
 
 	if (!couchdb_document_is_contact (document))
 		return NULL;
@@ -43,15 +44,45 @@ vcard_from_couch_document (CouchDBDocument *document)
 		       (const gpointer) couchdb_document_contact_get_last_name (document));
 
 	/* parse email addresses */
+	attr_list = NULL;
+
 	list = couchdb_document_contact_get_email_addresses (document);
 	while (list != NULL) {
+		const char *email_str, *description_str;
+		EVCardAttribute *attr;
 		CouchDBStructField *email_address = (CouchDBStructField *) list->data;
 
-		
+		email_str = couchdb_document_contact_email_get_address (email_address);
+		description_str = couchdb_document_contact_email_get_description (email_address);
+		g_print ("email = %s, description = %s\n", email_str, description_str);
+
+		attr = e_vcard_attribute_new ("", e_contact_vcard_attribute (E_CONTACT_EMAIL));
+		if (description_str) {
+			EVCardAttributeParam *param;
+
+			param = e_vcard_attribute_param_new (EVC_TYPE);
+			if (!g_ascii_strcasecmp (description_str, "home"))
+				e_vcard_attribute_add_param_with_value (attr, param, "HOME");
+			else if (!g_ascii_strcasecmp (description_str, "work"))
+				e_vcard_attribute_add_param_with_value (attr, param, "WORK");
+			else
+				e_vcard_attribute_param_free (param);
+		}
+
+		e_vcard_attribute_add_value (attr, email_str);
+		attr_list = g_list_append (attr_list, attr);
+
+		/* remove address from list */
 		list = g_slist_remove (list, email_address);
 		couchdb_struct_field_unref (email_address);
 	}
 
+	if (attr_list) {
+		e_contact_set_attributes (contact, E_CONTACT_EMAIL, attr_list);
+		g_list_foreach (attr_list, (GFunc) e_vcard_attribute_free, NULL);
+		g_list_free (attr_list);
+	}
+
 	/* birth date */
 	str = (char *) couchdb_document_contact_get_birth_date (document);
 	if (str) {
@@ -134,7 +165,7 @@ e_book_backend_couchdb_remove (EBookBackend *backend, EDataBook *book, guint32 o
 static char *
 e_book_backend_couchdb_get_static_capabilities (EBookBackend *backend)
 {
-	return g_strdup("local,do-initial-query,bulk-removes,contact-lists");
+	return g_strdup ("local,do-initial-query,bulk-removes,contact-lists");
 }
 
 static void
diff --git a/addressbook/e-book-backend-couchdb.h b/addressbook/e-book-backend-couchdb.h
index b1bc93a..0fa1cf0 100644
--- a/addressbook/e-book-backend-couchdb.h
+++ b/addressbook/e-book-backend-couchdb.h
@@ -25,6 +25,7 @@
 #define __E_BOOK_BACKEND_COUCHDB_H__
 
 #include <couchdb-glib.h>
+#include <couchdb-document-contact.h>
 #include <libedata-book/e-book-backend.h>
 
 #define E_TYPE_BOOK_BACKEND_COUCHDB        (e_book_backend_couchdb_get_type ())



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]