[couchdb-glib] Added API to manipulate IM addresses for contact records



commit 53a9a9fae7b97a1ab10543b3020924d7315680a8
Author: Rodrigo Moya <rodrigo gnome-db org>
Date:   Tue Sep 22 00:34:18 2009 +0200

    Added API to manipulate IM addresses for contact records

 couchdb-glib/couchdb-document-contact.c |  140 +++++++++++++++++++++++++++++--
 couchdb-glib/couchdb-document-contact.h |   59 +++++++++++++
 2 files changed, 191 insertions(+), 8 deletions(-)
---
diff --git a/couchdb-glib/couchdb-document-contact.c b/couchdb-glib/couchdb-document-contact.c
index d0cba74..ad8e42e 100644
--- a/couchdb-glib/couchdb-document-contact.c
+++ b/couchdb-glib/couchdb-document-contact.c
@@ -372,12 +372,10 @@ couchdb_document_contact_set_email_addresses (CouchDBDocument *document, GSList
 			json_object_set_object_member (addresses_json,
 						       couchdb_struct_field_get_uuid (sf),
 						       this_address);
-			/* FIXME: crashes if we _unref json_object_unref (this_address); */
 		}
 	}
 
 	json_object_set_object_member (json_node_get_object (document->root_node), "email_addresses", addresses_json);
-	/* FIXME: crashes if we _unref json_object_unref (addresses_json); */
 }
 
 GSList *
@@ -427,12 +425,10 @@ couchdb_document_contact_set_phone_numbers (CouchDBDocument *document, GSList *l
 			json_object_set_object_member (phone_numbers,
 						       couchdb_struct_field_get_uuid (sf),
 						       this_phone);
-			/* FIXME: crashes if we _unref json_object_unref (this_phone); */
 		}
 	}
 
 	json_object_set_object_member (json_node_get_object (document->root_node), "phone_numbers", phone_numbers);
-	/* FIXME: crashes if we _unref json_object_unref (phone_numbers); */
 }
 
 GSList *
@@ -490,12 +486,64 @@ couchdb_document_contact_set_addresses (CouchDBDocument *document, GSList *list)
 			json_object_set_object_member (addresses,
 						       couchdb_struct_field_get_uuid (sf),
 						       this_address);
-			/* FIXME: crashes if we _unref json_object_unref (this_address); */
 		}
 	}
 
 	json_object_set_object_member (json_node_get_object (document->root_node), "addresses", addresses);
-	/* FIXME: crashes if we _unref json_object_unref (addresses); */
+}
+
+GSList *
+couchdb_document_contact_get_im_addresses (CouchDBDocument *document)
+{
+	GSList *list = NULL;
+	JsonObject *im_addresses;
+
+	g_return_val_if_fail (COUCHDB_IS_DOCUMENT (document), NULL);
+	g_return_val_if_fail (couchdb_document_is_contact (document), NULL);
+
+	im_addresses = json_object_get_object_member (
+		json_node_get_object (document->root_node), "im_addresses");
+	if (im_addresses != NULL) {
+		json_object_foreach_member (im_addresses,
+					    (JsonObjectForeach) foreach_object_cb,
+					    &list);
+	}
+
+	return list;
+}
+
+void
+couchdb_document_contact_set_im_addresses (CouchDBDocument *document, GSList *list)
+{
+	GSList *l;
+	JsonObject *im_addresses_json;
+
+	g_return_if_fail (COUCHDB_IS_DOCUMENT (document));
+	g_return_if_fail (couchdb_document_is_contact (document));
+
+	im_addresses_json = json_object_new ();
+	for (l = list; l != NULL; l = l->next) {
+		const gchar *address_str;
+		CouchDBStructField *sf = (CouchDBStructField *) l->data;
+
+		address_str = couchdb_document_contact_im_get_address (sf);
+		if (address_str != NULL) {
+			JsonObject *this_address;
+
+			this_address = json_object_new ();
+			json_object_set_string_member (this_address, "address", address_str);
+			json_object_set_string_member (this_address, "description",
+						       couchdb_document_contact_im_get_description (sf));
+			json_object_set_string_member (this_address, "protocol",
+						       couchdb_document_contact_im_get_protocol (sf));
+
+			json_object_set_object_member (im_addresses_json,
+						       couchdb_struct_field_get_uuid (sf),
+						       this_address);
+		}
+	}
+
+	json_object_set_object_member (json_node_get_object (document->root_node), "im_addresses", im_addresses_json);
 }
 
 GSList *
