[couchdb-glib] Added missing bits to desktopcouch_database_create_document_from_json



commit 1f0eeb10b4617345d5ff67b108afc4070f487f52
Author: Rodrigo Moya <rodrigo gnome-db org>
Date:   Mon May 17 17:48:45 2010 +0200

    Added missing bits to desktopcouch_database_create_document_from_json

 desktopcouch-glib/desktopcouch-session.c |   17 +++++++++++++++++
 1 files changed, 17 insertions(+), 0 deletions(-)
---
diff --git a/desktopcouch-glib/desktopcouch-session.c b/desktopcouch-glib/desktopcouch-session.c
index 85369f5..ec1c0a2 100644
--- a/desktopcouch-glib/desktopcouch-session.c
+++ b/desktopcouch-glib/desktopcouch-session.c
@@ -21,6 +21,7 @@
 
 #include <dbus/dbus-glib.h>
 #include <gnome-keyring.h>
+#include <couchdb-glib/utils.h>
 #include "desktopcouch-session.h"
 
 typedef struct {
@@ -36,6 +37,22 @@ G_DEFINE_TYPE(DesktopcouchDatabase, desktopcouch_database, COUCHDB_TYPE_DATABASE
 static CouchdbDocument *
 desktopcouch_database_create_document_from_json (CouchdbDatabase *database, gpointer json_data)
 {
+	DesktopcouchDocument *document;
+
+	JsonObject *json_object = (JsonObject *) json_data;
+
+	if (json_object_has_member (json_object, "record_type")) {
+		if (g_strcmp0 (json_object_get_string_member (json_object, "record_type"),
+			       DESKTOPCOUCH_RECORD_TYPE_CONTACT))
+			document = desktopcouch_document_contact_new ();
+		else
+			document = desktopcouch_document_new ();
+	} else
+		document = desktopcouch_document_new ();
+
+	couchdb_document_set_from_json_object (COUCHDB_DOCUMENT (document), json_object);
+
+	return COUCHDB_DOCUMENT (document);
 }
 
 static void



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