[couchdb-glib] Objectify DesktopcouchDocumentTask



commit 2a63212bb749fc09fa9d677f6ff047da5cbe357e
Author: Miguel Ã?ngel Rodelas Delgado <miguel rodelas gmail com>
Date:   Mon Jul 5 16:14:09 2010 +0200

    Objectify DesktopcouchDocumentTask

 desktopcouch-glib/desktopcouch-document-task.c |   65 ++++++++++++------------
 desktopcouch-glib/desktopcouch-document-task.h |   22 ++++++--
 desktopcouch-glib/desktopcouch-document.c      |   18 +++++++
 desktopcouch-glib/desktopcouch-document.h      |    2 +
 4 files changed, 69 insertions(+), 38 deletions(-)
---
diff --git a/desktopcouch-glib/desktopcouch-document-task.c b/desktopcouch-glib/desktopcouch-document-task.c
index b0652b7..305c156 100755
--- a/desktopcouch-glib/desktopcouch-document-task.c
+++ b/desktopcouch-glib/desktopcouch-document-task.c
@@ -22,63 +22,64 @@
 #include "desktopcouch-document-task.h"
 #include "utils.h"
 
-CouchdbDocument *
-desktopcouch_document_task_new (CouchdbSession *couchdb)
-{
-	CouchdbDocument *document;
-
-	g_return_val_if_fail (COUCHDB_IS_SESSION (couchdb), NULL);
+G_DEFINE_TYPE(DesktopcouchDocumentTask, desktopcouch_document_task, DESKTOPCOUCH_TYPE_DOCUMENT)
 
-	document = couchdb_document_new (couchdb);
-	if (document)
-		desktopcouch_document_set_record_type (document, DESKTOPCOUCH_RECORD_TYPE_TASK);
-
-	return document;
+static void
+desktopcouch_document_task_class_init (DesktopcouchDocumentTaskClass *klass)
+{
 }
 
-gboolean
-desktopcouch_document_is_task (CouchdbDocument *document)
+static void
+desktopcouch_document_task_init (DesktopcouchDocumentTask *document)
 {
-	g_return_val_if_fail (COUCHDB_IS_DOCUMENT (document), FALSE);
+	desktopcouch_document_set_record_type (DESKTOPCOUCH_DOCUMENT (document), DESKTOPCOUCH_RECORD_TYPE_TASK);
+}
 
-	return !g_ascii_strcasecmp (desktopcouch_document_get_record_type (document),
-				    DESKTOPCOUCH_RECORD_TYPE_TASK);
+/**
+ * desktopcouch_document_task_new:
+ *
+ * Create a new #DesktopcouchDocumentTask object.
+ */
+DesktopcouchDocumentTask *
+desktopcouch_document_task_new (CouchdbSession *couchdb)
+{
+	return g_object_new (DESKTOPCOUCH_TYPE_DOCUMENT_TASK, NULL);
 }
 
 const char *
-desktopcouch_document_task_get_summary (CouchdbDocument *document)
+desktopcouch_document_task_get_summary (DesktopcouchDocumentTask *document)
 {
-	g_return_val_if_fail (COUCHDB_IS_DOCUMENT (document), NULL);
-	g_return_val_if_fail (desktopcouch_document_is_task (document), NULL);
+	g_return_val_if_fail (DESKTOPCOUCH_IS_DOCUMENT_TASK (document), NULL);
+	g_return_val_if_fail (desktopcouch_document_is_task (DESKTOPCOUCH_DOCUMENT (document)), NULL);
 
-	return couchdb_document_get_string_field (document, "summary");
+	return couchdb_document_get_string_field (COUCHDB_DOCUMENT (document), "summary");
 }
 
 void
-desktopcouch_document_task_set_summary (CouchdbDocument *document, const char *summary)
+desktopcouch_document_task_set_summary (DesktopcouchDocumentTask *document, const char *summary)
 {
-      	g_return_if_fail (COUCHDB_IS_DOCUMENT (document));
-	g_return_if_fail (desktopcouch_document_is_task (document));
+      	g_return_if_fail (DESKTOPCOUCH_IS_DOCUMENT_TASK (document));
+	g_return_if_fail (desktopcouch_document_is_task (DESKTOPCOUCH_DOCUMENT (document)));
 	g_return_if_fail (summary != NULL);
 
-	couchdb_document_set_string_field (document, "summary", summary);
+	couchdb_document_set_string_field (COUCHDB_DOCUMENT (document), "summary", summary);
 }
 
 const char *
-desktopcouch_document_task_get_description (CouchdbDocument *document)
+desktopcouch_document_task_get_description (DesktopcouchDocumentTask *document)
 {
-	g_return_val_if_fail (COUCHDB_IS_DOCUMENT (document), NULL);
-	g_return_val_if_fail (desktopcouch_document_is_task (document), NULL);
+	g_return_val_if_fail (DESKTOPCOUCH_IS_DOCUMENT_TASK (document), NULL);
+	g_return_val_if_fail (desktopcouch_document_is_task (DESKTOPCOUCH_DOCUMENT (document)), NULL);
 
-	return couchdb_document_get_string_field (document, "description");
+	return couchdb_document_get_string_field (COUCHDB_DOCUMENT (document), "description");
 }
 
 void
-desktopcouch_document_task_set_description (CouchdbDocument *document, const char *description)
+desktopcouch_document_task_set_description (DesktopcouchDocumentTask *document, const char *description)
 {
-      	g_return_if_fail (COUCHDB_IS_DOCUMENT (document));
-	g_return_if_fail (desktopcouch_document_is_task (document));
+      	g_return_if_fail (DESKTOPCOUCH_IS_DOCUMENT_TASK (document));
+	g_return_if_fail (desktopcouch_document_is_task (DESKTOPCOUCH_DOCUMENT (document)));
 	g_return_if_fail (description != NULL);
 
-	couchdb_document_set_string_field (document, "description", description);
+	couchdb_document_set_string_field (COUCHDB_DOCUMENT (document), "description", description);
 }
diff --git a/desktopcouch-glib/desktopcouch-document-task.h b/desktopcouch-glib/desktopcouch-document-task.h
index aa896f7..d30be87 100755
--- a/desktopcouch-glib/desktopcouch-document-task.h
+++ b/desktopcouch-glib/desktopcouch-document-task.h
@@ -27,14 +27,24 @@
 
 G_BEGIN_DECLS
 
-#define DESKTOPCOUCH_RECORD_TYPE_TASK "http://www.freedesktop.org/wiki/Specifications/desktopcouch/task";
+#define DESKTOPCOUCH_TYPE_DOCUMENT_TASK                (desktopcouch_document_task_get_type ())
+#define DESKTOPCOUCH_DOCUMENT_TASK(obj)                (G_TYPE_CHECK_INSTANCE_CAST ((obj), DESKTOPCOUCH_TYPE_DOCUMENT_TASK, DesktopcouchDocumentTask))
+#define DESKTOPCOUCH_IS_DOCUMENT_TASK(obj)             (G_TYPE_CHECK_INSTANCE_TYPE ((obj), DESKTOPCOUCH_TYPE_DOCUMENT_TASK))
+#define DESKTOPCOUCH_DOCUMENT_TASK_CLASS(klass)        (G_TYPE_CHECK_CLASS_CAST ((klass), DESKTOPCOUCH_TYPE_DOCUMENT_TASK, DesktopcouchDocumentTaskClass))
+#define DESKTOPCOUCH_IS_DOCUMENT_TASK_CLASS(klass)     (G_TYPE_CHECK_CLASS_TYPE ((klass), DESKTOPCOUCH_TYPE_DOCUMENT_TASK))
+#define DESKTOPCOUCH_DOCUMENT_TASKGET_CLASS(obj)      (G_TYPE_INSTANCE_GET_CLASS ((obj), DESKTOPCOUCH_TYPE_DOCUMENT_TASK, DesktopouchDocumentTaskClass))
 
-CouchdbDocument *desktopcouch_document_task_new (CouchdbSession *couchdb);
-gboolean         desktopcouch_document_is_task (CouchdbDocument *document);
+typedef struct {
+	DesktopcouchDocument parent;
+} DesktopcouchDocumentTask;
 
-/*
- * Top level functions to manipulate documents representing a task
- */
+typedef struct {
+	DesktopcouchDocumentClass parent_class;
+} DesktopcouchDocumentTaskClass;
+
+GType       desktopcouch_document_task_get_type (void);
+
+DesktopcouchDocumentTask *desktopcouch_document_task_new (void);
 
 const char *desktopcouch_document_task_get_summary (CouchdbDocument *document);
 void        desktopcouch_document_task_set_summary (CouchdbDocument *document, const char *summary);
diff --git a/desktopcouch-glib/desktopcouch-document.c b/desktopcouch-glib/desktopcouch-document.c
index dd1a0d9..8d3295a 100644
--- a/desktopcouch-glib/desktopcouch-document.c
+++ b/desktopcouch-glib/desktopcouch-document.c
@@ -131,3 +131,21 @@ desktopcouch_document_is_contact (DesktopcouchDocument *document)
 	return !g_ascii_strcasecmp (desktopcouch_document_get_record_type (document),
 				    DESKTOPCOUCH_RECORD_TYPE_CONTACT);
 }
