[evolution-couchdb] s fixes the losing of the postal addresses when saving contacts in Evolution,



commit d4030dad34573ab64841b6a29a860afe99d8ab78
Author: Rodrigo Moya <rodrigo gnome-db org>
Date:   Mon Nov 16 19:04:19 2009 +0100

    s fixes the losing of the postal addresses when saving contacts in Evolution,
    which I broke by using e_contact_get_const instead of e_contact_get. Also,
    it deals correctly with multiline address' streets

 addressbook/e-book-backend-couchdb.c |   96 ++++++++++++++++++---------------
 1 files changed, 52 insertions(+), 44 deletions(-)
---
diff --git a/addressbook/e-book-backend-couchdb.c b/addressbook/e-book-backend-couchdb.c
index 6c957d8..b30c1d2 100644
--- a/addressbook/e-book-backend-couchdb.c
+++ b/addressbook/e-book-backend-couchdb.c
@@ -260,13 +260,23 @@ vcard_from_couch_document (CouchDBDocument *document)
 	/* parse postal addresses */
 	list = couchdb_document_contact_get_addresses (document);
 	while (list != NULL) {
+		char **street_lines;
 		const char *description_str;
 		EContactAddress *contact_address;
 		CouchDBStructField *address = (CouchDBStructField *) list->data;
 
 		contact_address = g_new0 (EContactAddress, 1);
 		contact_address->address_format = g_strdup ("");
-		contact_address->street = g_strdup (couchdb_document_contact_address_get_street (address));
+
+		street_lines = g_strsplit (couchdb_document_contact_address_get_street (address), "\n", 2);
+		if (street_lines != NULL) {
+			contact_address->street = g_strdup (street_lines[0]);
+			if (street_lines[1] != NULL)
+				contact_address->ext = g_strdup (street_lines[1]);
+			g_strfreev (street_lines);
+		} else
+			contact_address->street = g_strdup (couchdb_document_contact_address_get_street (address));
+
 		contact_address->locality = g_strdup (couchdb_document_contact_address_get_city (address));
 		contact_address->region = g_strdup (couchdb_document_contact_address_get_state (address));
 		contact_address->country = g_strdup (couchdb_document_contact_address_get_country (address));
@@ -544,6 +554,37 @@ contact_phone_to_struct_field (EVCardAttribute *attr)
 }
 
 static CouchDBStructField *
+contact_postal_address_to_struct_field (EContact *contact, EContactField field, const char *description)
+{
+	CouchDBStructField *sf = NULL;
+	EContactAddress *contact_address;
+
+	contact_address = e_contact_get (contact, field);
+	if (contact_address) {
+		char *street = NULL;
+
+		if (contact_address->ext && *contact_address->ext)
+			street = g_strdup_printf ("%s\n%s", contact_address->street, contact_address->ext);
+		else if (contact_address->street && *contact_address->street)
+			street = g_strdup (contact_address->street);
+
+		sf = couchdb_document_contact_address_new (/* FIXME */ NULL,
+							   street,
+							   contact_address->locality,
+							   contact_address->region,
+							   contact_address->country,
+							   contact_address->code,
+							   contact_address->po,
+							   description);
+		
+		e_contact_address_free (contact_address);
+		g_free (street);
+	}
+
+	return sf;
+}
+
+static CouchDBStructField *
 contact_url_to_struct_field (EVCardAttribute *attr, const gchar *description)
 {
 	const gchar *address, *uuid;
@@ -618,7 +659,7 @@ couch_document_from_contact (EBookBackendCouchDB *couchdb_backend, EContact *con
 	const char *str;
 	CouchDBDocument *document;
 	gint i;
-	const EContactAddress *contact_address;
+	CouchDBStructField *postal_address;
 
 	/* create the CouchDBDocument to put on the database */
 	document = couchdb_document_contact_new (couchdb_backend->couchdb);
@@ -687,50 +728,17 @@ couch_document_from_contact (EBookBackendCouchDB *couchdb_backend, EContact *con
 
 	/* postal addresses */
 	list = NULL;
-	contact_address = e_contact_get_const (contact, E_CONTACT_ADDRESS_HOME);
-	if (contact_address) {
-		CouchDBStructField *sf;
-
-		sf = couchdb_document_contact_address_new (/* FIXME */ NULL,
-							   contact_address->street,
-							   contact_address->locality,
-							   contact_address->region,
-							   contact_address->country,
-							   contact_address->code,
-							   contact_address->po,
-							   "home");
-		list = g_slist_append (list, sf);
-	}
-
-	contact_address = e_contact_get_const (contact, E_CONTACT_ADDRESS_WORK);
-	if (contact_address) {
-		CouchDBStructField *sf;
-
-		sf = couchdb_document_contact_address_new (/* FIXME */ NULL,
-							   contact_address->street,
-							   contact_address->locality,
-							   contact_address->region,
-							   contact_address->country,
-							   contact_address->code,
-							   contact_address->po,
-							   "work");
-		list = g_slist_append (list, sf);
-	}
+	postal_address = contact_postal_address_to_struct_field (contact, E_CONTACT_ADDRESS_HOME, "home");
+	if (postal_address)
+		list = g_slist_append (list, postal_address);
 
-	contact_address = e_contact_get_const (contact, E_CONTACT_ADDRESS_OTHER);
-	if (contact_address) {
-		CouchDBStructField *sf;
+	postal_address = contact_postal_address_to_struct_field (contact, E_CONTACT_ADDRESS_WORK, "work");
+	if (postal_address)
+		list = g_slist_append (list, postal_address);
 
-		sf = couchdb_document_contact_address_new (/* FIXME */ NULL,
-							   contact_address->street,
-							   contact_address->locality,
-							   contact_address->region,
-							   contact_address->country,
-							   contact_address->code,
-							   contact_address->po,
-							   "other");
-		list = g_slist_append (list, sf);
-	}
+	postal_address = contact_postal_address_to_struct_field (contact, E_CONTACT_ADDRESS_OTHER, "other");
+	if (postal_address)
+		list = g_slist_append (list, postal_address);
 
 	if (list) {
 		couchdb_document_contact_set_addresses (document, list);



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