From b5f2c819fc62acdccf4de00e3a002cc6d9706090 Mon Sep 17 00:00:00 2001 From: Thibault Saunier Date: Sat, 23 Mar 2013 09:46:38 +0100 Subject: [PATCH] container: Properly implement ges_container_group --- ges/ges-clip.c | 1 + ges/ges-container.c | 40 +++++++++++++++++++++++++++++++++++++--- ges/ges-container.h | 2 ++ 3 files changed, 40 insertions(+), 3 deletions(-) diff --git a/ges/ges-clip.c b/ges/ges-clip.c index 296ae26a50..61f6b1e8fb 100644 --- a/ges/ges-clip.c +++ b/ges/ges-clip.c @@ -473,6 +473,7 @@ ges_clip_class_init (GESClipClass * klass) container_class->remove_child = _remove_child; container_class->ungroup = _ungroup; container_class->group = _group; + container_class->grouping_priority = G_MAXUINT; klass->need_fill_track = TRUE; } diff --git a/ges/ges-container.c b/ges/ges-container.c index 22de7c0b6c..80b79b7205 100644 --- a/ges/ges-container.c +++ b/ges/ges-container.c @@ -139,6 +139,25 @@ _free_mapping (ChildMapping * mapping) g_slice_free (ChildMapping, mapping); } +static gint +compare_grouping_prio (GType * a, GType * b) +{ + gint ret = 0; + GObjectClass *aclass = g_type_class_ref (*a); + GObjectClass *bclass = g_type_class_ref (*b); + + if (GES_CONTAINER_CLASS (aclass)->grouping_priority < + GES_CONTAINER_CLASS (bclass)->grouping_priority) + ret = -1; + else if (GES_CONTAINER_CLASS (aclass)->grouping_priority > + GES_CONTAINER_CLASS (bclass)->grouping_priority) + ret = 1; + + g_type_class_unref (aclass); + g_type_class_unref (bclass); + return ret; +} + /***************************************************** * * * GESTimelineElement virtual methods implementation * @@ -390,6 +409,7 @@ ges_container_class_init (GESContainerClass * klass) klass->add_child = NULL; klass->ungroup = NULL; klass->group = NULL; + klass->grouping_priority = 0; } static void @@ -734,11 +754,15 @@ GESContainer * ges_container_group (GList * containers) { GList *tmp; - GESContainer *ret; + guint n_children; GESTimeline *timeline; + GType *children_types; GESTimelineElement *element; GObjectClass *clip_class; + guint i = 0; + GESContainer *ret = NULL; + g_return_val_if_fail (containers, NULL); element = GES_TIMELINE_ELEMENT (containers->data); timeline = ges_timeline_element_get_timeline (element); @@ -753,8 +777,18 @@ ges_container_group (GList * containers) (GES_TIMELINE_ELEMENT (tmp->data)) == timeline, NULL); } - clip_class = g_type_class_peek (GES_TYPE_CLIP); - ret = GES_CONTAINER_CLASS (clip_class)->group (containers); + children_types = g_type_children (GES_TYPE_CONTAINER, &n_children); + g_qsort_with_data (children_types, n_children, sizeof (GType), + (GCompareDataFunc) compare_grouping_prio, NULL); + for (i = 0; i < n_children; i++) { + clip_class = g_type_class_peek (children_types[i]); + ret = GES_CONTAINER_CLASS (clip_class)->group (containers); + + if (ret) + break; + } + + g_free (children_types); return ret; } diff --git a/ges/ges-container.h b/ges/ges-container.h index 1f6a5718d7..3953118341 100644 --- a/ges/ges-container.h +++ b/ges/ges-container.h @@ -118,6 +118,8 @@ struct _GESContainerClass /*< private >*/ + guint grouping_priority; + /* Padding for API extension */ gpointer _ges_reserved[GES_PADDING_LARGE]; };