[gnac/devel] Code cleanup



commit d0c29fa7205af446351468634dcc56a6ebf50e65
Author: BenoÃt Dupasquier <bdupasqu src gnome org>
Date:   Sat Oct 22 18:23:42 2011 +0100

    Code cleanup

 libgnac/libgnac-error.c      |   32 +++++++++++++++++++++++----
 libgnac/libgnac-error.h      |    5 ++++
 libgnac/libgnac-media-item.c |   48 ++++++++++++++++++-----------------------
 libgnac/libgnac-media-item.h |    1 +
 4 files changed, 54 insertions(+), 32 deletions(-)
---
diff --git a/libgnac/libgnac-error.c b/libgnac/libgnac-error.c
index 77a359b..ddac65e 100644
--- a/libgnac/libgnac-error.c
+++ b/libgnac/libgnac-error.c
@@ -23,16 +23,38 @@
  * Boston, MA  02110-1301  USA
  */
 
+#include "libgnac-converter.h"
+#include "libgnac-debug.h"
 #include "libgnac-error.h"
 
 GQuark
 libgnac_error_quark(void)
 {
-  static GQuark quark = 0;
+  return g_quark_from_static_string("libgnac-error-quark");
+}
 
-  if (quark == 0) {
-    quark = g_quark_from_static_string("libgnac-error-quark");
-  }
 
-  return quark;
+void
+libgnac_error_handle_missing_plugin(LibgnacMediaItem *item,
+                                    const GError     *error)
+{
+  gchar *detail;
+  GstMessage *msg;
+
+  msg = gst_missing_element_message_new(item->pipeline, error->message);
+  g_return_if_fail(msg);
+  detail = gst_missing_plugin_message_get_installer_detail(msg);
+  gst_message_unref(msg);
+  if (detail) {
+    GstInstallPluginsReturn ret;
+    gchar *details[] = { detail, NULL };
+    ret = gst_install_plugins_async(details, NULL,
+        libgnac_converter_missing_plugin_result_cb, item->parent);
+    g_free(detail);
+    if (ret != GST_INSTALL_PLUGINS_STARTED_OK) {
+      libgnac_warning("Could not launch installer for required plugins");
+    } else {
+      libgnac_converter_emit_plugin_install(item->parent);
+    }
+  }
 }
diff --git a/libgnac/libgnac-error.h b/libgnac/libgnac-error.h
index 146fbbb..ce0c1c9 100644
--- a/libgnac/libgnac-error.h
+++ b/libgnac/libgnac-error.h
@@ -27,6 +27,7 @@
 #define __LIBGNAC_ERROR_H__
 
 #include <glib.h>
+#include "libgnac-media-item.h"
 
 #define LIBGNAC_ERROR libgnac_error_quark()
 
@@ -46,6 +47,10 @@ typedef enum
 
 GQuark libgnac_error_quark(void) G_GNUC_CONST;
 
+void
+libgnac_error_handle_missing_plugin(LibgnacMediaItem *item,
+                                    const GError     *error);
+
 G_END_DECLS
 
 #endif /* __LIBGNAC_ERROR_H__ */
diff --git a/libgnac/libgnac-media-item.c b/libgnac/libgnac-media-item.c
index fbea60e..5a88d0d 100644
--- a/libgnac/libgnac-media-item.c
+++ b/libgnac/libgnac-media-item.c
@@ -33,12 +33,17 @@
 #include "libgnac-error.h"
 #include "libgnac-gst.h"
 #include "libgnac-gst-utils.h"
+#include "libgnac-media-item.h"
 #include "libgnac-metadata.h"
 #include "libgnac-output.h"
 
 
 extern LibgnacMetadata *metadata;
 
+static gboolean
+libgnac_item_has_video(LibgnacMediaItem *item);
+
+
 LibgnacMediaItem *
 libgnac_item_new(GFile          *source,
                  LibgnacProfile *profile,
@@ -67,14 +72,12 @@ void
 libgnac_item_build(LibgnacMediaItem  *item, 
                    GError           **error)
 {
+  g_return_if_fail(error == NULL || *error == NULL);
+
   gboolean has_video = FALSE;
   GError *err = NULL;
-  LibgnacTags *tags;
   LibgnacOutputConfig *config;
 
-  g_return_if_fail(error == NULL || *error == NULL);
-
-  /* output */
   config = libgnac_converter_get_config(item->parent);
 
   if (item->destination) {
@@ -91,35 +94,14 @@ libgnac_item_build(LibgnacMediaItem  *item,
     return;
   }
 
-  /* is it a video file? */
-  tags = libgnac_metadata_extract(metadata, item->source, NULL);
-  if (tags && libgnac_metadata_tag_exists(tags, GNAC_TAG_HAS_VIDEO)) {
-    has_video = TRUE;
-  }
+  has_video = libgnac_item_has_video(item);
 
   libgnac_gst_build_pipeline(item, item->profile, has_video, &err);
   if (err) {
     if (g_error_matches(err, LIBGNAC_ERROR, LIBGNAC_ERROR_MISSING_PLUGIN) &&
         gst_install_plugins_supported())
     {
-      gchar *detail;
-      GstMessage *msg;
-      msg = gst_missing_element_message_new(item->pipeline, err->message);
-      g_return_if_fail(msg);
-      detail = gst_missing_plugin_message_get_installer_detail(msg);
-      gst_message_unref(msg);
-      if (detail) {
-        GstInstallPluginsReturn ret;
-        gchar *details[] = { detail, NULL };
-        ret = gst_install_plugins_async(details, NULL,
-            libgnac_converter_missing_plugin_result_cb, item->parent);
-        g_free(detail);
-        if (ret != GST_INSTALL_PLUGINS_STARTED_OK) {
-          libgnac_warning("Could not launch installer for required plugins");
-        } else {
-          libgnac_converter_emit_plugin_install(item->parent);
-        }
-      }
+      libgnac_error_handle_missing_plugin(item, err);
       return;
     } else {
       libgnac_warning("Unable to build pipeline");
@@ -143,6 +125,18 @@ libgnac_item_build(LibgnacMediaItem  *item,
 }
 
 
+static gboolean
+libgnac_item_has_video(LibgnacMediaItem *item)
+{
+  LibgnacTags *tags;
+  tags = libgnac_metadata_extract(metadata, item->source, NULL);
+  if (tags && libgnac_metadata_tag_exists(tags, GNAC_TAG_HAS_VIDEO)) {
+    return TRUE;
+  }
+  return FALSE;
+}
+
+
 void
 libgnac_item_run(LibgnacMediaItem  *item, 
                            GError **error)
diff --git a/libgnac/libgnac-media-item.h b/libgnac/libgnac-media-item.h
index 3ade56c..5d6cfb2 100644
--- a/libgnac/libgnac-media-item.h
+++ b/libgnac/libgnac-media-item.h
@@ -26,6 +26,7 @@
 #ifndef __LIBGNAC_MEDIA_ITEM_H__
 #define __LIBGNAC_MEDIA_ITEM_H__
 
+#include <gio/gio.h>
 #include <glib.h>
 #include <glib-object.h>
 #include <gst/gst.h>



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]