[couchdb-glib/gnome-2-28] Move from multiline 'street' field to 'address1' + 'address2'



commit dd31ec84c996d424804fe9690161890077eb08a9
Author: Rodrigo Moya <rodrigo gnome-db org>
Date:   Thu Apr 29 16:30:09 2010 +0200

    Move from multiline 'street' field to 'address1' + 'address2'

 couchdb-glib/couchdb-document-contact.c |   55 +++++++++++++++++++++++++++++--
 1 files changed, 52 insertions(+), 3 deletions(-)
---
diff --git a/couchdb-glib/couchdb-document-contact.c b/couchdb-glib/couchdb-document-contact.c
index 9446905..44eef57 100644
--- a/couchdb-glib/couchdb-document-contact.c
+++ b/couchdb-glib/couchdb-document-contact.c
@@ -467,9 +467,20 @@ couchdb_document_contact_set_addresses (CouchDBDocument *document, GSList *list)
 		street_str = couchdb_document_contact_address_get_street (sf);
 		if (street_str) {
 			JsonObject *this_address;
+			gchar **lines;
 
 			this_address = json_object_new ();
-			json_object_set_string_member (this_address, "street", street_str);
+
+			lines = g_strsplit (street_str, "\n", 2);
+			if (lines != NULL) {
+				json_object_set_string_member (this_address, "address1", lines[0]);
+				if (lines[1] != NULL)
+					json_object_set_string_member (this_address, "address2", lines[1]);
+
+				g_strfreev (lines);
+			} else
+				json_object_set_string_member (this_address, "address1", street_str);
+
 			json_object_set_string_member (this_address, "city",
 						       couchdb_document_contact_address_get_city (sf));
 			json_object_set_string_member (this_address, "state",
@@ -784,17 +795,55 @@ couchdb_document_contact_address_new (const char *uuid,
 const char *
 couchdb_document_contact_address_get_street (CouchDBStructField *sf)
 {
+	const char *street;
+
 	g_return_val_if_fail (sf != NULL, NULL);
 
-	return couchdb_struct_field_get_string_field (sf, "street");
+	/* In previous versions of the Freedesktop specification for contacts,
+	   "street" was used to contain a multiline text for the street and
+	   extended street information. This has been changed to "address1" and
+	   "address2" to match what is used on the Ubuntu One web contacts web UI,
+	   so this is the migration path, to support old records */
+	street = couchdb_struct_field_get_string_field (sf, "street");
+	if (street == NULL) {
+		const char *address1, *address2;
+
+		address1 = couchdb_struct_field_get_string_field (sf, "address1");
+		if (address1 != NULL) {
+			address2 = couchdb_struct_field_get_string_field (sf, "address2");
+			if (address2 != NULL) {
+				static gchar *multiline_street = NULL;
+
+				if (multiline_street != NULL)
+					g_free (multiline_street);
+
+				multiline_street = g_strdup_printf ("%s\n%s", address1, address2);
+
+				return (const char *) multiline_street;
+			} else
+				return address1;
+		}
+	}
+
+	return street;
 }
 
 void
 couchdb_document_contact_address_set_street (CouchDBStructField *sf, const char *street)
 {
+	gchar **lines;
+
 	g_return_if_fail (sf != NULL);
 
-	couchdb_struct_field_set_string_field (sf, "street", street);
+	lines = g_strsplit (street, "\n", 2);
+	if (lines != NULL) {
+		couchdb_struct_field_set_string_field (sf, "address1", lines[0]);
+		if (lines[1] != NULL)
+			couchdb_struct_field_set_string_field (sf, "address2", lines[1]);
+
+		g_strfreev (lines);
+	} else
+		couchdb_struct_field_set_string_field (sf, "address1", street);
 }
 
 const char *



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