+
+/**
+ * desktopcouch_document_is_task:
+ * @document: A #DesktopcouchDocument object
+ *
+ * Check whether the given document represents a contact record, as specified
+ * at http://www.freedesktop.org/wiki/Specifications/desktopcouch/task
+ *
+ * Return value: TRUE if the document represents a task, FALSE otherwise.
+ */
+gboolean
+desktopcouch_document_is_task (DesktopcouchDocument *document)
+{
+	g_return_val_if_fail (DESKTOPCOUCH_IS_DOCUMENT (document), FALSE);
+
+	return !g_ascii_strcasecmp (desktopcouch_document_get_record_type (document),
+				    DESKTOPCOUCH_RECORD_TYPE_TASK);
+}
diff --git a/desktopcouch-glib/desktopcouch-document.h b/desktopcouch-glib/desktopcouch-document.h
index ec4dcf7..a484b7b 100644
--- a/desktopcouch-glib/desktopcouch-document.h
+++ b/desktopcouch-glib/desktopcouch-document.h
@@ -53,8 +53,10 @@ void                  desktopcouch_document_set_application_annotations (Desktop
 									 CouchdbStructField *annotations);
 
 #define DESKTOPCOUCH_RECORD_TYPE_CONTACT "http://www.freedesktop.org/wiki/Specifications/desktopcouch/contact";
+#define DESKTOPCOUCH_RECORD_TYPE_TASK "http://www.freedesktop.org/wiki/Specifications/desktopcouch/task";
 
 gboolean              desktopcouch_document_is_contact (DesktopcouchDocument *document);
+gboolean              desktopcouch_document_is_task (DesktopcouchDocument *document);
 
 G_END_DECLS
 



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