[libgdata] [documents] Move initialisation code into constructor() in Documents service



commit f5722095a0f1daafc862ad7985b7b08a10805166
Author: Philip Withnall <philip tecnocode co uk>
Date:   Wed Aug 11 09:49:33 2010 +0100

    [documents] Move initialisation code into constructor() in Documents service

 gdata/gdata-private.h                              |    1 -
 gdata/services/documents/gdata-documents-entry.c   |   33 +++++++++++--------
 gdata/services/documents/gdata-documents-folder.c  |    8 +----
 .../documents/gdata-documents-presentation.c       |    8 +----
 .../documents/gdata-documents-spreadsheet.c        |    8 +----
 gdata/services/documents/gdata-documents-text.c    |    8 +----
 6 files changed, 23 insertions(+), 43 deletions(-)
---
diff --git a/gdata/gdata-private.h b/gdata/gdata-private.h
index 502fcf3..faec36f 100644
--- a/gdata/gdata-private.h
+++ b/gdata/gdata-private.h
@@ -86,7 +86,6 @@ G_GNUC_INTERNAL void _gdata_entry_set_batch_data (GDataEntry *self, guint id, GD
 G_GNUC_INTERNAL GFile *_gdata_documents_entry_download_document (GDataDocumentsEntry *self, GDataService *service, gchar **content_type, const gchar *download_uri,
                                                                  GFile *destination_directory, const gchar *file_extension, gboolean replace_file_if_exists,
                                                                  GCancellable *cancellable, GError **error) G_GNUC_WARN_UNUSED_RESULT G_GNUC_MALLOC;
-G_GNUC_INTERNAL void _gdata_documents_entry_init_edited (GDataDocumentsEntry *self);
 
 #include "gdata/services/documents/gdata-documents-service.h"
 
diff --git a/gdata/services/documents/gdata-documents-entry.c b/gdata/services/documents/gdata-documents-entry.c
index fb7f0ec..b76077d 100644
--- a/gdata/services/documents/gdata-documents-entry.c
+++ b/gdata/services/documents/gdata-documents-entry.c
@@ -50,6 +50,7 @@
 #include "gdata-download-stream.h"
 
 static void gdata_documents_entry_access_handler_init (GDataAccessHandlerIface *iface);
+static GObject *gdata_documents_entry_constructor (GType type, guint n_construct_params, GObjectConstructParam *construct_params);
 static void gdata_documents_entry_finalize (GObject *object);
 static void gdata_entry_dispose (GObject *object);
 static void get_namespaces (GDataParsable *parsable, GHashTable *namespaces);
@@ -87,6 +88,7 @@ gdata_documents_entry_class_init (GDataDocumentsEntryClass *klass)
 
 	g_type_class_add_private (klass, sizeof (GDataDocumentsEntryPrivate));
 
+	gobject_class->constructor = gdata_documents_entry_constructor;
 	gobject_class->get_property = gdata_documents_entry_get_property;
 	gobject_class->set_property = gdata_documents_entry_set_property;
 	gobject_class->finalize = gdata_documents_entry_finalize;
@@ -198,21 +200,24 @@ gdata_documents_entry_init (GDataDocumentsEntry *self)
 	self->priv = G_TYPE_INSTANCE_GET_PRIVATE (self, GDATA_TYPE_DOCUMENTS_ENTRY, GDataDocumentsEntryPrivate);
 }
 
-/*
- * _gdata_documents_entry_init_edited:
- * @self: a #GDataDocumentsEntry
- *
- * Initialises the #GDataDocumentsEntry:edited property of @self to the current time. This is designed
- * to be called from the public constructors of classes which derive #GDataDocumentsEntry; it can't be
- * put in the init function of #GDataDocumentsEntry, as it would then be called even for entries parsed
- * from XML from the server, which would break duplicate element detection for the app:edited element.
- *
- * Since: 0.7.0
- */
-void
-_gdata_documents_entry_init_edited (GDataDocumentsEntry *self)
+static GObject *
+gdata_documents_entry_constructor (GType type, guint n_construct_params, GObjectConstructParam *construct_params)
 {
-	g_get_current_time (&(self->priv->edited));
+	GObject *object;
+
+	/* Chain up to the parent class */
+	object = G_OBJECT_CLASS (gdata_documents_entry_parent_class)->constructor (type, n_construct_params, construct_params);
+
+	/* We can't create these in init, or they would collide with the group and control created when parsing the XML */
+	if (_gdata_parsable_is_constructed_from_xml (GDATA_PARSABLE (object)) == FALSE) {
+		GDataDocumentsEntryPrivate *priv = GDATA_DOCUMENTS_ENTRY (object)->priv;
+
+		/* This can't be put in the init function of #GDataDocumentsEntry, as it would then be called even for entries parsed from XML from
+		 * the server, which would break duplicate element detection for the app:edited element. */
+		g_get_current_time (&(priv->edited));
+	}
+
+	return object;
 }
 
 static void
