[couchdb-glib] Added functions to deal with phone numbers in contacts



commit d1045f589b19e960251d2c649b6fc3f45dde35ee
Author: Rodrigo Moya <rodrigo gnome-db org>
Date:   Fri Jun 19 17:40:20 2009 +0200

    Added functions to deal with phone numbers in contacts

 couchdb-glib/couchdb-document-contact.c |   79 +++++++++++++++++++++++++++++--
 couchdb-glib/couchdb-document-contact.h |   13 +++++
 2 files changed, 87 insertions(+), 5 deletions(-)
---
diff --git a/couchdb-glib/couchdb-document-contact.c b/couchdb-glib/couchdb-document-contact.c
index 4c727c7..0e098e2 100644
--- a/couchdb-glib/couchdb-document-contact.c
+++ b/couchdb-glib/couchdb-document-contact.c
@@ -82,7 +82,7 @@ couchdb_document_contact_set_birth_date (CouchDBDocument *document, const char *
 }
 
 static void
-foreach_email_cb (JsonObject *object,
+foreach_object_cb (JsonObject *object,
 		  const char *member_name,
 		  JsonNode *member_node,
 		  gpointer user_data)
@@ -120,12 +120,11 @@ couchdb_document_contact_get_email_addresses (CouchDBDocument *document)
 	g_return_val_if_fail (COUCHDB_IS_DOCUMENT (document), NULL);
 	g_return_val_if_fail (couchdb_document_is_contact (document), NULL);
 
-	/* first, retrieve the email_addresses object */
-	addresses_json = json_object_get_object_member (json_node_get_object (document->root_node),
-							"email_addresses");
+	addresses_json = json_object_get_object_member (
+		json_node_get_object (document->root_node), "email_addresses");;
 	if (addresses_json) {
 		json_object_foreach_member (addresses_json,
-					    (JsonObjectForeach) foreach_email_cb,
+					    (JsonObjectForeach) foreach_object_cb,
 					    &list);
 	}
 
@@ -137,6 +136,26 @@ couchdb_document_contact_set_email_addresses (CouchDBDocument *document, GSList
 {
 }
 
+GSList *
+couchdb_document_contact_get_phone_numbers (CouchDBDocument *document)
+{
+	GSList *list = NULL;
+	JsonObject *phone_numbers;
+
+	g_return_val_if_fail (COUCHDB_IS_DOCUMENT (document), NULL);
+	g_return_val_if_fail (couchdb_document_is_contact (document), NULL);
+
+	phone_numbers = json_object_get_object_member (
+		json_node_get_object (document->root_node), "phone_numbers");
+	if (phone_numbers) {
+		json_object_foreach_member (phone_numbers,
+					    (JsonObjectForeach) foreach_object_cb,
+					    &list);
+	}
+
+	return list;
+}
+
 const char *
 couchdb_document_contact_email_get_address (CouchDBStructField *sf)
 {
@@ -170,3 +189,53 @@ couchdb_document_contact_email_set_description (CouchDBStructField *sf, const ch
 
 	json_object_set_string_member (sf->json_object, "description", description);
 }
+
+gint
+couchdb_document_contact_phone_get_priority (CouchDBStructField *sf)
+{
+	g_return_val_if_fail (sf != NULL, 0);
+
+	return json_object_get_int_member (sf->json_object, "priority");
+}
+
+void
+couchdb_document_contact_phone_set_priority (CouchDBStructField *sf, gint priority)
+{
+	g_return_if_fail (sf != NULL);
+
+	json_object_set_int_member (sf->json_object, "priority", priority);
+}
+
+const char *
+couchdb_document_contact_phone_get_number (CouchDBStructField *sf)
+{
+	g_return_val_if_fail (sf->json_object, NULL);
+
+	return json_object_get_string_member (sf->json_object, "number");
+}
+
+void
+couchdb_document_contact_phone_set_number (CouchDBStructField *sf, const char *number)
+{
+	g_return_if_fail (sf != NULL);
+	g_return_if_fail (number != NULL);
+
+	json_object_set_string_member (sf->json_object, "number", number);
+}
+
+const char *
+couchdb_document_contact_phone_get_description (CouchDBStructField *sf)
+{
+	g_return_val_if_fail (sf != NULL, NULL);
+
+	return json_object_get_string_member (sf->json_object, "description");
+}
+
+void
+couchdb_document_contact_phone_set_description (CouchDBStructField *sf, const char *description)
+{
+	g_return_if_fail (sf != NULL);
+	g_return_if_fail (description != NULL);
+
+	json_object_set_string_member (sf->json_object, "description", description);
+}
diff --git a/couchdb-glib/couchdb-document-contact.h b/couchdb-glib/couchdb-document-contact.h
index 0b34dcc..01b6e5c 100644
--- a/couchdb-glib/couchdb-document-contact.h
+++ b/couchdb-glib/couchdb-document-contact.h
@@ -38,6 +38,8 @@ void        couchdb_document_contact_set_birth_date (CouchDBDocument *document,
 GSList     *couchdb_document_contact_get_email_addresses (CouchDBDocument *document);
 void        couchdb_document_contact_set_email_addresses (CouchDBDocument *document, GSList *list);
 
+GSList     *couchdb_document_contact_get_phone_numbers (CouchDBDocument *document);
+
 /*
  * Utility functions to manipulate email addresses fields
  */
@@ -47,4 +49,15 @@ void        couchdb_document_contact_email_set_address (CouchDBStructField *sf,
 const char *couchdb_document_contact_email_get_description (CouchDBStructField *sf);
 void        couchdb_document_contact_email_set_description (CouchDBStructField *sf, const char *description);
 
+/*
+ * Utility functions to manipulate phone numbers
+ */
+
+gint        couchdb_document_contact_phone_get_priority (CouchDBStructField *sf);
+void        couchdb_document_contact_phone_set_priority (CouchDBStructField *sf, gint priority);
+const char *couchdb_document_contact_phone_get_number (CouchDBStructField *sf);
+void        couchdb_document_contact_phone_set_number (CouchDBStructField *sf, const char *number);
+const char *couchdb_document_contact_phone_get_description (CouchDBStructField *sf);
+void        couchdb_document_contact_phone_set_description (CouchDBStructField *sf, const char *description);
+
 #endif



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