From f8037f857d9834b39a8e678d26f3a98803fcbf6d Mon Sep 17 00:00:00 2001 From: Thibault Saunier Date: Wed, 19 Dec 2012 10:37:02 -0300 Subject: [PATCH] trackobject: Properly rename get/set_child_property We used to have a ges_track_object_get/set_child_property that was in fact letting user set/get various properties at once, rename it to get/set_properties, and implement: API: ges_track_object_get_child_property (GESTrackObject *object, const gchar *property_name, GValue * value); ges_track_object_set_child_property (GESTrackObject *object, const gchar *property_name, GValue * value); --- docs/design/effects.txt | 4 +- docs/libs/ges-sections.txt | 2 + ges/ges-pitivi-formatter.c | 2 +- ges/ges-track-object.c | 107 +++++++++++++++++++++++++++++++++++-- ges/ges-track-object.h | 12 ++++- tests/check/ges/effects.c | 15 +++--- 6 files changed, 127 insertions(+), 15 deletions(-) diff --git a/docs/design/effects.txt b/docs/design/effects.txt index c88cc3f44c..59450896f3 100644 --- a/docs/design/effects.txt +++ b/docs/design/effects.txt @@ -164,8 +164,8 @@ C. Keyframes * Gets a property of a GstElement contained in @object. */ void ges_track_object_get_child_property (GESTrackObject *object, - const gchar *property_name, - gpointer value); + const gchar *property_name, + GValue * value); => DONE /** diff --git a/docs/libs/ges-sections.txt b/docs/libs/ges-sections.txt index 8c4899414a..50b7e7e8b5 100644 --- a/docs/libs/ges-sections.txt +++ b/docs/libs/ges-sections.txt @@ -107,9 +107,11 @@ ges_track_object_is_active ges_track_object_lookup_child ges_track_object_list_children_properties ges_track_object_set_child_property +ges_track_object_set_child_properties ges_track_object_set_child_property_valist ges_track_object_set_child_property_by_pspec ges_track_object_get_child_property +ges_track_object_get_child_properties ges_track_object_get_child_property_valist ges_track_object_get_child_property_by_pspec ges_track_object_edit diff --git a/ges/ges-pitivi-formatter.c b/ges/ges-pitivi-formatter.c index 61dc7ed7b5..9423fe9d6e 100644 --- a/ges/ges-pitivi-formatter.c +++ b/ges/ges-pitivi-formatter.c @@ -1028,7 +1028,7 @@ make_source (GESFormatter * self, GList * reflist, GHashTable * source_table) if (g_strstr_len (prop_val, -1, "(GEnum)")) { gchar **val = g_strsplit (prop_val, ")", 2); - ges_track_object_set_child_property (GES_TRACK_OBJECT (effect), + ges_track_object_set_child_properties (GES_TRACK_OBJECT (effect), (gchar *) tmp_key->data, atoi (val[1]), NULL); g_strfreev (val); diff --git a/ges/ges-track-object.c b/ges/ges-track-object.c index 8d1aac6e31..a3a957c434 100644 --- a/ges/ges-track-object.c +++ b/ges/ges-track-object.c @@ -1153,6 +1153,9 @@ ges_track_object_lookup_child (GESTrackObject * object, const gchar * prop_name, priv = object->priv; + if (!priv->properties_hashtable) + goto prop_hash_not_set; + classename = NULL; res = FALSE; @@ -1181,6 +1184,12 @@ ges_track_object_lookup_child (GESTrackObject * object, const gchar * prop_name, g_strfreev (names); return res; + +prop_hash_not_set: + { + GST_WARNING_OBJECT (object, "The child properties haven't been set yet"); + return FALSE; + } } /** @@ -1299,7 +1308,7 @@ cant_copy: } /** - * ges_track_object_set_child_property: + * ges_track_object_set_child_properties: * @object: The #GESTrackObject parent object * @first_property_name: The name of the first property to set * @...: value for the first property, followed optionally by more @@ -1313,7 +1322,7 @@ cant_copy: * Since: 0.10.2 */ void -ges_track_object_set_child_property (GESTrackObject * object, +ges_track_object_set_child_properties (GESTrackObject * object, const gchar * first_property_name, ...) { va_list var_args; @@ -1412,7 +1421,7 @@ ges_track_object_list_children_properties (GESTrackObject * object, } /** - * ges_track_object_get_child_property: + * ges_track_object_get_child_properties: * @object: The origin #GESTrackObject * @first_property_name: The name of the first property to get * @...: return location for the first property, followed optionally by more @@ -1423,7 +1432,7 @@ ges_track_object_list_children_properties (GESTrackObject * object, * Since: 0.10.2 */ void -ges_track_object_get_child_property (GESTrackObject * object, +ges_track_object_get_child_properties (GESTrackObject * object, const gchar * first_property_name, ...) { va_list var_args; @@ -1480,6 +1489,96 @@ prop_hash_not_set: } } +/** + * ges_track_object_set_child_property: + * @object: The origin #GESTrackObject + * @property_name: The name of the property + * @value: the value + * + * Sets a property of a GstElement contained in @object. + * + * Note that #ges_track_object_set_child_property is really + * intended for language bindings, #ges_track_object_set_child_properties + * is much more convenient for C programming. + * + * Returns: %TRUE if the property was set, %FALSE otherwize + */ +gboolean +ges_track_object_set_child_property (GESTrackObject * object, + const gchar * property_name, GValue * value) +{ + GParamSpec *pspec; + GstElement *element; + + g_return_val_if_fail (GES_IS_TRACK_OBJECT (object), FALSE); + + if (!ges_track_object_lookup_child (object, property_name, &element, &pspec)) + goto not_found; + + g_object_set_property (G_OBJECT (element), pspec->name, value); + + g_object_unref (element); + g_param_spec_unref (pspec); + + return TRUE; + +not_found: + { + GST_WARNING_OBJECT (object, "The %s property doesn't exist", property_name); + + return FALSE; + } +} + +/** +* ges_track_object_get_child_property: +* @object: The origin #GESTrackObject +* @property_name: The name of the property +* @value: (out): return location for the property value, it will +* be initialized if it is initialized with 0 +* +* In general, a copy is made of the property contents and +* the caller is responsible for freeing the memory by calling +* g_value_unset(). +* +* Gets a property of a GstElement contained in @object. +* +* Note that #ges_track_object_get_child_property is really +* intended for language bindings, #ges_track_object_get_child_properties +* is much more convenient for C programming. +* +* Returns: %TRUE if the property was found, %FALSE otherwize +*/ +gboolean +ges_track_object_get_child_property (GESTrackObject * object, + const gchar * property_name, GValue * value) +{ + GParamSpec *pspec; + GstElement *element; + + g_return_val_if_fail (GES_IS_TRACK_OBJECT (object), FALSE); + + if (!ges_track_object_lookup_child (object, property_name, &element, &pspec)) + goto not_found; + + if (G_VALUE_TYPE (value) == G_TYPE_INVALID) + g_value_init (value, pspec->value_type); + + g_object_get_property (G_OBJECT (element), pspec->name, value); + + g_object_unref (element); + g_param_spec_unref (pspec); + + return TRUE; + +not_found: + { + GST_WARNING_OBJECT (object, "The %s property doesn't exist", property_name); + + return FALSE; + } +} + static GParamSpec ** default_list_children_properties (GESTrackObject * object, guint * n_properties) { diff --git a/ges/ges-track-object.h b/ges/ges-track-object.h index db8d2e92bc..a9bdc79c98 100644 --- a/ges/ges-track-object.h +++ b/ges/ges-track-object.h @@ -208,7 +208,7 @@ ges_track_object_get_child_property_valist (GESTrackObject * object, const gchar * first_property_name, va_list var_args); -void ges_track_object_get_child_property (GESTrackObject *object, +void ges_track_object_get_child_properties (GESTrackObject *object, const gchar * first_property_name, ...) G_GNUC_NULL_TERMINATED; @@ -222,13 +222,21 @@ ges_track_object_set_child_property_by_pspec (GESTrackObject * object, GParamSpec * pspec, GValue * value); -void ges_track_object_set_child_property (GESTrackObject * object, +void ges_track_object_set_child_properties (GESTrackObject * object, const gchar * first_property_name, ...) G_GNUC_NULL_TERMINATED; GESTrackObject * ges_track_object_copy (GESTrackObject * object, gboolean deep); +gboolean ges_track_object_set_child_property (GESTrackObject *object, + const gchar *property_name, + GValue * value); + +gboolean ges_track_object_get_child_property (GESTrackObject *object, + const gchar *property_name, + GValue * value); + gboolean ges_track_object_edit (GESTrackObject * object, GList *layers, GESEditMode mode, diff --git a/tests/check/ges/effects.c b/tests/check/ges/effects.c index 0ec7542287..17ea2144fa 100644 --- a/tests/check/ges/effects.c +++ b/tests/check/ges/effects.c @@ -356,9 +356,9 @@ GST_START_TEST (test_track_effect_set_properties) (tl_effect), tck_effect)); fail_unless (ges_track_add_object (track_video, tck_effect)); - ges_track_object_set_child_property (tck_effect, + ges_track_object_set_child_properties (tck_effect, "GstAgingTV::scratch-lines", 17, "color-aging", FALSE, NULL); - ges_track_object_get_child_property (tck_effect, + ges_track_object_get_child_properties (tck_effect, "GstAgingTV::scratch-lines", &scratch_line, "color-aging", &color_aging, NULL); fail_unless (scratch_line == 17); @@ -417,7 +417,7 @@ GST_START_TEST (test_tl_obj_signals) GESTrack *track_video; GESTimelineParseLaunchEffect *tl_effect; GESTrackParseLaunchEffect *tck_effect; - guint val; + GValue val = { 0, }; ges_init (); @@ -446,11 +446,14 @@ GST_START_TEST (test_tl_obj_signals) g_signal_connect (tck_effect, "deep-notify", (GCallback) deep_prop_changed_cb, tck_effect); - ges_track_object_set_child_property (GES_TRACK_OBJECT (tck_effect), + ges_track_object_set_child_properties (GES_TRACK_OBJECT (tck_effect), "GstAgingTV::scratch-lines", 17, NULL); + + g_value_init (&val, G_TYPE_UINT); ges_track_object_get_child_property (GES_TRACK_OBJECT (tck_effect), - "GstAgingTV::scratch-lines", &val, NULL); - fail_unless (val == 17); + "GstAgingTV::scratch-lines", &val); + fail_unless (G_VALUE_HOLDS_UINT (&val)); + g_value_unset (&val); ges_timeline_layer_remove_object (layer, (GESTimelineObject *) tl_effect);