From a89683f06ab7cb1febe7b436f4895e2949a54f5f Mon Sep 17 00:00:00 2001 From: Thibault Saunier Date: Mon, 24 Sep 2012 22:24:42 +0200 Subject: [PATCH] formatter: Implement the GESExtractable interface Make it a GInitially unowned, GESProject will become the owner --- ges/ges-formatter.c | 74 ++++++++++++++++++++++++++++++++++++++++++++- ges/ges-formatter.h | 4 +-- 2 files changed, 75 insertions(+), 3 deletions(-) diff --git a/ges/ges-formatter.c b/ges/ges-formatter.c index aaf8884351..78e0bb72e3 100644 --- a/ges/ges-formatter.c +++ b/ges/ges-formatter.c @@ -51,7 +51,11 @@ #include "ges-internal.h" #include "ges.h" -G_DEFINE_ABSTRACT_TYPE (GESFormatter, ges_formatter, G_TYPE_OBJECT); +static void ges_extractable_interface_init (GESExtractableInterface * iface); + +G_DEFINE_ABSTRACT_TYPE_WITH_CODE (GESFormatter, ges_formatter, + G_TYPE_INITIALLY_UNOWNED, G_IMPLEMENT_INTERFACE (GES_TYPE_EXTRACTABLE, + ges_extractable_interface_init)); struct _GESFormatterPrivate { @@ -71,6 +75,74 @@ enum LAST_SIGNAL }; +/* Utils */ +static GESFormatterClass * +ges_formatter_find_for_uri (const gchar * uri) +{ + GType *formatters; + guint n_formatters, i; + GESFormatterClass *class, *ret = NULL; + + formatters = g_type_children (GES_TYPE_FORMATTER, &n_formatters); + for (i = 0; i < n_formatters; i++) { + class = g_type_class_ref (formatters[i]); + + if (class->can_load_uri (uri, NULL)) { + ret = class; + break; + } + g_type_class_unref (class); + } + + g_free (formatters); + + return ret; +} + +/* GESExtractable implementation */ +static gchar * +extractable_check_id (GType type, const gchar * id) +{ + if (gst_uri_is_valid (id)) + return g_strdup (id); + + return NULL; +} + +static gchar * +extractable_get_id (GESExtractable * self) +{ + GESAsset *asset; + + if (!(asset = ges_extractable_get_asset (self))) + return NULL; + + return g_strdup (ges_asset_get_id (asset)); +} + +static GType +extractable_get_real_extractable_type (GType type, const gchar * id) +{ + GType real_type = G_TYPE_NONE; + GESFormatterClass *class; + + class = ges_formatter_find_for_uri (id); + if (class) { + real_type = G_OBJECT_CLASS_TYPE (class); + g_type_class_unref (class); + } + + return real_type; +} + +static void +ges_extractable_interface_init (GESExtractableInterface * iface) +{ + iface->check_id = (GESExtractableCheckId) extractable_check_id; + iface->get_id = extractable_get_id; + iface->get_real_extractable_type = extractable_get_real_extractable_type; +} + static void ges_formatter_class_init (GESFormatterClass * klass) { diff --git a/ges/ges-formatter.h b/ges/ges-formatter.h index 93e2e67343..b4159f584d 100644 --- a/ges/ges-formatter.h +++ b/ges/ges-formatter.h @@ -50,7 +50,7 @@ typedef struct _GESFormatterPrivate GESFormatterPrivate; */ struct _GESFormatter { - GObject parent; + GInitiallyUnowned parent; /*< private >*/ GESFormatterPrivate *priv; @@ -114,7 +114,7 @@ typedef gboolean (*GESFormatterSaveToURIMethod) (GESFormatter *formatter, */ struct _GESFormatterClass { - GObjectClass parent_class; + GInitiallyUnownedClass parent_class; GESFormatterCanLoadURIMethod can_load_uri; GESFormatterCanSaveURIMethod can_save_uri;