formatter: Add GError everywhere needed in the API
authorThibault Saunier <thibault.saunier@collabora.com>
Sun, 23 Sep 2012 00:05:42 +0000 (02:05 +0200)
committerThibault Saunier <thibault.saunier@collabora.com>
Sun, 23 Sep 2012 00:37:12 +0000 (02:37 +0200)
We should give as much information as possible to the user when serialization/deserialization doesn't work.

ges/ges-formatter.c
ges/ges-formatter.h
ges/ges-pitivi-formatter.c
ges/ges-timeline.c
ges/ges-timeline.h
ges/ges.c
tests/check/ges/save_and_load.c
tests/examples/ges-ui.c
tools/ges-launch.c

index bf5828d2d642333b73ed32c4d41fa4dd8702a4bf..8593646e1d87c6808038a4bef0c70fe90c3f6ac1 100644 (file)
@@ -67,11 +67,11 @@ struct _GESFormatterPrivate
 
 static void ges_formatter_dispose (GObject * object);
 static gboolean load_from_uri (GESFormatter * formatter, GESTimeline *
-    timeline, const gchar * uri);
+    timeline, const gchar * uri, GError ** error);
 static gboolean save_to_uri (GESFormatter * formatter, GESTimeline *
-    timeline, const gchar * uri);
-static gboolean default_can_load_uri (const gchar * uri);
-static gboolean default_can_save_uri (const gchar * uri);
+    timeline, const gchar * uri, GError ** error);
+static gboolean default_can_load_uri (const gchar * uri, GError ** error);
+static gboolean default_can_save_uri (const gchar * uri, GError ** error);
 static void discovery_error_cb (GESTimeline * timeline,
     GESTimelineFileSource * tfs, GError * error, GESFormatter * formatter);
 
@@ -158,7 +158,7 @@ ges_formatter_dispose (GObject * object)
 GESFormatter *
 ges_formatter_new_for_uri (const gchar * uri)
 {
-  if (ges_formatter_can_load_uri (uri))
+  if (ges_formatter_can_load_uri (uri, NULL))
     return GES_FORMATTER (ges_keyfile_formatter_new ());
   return NULL;
 }
@@ -179,14 +179,14 @@ ges_default_formatter_new (void)
 }
 
 static gboolean
-default_can_load_uri (const gchar * uri)
+default_can_load_uri (const gchar * uri, GError ** error)
 {
   GST_ERROR ("No 'can_load_uri' vmethod implementation");
   return FALSE;
 }
 
 static gboolean
