[svn r522] Some adding on GObject properties set/get.
1.1 --- a/gmyth/src/gmyth_file.c Tue Apr 10 01:07:35 2007 +0100
1.2 +++ b/gmyth/src/gmyth_file.c Tue Apr 10 23:24:29 2007 +0100
1.3 @@ -54,9 +54,9 @@
1.4 (G_TYPE_INSTANCE_GET_PRIVATE ((obj), GMYTH_FILE_TYPE, GMythFilePrivate))
1.5
1.6 struct _GMythFilePrivate {
1.7 - gboolean disposed;
1.8 - gint64 offset;
1.9 - guint64 filesize;
1.10 + gboolean disposed;
1.11 + gint64 offset;
1.12 + guint64 filesize;
1.13
1.14 GMythBackendInfo *backend_info;
1.15
1.16 @@ -66,7 +66,8 @@
1.17 gint file_id;
1.18 };
1.19
1.20 -enum {
1.21 +enum
1.22 +{
1.23 PROP_GMYTH_FILE_FILENAME,
1.24 PROP_GMYTH_FILE_OFFSET,
1.25 PROP_GMYTH_FILE_FILESIZE,
1.26 @@ -74,6 +75,11 @@
1.27 PROP_GMYTH_FILE_FILEID
1.28 };
1.29
1.30 +static void gmyth_file_set_property (GObject * object, guint prop_id,
1.31 + const GValue * value, GParamSpec * pspec);
1.32 +static void gmyth_file_get_property (GObject * object, guint prop_id,
1.33 + GValue * value, GParamSpec * pspec);
1.34 +
1.35 static void gmyth_file_class_init (GMythFileClass *klass);
1.36 static void gmyth_file_init (GMythFile *object);
1.37 static void gmyth_file_dispose (GObject *object);
1.38 @@ -145,7 +151,7 @@
1.39
1.40 g_return_if_fail( file != NULL );
1.41
1.42 - priv = GMYTH_FILE_GET_PRIVATE(file);
1.43 + priv = GMYTH_FILE_GET_PRIVATE(file);
1.44
1.45 if (priv->disposed) {
1.46 /* If dispose did already run, return. */
1.47 @@ -188,9 +194,11 @@
1.48 gmyth_file_new (GMythBackendInfo *backend_info)
1.49 {
1.50 GMythFile *file = GMYTH_FILE (g_object_new (GMYTH_FILE_TYPE, NULL));
1.51 - GMythFilePrivate *priv = GMYTH_FILE_GET_PRIVATE (file);
1.52
1.53 - priv->backend_info = g_object_ref (backend_info);
1.54 + GValue val = {0,};
1.55 + g_value_init (&val, G_TYPE_OBJECT);
1.56 + g_value_set_object (&val, backend_info);
1.57 + g_object_set_property (G_OBJECT (file), "backend-info", &val);
1.58
1.59 return file;
1.60 }
1.61 @@ -221,7 +229,7 @@
1.62 GMythFile*
1.63 gmyth_file_new_with_uri (const gchar* uri_str)
1.64 {
1.65 - GMythFile *file = GMYTH_FILE (g_object_new (GMYTH_FILE_TYPE, NULL));
1.66 + GMythFile *file = GMYTH_FILE ( g_object_new (GMYTH_FILE_TYPE, NULL) );
1.67 GMythFilePrivate *priv = GMYTH_FILE_GET_PRIVATE (file);
1.68
1.69 priv->backend_info = gmyth_backend_info_new_with_uri (uri_str);
1.70 @@ -267,8 +275,6 @@
1.71 {
1.72 GMythFilePrivate *priv;
1.73
1.74 - g_return_if_fail (file != NULL);
1.75 -
1.76 priv = GMYTH_FILE_GET_PRIVATE (file);
1.77
1.78 if (priv->filename) {
1.79 @@ -307,8 +313,6 @@
1.80 {
1.81 GMythFilePrivate *priv;
1.82
1.83 - g_return_val_if_fail (file != NULL, 0);
1.84 -
1.85 priv = GMYTH_FILE_GET_PRIVATE (file);
1.86
1.87 priv->filesize = filesize;
1.88 @@ -342,11 +346,100 @@
1.89 gmyth_file_set_offset (GMythFile *file, gint64 offset)
1.90 {
1.91 GMythFilePrivate *priv;
1.92 -
1.93 - g_return_val_if_fail (file != NULL, 0);
1.94 -
1.95 +
1.96 priv = GMYTH_FILE_GET_PRIVATE (file);
1.97
1.98 priv->offset = offset;
1.99 }
1.100
1.101 +static void
1.102 +gmyth_file_set_property (GObject * object, guint prop_id,
1.103 + const GValue * value, GParamSpec * pspec)
1.104 +{
1.105 + GMythFilePrivate* priv = GMYTH_FILE_GET_PRIVATE( GMYTH_FILE(object) );
1.106 +
1.107 + switch (prop_id) {
1.108 + case PROP_GMYTH_FILE_FILENAME:
1.109 + {
1.110 + if (!g_value_get_string (value)) {
1.111 + break;
1.112 + }
1.113 +
1.114 + if (priv->filename != NULL) {
1.115 + g_free (priv->filename);
1.116 + priv->filename = NULL;
1.117 + }
1.118 + priv->filename = g_value_dup_string (value);
1.119 + break;
1.120 + }
1.121 + case PROP_GMYTH_FILE_OFFSET:
1.122 + {
1.123 + priv->offset = g_value_get_int64 (value);
1.124 + break;
1.125 + }
1.126 + case PROP_GMYTH_FILE_FILESIZE:
1.127 + {
1.128 + priv->filesize = g_value_get_uint64 (value);
1.129 + break;
1.130 + }
1.131 + case PROP_GMYTH_FILE_BACKEND_INFO:
1.132 + {
1.133 + if (!g_value_get_object (value)) {
1.134 + break;
1.135 + }
1.136 +
1.137 + if (priv->backend_info != NULL) {
1.138 + g_object_unref (priv->backend_info);
1.139 + priv->backend_info = NULL;
1.140 + }
1.141 + priv->backend_info = g_value_get_object (value);
1.142 + break;
1.143 + }
1.144 + case PROP_GMYTH_FILE_FILEID:
1.145 + {
1.146 + priv->file_id = g_value_get_int (value);
1.147 + break;
1.148 + }
1.149 + default:
1.150 + G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
1.151 + break;
1.152 + }
1.153 +
1.154 +}
1.155 +
1.156 +static void
1.157 +gmyth_file_get_property (GObject * object, guint prop_id,
1.158 + GValue * value, GParamSpec * pspec)
1.159 +{
1.160 + GMythFilePrivate *priv = GMYTH_FILE_GET_PRIVATE( GMYTH_FILE (object) );
1.161 +
1.162 + switch (prop_id) {
1.163 + case PROP_GMYTH_FILE_FILENAME:
1.164 + {
1.165 + g_value_set_string (value, priv->filename);
1.166 + break;
1.167 + }
1.168 + case PROP_GMYTH_FILE_OFFSET:
1.169 + {
1.170 + g_value_set_int64 (value, priv->offset);
1.171 + break;
1.172 + }
1.173 + case PROP_GMYTH_FILE_FILESIZE:
1.174 + {
1.175 + g_value_set_uint64 (value, priv->filesize);
1.176 + break;
1.177 + }
1.178 + case PROP_GMYTH_FILE_BACKEND_INFO:
1.179 + g_value_set_object (value, priv->backend_info);
1.180 + break;
1.181 + case PROP_GMYTH_FILE_FILEID:
1.182 + g_value_set_int (value, priv->file_id);
1.183 + break;
1.184 + default:
1.185 + G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
1.186 + break;
1.187 + }
1.188 +
1.189 +}
1.190 +
1.191 +