formatter: Implement the GESExtractable interface
authorThibault Saunier <thibault.saunier@collabora.com>
Mon, 24 Sep 2012 20:24:42 +0000 (22:24 +0200)
committerThibault Saunier <thibault.saunier@collabora.com>
Wed, 19 Dec 2012 21:59:50 +0000 (18:59 -0300)
Make it a GInitially unowned, GESProject will become the owner

ges/ges-formatter.c
ges/ges-formatter.h

index aaf8884..78e0bb7 100644 (file)
 #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)
 {
index 93e2e67..b4159f5 100644 (file)
@@ -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;