@@ -543,12 +591,10 @@ couchdb_document_contact_set_urls (CouchDBDocument *document, GSList *list)
 			json_object_set_object_member (urls_json,
 						       couchdb_struct_field_get_uuid (sf),
 						       this_url);
-			/* FIXME: crashes if we _unref json_object_unref (this_url); */
 		}
 	}
 
 	json_object_set_object_member (json_node_get_object (document->root_node), "urls", urls_json);
-	/* FIXME: crashes if we _unref json_object_unref (urls_json); */
 }
 
 const char *
@@ -849,6 +895,84 @@ couchdb_document_contact_address_set_description (CouchDBStructField *sf, const
 }
 
 CouchDBStructField *
+couchdb_document_contact_im_new (const char *uuid,
+				 const char *address,
+				 const char *description,
+				 const char *protocol)
+{
+	CouchDBStructField *sf;
+
+	sf = couchdb_struct_field_new_from_json_object (json_object_new ());
+	if (uuid != NULL)
+		couchdb_struct_field_set_uuid (sf, uuid);
+	else {
+		char *new_uuid = generate_uuid ();
+		couchdb_struct_field_set_uuid (sf, new_uuid);
+		g_free (new_uuid);
+	}
+
+	if (address != NULL)
+		couchdb_document_contact_im_set_address (sf, address);
+	if (description != NULL)
+		couchdb_document_contact_im_set_description (sf, description);
+	if (protocol != NULL)
+		couchdb_document_contact_im_set_protocol (sf, protocol);
+
+	return sf;
+}
+
+const char *
+couchdb_document_contact_im_get_address (CouchDBStructField *sf)
+{
+	g_return_val_if_fail (sf != NULL, NULL);
+
+	return couchdb_struct_field_get_string_field (sf, "address");
+}
+
+void
+couchdb_document_contact_im_set_address (CouchDBStructField *sf, const char *address)
+{
+	g_return_if_fail (sf != NULL);
+	g_return_if_fail (address != NULL);
+
+	couchdb_struct_field_set_string_field (sf, "address", address);
+}
+
+const char *
+couchdb_document_contact_im_get_description (CouchDBStructField *sf)
+{
+	g_return_val_if_fail (sf != NULL, NULL);
+
+	return couchdb_struct_field_get_string_field (sf, "description");
+}
+
+void
+couchdb_document_contact_im_set_description (CouchDBStructField *sf, const char *description)
+{
+	g_return_if_fail (sf != NULL);
+	g_return_if_fail (description != NULL);
+
+	couchdb_struct_field_set_string_field (sf, "address", description);
+}
+
+const char *
+couchdb_document_contact_im_get_protocol (CouchDBStructField *sf)
+{
+	g_return_val_if_fail (sf != NULL, NULL);
+
+	return couchdb_struct_field_get_string_field (sf, "protocol");
+}
+
+void
+couchdb_document_contact_im_set_protocol (CouchDBStructField *sf, const char *protocol)
+{
+	g_return_if_fail (sf != NULL);
+	g_return_if_fail (protocol != NULL);
+
+	couchdb_struct_field_set_string_field (sf, "protocol", protocol);
+}
+
+CouchDBStructField *
 couchdb_document_contact_url_new (const char *uuid, const char *address, const char *description)
 {
 	CouchDBStructField *sf;
diff --git a/couchdb-glib/couchdb-document-contact.h b/couchdb-glib/couchdb-document-contact.h
index b94bc0f..a2e6c50 100644
--- a/couchdb-glib/couchdb-document-contact.h
+++ b/couchdb-glib/couchdb-document-contact.h
@@ -70,6 +70,9 @@ void        couchdb_document_contact_set_phone_numbers (CouchDBDocument *documen
 GSList     *couchdb_document_contact_get_addresses (CouchDBDocument *document);
 void        couchdb_document_contact_set_addresses (CouchDBDocument *document, GSList *list);
 
+GSList     *couchdb_document_contact_get_im_addresses (CouchDBDocument *document);
+void        couchdb_document_contact_set_im_addresses (CouchDBDocument *document, GSList *list);
+
 GSList     *couchdb_document_contact_get_urls (CouchDBDocument *document);
 void        couchdb_document_contact_set_urls (CouchDBDocument *document, GSList *list);
 
@@ -83,6 +86,11 @@ void        couchdb_document_contact_set_notes (CouchDBDocument *document, const
 CouchDBStructField *couchdb_document_contact_email_new (const char *uuid, const char *address, const char *description);
 const char         *couchdb_document_contact_email_get_address (CouchDBStructField *sf);
 void                couchdb_document_contact_email_set_address (CouchDBStructField *sf, const char *email);
+
+#define COUCHDB_DOCUMENT_CONTACT_EMAIL_DESCRIPTION_HOME  "home"
+#define COUCHDB_DOCUMENT_CONTACT_EMAIL_DESCRIPTION_OTHER "other"
+#define COUCHDB_DOCUMENT_CONTACT_EMAIL_DESCRIPTION_WORK  "work"
+
 const char         *couchdb_document_contact_email_get_description (CouchDBStructField *sf);
 void                couchdb_document_contact_email_set_description (CouchDBStructField *sf, const char *description);
 
@@ -95,6 +103,23 @@ gint                couchdb_document_contact_phone_get_priority (CouchDBStructFi
 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);
+
+#define COUCHDB_DOCUMENT_CONTACT_PHONE_DESCRIPTION_ASSISTANT "assistant"
+#define COUCHDB_DOCUMENT_CONTACT_PHONE_DESCRIPTION_CALLBACK  "callback"
+#define COUCHDB_DOCUMENT_CONTACT_PHONE_DESCRIPTION_CAR       "car"
+#define COUCHDB_DOCUMENT_CONTACT_PHONE_DESCRIPTION_COMPANY   "company"
+#define COUCHDB_DOCUMENT_CONTACT_PHONE_DESCRIPTION_HOME      "home"
+#define COUCHDB_DOCUMENT_CONTACT_PHONE_DESCRIPTION_HOME_FAX  "home fax"
+#define COUCHDB_DOCUMENT_CONTACT_PHONE_DESCRIPTION_MOBILE    "mobile"
+#define COUCHDB_DOCUMENT_CONTACT_PHONE_DESCRIPTION_OTHER     "other"
+#define COUCHDB_DOCUMENT_CONTACT_PHONE_DESCRIPTION_OTHER_FAX "other fax"
+#define COUCHDB_DOCUMENT_CONTACT_PHONE_DESCRIPTION_PAGER     "pager"
+#define COUCHDB_DOCUMENT_CONTACT_PHONE_DESCRIPTION_PRIMARY   "primary"
+#define COUCHDB_DOCUMENT_CONTACT_PHONE_DESCRIPTION_RADIO     "radio"
+#define COUCHDB_DOCUMENT_CONTACT_PHONE_DESCRIPTION_TELEX     "telex"
+#define COUCHDB_DOCUMENT_CONTACT_PHONE_DESCRIPTION_WORK      "work"
+#define COUCHDB_DOCUMENT_CONTACT_PHONE_DESCRIPTION_WORK_FAX  "work fax"
+
 const char         *couchdb_document_contact_phone_get_description (CouchDBStructField *sf);
 void                couchdb_document_contact_phone_set_description (CouchDBStructField *sf, const char *description);
 
@@ -121,15 +146,49 @@ const char         *couchdb_document_contact_address_get_postalcode (CouchDBStru
 void                couchdb_document_contact_address_set_postalcode (CouchDBStructField *sf, const char *postalcode);
 const char         *couchdb_document_contact_address_get_pobox (CouchDBStructField *sf);
 void                couchdb_document_contact_address_set_pobox (CouchDBStructField *sf, const char *pobox);
+
+#define COUCHDB_DOCUMENT_CONTACT_ADDRESS_DESCRIPTION_HOME  "home"
+#define COUCHDB_DOCUMENT_CONTACT_ADDRESS_DESCRIPTION_OTHER "other"
+#define COUCHDB_DOCUMENT_CONTACT_ADDRESS_DESCRIPTION_WORK  "work"
+
 const char         *couchdb_document_contact_address_get_description (CouchDBStructField *sf);
 void                couchdb_document_contact_address_set_description (CouchDBStructField *sf, const char *description);
 
 /*
+ * Utility functions to manipulate IM addresses
+ */
+CouchDBStructField *couchdb_document_contact_im_new (const char *uuid,
+						     const char *address,
+						     const char *description,
+						     const char *protocol);
+const char         *couchdb_document_contact_im_get_address (CouchDBStructField *sf);
+void                couchdb_document_contact_im_set_address (CouchDBStructField *sf, const char *address);
+const char         *couchdb_document_contact_im_get_description (CouchDBStructField *sf);
+void                couchdb_document_contact_im_set_description (CouchDBStructField *sf, const char *description);
+
+#define COUCHDB_DOCUMENT_CONTACT_IM_PROTOCOL_AIM       "aim"
+#define COUCHDB_DOCUMENT_CONTACT_IM_PROTOCOL_GADU_GADU "gadu-gadu"
+#define COUCHDB_DOCUMENT_CONTACT_IM_PROTOCOL_GROUPWISE "groupwise"
+#define COUCHDB_DOCUMENT_CONTACT_IM_PROTOCOL_ICQ       "icq"
+#define COUCHDB_DOCUMENT_CONTACT_IM_PROTOCOL_IRC       "irc"
+#define COUCHDB_DOCUMENT_CONTACT_IM_PROTOCOL_JABBER    "jabber"
+#define COUCHDB_DOCUMENT_CONTACT_IM_PROTOCOL_MSN       "msn"
+#define COUCHDB_DOCUMENT_CONTACT_IM_PROTOCOL_SKYPE     "skype"
+#define COUCHDB_DOCUMENT_CONTACT_IM_PROTOCOL_YAHOO     "yahoo"
+
+const char         *couchdb_document_contact_im_get_protocol (CouchDBStructField *sf);
+void                couchdb_document_contact_im_set_protocol (CouchDBStructField *sf, const char *protocol);
+
+/*
  * Utility functions to manipulate URLs
  */
 CouchDBStructField *couchdb_document_contact_url_new (const char *uuid, const char *address, const char *description);
 const char         *couchdb_document_contact_url_get_address  (CouchDBStructField *sf);
 void                couchdb_document_contact_url_set_address (CouchDBStructField *sf, const char *address);
+
+#define COUCHDB_DOCUMENT_CONTACT_URL_DESCRIPTION_BLOG     "blog"
+#define COUCHDB_DOCUMENT_CONTACT_URL_DESCRIPTION_HOMEPAGE "home page"
+
 const char         *couchdb_document_contact_url_get_description (CouchDBStructField *sf);
 void                couchdb_document_contact_url_set_description (CouchDBStructField *sf, const char *description);
 #endif



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