[libgdata/construction: 4/5] [youtube] Move initialisation code to constructor() in GDataYouTubeVideo



commit ee1be8f9be5abe6151dab8673ada1714252e9239
Author: Philip Withnall <philip withnall collabora co uk>
Date:   Sat Aug 7 15:58:21 2010 +0100

    [youtube] Move initialisation code to constructor() in GDataYouTubeVideo

 gdata/services/youtube/gdata-youtube-video.c |   26 +++++++++++++++++++++-----
 1 files changed, 21 insertions(+), 5 deletions(-)
---
diff --git a/gdata/services/youtube/gdata-youtube-video.c b/gdata/services/youtube/gdata-youtube-video.c
index f523538..181397d 100644
--- a/gdata/services/youtube/gdata-youtube-video.c
+++ b/gdata/services/youtube/gdata-youtube-video.c
@@ -79,6 +79,7 @@
 #include "gdata-youtube-control.h"
 #include "gdata-youtube-enums.h"
 
+static GObject *gdata_youtube_video_constructor (GType type, guint n_construct_params, GObjectConstructParam *construct_params);
 static void gdata_youtube_video_dispose (GObject *object);
 static void gdata_youtube_video_finalize (GObject *object);
 static void gdata_youtube_video_get_property (GObject *object, guint property_id, GValue *value, GParamSpec *pspec);
@@ -145,6 +146,7 @@ gdata_youtube_video_class_init (GDataYouTubeVideoClass *klass)
 
 	g_type_class_add_private (klass, sizeof (GDataYouTubeVideoPrivate));
 
+	gobject_class->constructor = gdata_youtube_video_constructor;
 	gobject_class->get_property = gdata_youtube_video_get_property;
 	gobject_class->set_property = gdata_youtube_video_set_property;
 	gobject_class->dispose = gdata_youtube_video_dispose;
@@ -465,6 +467,24 @@ gdata_youtube_video_init (GDataYouTubeVideo *self)
 	g_signal_connect (GDATA_ENTRY (self), "notify::title", G_CALLBACK (notify_title_cb), NULL);
 }
 
+static GObject *
+gdata_youtube_video_constructor (GType type, guint n_construct_params, GObjectConstructParam *construct_params)
+{
+	GObject *object;
+
+	/* Chain up to the parent class */
+	object = G_OBJECT_CLASS (gdata_youtube_video_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) {
+		GDataYouTubeVideoPrivate *priv = GDATA_YOUTUBE_VIDEO (object)->priv;
+		priv->media_group = g_object_new (GDATA_TYPE_YOUTUBE_GROUP, NULL);
+		priv->youtube_control = g_object_new (GDATA_TYPE_YOUTUBE_CONTROL, NULL);
+	}
+
+	return object;
+}
+
 static void
 gdata_youtube_video_dispose (GObject *object)
 {
@@ -884,11 +904,7 @@ get_entry_uri (const gchar *id)
 GDataYouTubeVideo *
 gdata_youtube_video_new (const gchar *id)
 {
-	GDataYouTubeVideo *video = g_object_new (GDATA_TYPE_YOUTUBE_VIDEO, "id", id, NULL);
-	/* We can't create these in init, or they would collide with the group and control created when parsing the XML */
-	video->priv->media_group = g_object_new (GDATA_TYPE_YOUTUBE_GROUP, NULL);
-	video->priv->youtube_control = g_object_new (GDATA_TYPE_YOUTUBE_CONTROL, NULL);
-	return video;
+	return g_object_new (GDATA_TYPE_YOUTUBE_VIDEO, "id", id, NULL);
 }
 
 /**



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