[couchdb-glib] Add get/set_ext_street API for multiline streets



commit d8ba4f583ef60c4f7add1bfcf0d2bdedc24a6174
Author: Rodrigo Moya <rodrigo gnome-db org>
Date:   Mon May 3 10:09:40 2010 +0200

    Add get/set_ext_street API for multiline streets

 configure.ac                                      |    4 +-
 desktopcouch-glib/desktopcouch-document-contact.c |   77 +++++++-------------
 desktopcouch-glib/desktopcouch-document-contact.h |   17 +++--
 3 files changed, 39 insertions(+), 59 deletions(-)
---
diff --git a/configure.ac b/configure.ac
index 75aa43a..bcee9ef 100644
--- a/configure.ac
+++ b/configure.ac
@@ -1,4 +1,4 @@
-AC_INIT([couchdb-glib], [0.6.3], [], [couchdb-glib])
+AC_INIT([couchdb-glib], [0.6.90], [], [couchdb-glib])
 
 AC_PREREQ([2.59])
 
@@ -51,7 +51,7 @@ AC_SUBST(DESKTOPCOUCH_GLIB_CFLAGS)
 AC_SUBST(DESKTOPCOUCH_GLIB_LIBS)
 
 LIBCOUCHDBGLIB_CURRENT=2
-LIBCOUCHDBGLIB_REVISION=0
+LIBCOUCHDBGLIB_REVISION=1
 LIBCOUCHDBGLIB_AGE=0
 AC_SUBST(LIBCOUCHDBGLIB_CURRENT)
 AC_SUBST(LIBCOUCHDBGLIB_REVISION)
diff --git a/desktopcouch-glib/desktopcouch-document-contact.c b/desktopcouch-glib/desktopcouch-document-contact.c
index 800c597..ea574b9 100644
--- a/desktopcouch-glib/desktopcouch-document-contact.c
+++ b/desktopcouch-glib/desktopcouch-document-contact.c
@@ -505,21 +505,12 @@ desktopcouch_document_contact_set_addresses (CouchdbDocument *document, GSList *
 		street_str = desktopcouch_document_contact_address_get_street (sf);
 		if (street_str) {
 			JsonObject *this_address;
-			gchar **lines;
 
 			this_address = json_object_new ();
 
-			lines = g_strsplit (street_str, "\n", 2);
-			if (lines != NULL) {
-				g_debug ("lines[0] = %s, lines[1] = %s", lines[0], lines[1]);
-				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, "address1", street_str);
+			json_object_set_string_member (this_address, "address2",
+						       desktopcouch_document_contact_address_get_ext_street (sf));
 			json_object_set_string_member (this_address, "city",
 						       desktopcouch_document_contact_address_get_city (sf));
 			json_object_set_string_member (this_address, "state",
@@ -822,6 +813,7 @@ desktopcouch_document_contact_phone_set_description (CouchdbStructField *sf, con
 CouchdbStructField *
 desktopcouch_document_contact_address_new (const char *uuid,
 					   const char *street,
+					   const char *ext_street,
 					   const char *city,
 					   const char *state,
 					   const char *country,
@@ -842,6 +834,8 @@ desktopcouch_document_contact_address_new (const char *uuid,
 
 	if (street)
 		desktopcouch_document_contact_address_set_street (sf, street);
+	if (ext_street)
+		desktopcouch_document_contact_address_set_ext_street (sf, ext_street);
 	if (city)
 		desktopcouch_document_contact_address_set_city (sf, city);
 	if (state)
@@ -861,55 +855,38 @@ desktopcouch_document_contact_address_new (const char *uuid,
 const char *
 desktopcouch_document_contact_address_get_street (CouchdbStructField *sf)
 {
-	const char *street;
-
 	g_return_val_if_fail (sf != NULL, NULL);
 
-	/* 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;
-		}
-	}
+	if (couchdb_struct_field_has_field (sf, "address1"))
+		return couchdb_struct_field_get_string_field (sf, "address1");
+	else if (couchdb_struct_field_has_field (sf, "street"))
+		return couchdb_struct_field_get_string_field (sf, "street");
 
-	return street;
+	return NULL;
 }
 
 void
 desktopcouch_document_contact_address_set_street (CouchdbStructField *sf, const char *street)
 {
-	gchar **lines;
-
 	g_return_if_fail (sf != NULL);
 
-	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]);
+	couchdb_struct_field_set_string_field (sf, "address1", street);
+}
+
+const char *
+desktopcouch_document_contact_address_get_ext_street (CouchdbStructField *sf)
+{
+	g_return_val_if_fail (sf != NULL, NULL);
+
+	return couchdb_struct_field_get_string_field (sf, "address2");
+}
+
+void
+desktopcouch_document_contact_address_set_ext_street (CouchdbStructField *sf, const char *ext_street)
+{
+	g_return_if_fail (sf != NULL);
 
-		g_strfreev (lines);
-	} else
-		couchdb_struct_field_set_string_field (sf, "address1", street);
+	couchdb_struct_field_set_string_field (sf, "address2", ext_street);
 }
 
 const char *
diff --git a/desktopcouch-glib/desktopcouch-document-contact.h b/desktopcouch-glib/desktopcouch-document-contact.h
index 5f3c431..9c28acb 100644
--- a/desktopcouch-glib/desktopcouch-document-contact.h
+++ b/desktopcouch-glib/desktopcouch-document-contact.h
@@ -138,15 +138,18 @@ void                desktopcouch_document_contact_phone_set_description (Couchdb
  * Utility functions to manipulate addresses
  */
 CouchdbStructField *desktopcouch_document_contact_address_new (const char *uuid,
-							  const char *street,
-							  const char *city,
-							  const char *state,
-							  const char *country,
-							  const char *postalcode,
-							  const char *pobox,
-							  const char *description);
+							       const char *street,
+							       const char *ext_street,
+							       const char *city,
+							       const char *state,
+							       const char *country,
+							       const char *postalcode,
+							       const char *pobox,
+							       const char *description);
 const char         *desktopcouch_document_contact_address_get_street (CouchdbStructField *sf);
 void                desktopcouch_document_contact_address_set_street (CouchdbStructField *sf, const char *street);
+const char         *desktopcouch_document_contact_address_get_ext_street (CouchdbStructField *sf);
+void                desktopcouch_document_contact_address_set_ext_street (CouchdbStructField *sf, const char *ext_street);
 const char         *desktopcouch_document_contact_address_get_city (CouchdbStructField *sf);
 void                desktopcouch_document_contact_address_set_city (CouchdbStructField *sf, const char *city);
 const char         *desktopcouch_document_contact_address_get_state (CouchdbStructField *sf);



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