-default_can_save_uri (const gchar * uri)
+default_can_save_uri (const gchar * uri, GError ** error)
 {
   GST_ERROR ("No 'can_save_uri' vmethod implementation");
   return FALSE;
@@ -195,6 +195,7 @@ default_can_save_uri (const gchar * uri)
 /**
  * ges_formatter_can_load_uri:
  * @uri: a #gchar * pointing to the URI
+ * @error: A #GError that will be set in case of error
  *
  * Checks if there is a #GESFormatter available which can load a #GESTimeline
  * from the given URI.
@@ -204,7 +205,7 @@ default_can_save_uri (const gchar * uri)
  */
 
 gboolean
-ges_formatter_can_load_uri (const gchar * uri)
+ges_formatter_can_load_uri (const gchar * uri, GError ** error)
 {
   if (!(gst_uri_is_valid (uri))) {
     GST_ERROR ("Invalid uri!");
@@ -228,6 +229,7 @@ ges_formatter_can_load_uri (const gchar * uri)
 /**
  * ges_formatter_can_save_uri:
  * @uri: a #gchar * pointing to a URI
+ * @error: A #GError that will be set in case of error
  *
  * Returns TRUE if there is a #GESFormatter available which can save a
  * #GESTimeline to the given URI.
@@ -236,7 +238,7 @@ ges_formatter_can_load_uri (const gchar * uri)
  */
 
 gboolean
-ges_formatter_can_save_uri (const gchar * uri)
+ges_formatter_can_save_uri (const gchar * uri, GError ** error)
 {
   if (!(gst_uri_is_valid (uri))) {
     GST_ERROR ("%s invalid uri!", uri);
@@ -386,6 +388,7 @@ ges_formatter_save (GESFormatter * formatter, GESTimeline * timeline)
  * @formatter: a #GESFormatter
  * @timeline: a #GESTimeline
  * @uri: a #gchar * pointing to a URI
+ * @error: A #GError that will be set in case of error
  *
  * Load data from the given URI into timeline.
  *
@@ -395,7 +398,7 @@ ges_formatter_save (GESFormatter * formatter, GESTimeline * timeline)
 
 gboolean
 ges_formatter_load_from_uri (GESFormatter * formatter, GESTimeline * timeline,
-    const gchar * uri)
+    const gchar * uri, GError ** error)
 {
   gboolean ret = FALSE;
   GESFormatterClass *klass = GES_FORMATTER_GET_CLASS (formatter);
@@ -408,7 +411,7 @@ ges_formatter_load_from_uri (GESFormatter * formatter, GESTimeline * timeline,
   if (klass->load_from_uri) {
     ges_timeline_enable_update (timeline, FALSE);
     formatter->timeline = timeline;
-    ret = klass->load_from_uri (formatter, timeline, uri);
+    ret = klass->load_from_uri (formatter, timeline, uri, error);
     ges_timeline_enable_update (timeline, TRUE);
   }
 
@@ -417,7 +420,7 @@ ges_formatter_load_from_uri (GESFormatter * formatter, GESTimeline * timeline,
 
 static gboolean
 load_from_uri (GESFormatter * formatter, GESTimeline * timeline,
-    const gchar * uri)
+    const gchar * uri, GError ** error)
 {
   gchar *location;
   GError *e = NULL;
@@ -455,6 +458,7 @@ load_from_uri (GESFormatter * formatter, GESTimeline * timeline,
  * @formatter: a #GESFormatter
  * @timeline: a #GESTimeline
  * @uri: a #gchar * pointing to a URI
+ * @error: A #GError that will be set in case of error
  *
  * Save data from timeline to the given URI.
  *
@@ -464,12 +468,12 @@ load_from_uri (GESFormatter * formatter, GESTimeline * timeline,
 
 gboolean
 ges_formatter_save_to_uri (GESFormatter * formatter, GESTimeline *
-    timeline, const gchar * uri)
+    timeline, const gchar * uri, GError ** error)
 {
   GESFormatterClass *klass = GES_FORMATTER_GET_CLASS (formatter);
 
   if (klass->save_to_uri)
-    return klass->save_to_uri (formatter, timeline, uri);
+    return klass->save_to_uri (formatter, timeline, uri, error);
 
   GST_ERROR ("not implemented!");
 
@@ -478,7 +482,7 @@ ges_formatter_save_to_uri (GESFormatter * formatter, GESTimeline *
 
 static gboolean
 save_to_uri (GESFormatter * formatter, GESTimeline * timeline,
-    const gchar * uri)
+    const gchar * uri, GError ** error)
 {
   gchar *location;
   GError *e = NULL;
index 9d59ce2b8403928d15e195dd42a28b5621f3517f..df76e1478899b55c0ed22cd100ba1c34f9915e5d 100644 (file)
@@ -62,8 +62,8 @@ struct _GESFormatter {
   gpointer _ges_reserved[GES_PADDING - 1];
 };
 
-typedef gboolean (*GESFormatterCanLoadURIMethod) (const gchar * uri);
-typedef gboolean (*GESFormatterCanSaveURIMethod) (const gchar * uri);
+typedef gboolean (*GESFormatterCanLoadURIMethod) (const gchar * uri, GError **error);
+typedef gboolean (*GESFormatterCanSaveURIMethod) (const gchar * uri, GError **error);
 
 /**
  * GESFormatterLoadFromURIMethod:
@@ -79,8 +79,9 @@ typedef gboolean (*GESFormatterCanSaveURIMethod) (const gchar * uri);
  * else FALSE.
  **/
 typedef gboolean (*GESFormatterLoadFromURIMethod) (GESFormatter *formatter,
-                                                    GESTimeline *timeline,
-                                                    const gchar * uri);
+                  GESTimeline *timeline,
+                  const gchar * uri,
+                  GError **error);
 
 /**
  * GESFormatterSaveToURIMethod:
@@ -96,12 +97,12 @@ typedef gboolean (*GESFormatterLoadFromURIMethod) (GESFormatter *formatter,
  * else FALSE.
  */
 typedef gboolean (*GESFormatterSaveToURIMethod) (GESFormatter *formatter,
-                                                  GESTimeline *timeline,
-                                                  const gchar * uri);
+               GESTimeline *timeline,
+               const gchar * uri, GError **error);
 typedef gboolean (*GESFormatterSaveMethod) (GESFormatter * formatter,
-                                             GESTimeline * timeline);
+                GESTimeline * timeline);
 typedef gboolean (*GESFormatterLoadMethod) (GESFormatter * formatter,
-                                             GESTimeline * timeline);
+                GESTimeline * timeline);
 
 /**
  * GESFormatterSourceMovedMethod:
@@ -118,7 +119,7 @@ typedef gboolean (*GESFormatterLoadMethod) (GESFormatter * formatter,
  * Returns: %TRUE if the source URI could be modified properly, %FALSE otherwize.
  */
 typedef gboolean (*GESFormatterSourceMovedMethod)        (GESFormatter *formatter,
-                                          GESTimelineFileSource *tfs, gchar *new_uri);
+             GESTimelineFileSource *tfs, gchar *new_uri);
 
 /**
  * GESFormatterLoadedMethod:
@@ -171,20 +172,23 @@ GType ges_formatter_get_type (void);
 GESFormatter *ges_formatter_new_for_uri (const gchar *uri);
 GESFormatter *ges_default_formatter_new (void);
 
-gboolean ges_formatter_can_load_uri     (const gchar * uri);
-gboolean ges_formatter_can_save_uri     (const gchar * uri);
+gboolean ges_formatter_can_load_uri     (const gchar * uri, GError **error);
+gboolean ges_formatter_can_save_uri     (const gchar * uri, GError **error);
 
 gboolean ges_formatter_load_from_uri    (GESFormatter * formatter,
-                                        GESTimeline  *timeline,
-                                        const gchar *uri);
+                                         GESTimeline  *timeline,
+                                         const gchar *uri,
+                                         GError **error);
 
 gboolean ges_formatter_save_to_uri      (GESFormatter * formatter,
-                                        GESTimeline *timeline,
-                                        const gchar *uri);
+                                         GESTimeline *timeline,
+                                         const gchar *uri,
+                                         GError **error);
 
 gboolean
 ges_formatter_update_source_uri         (GESFormatter * formatter,
-    GESTimelineFileSource * source, gchar * new_uri);
+                                         GESTimelineFileSource * source,
+                                         gchar * new_uri);
 
 /*< protected >*/
 gboolean
@@ -192,14 +196,14 @@ ges_formatter_emit_loaded       (GESFormatter * formatter);
 
 /* Non-standard methods. WILL BE DEPRECATED */
 gboolean ges_formatter_load             (GESFormatter * formatter,
-                                        GESTimeline * timeline);
+           GESTimeline * timeline);
 gboolean ges_formatter_save             (GESFormatter * formatter,
-                                        GESTimeline * timeline);
+           GESTimeline * timeline);
 
 void ges_formatter_set_data             (GESFormatter * formatter,
-                                        void *data, gsize length);
+           void *data, gsize length);
 void *ges_formatter_get_data            (GESFormatter *formatter,
-                                        gsize *length);
+           gsize *length);
 void ges_formatter_clear_data           (GESFormatter *formatter);
 
 
index b4d4059c8a77eb93eb925977c537d80944637167..6515e2edcb14a59c0ba2aeea8b907f35bd2c4a3e 100644 (file)
@@ -43,10 +43,12 @@ GST_DEBUG_CATEGORY_STATIC (ges_pitivi_formatter_debug);
 /* The PiTiVi etree formatter is 0.1 we set GES one to 0.2 */
 #define VERSION "0.2"
 
+
+/* FIXME Properly set the GError when needed */
 static gboolean save_pitivi_timeline_to_uri (GESFormatter * formatter,
-    GESTimeline * timeline, const gchar * uri);
+    GESTimeline * timeline, const gchar * uri, GError ** error);
 static gboolean load_pitivi_file_from_uri (GESFormatter * self,
-    GESTimeline * timeline, const gchar * uri);
+    GESTimeline * timeline, const gchar * uri, GError ** error);
 static void ges_pitivi_formatter_finalize (GObject * object);
 static gboolean pitivi_formatter_update_source_uri (GESFormatter * formatter,
     GESTimelineFileSource * tfs, gchar * new_uri);