diff --git a/gdata/services/documents/gdata-documents-folder.c b/gdata/services/documents/gdata-documents-folder.c
index bacc3d4..91ad85c 100644
--- a/gdata/services/documents/gdata-documents-folder.c
+++ b/gdata/services/documents/gdata-documents-folder.c
@@ -89,11 +89,5 @@ get_xml (GDataParsable *parsable, GString *xml_string)
 GDataDocumentsFolder *
 gdata_documents_folder_new (const gchar *id)
 {
-	GDataDocumentsFolder *folder = GDATA_DOCUMENTS_FOLDER (g_object_new (GDATA_TYPE_DOCUMENTS_FOLDER, "id", id, NULL));
-
-	/* Set the edited property to the current time (creation time). We don't do this in *_init() since that would cause
-	 * setting it from parse_xml() to fail (duplicate element). */
-	_gdata_documents_entry_init_edited (GDATA_DOCUMENTS_ENTRY (folder));
-
-	return folder;
+	return GDATA_DOCUMENTS_FOLDER (g_object_new (GDATA_TYPE_DOCUMENTS_FOLDER, "id", id, NULL));
 }
diff --git a/gdata/services/documents/gdata-documents-presentation.c b/gdata/services/documents/gdata-documents-presentation.c
index 40bbb2a..0107796 100644
--- a/gdata/services/documents/gdata-documents-presentation.c
+++ b/gdata/services/documents/gdata-documents-presentation.c
@@ -98,13 +98,7 @@ get_xml (GDataParsable *parsable, GString *xml_string)
 GDataDocumentsPresentation *
 gdata_documents_presentation_new (const gchar *id)
 {
-	GDataDocumentsPresentation *presentation = GDATA_DOCUMENTS_PRESENTATION (g_object_new (GDATA_TYPE_DOCUMENTS_PRESENTATION, "id", id, NULL));
-
-	/* Set the edited property to the current time (creation time). We don't do this in *_init() since that would cause
-	 * setting it from parse_xml() to fail (duplicate element). */
-	_gdata_documents_entry_init_edited (GDATA_DOCUMENTS_ENTRY (presentation));
-
-	return presentation;
+	return GDATA_DOCUMENTS_PRESENTATION (g_object_new (GDATA_TYPE_DOCUMENTS_PRESENTATION, "id", id, NULL));
 }
 
 /**
diff --git a/gdata/services/documents/gdata-documents-spreadsheet.c b/gdata/services/documents/gdata-documents-spreadsheet.c
index 43b2a7b..0a139b5 100644
--- a/gdata/services/documents/gdata-documents-spreadsheet.c
+++ b/gdata/services/documents/gdata-documents-spreadsheet.c
@@ -98,13 +98,7 @@ get_xml (GDataParsable *parsable, GString *xml_string)
 GDataDocumentsSpreadsheet *
 gdata_documents_spreadsheet_new (const gchar *id)
 {
-	GDataDocumentsSpreadsheet *spreadsheet = GDATA_DOCUMENTS_SPREADSHEET (g_object_new (GDATA_TYPE_DOCUMENTS_SPREADSHEET, "id", id, NULL));
-
-	/* Set the edited property to the current time (creation time). We don't do this in *_init() since that would cause
-	 * setting it from parse_xml() to fail (duplicate element). */
-	_gdata_documents_entry_init_edited (GDATA_DOCUMENTS_ENTRY (spreadsheet));
-
-	return spreadsheet;
+	return GDATA_DOCUMENTS_SPREADSHEET (g_object_new (GDATA_TYPE_DOCUMENTS_SPREADSHEET, "id", id, NULL));
 }
 
 /**
diff --git a/gdata/services/documents/gdata-documents-text.c b/gdata/services/documents/gdata-documents-text.c
index 7fc4abd..4b5c719 100644
--- a/gdata/services/documents/gdata-documents-text.c
+++ b/gdata/services/documents/gdata-documents-text.c
@@ -100,13 +100,7 @@ get_xml (GDataParsable *parsable, GString *xml_string)
 GDataDocumentsText *
 gdata_documents_text_new (const gchar *id)
 {
-	GDataDocumentsText *text = GDATA_DOCUMENTS_TEXT (g_object_new (GDATA_TYPE_DOCUMENTS_TEXT, "id", id, NULL));
-
-	/* Set the edited property to the current time (creation time). We don't do this in *_init() since that would cause
-	 * setting it from parse_xml() to fail (duplicate element). */
-	_gdata_documents_entry_init_edited (GDATA_DOCUMENTS_ENTRY (text));
-
-	return text;
+	return GDATA_DOCUMENTS_TEXT (g_object_new (GDATA_TYPE_DOCUMENTS_TEXT, "id", id, NULL));
 }
 
 /**



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