[rhythmbox] rhythmdb: relax type checks for entry property values
- From: Jonathan Matthew <jmatthew src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [rhythmbox] rhythmdb: relax type checks for entry property values
- Date: Sun, 6 Feb 2011 10:22:05 +0000 (UTC)
commit d41d2eea8ce72ab5efe6e33cda659346a1a1973b
Author: Jonathan Matthew <jonathan d14n org>
Date: Sun Feb 6 19:19:37 2011 +1000
rhythmdb: relax type checks for entry property values
When calling rhythmdb_entry_set via introspection, the caller may not
be able to specify the exact type used for the property, so accept
anything we can transform to the right type.
rhythmdb/rhythmdb.c | 24 +++++++++++++++++++++++-
1 files changed, 23 insertions(+), 1 deletions(-)
---
diff --git a/rhythmdb/rhythmdb.c b/rhythmdb/rhythmdb.c
index 66df7c9..301df28 100644
--- a/rhythmdb/rhythmdb.c
+++ b/rhythmdb/rhythmdb.c
@@ -3294,11 +3294,25 @@ rhythmdb_entry_set_internal (RhythmDB *db,
RhythmDBClass *klass = RHYTHMDB_GET_CLASS (db);
gboolean handled;
RhythmDBPodcastFields *podcast = NULL;
+ GValue conv_value = {0,};
GValue old_value = {0,};
gboolean nop;
g_return_if_fail (entry != NULL);
+ /* convert the value if necessary */
+ if (G_VALUE_TYPE (value) != rhythmdb_get_property_type (db, propid)) {
+ g_value_init (&conv_value, rhythmdb_get_property_type (db, propid));
+ if (g_value_transform (value, &conv_value) == FALSE) {
+ g_warning ("Unable to convert new value for property %s from %s to %s",
+ rhythmdb_nice_elt_name_from_propid (db, propid),
+ g_type_name (G_VALUE_TYPE (value)),
+ g_type_name (rhythmdb_get_property_type (db, propid)));
+ g_assert_not_reached ();
+ }
+ value = &conv_value;
+ }
+
/* compare the value with what's already there */
g_value_init (&old_value, G_VALUE_TYPE (value));
rhythmdb_entry_get (db, entry, propid, &old_value);
@@ -3337,8 +3351,12 @@ rhythmdb_entry_set_internal (RhythmDB *db,
}
g_value_unset (&old_value);
- if (nop)
+ if (nop) {
+ if (value == &conv_value) {
+ g_value_unset (&conv_value);
+ }
return;
+ }
handled = klass->impl_entry_set (db, entry, propid, value);
@@ -3556,6 +3574,10 @@ rhythmdb_entry_set_internal (RhythmDB *db,
}
}
+ if (value == &conv_value) {
+ g_value_unset (&conv_value);
+ }
+
/* set the dirty state */
db->priv->dirty = TRUE;
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]