@@ -120,6 +122,10 @@ ges_pitivi_formatter_class_init (GESPitiviFormatterClass * klass)
 {
   GESFormatterClass *formatter_klass;
   GObjectClass *object_class;
+
+  GST_DEBUG_CATEGORY_INIT (ges_pitivi_formatter_debug, "ges_pitivi_formatter",
+      GST_DEBUG_FG_YELLOW, "ges pitivi formatter");
+
   object_class = G_OBJECT_CLASS (klass);
   formatter_klass = GES_FORMATTER_CLASS (klass);
   g_type_class_add_private (klass, sizeof (GESPitiviFormatterPrivate));
@@ -135,9 +141,6 @@ ges_pitivi_formatter_init (GESPitiviFormatter * self)
 {
   GESPitiviFormatterPrivate *priv;
 
-  GST_DEBUG_CATEGORY_INIT (ges_pitivi_formatter_debug, "ges_pitivi_formatter",
-      GST_DEBUG_FG_YELLOW, "ges pitivi formatter");
-
   self->priv = G_TYPE_INSTANCE_GET_PRIVATE (self,
       GES_TYPE_PITIVI_FORMATTER, GESPitiviFormatterPrivate);
 
@@ -497,7 +500,7 @@ save_timeline_objects (xmlTextWriterPtr writer, GList * list)
 
 static gboolean
 save_pitivi_timeline_to_uri (GESFormatter * formatter,
-    GESTimeline * timeline, const gchar * uri)
+    GESTimeline * timeline, const gchar * uri, GError ** error)
 {
   xmlTextWriterPtr writer;
   GList *list = NULL, *layers = NULL;
@@ -1050,7 +1053,7 @@ make_timeline_objects (GESFormatter * self)
 
 static gboolean
 load_pitivi_file_from_uri (GESFormatter * self,
-    GESTimeline * timeline, const gchar * uri)
+    GESTimeline * timeline, const gchar * uri, GError ** error)
 {
   xmlDocPtr doc;
   GESTimelineLayer *layer;
index 1d6d3b3b61fb04327d891e710ad53334bc814fb8..efba2ef4bb1dbba32a3185837f1f624cdaa9da3e 100644 (file)
@@ -1951,7 +1951,7 @@ ges_timeline_new (void)
  */
 
 GESTimeline *
-ges_timeline_new_from_uri (const gchar * uri)
+ges_timeline_new_from_uri (const gchar * uri, GError ** error)
 {
   GESTimeline *ret;
 
@@ -1961,7 +1961,7 @@ ges_timeline_new_from_uri (const gchar * uri)
 
   ret = ges_timeline_new ();
 
-  if (!ges_timeline_load_from_uri (ret, uri)) {
+  if (!ges_timeline_load_from_uri (ret, uri, error)) {
     g_object_unref (ret);
     return NULL;
   }
@@ -1982,7 +1982,8 @@ ges_timeline_new_from_uri (const gchar * uri)
  */
 
 gboolean
-ges_timeline_load_from_uri (GESTimeline * timeline, const gchar * uri)
+ges_timeline_load_from_uri (GESTimeline * timeline, const gchar * uri,
+    GError ** error)
 {
   GESFormatter *p = NULL;
   gboolean ret = FALSE;
@@ -1996,7 +1997,7 @@ ges_timeline_load_from_uri (GESTimeline * timeline, const gchar * uri)
     goto fail;
   }
 
-  if (!ges_formatter_load_from_uri (p, timeline, uri)) {
+  if (!ges_formatter_load_from_uri (p, timeline, uri, error)) {
     GST_ERROR ("error deserializing formatter");
     goto fail;
   }
@@ -2021,7 +2022,8 @@ fail:
  */
 
 gboolean
-ges_timeline_save_to_uri (GESTimeline * timeline, const gchar * uri)
+ges_timeline_save_to_uri (GESTimeline * timeline, const gchar * uri,
+    GError ** error)
 {
   GESFormatter *p = NULL;
   gboolean ret = FALSE;
@@ -2033,16 +2035,12 @@ ges_timeline_save_to_uri (GESTimeline * timeline, const gchar * uri)
    * will be saved with the same one by default ? We need to make this
    * easy from an API perspective */
 
-  /* FIXME : we should have a GError** argument so the user can know why
-   * it wasn't able to save
-   */
-
   if (!(p = ges_formatter_new_for_uri (uri))) {
     GST_ERROR ("unsupported uri '%s'", uri);
     goto fail;
   }
 
-  if (!ges_formatter_save_to_uri (p, timeline, uri)) {
+  if (!ges_formatter_save_to_uri (p, timeline, uri, error)) {
     GST_ERROR ("error serializing formatter");
     goto fail;
   }
index ad1992ca6ead54e3520c60c867df356a27799cf5..22a26ae6cc98ba8b15b8b765eec912114d65d1f0 100644 (file)
@@ -83,10 +83,10 @@ struct _GESTimelineClass {
 GType ges_timeline_get_type (void);
 
 GESTimeline* ges_timeline_new (void);
-GESTimeline* ges_timeline_new_from_uri (const gchar *uri);
+GESTimeline* ges_timeline_new_from_uri (const gchar *uri, GError **error);
 
-gboolean ges_timeline_load_from_uri (GESTimeline *timeline, const gchar *uri);
-gboolean ges_timeline_save_to_uri (GESTimeline *timeline, const gchar *uri);
+gboolean ges_timeline_load_from_uri (GESTimeline *timeline, const gchar *uri, GError **error);
+gboolean ges_timeline_save_to_uri (GESTimeline *timeline, const gchar *uri, GError **error);
 
 gboolean ges_timeline_add_layer (GESTimeline *timeline, GESTimelineLayer *layer);
 GESTimelineLayer * ges_timeline_append_layer (GESTimeline * timeline);
index abb137af8e37ad8d99d28cd68b3992f9678598b6..2f4073eb04cbe5e1e3a369413dede147df0b8370 100644 (file)
--- a/ges/ges.c
+++ b/ges/ges.c
@@ -70,6 +70,10 @@ ges_init (void)
   GES_TYPE_TIMELINE_STANDARD_TRANSITION;
   GES_TYPE_TIMELINE_OVERLAY;
 
+  /* register formatter types with the system */
+  GES_TYPE_PITIVI_FORMATTER;
+  GES_TYPE_KEYFILE_FORMATTER;
+
   /* check the gnonlin elements are available */
   if (!ges_check_gnonlin_availability ())
     return FALSE;
index b834ed499d4ee5905176967db6eaa554b7165519..af230f8e81479bedad60fce3ade6e0f011aae8d6 100644 (file)
@@ -660,14 +660,14 @@ GST_START_TEST (test_pitivi_file_load)
     return;
   }
 
-  ges_formatter_load_from_uri (formatter, timeline, uri);
+  ges_formatter_load_from_uri (formatter, timeline, uri, NULL);
   g_timeout_add (1000, (GSourceFunc) g_main_loop_quit, mainloop);
   g_main_loop_run (mainloop);
 
   formatter = GES_FORMATTER (ges_pitivi_formatter_new ());
-  ges_formatter_save_to_uri (formatter, timeline, save_uri);
+  ges_formatter_save_to_uri (formatter, timeline, save_uri, NULL);
   formatter = GES_FORMATTER (ges_pitivi_formatter_new ());
-  ges_formatter_load_from_uri (formatter, expected, uri);
+  ges_formatter_load_from_uri (formatter, expected, uri, NULL);
   g_timeout_add (1000, (GSourceFunc) g_main_loop_quit, mainloop);
   g_main_loop_run (mainloop);
 
index 249a0f29e4056f38cf240fb1f84cbd17554d7d61..12b0b7f6f9a80ecc95f55937325edb9fbe8b7cf7 100644 (file)
@@ -1184,7 +1184,7 @@ app_launch_project (App * app, gchar * uri)
   mainloop = g_main_loop_new (NULL, FALSE);
 
   ges_timeline_pipeline_add_timeline (pipeline, timeline);
-  ges_formatter_load_from_uri (formatter, timeline, uri);
+  ges_formatter_load_from_uri (formatter, timeline, uri, NULL);
   ges_timeline_pipeline_set_mode (pipeline, TIMELINE_MODE_PREVIEW_VIDEO);
   gst_element_set_state (GST_ELEMENT (pipeline), GST_STATE_PLAYING);
   gst_bus_add_signal_watch (bus);
@@ -1239,7 +1239,7 @@ app_add_transition (App * app)
 static void
 app_save_to_uri (App * app, gchar * uri)
 {
-  ges_timeline_save_to_uri (app->timeline, uri);
+  ges_timeline_save_to_uri (app->timeline, uri, NULL);
 }
 
 static void
@@ -1381,7 +1381,8 @@ load_file_async (App * app)
   g_printf ("%s\n", app->pending_uri);
 
   formatter = ges_formatter_new_for_uri (app->pending_uri);
-  ges_formatter_load_from_uri (formatter, app->timeline, app->pending_uri);
+  ges_formatter_load_from_uri (formatter, app->timeline, app->pending_uri,
+      NULL);
 
   g_free (app->pending_uri);
   app->pending_uri = NULL;
index 18124d7fa6cc2d136903714e0dfc22feefa11f6e..1771a67c35559a2dee25659326dd2b5937f97203 100644 (file)
@@ -256,7 +256,7 @@ create_pipeline (gchar * load_path, gchar * save_path, int argc, char **argv,
       goto failure;
     }
     g_printf ("reading from '%s' (arguments ignored)\n", load_path);
-    if (!(timeline = ges_timeline_new_from_uri (uri))) {
+    if (!(timeline = ges_timeline_new_from_uri (uri, NULL))) {
       g_error ("failed to create timeline from file '%s'", load_path);
       goto failure;
     }
@@ -275,7 +275,7 @@ create_pipeline (gchar * load_path, gchar * save_path, int argc, char **argv,
       g_error ("couldn't create uri for '%s", save_path);
       goto failure;
     }
-    ges_timeline_save_to_uri (timeline, uri);
+    ges_timeline_save_to_uri (timeline, uri, NULL);
     g_free (uri);
   }
 
@@ -381,7 +381,7 @@ load_project (gchar * uri)
   mainloop = g_main_loop_new (NULL, FALSE);
 
   ges_timeline_pipeline_add_timeline (pipeline, timeline);
-  ges_formatter_load_from_uri (formatter, timeline, uri);
+  ges_formatter_load_from_uri (formatter, timeline, uri, NULL);
   ges_timeline_pipeline_set_mode (pipeline, TIMELINE_MODE_PREVIEW_VIDEO);
 
   gst_element_set_state (GST_ELEMENT (pipeline), GST_STATE_PLAYING);