[gnac/devel: 4/5] Partly finish separation between libgnac-output, converter and media-item.



commit fff4db9ced55eb25bee158416563bc45519ffc99
Author: David Joaquim <djoaquim src gnome org>
Date:   Sun May 9 16:05:47 2010 +0200

    Partly finish separation between libgnac-output, converter and media-item.

 libgnac/libgnac-converter.c  |   16 +++++++++-
 libgnac/libgnac-converter.h  |    5 +++
 libgnac/libgnac-media-item.c |   10 +++++-
 libgnac/libgnac-output.c     |   70 ++++++++++++++----------------------------
 libgnac/libgnac-output.h     |   28 ++++++++---------
 5 files changed, 65 insertions(+), 64 deletions(-)
---
diff --git a/libgnac/libgnac-converter.c b/libgnac/libgnac-converter.c
index 9d777e2..c0812de 100644
--- a/libgnac/libgnac-converter.c
+++ b/libgnac/libgnac-converter.c
@@ -35,7 +35,6 @@
 #include "libgnac-error.h"
 #include "libgnac-gst.h"
 #include "libgnac-marshallers.h"
-#include "libgnac-output.h"
 
 
 // TODO add WARNING and PAUSED, and RESUMED ?
@@ -645,6 +644,21 @@ libgnac_converter_new(LibgnacMetadata *mdata)
   return g_object_new(LIBGNAC_TYPE_CONVERTER, NULL);
 }
 
