[couchdb-glib] Add lots of new contact record fields
- From: Rodrigo Moya <rodrigo src gnome org>
- To: svn-commits-list gnome org
- Cc:
- Subject: [couchdb-glib] Add lots of new contact record fields
- Date: Fri, 21 Aug 2009 15:47:59 +0000 (UTC)
commit 2a8d5e57761090ccb05c8eb0c45f428181d25efd
Author: Rodrigo Moya <rodrigo gnome-db org>
Date: Fri Aug 21 17:47:32 2009 +0200
Add lots of new contact record fields
Check presence of fields in JSON objects before accessing them to avoid lots
of warnings
couchdb-glib/couchdb-document-contact.c | 211 +++++++++++++++++++++++++++++++
couchdb-glib/couchdb-document-contact.h | 24 ++++
couchdb-glib/couchdb-document.c | 14 ++
3 files changed, 249 insertions(+), 0 deletions(-)
---
diff --git a/couchdb-glib/couchdb-document-contact.c b/couchdb-glib/couchdb-document-contact.c
index 31e2c5d..d2944b4 100644
--- a/couchdb-glib/couchdb-document-contact.c
+++ b/couchdb-glib/couchdb-document-contact.c
@@ -84,6 +84,44 @@ couchdb_document_contact_set_last_name (CouchDBDocument *document, const char *l
}
const char *
+couchdb_document_contact_get_nick_name (CouchDBDocument *document)
+{
+ g_return_val_if_fail (COUCHDB_IS_DOCUMENT (document), NULL);
+ g_return_val_if_fail (couchdb_document_is_contact (document), NULL);
+
+ return couchdb_document_get_string_field (document, "nick_name");
+}
+
+void
+couchdb_document_contact_set_nick_name (CouchDBDocument *document, const char *nick_name)
+{
+ g_return_if_fail (COUCHDB_IS_DOCUMENT (document));
+ g_return_if_fail (couchdb_document_is_contact (document));
+ g_return_if_fail (nick_name != NULL);
+
+ couchdb_document_set_string_field (document, "nick_name", nick_name);
+}
+
+const char *
+couchdb_document_contact_get_spouse_name (CouchDBDocument *document)
+{
+ g_return_val_if_fail (COUCHDB_IS_DOCUMENT (document), NULL);
+ g_return_val_if_fail (couchdb_document_is_contact (document), NULL);
+
+ return couchdb_document_get_string_field (document, "spouse_name");
+}
+
+void
+couchdb_document_contact_set_spouse_name (CouchDBDocument *document, const char *spouse_name)
+{
+ g_return_if_fail (COUCHDB_IS_DOCUMENT (document));
+ g_return_if_fail (couchdb_document_is_contact (document));
+ g_return_if_fail (spouse_name != NULL);
+
+ couchdb_document_set_string_field (document, "spouse_name", spouse_name);
+}
+
+const char *
couchdb_document_contact_get_birth_date (CouchDBDocument *document)
{
JsonObject *object;
@@ -104,6 +142,160 @@ couchdb_document_contact_set_birth_date (CouchDBDocument *document, const char *
couchdb_document_set_string_field (document, "birth_date", birth_date);
}
+const char *
+couchdb_document_contact_get_wedding_date (CouchDBDocument *document)
+{
+ JsonObject *object;
+
+ g_return_val_if_fail (COUCHDB_IS_DOCUMENT (document), NULL);
+ g_return_val_if_fail (couchdb_document_is_contact (document), NULL);
+
+ return couchdb_document_get_string_field (document, "wedding_date");
+}
+
+void
+couchdb_document_contact_set_wedding_date (CouchDBDocument *document, const char *wedding_date)
+{
+ g_return_if_fail (COUCHDB_IS_DOCUMENT (document));
+ g_return_if_fail (couchdb_document_is_contact (document));
+ g_return_if_fail (wedding_date != NULL);
+
+ couchdb_document_set_string_field (document, "wedding_date", wedding_date);
+}
+
+const char *
+couchdb_document_contact_get_company (CouchDBDocument *document)
+{
+ g_return_val_if_fail (COUCHDB_IS_DOCUMENT (document), NULL);
+ g_return_val_if_fail (couchdb_document_is_contact (document), NULL);
+
+ return couchdb_document_get_string_field (document, "company");
+}
+
+void
+couchdb_document_contact_set_company (CouchDBDocument *document, const char *company)
+{
+ g_return_if_fail (COUCHDB_IS_DOCUMENT (document));
+ g_return_if_fail (couchdb_document_is_contact (document));
+ g_return_if_fail (company != NULL);
+
+ couchdb_document_set_string_field (document, "company", company);
+}
+
+const char *
+couchdb_document_contact_get_department (CouchDBDocument *document)
+{
+ g_return_val_if_fail (COUCHDB_IS_DOCUMENT (document), NULL);
+ g_return_val_if_fail (couchdb_document_is_contact (document), NULL);
+
+ return couchdb_document_get_string_field (document, "department");
+}
+
+void
+couchdb_document_contact_set_department (CouchDBDocument *document, const char *department)
+{
+ g_return_if_fail (COUCHDB_IS_DOCUMENT (document));
+ g_return_if_fail (couchdb_document_is_contact (document));
+ g_return_if_fail (department != NULL);
+
+ couchdb_document_set_string_field (document, "department", department);
+}
+
+const char *
+couchdb_document_contact_get_title (CouchDBDocument *document)
+{
+ g_return_val_if_fail (COUCHDB_IS_DOCUMENT (document), NULL);
+ g_return_val_if_fail (couchdb_document_is_contact (document), NULL);
+
+ return couchdb_document_get_string_field (document, "title");
+}
+
+void
+couchdb_document_contact_set_title (CouchDBDocument *document, const char *title)
+{
+ g_return_if_fail (COUCHDB_IS_DOCUMENT (document));
+ g_return_if_fail (couchdb_document_is_contact (document));
+ g_return_if_fail (title != NULL);
+
+ couchdb_document_set_string_field (document, "title", title);
+}
+
+const char *
+couchdb_document_contact_get_job_title (CouchDBDocument *document)
+{
+ g_return_val_if_fail (COUCHDB_IS_DOCUMENT (document), NULL);
+ g_return_val_if_fail (couchdb_document_is_contact (document), NULL);
+
+ return couchdb_document_get_string_field (document, "job_title");
+}
+
+void
+couchdb_document_contact_set_job_title (CouchDBDocument *document, const char *job_title)
+{
+ g_return_if_fail (COUCHDB_IS_DOCUMENT (document));
+ g_return_if_fail (couchdb_document_is_contact (document));
+ g_return_if_fail (job_title != NULL);
+
+ couchdb_document_set_string_field (document, "job_title", job_title);
+}
+
+const char *
+couchdb_document_contact_get_manager_name (CouchDBDocument *document)
+{
+ g_return_val_if_fail (COUCHDB_IS_DOCUMENT (document), NULL);
+ g_return_val_if_fail (couchdb_document_is_contact (document), NULL);
+
+ return couchdb_document_get_string_field (document, "manager_name");
+}
+
+void
+couchdb_document_contact_set_manager_name (CouchDBDocument *document, const char *manager_name)
+{
+ g_return_if_fail (COUCHDB_IS_DOCUMENT (document));
+ g_return_if_fail (couchdb_document_is_contact (document));
+ g_return_if_fail (manager_name != NULL);
+
+ couchdb_document_set_string_field (document, "manager_name", manager_name);
+}
+
+const char *
+couchdb_document_contact_get_assistant_name (CouchDBDocument *document)
+{
+ g_return_val_if_fail (COUCHDB_IS_DOCUMENT (document), NULL);
+ g_return_val_if_fail (couchdb_document_is_contact (document), NULL);
+
+ return couchdb_document_get_string_field (document, "assistant_name");
+}
+
+void
+couchdb_document_contact_set_assistant_name (CouchDBDocument *document, const char *assistant_name)
+{
+ g_return_if_fail (COUCHDB_IS_DOCUMENT (document));
+ g_return_if_fail (couchdb_document_is_contact (document));
+ g_return_if_fail (assistant_name != NULL);
+
+ couchdb_document_set_string_field (document, "assistant_name", assistant_name);
+}
+
+const char *
+couchdb_document_contact_get_office (CouchDBDocument *document)
+{
+ g_return_val_if_fail (COUCHDB_IS_DOCUMENT (document), NULL);
+ g_return_val_if_fail (couchdb_document_is_contact (document), NULL);
+
+ return couchdb_document_get_string_field (document, "office");
+}
+
+void
+couchdb_document_contact_set_office (CouchDBDocument *document, const char *office)
+{
+ g_return_if_fail (COUCHDB_IS_DOCUMENT (document));
+ g_return_if_fail (couchdb_document_is_contact (document));
+ g_return_if_fail (office != NULL);
+
+ couchdb_document_set_string_field (document, "office", office);
+}
+
static void
foreach_object_cb (JsonObject *object,
const char *member_name,
@@ -306,6 +498,25 @@ couchdb_document_contact_set_addresses (CouchDBDocument *document, GSList *list)
/* FIXME: crashes if we _unref json_object_unref (addresses); */
}
+const char *
+couchdb_document_contact_get_notes (CouchDBDocument *document)
+{
+ g_return_val_if_fail (COUCHDB_IS_DOCUMENT (document), NULL);
+ g_return_val_if_fail (couchdb_document_is_contact (document), NULL);
+
+ return couchdb_document_get_string_field (document, "notes");
+}
+
+void
+couchdb_document_contact_set_notes (CouchDBDocument *document, const char *notes)
+{
+ g_return_if_fail (COUCHDB_IS_DOCUMENT (document));
+ g_return_if_fail (couchdb_document_is_contact (document));
+ g_return_if_fail (notes != NULL);
+
+ couchdb_document_set_string_field (document, "notes", notes);
+}
+
CouchDBStructField *
couchdb_document_contact_email_new (const char *uuid, const char *address, const char *description)
{
diff --git a/couchdb-glib/couchdb-document-contact.h b/couchdb-glib/couchdb-document-contact.h
index 06cccfd..4637723 100644
--- a/couchdb-glib/couchdb-document-contact.h
+++ b/couchdb-glib/couchdb-document-contact.h
@@ -37,8 +37,29 @@ const char *couchdb_document_contact_get_first_name (CouchDBDocument *document);
void couchdb_document_contact_set_first_name (CouchDBDocument *document, const char *first_name);
const char *couchdb_document_contact_get_last_name (CouchDBDocument *document);
void couchdb_document_contact_set_last_name (CouchDBDocument *document, const char *last_name);
+const char *couchdb_document_contact_get_nick_name (CouchDBDocument *document);
+void couchdb_document_contact_set_nick_name (CouchDBDocument *document, const char *nick_name);
+const char *couchdb_document_contact_get_spouse_name (CouchDBDocument *document);
+void couchdb_document_contact_set_spouse_name (CouchDBDocument *document, const char *spouse_name);
const char *couchdb_document_contact_get_birth_date (CouchDBDocument *document);
void couchdb_document_contact_set_birth_date (CouchDBDocument *document, const char *birth_date);
+const char *couchdb_document_contact_get_wedding_date (CouchDBDocument *document);
+void couchdb_document_contact_set_wedding_date (CouchDBDocument *document, const char *wedding_date);
+
+const char *couchdb_document_contact_get_company (CouchDBDocument *document);
+void couchdb_document_contact_set_company (CouchDBDocument *document, const char *company);
+const char *couchdb_document_contact_get_department (CouchDBDocument *document);
+void couchdb_document_contact_set_department (CouchDBDocument *document, const char *department);
+const char *couchdb_document_contact_get_title (CouchDBDocument *document);
+void couchdb_document_contact_set_title (CouchDBDocument *document, const char *title);
+const char *couchdb_document_contact_get_job_title (CouchDBDocument *document);
+void couchdb_document_contact_set_job_title (CouchDBDocument *document, const char *job_title);
+const char *couchdb_document_contact_get_manager_name (CouchDBDocument *document);
+void couchdb_document_contact_set_manager_name (CouchDBDocument *document, const char *manager_name);
+const char *couchdb_document_contact_get_assistant_name (CouchDBDocument *document);
+void couchdb_document_contact_set_assistant_name (CouchDBDocument *document, const char *assistant_name);
+const char *couchdb_document_contact_get_office (CouchDBDocument *document);
+void couchdb_document_contact_set_office (CouchDBDocument *document, const char *office);
GSList *couchdb_document_contact_get_email_addresses (CouchDBDocument *document);
void couchdb_document_contact_set_email_addresses (CouchDBDocument *document, GSList *list);
@@ -49,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);
+const char *couchdb_document_contact_get_notes (CouchDBDocument *document);
+void couchdb_document_contact_set_notes (CouchDBDocument *document, const char *notes);
+
/*
* Utility functions to manipulate email addresses fields
*/
diff --git a/couchdb-glib/couchdb-document.c b/couchdb-glib/couchdb-document.c
index 243a019..e5dbd36 100644
--- a/couchdb-glib/couchdb-document.c
+++ b/couchdb-glib/couchdb-document.c
@@ -279,6 +279,9 @@ couchdb_document_get_boolean_field (CouchDBDocument *document, const char *field
g_return_val_if_fail (COUCHDB_IS_DOCUMENT (document), FALSE);
g_return_val_if_fail (field != NULL, FALSE);
+ if (!json_object_has_member (json_node_get_object (document->root_node), field))
+ return FALSE;
+
return json_object_get_boolean_member (json_node_get_object (document->root_node),
field);
}
@@ -300,6 +303,9 @@ couchdb_document_get_int_field (CouchDBDocument *document, const char *field)
g_return_val_if_fail (COUCHDB_IS_DOCUMENT (document), -1);
g_return_val_if_fail (field != NULL, -1);
+ if (!json_object_has_member (json_node_get_object (document->root_node), field))
+ return 0;
+
return json_object_get_int_member (json_node_get_object (document->root_node),
field);
}
@@ -321,6 +327,8 @@ couchdb_document_get_double_field (CouchDBDocument *document, const char *field)
g_return_val_if_fail (COUCHDB_IS_DOCUMENT (document), -1);
g_return_val_if_fail (field != NULL, -1);
+ if (!json_object_has_member (json_node_get_object (document->root_node), field))
+ return 0.0;
return json_object_get_double_member (json_node_get_object (document->root_node),
field);
}
@@ -342,6 +350,9 @@ couchdb_document_get_string_field (CouchDBDocument *document, const char *field)
g_return_val_if_fail (COUCHDB_IS_DOCUMENT (document), NULL);
g_return_val_if_fail (field != NULL, NULL);
+ if (!json_object_has_member (json_node_get_object (document->root_node), field))
+ return NULL;
+
return json_object_get_string_member (json_node_get_object (document->root_node),
field);
}
@@ -368,6 +379,9 @@ couchdb_document_get_struct_field (CouchDBDocument *document, const char *field)
g_return_val_if_fail (COUCHDB_IS_DOCUMENT (document), NULL);
g_return_val_if_fail (field != NULL, NULL);
+ if (!json_object_has_member (json_node_get_object (document->root_node), field))
+ return NULL;
+
return couchdb_struct_field_new_from_json_object (
json_object_ref (json_object_get_object_member (json_node_get_object (document->root_node),
field)));
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]