# HG changeset patch # User rosfran # Date 1176243869 -3600 # Node ID 348964b09e4a62f71975d3b98d1f13a8805cfcbc # Parent f353f0da6f07429e07ce8626fac8a16b1227662f [svn r522] Some adding on GObject properties set/get. diff -r f353f0da6f07 -r 348964b09e4a gmyth/src/gmyth_file.c --- a/gmyth/src/gmyth_file.c Tue Apr 10 01:07:35 2007 +0100 +++ b/gmyth/src/gmyth_file.c Tue Apr 10 23:24:29 2007 +0100 @@ -54,9 +54,9 @@ (G_TYPE_INSTANCE_GET_PRIVATE ((obj), GMYTH_FILE_TYPE, GMythFilePrivate)) struct _GMythFilePrivate { - gboolean disposed; - gint64 offset; - guint64 filesize; + gboolean disposed; + gint64 offset; + guint64 filesize; GMythBackendInfo *backend_info; @@ -66,7 +66,8 @@ gint file_id; }; -enum { +enum +{ PROP_GMYTH_FILE_FILENAME, PROP_GMYTH_FILE_OFFSET, PROP_GMYTH_FILE_FILESIZE, @@ -74,6 +75,11 @@ PROP_GMYTH_FILE_FILEID }; +static void gmyth_file_set_property (GObject * object, guint prop_id, + const GValue * value, GParamSpec * pspec); +static void gmyth_file_get_property (GObject * object, guint prop_id, + GValue * value, GParamSpec * pspec); + static void gmyth_file_class_init (GMythFileClass *klass); static void gmyth_file_init (GMythFile *object); static void gmyth_file_dispose (GObject *object); @@ -145,7 +151,7 @@ g_return_if_fail( file != NULL ); - priv = GMYTH_FILE_GET_PRIVATE(file); + priv = GMYTH_FILE_GET_PRIVATE(file); if (priv->disposed) { /* If dispose did already run, return. */ @@ -188,9 +194,11 @@ gmyth_file_new (GMythBackendInfo *backend_info) { GMythFile *file = GMYTH_FILE (g_object_new (GMYTH_FILE_TYPE, NULL)); - GMythFilePrivate *priv = GMYTH_FILE_GET_PRIVATE (file); - priv->backend_info = g_object_ref (backend_info); + GValue val = {0,}; + g_value_init (&val, G_TYPE_OBJECT); + g_value_set_object (&val, backend_info); + g_object_set_property (G_OBJECT (file), "backend-info", &val); return file; } @@ -221,7 +229,7 @@ GMythFile* gmyth_file_new_with_uri (const gchar* uri_str) { - GMythFile *file = GMYTH_FILE (g_object_new (GMYTH_FILE_TYPE, NULL)); + GMythFile *file = GMYTH_FILE ( g_object_new (GMYTH_FILE_TYPE, NULL) ); GMythFilePrivate *priv = GMYTH_FILE_GET_PRIVATE (file); priv->backend_info = gmyth_backend_info_new_with_uri (uri_str); @@ -267,8 +275,6 @@ { GMythFilePrivate *priv; - g_return_if_fail (file != NULL); - priv = GMYTH_FILE_GET_PRIVATE (file); if (priv->filename) { @@ -307,8 +313,6 @@ { GMythFilePrivate *priv; - g_return_val_if_fail (file != NULL, 0); - priv = GMYTH_FILE_GET_PRIVATE (file); priv->filesize = filesize; @@ -342,11 +346,100 @@ gmyth_file_set_offset (GMythFile *file, gint64 offset) { GMythFilePrivate *priv; - - g_return_val_if_fail (file != NULL, 0); - + priv = GMYTH_FILE_GET_PRIVATE (file); priv->offset = offset; } +static void +gmyth_file_set_property (GObject * object, guint prop_id, + const GValue * value, GParamSpec * pspec) +{ + GMythFilePrivate* priv = GMYTH_FILE_GET_PRIVATE( GMYTH_FILE(object) ); + + switch (prop_id) { + case PROP_GMYTH_FILE_FILENAME: + { + if (!g_value_get_string (value)) { + break; + } + + if (priv->filename != NULL) { + g_free (priv->filename); + priv->filename = NULL; + } + priv->filename = g_value_dup_string (value); + break; + } + case PROP_GMYTH_FILE_OFFSET: + { + priv->offset = g_value_get_int64 (value); + break; + } + case PROP_GMYTH_FILE_FILESIZE: + { + priv->filesize = g_value_get_uint64 (value); + break; + } + case PROP_GMYTH_FILE_BACKEND_INFO: + { + if (!g_value_get_object (value)) { + break; + } + + if (priv->backend_info != NULL) { + g_object_unref (priv->backend_info); + priv->backend_info = NULL; + } + priv->backend_info = g_value_get_object (value); + break; + } + case PROP_GMYTH_FILE_FILEID: + { + priv->file_id = g_value_get_int (value); + break; + } + default: + G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); + break; + } + +} + +static void +gmyth_file_get_property (GObject * object, guint prop_id, + GValue * value, GParamSpec * pspec) +{ + GMythFilePrivate *priv = GMYTH_FILE_GET_PRIVATE( GMYTH_FILE (object) ); + + switch (prop_id) { + case PROP_GMYTH_FILE_FILENAME: + { + g_value_set_string (value, priv->filename); + break; + } + case PROP_GMYTH_FILE_OFFSET: + { + g_value_set_int64 (value, priv->offset); + break; + } + case PROP_GMYTH_FILE_FILESIZE: + { + g_value_set_uint64 (value, priv->filesize); + break; + } + case PROP_GMYTH_FILE_BACKEND_INFO: + g_value_set_object (value, priv->backend_info); + break; + case PROP_GMYTH_FILE_FILEID: + g_value_set_int (value, priv->file_id); + break; + default: + G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); + break; + } + +} + +