+LibgnacOutputConfig *
+libgnac_converter_get_config(LibgnacConverter *self)
+{
+  LibgnacOutputConfig *config = g_malloc(sizeof(LibgnacOutputConfig));
+
+  g_object_get(self, "extension", &(config->extension), NULL);
+  g_object_get(self, "strip-special", &(config->strip_special), NULL);
+  g_object_get(self, "folder-hierarchy", &(config->folder_hierarchy), NULL); 
+  g_object_get(self, "folder-path", &(config->folder_path), NULL); 
+  g_object_get(self, "rename-pattern", &(config->rename_pattern), NULL);
+  g_object_get(self, "folder-type", &(config->folder_type), NULL);
+
+  return config;
+}
+
 
 void
 libgnac_converter_add(LibgnacConverter  *self, 
diff --git a/libgnac/libgnac-converter.h b/libgnac/libgnac-converter.h
index 65063a0..ed7f3a4 100644
--- a/libgnac/libgnac-converter.h
+++ b/libgnac/libgnac-converter.h
@@ -35,6 +35,7 @@
 #include "libgnac-media-item.h"
 #include "libgnac-metadata.h"
 #include "libgnac-metadata-tags.h"
+#include "libgnac-output.h"
 
 #define PROGRESS_TIMEOUT 250
 
@@ -89,6 +90,10 @@ typedef struct
 GType 
 libgnac_converter_get_type(void);
 
+LibgnacOutputConfig *
+libgnac_converter_get_config(LibgnacConverter *self);
+
+
 GObject *
 libgnac_converter_new(LibgnacMetadata *mdata);
 
diff --git a/libgnac/libgnac-media-item.c b/libgnac/libgnac-media-item.c
index 6ba3099..710de0c 100644
--- a/libgnac/libgnac-media-item.c
+++ b/libgnac/libgnac-media-item.c
@@ -69,11 +69,19 @@ libgnac_item_build(LibgnacMediaItem  *item,
   gboolean has_video = FALSE;
   GError *err = NULL;
   LibgnacTags *tags;
+  LibgnacOutputConfig *config;
 
   g_return_if_fail(error == NULL || *error == NULL);
 
   /* output */
-  libgnac_output_build_output(item, &err);
+  config = libgnac_converter_get_config(item->parent);
+  // destination is already there
+  if (item->destination) return;
+  item->destination = libgnac_output_build_output(item->source, config, &err);
+  // TODO free config->*
+  g_free(config);
+
+
   if (err) {
     libgnac_warning("Output creation failed");
     g_propagate_error(error, err);
diff --git a/libgnac/libgnac-output.c b/libgnac/libgnac-output.c
index 95179d2..2e3bc95 100644
--- a/libgnac/libgnac-output.c
+++ b/libgnac/libgnac-output.c
@@ -341,7 +341,7 @@ libgnac_output_rename_pattern_process(LibgnacRenamePattern  *pattern,
 
 
 static gchar *
-libgnac_output_get_filename(LibgnacMediaItem *item, 
+libgnac_output_get_filename(GFile                *source, 
                             const gchar          *rename_pattern, 
                             GError              **error)
 {
@@ -354,16 +354,13 @@ libgnac_output_get_filename(GFile *input_file,
 */
 
   GError      *err = NULL;
-  GFile       *file = NULL;
   LibgnacTags *tags = NULL;
   gchar       *output = NULL;
 
-  file = item->source;
-
-  tags = libgnac_metadata_extract(metadata, item->source, NULL);
+  tags = libgnac_metadata_extract(metadata, source, NULL);
   if (!tags) 
   {
-    output = libgnac_output_remove_extension_from_file(file, &err);
+    output = libgnac_output_remove_extension_from_file(source, &err);
     if (err) 
     {
       libgnac_debug("Unable to remove extension");
@@ -393,45 +390,26 @@ libgnac_output_finalize(void)
 }
 
 
-void
-libgnac_output_build_output(LibgnacMediaItem  *item,
-                            GError               **error)
-{
-  /*
-void
-libgnac_output_build_output(GFile                 *file,
+GFile *
+libgnac_output_build_output(GFile  *source,
                             LibgnacOutputConfig   *config,
                             GError               **error)
-{*/
+{
+  GFile  *destination;
   GError *output_error = NULL;
   GFile  *out_directory;
   GFile  *parent;
-  gchar  *extension;
   gchar  *filename = NULL;
-  gchar  *folder_hierarchy;
-  gchar  *folder_path;
   gchar  *output_name;
   gchar  *sanitized;
-  gchar  *rename_pattern;
-  gboolean strip_special;
-  GnacFolderId folder_type;
-
-  g_return_if_fail(!error || !*error);
-
-  if (item->destination) return;
 
-  g_object_get(item->parent, "extension", &extension, NULL);
-  g_object_get(item->parent, "strip-special", &strip_special, NULL);
-  g_object_get(item->parent, "folder-hierarchy", &folder_hierarchy, NULL); 
-  g_object_get(item->parent, "folder-path", &folder_path, NULL); 
-  g_object_get(item->parent, "rename-pattern", &rename_pattern, NULL);
-  g_object_get(item->parent, "folder-type", &folder_type, NULL);
+  g_return_val_if_fail(!error || !*error, NULL);
 
-  filename = libgnac_output_get_filename(item, rename_pattern, &output_error);
+  filename = libgnac_output_get_filename(source, config->rename_pattern, &output_error);
   if (output_error) {  
     libgnac_debug("Filename creation failed");
     g_propagate_error(error, output_error);
-    return;
+    return NULL;
   }
   
   /*if (!filename) {
@@ -441,53 +419,51 @@ libgnac_output_build_output(GFile                 *file,
                 "Invalid output filename");
   }*/
 
-  switch (folder_type)
+  switch (config->folder_type)
   {
     case FOLDER_SUBDIRECTORY:
-      parent = g_file_get_parent(item->source);
-      out_directory = g_file_get_child(parent, folder_path);
+      parent = g_file_get_parent(source);
+      out_directory = g_file_get_child(parent, config->folder_path);
       g_object_unref(parent);
     break;
 
     case FOLDER_SELECTED:
-      out_directory = g_file_new_for_uri(folder_path);
+      out_directory = g_file_new_for_uri(config->folder_path);
     break;
 
     case FOLDER_CURRENT:
     default:
-      out_directory = g_file_get_parent(item->source);
+      out_directory = g_file_get_parent(source);
     break;
   }
 
   /* check whether we have to build a folder hierarchy */
-  if (!g_str_equal(g_strstrip(folder_hierarchy), "")) 
+  if (!g_str_equal(g_strstrip(config->folder_hierarchy), "")) 
   {
     /* replace all known patterns by their value */
     g_slist_foreach(rename_patterns,
-        (GFunc)libgnac_output_rename_pattern_process, &folder_hierarchy);
+        (GFunc)libgnac_output_rename_pattern_process, &(config->folder_hierarchy));
     /* build the output filename */
     output_name = g_strdup_printf("%s%c%s.%s", 
-                    folder_hierarchy, G_DIR_SEPARATOR, filename, extension);
+                    config->folder_hierarchy, G_DIR_SEPARATOR, filename, config->extension);
   }
   else
   {
-    output_name = g_strdup_printf("%s.%s", filename, extension);
+    output_name = g_strdup_printf("%s.%s", filename, config->extension);
   }
 
   /* sanitize the whole path */
-  sanitized = libgnac_output_sanitize_path(output_name, strip_special);
+  sanitized = libgnac_output_sanitize_path(output_name, config->strip_special);
 
   /* create the folder hierarchy and destination file */
-  item->destination = g_file_get_child(out_directory, sanitized);
+  destination = g_file_get_child(out_directory, sanitized);
 
   /* cleanup */
-  g_free(extension);
-  g_free(folder_hierarchy);
-  g_free(folder_path);
-  g_free(rename_pattern);
   g_free(output_name);
   g_free(sanitized);
   g_free(filename);
+
+  return destination;
 }
 
 
diff --git a/libgnac/libgnac-output.h b/libgnac/libgnac-output.h
index 57cbbf0..a3b52be 100644
--- a/libgnac/libgnac-output.h
+++ b/libgnac/libgnac-output.h
@@ -29,9 +29,6 @@
 #include <gio/gio.h>
 #include <glib.h>
 
-#include "libgnac-media-item.h"
-#include "libgnac-converter.h"
-
 G_BEGIN_DECLS
 
 #define RENAME_PATTERN_SEPARATOR '%'
@@ -69,16 +66,6 @@ G_BEGIN_DECLS
         (((LibgnacRenamePattern*)(o))->regex)
 
 typedef struct {
-  gchar *extension;
-  gboolean strip_special;
-  gchar *folder_hierarchy;
-  gchar *folder_path;
-  gchar *rename_pattern;
-  gchar *folder_type;
-
-} LibgnacOutputConfig;
-
-typedef struct {
   const GRegex *regex;
   gchar        *replace;
   gchar         id; /* single letter representing the pattern */
@@ -92,11 +79,22 @@ typedef enum
   FOLDER_TYPE_N
 } GnacFolderId;
 
+typedef struct {
+  gchar *extension;
+  gboolean strip_special;
+  gchar *folder_hierarchy;
+  gchar *folder_path;
+  gchar *rename_pattern;
+  GnacFolderId folder_type;
+} LibgnacOutputConfig;
+
+
 void
 libgnac_output_finalize(void);
 
-void
-libgnac_output_build_output(LibgnacMediaItem  *item, 
+GFile *
+libgnac_output_build_output(GFile  *source, 
+                            LibgnacOutputConfig *config,
                             GError               **error);
 
 gchar *



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