[gnac] Code refactoring



commit 475e89aad41b2debe04ae068ca9a46ea8987c0f6
Author: BenoÃt Dupasquier <bdupasqu src gnome org>
Date:   Fri Jan 27 18:26:26 2012 +0000

    Code refactoring

 libgnac/libgnac-converter.c                  |    2 +-
 libgnac/libgnac-media-item.c                 |   44 ++++++++++++++-----------
 libgnac/libgnac-media-item.h                 |    4 --
 libgnac/libgnac-metadata.c                   |    4 ++-
 libgnac/libgnac-output.c                     |   32 ++++++++++---------
 src/profiles/formats/gnac-profiles-aac.c     |    2 -
 src/profiles/formats/gnac-profiles-flac.c    |    2 -
 src/profiles/formats/gnac-profiles-lame.c    |    1 -
 src/profiles/formats/gnac-profiles-speex.c   |    1 -
 src/profiles/formats/gnac-profiles-vorbis.c  |    1 -
 src/profiles/formats/gnac-profiles-wavpack.c |    1 -
 src/profiles/gnac-profiles-utils.c           |    1 -
 12 files changed, 46 insertions(+), 49 deletions(-)
---
diff --git a/libgnac/libgnac-converter.c b/libgnac/libgnac-converter.c
index 0fc9ccf..e21e2c5 100644
--- a/libgnac/libgnac-converter.c
+++ b/libgnac/libgnac-converter.c
@@ -94,7 +94,7 @@ libgnac_converter_init(LibgnacConverter *self)
   priv->file_table = g_hash_table_new_full(g_str_hash, g_str_equal, g_free,
       (GDestroyNotify) libgnac_item_free);
 
-  priv->profile = (LibgnacProfile *) g_malloc(sizeof(LibgnacProfile));
+  priv->profile = g_malloc(sizeof(LibgnacProfile));
 
   priv->profile->audio_desc = NULL;
   priv->profile->video_desc = NULL;
diff --git a/libgnac/libgnac-media-item.c b/libgnac/libgnac-media-item.c
index 192c692..1bdeb04 100644
--- a/libgnac/libgnac-media-item.c
+++ b/libgnac/libgnac-media-item.c
@@ -49,8 +49,7 @@ libgnac_item_new(GFile          *source,
                  LibgnacProfile *profile,
                  gpointer        parent)
 {
-  LibgnacMediaItem *item = (LibgnacMediaItem *)
-      g_malloc(sizeof(LibgnacMediaItem));
+  LibgnacMediaItem *item = g_malloc(sizeof(LibgnacMediaItem));
   
   item->parent = parent;
   item->source = g_file_dup(source);
@@ -67,7 +66,24 @@ libgnac_item_new(GFile          *source,
 }
 
 
-void
+static void
+libgnac_item_connect_signals(LibgnacMediaItem *item)
+{
+  /* Connect item callbacks*/
+  g_signal_connect(G_OBJECT(item->bus), "message::eos",
+      G_CALLBACK(libgnac_item_eos_cb), item);
+  g_signal_connect(G_OBJECT(item->bus), "message::error",
+      G_CALLBACK(libgnac_item_error_cb), item);
+
+  /* Connect parent callbacks */
+  g_signal_connect(G_OBJECT(item->bus), "message::eos",
+      G_CALLBACK(libgnac_converter_eos_cb), item->parent);
+  g_signal_connect(G_OBJECT(item->bus), "message::error",
+      G_CALLBACK(libgnac_converter_error_cb), item->parent);
+}
+
+
+static void
 libgnac_item_build(LibgnacMediaItem  *item, 
                    GError           **error)
 {
@@ -108,17 +124,7 @@ libgnac_item_build(LibgnacMediaItem  *item,
     }
   }
 
-  /* Connect item callbacks*/
-  g_signal_connect(G_OBJECT(item->bus), "message::eos", 
-      G_CALLBACK(libgnac_item_eos_cb), item);
-  g_signal_connect(G_OBJECT(item->bus), "message::error", 
-      G_CALLBACK(libgnac_item_error_cb), item);
-
-  /* Connect parent callbacks */
-  g_signal_connect(G_OBJECT(item->bus), "message::eos", 
-      G_CALLBACK(libgnac_converter_eos_cb), item->parent);
-  g_signal_connect(G_OBJECT(item->bus), "message::error", 
-      G_CALLBACK(libgnac_converter_error_cb), item->parent);
+  libgnac_item_connect_signals(item);
 }
 
 
@@ -126,7 +132,7 @@ static gboolean
 libgnac_item_has_video(LibgnacMediaItem *item)
 {
   LibgnacTags *tags = libgnac_metadata_extract(metadata, item->source, NULL);
-  if (tags && libgnac_metadata_tag_exists(tags, GNAC_TAG_HAS_VIDEO)) {
+  if (libgnac_metadata_tag_exists(tags, GNAC_TAG_HAS_VIDEO)) {
     return TRUE;
   }
 
@@ -136,7 +142,7 @@ libgnac_item_has_video(LibgnacMediaItem *item)
 
 void
 libgnac_item_run(LibgnacMediaItem  *item, 
-                           GError **error)
+                 GError           **error)
 {
   g_return_if_fail(!error || !*error);
 
@@ -144,7 +150,7 @@ libgnac_item_run(LibgnacMediaItem  *item,
 
   /* Build pipeline if doesn't exist */
   libgnac_item_build(item, &err);
-  if(err) {
+  if (err) {
     g_propagate_error(error, err);
     return;
   }
@@ -230,8 +236,8 @@ libgnac_item_clear_event_src(LibgnacMediaItem *item)
 
 void
 libgnac_item_eos_cb(GstBus     *bus, 
-                   GstMessage *message, 
-                   gpointer    data)
+                    GstMessage *message,
+                    gpointer    data)
 {
   LibgnacMediaItem *item = (LibgnacMediaItem *) data;
   libgnac_item_clear_event_src(item);
diff --git a/libgnac/libgnac-media-item.h b/libgnac/libgnac-media-item.h
index f9065ea..696fa23 100644
--- a/libgnac/libgnac-media-item.h
+++ b/libgnac/libgnac-media-item.h
@@ -58,10 +58,6 @@ libgnac_item_new(GFile          *source,
                  gpointer        parent);
 
 void
-libgnac_item_build(LibgnacMediaItem  *item, 
-                   GError           **error);
-
-void
 libgnac_item_run(LibgnacMediaItem  *item, 
                  GError           **error);
 
diff --git a/libgnac/libgnac-metadata.c b/libgnac/libgnac-metadata.c
index 9cba697..e677e29 100644
--- a/libgnac/libgnac-metadata.c
+++ b/libgnac/libgnac-metadata.c
@@ -698,13 +698,15 @@ libgnac_metadata_tag_exists(LibgnacTags *tags,
 gboolean
 libgnac_metadata_tags_exist(LibgnacTags *tags, ...)
 {
+  if (!tags) return FALSE;
+
   gboolean missing = FALSE;
   gchar *name;
   va_list names;
 
   va_start(names, tags);
 
-  while ((name = va_arg(names, gchar*)) && !missing) {
+  while ((name = va_arg(names, gchar *)) && !missing) {
     if (!g_hash_table_lookup(tags, name)) missing = TRUE;
   }
 
diff --git a/libgnac/libgnac-output.c b/libgnac/libgnac-output.c
index 6afa13e..f3cd7e6 100644
--- a/libgnac/libgnac-output.c
+++ b/libgnac/libgnac-output.c
@@ -99,7 +99,6 @@ libgnac_output_remove_extension_from_file(GFile   *source_uri,
   g_return_val_if_fail(source_uri, NULL);
 
   GError *err = NULL;
-
   GFileInfo *info = g_file_query_info(source_uri,
       G_FILE_ATTRIBUTE_STANDARD_NAME,
       G_FILE_QUERY_INFO_NONE, NULL, &err);
@@ -116,7 +115,7 @@ libgnac_output_remove_extension_from_file(GFile   *source_uri,
 }
 
 
-static gchar*
+static gchar *
 libgnac_output_sanitize_path(const gchar *str,
                              gboolean     strip_special)
 {
@@ -266,16 +265,20 @@ libgnac_output_replace_pattern(LibgnacRenamePattern *pattern,
 
 
 static void
-libgnac_output_rename_patterns_init(LibgnacTags *tags)
+libgnac_output_rename_patterns_init(void)
 {
-  if (!rename_patterns) {
-    guint i;
-    for (i = 0; rename_pattern_id[i] != -1; i++)
-    {
-      rename_patterns = g_slist_append(rename_patterns, 
-          libgnac_output_rename_pattern_new(rename_pattern_id[i]));
-    };
+  guint i;
+  for (i = 0; rename_pattern_id[i] != -1; i++) {
+    rename_patterns = g_slist_append(rename_patterns,
+        libgnac_output_rename_pattern_new(rename_pattern_id[i]));
   }
+}
+
+
+static void
+libgnac_output_rename_patterns_update(LibgnacTags *tags)
+{
+  if (!rename_patterns) libgnac_output_rename_patterns_init();
 
   /* update the replacement values according to 
    * the tags of the current file */
@@ -324,7 +327,7 @@ libgnac_output_get_filename(GFile        *source,
 
   LibgnacTags *tags = libgnac_metadata_extract(metadata, source, NULL);
   if (tags) {
-    libgnac_output_rename_patterns_init(tags);
+    libgnac_output_rename_patterns_update(tags);
     output = g_strdup(rename_pattern);
     /* replace all known patterns by their value for the given file */
     g_slist_foreach(rename_patterns, 
@@ -358,8 +361,8 @@ libgnac_output_get_output_directory(GFile               *source,
 {
   GFile *out_directory;
 
-  switch (config->folder_type)
-  {
+  switch (config->folder_type) {
+
     case FOLDER_SUBDIRECTORY: {
       GFile *parent = g_file_get_parent(source);
       out_directory = g_file_get_child(parent, config->folder_path);
@@ -389,7 +392,6 @@ libgnac_output_build_output(GFile                *source,
   g_return_val_if_fail(!error || !*error, NULL);
 
   GError *output_error = NULL;
-
   gchar *filename = libgnac_output_get_filename(source,
       config->rename_pattern, &output_error);
   if (output_error) {
@@ -440,7 +442,7 @@ libgnac_output_get_preview_from_pattern(const gchar *pattern,
 {
   gchar *preview = g_strdup(pattern);
   LibgnacTags *tags = libgnac_metadata_get_dummy_tags();
-  libgnac_output_rename_patterns_init(tags);
+  libgnac_output_rename_patterns_update(tags);
 
   /* replace all known patterns by their value for the given file */
   g_slist_foreach(rename_patterns, 
diff --git a/src/profiles/formats/gnac-profiles-aac.c b/src/profiles/formats/gnac-profiles-aac.c
index 98deea7..653e8ca 100755
--- a/src/profiles/formats/gnac-profiles-aac.c
+++ b/src/profiles/formats/gnac-profiles-aac.c
@@ -166,7 +166,6 @@ gnac_profiles_aac_generate_audio_profile(GError **error)
   AudioProfileGeneric *generic = gnac_profiles_default_generate_audio_profile(
       &aac_bfi);
   AudioProfileAAC *profile = g_malloc(sizeof(AudioProfileAAC));
-  if (!profile) return NULL;
 
   profile->generic = generic;
 
@@ -212,7 +211,6 @@ gnac_profiles_aac_load_specific_properties(XMLDoc              *doc,
                                            AudioProfileGeneric *generic)
 {
   AudioProfileAAC *profile = g_malloc(sizeof(AudioProfileAAC));
-  if (!profile) return NULL;
 
   profile->generic = generic;
   gnac_profiles_utils_load_saved_profile(doc,
diff --git a/src/profiles/formats/gnac-profiles-flac.c b/src/profiles/formats/gnac-profiles-flac.c
index 3e1c7d5..ddc6f7c 100755
--- a/src/profiles/formats/gnac-profiles-flac.c
+++ b/src/profiles/formats/gnac-profiles-flac.c
@@ -129,7 +129,6 @@ gnac_profiles_flac_generate_audio_profile(GError **error)
   AudioProfileGeneric *generic = gnac_profiles_default_generate_audio_profile(
       &flac_bfi);
   AudioProfileFlac *profile = g_malloc(sizeof(AudioProfileFlac));
-  if (!profile) return NULL;
 
   profile->generic = generic;
 
@@ -168,7 +167,6 @@ gnac_profiles_flac_load_specific_properties(XMLDoc              *doc,
                                             AudioProfileGeneric *generic)
 {
   AudioProfileFlac *profile = g_malloc(sizeof(AudioProfileFlac));
-  if (!profile) return NULL;
 
   profile->generic = generic;
 
diff --git a/src/profiles/formats/gnac-profiles-lame.c b/src/profiles/formats/gnac-profiles-lame.c
index 850f453..b3906b2 100755
--- a/src/profiles/formats/gnac-profiles-lame.c
+++ b/src/profiles/formats/gnac-profiles-lame.c
@@ -405,7 +405,6 @@ static AudioProfileLame *
 gnac_profiles_lame_audio_profile_new(void)
 {
   AudioProfileLame *profile = g_malloc(sizeof(AudioProfileLame));
-  if (!profile) return NULL;
   
   profile->encoding_mode = NULL;
   profile->mode = NULL;
diff --git a/src/profiles/formats/gnac-profiles-speex.c b/src/profiles/formats/gnac-profiles-speex.c
index f5dd839..acb22fe 100644
--- a/src/profiles/formats/gnac-profiles-speex.c
+++ b/src/profiles/formats/gnac-profiles-speex.c
@@ -392,7 +392,6 @@ static AudioProfileSpeex *
 gnac_profiles_speex_audio_profile_new(void)
 {
   AudioProfileSpeex *profile = g_malloc(sizeof(AudioProfileSpeex));
-  if (!profile) return NULL;
   
   profile->quality_cbr = -1;
   profile->quality_vbr = -1;
diff --git a/src/profiles/formats/gnac-profiles-vorbis.c b/src/profiles/formats/gnac-profiles-vorbis.c
index 2cf8353..5622a28 100755
--- a/src/profiles/formats/gnac-profiles-vorbis.c
+++ b/src/profiles/formats/gnac-profiles-vorbis.c
@@ -251,7 +251,6 @@ static AudioProfileVorbis *
 gnac_profiles_vorbis_audio_profile_new(void)
 {
   AudioProfileVorbis *profile = g_malloc(sizeof(AudioProfileVorbis));
-  if (!profile) return NULL;
   
   profile->quality = -1;
   profile->bitrate = NULL;
diff --git a/src/profiles/formats/gnac-profiles-wavpack.c b/src/profiles/formats/gnac-profiles-wavpack.c
index f1cac83..cb3ea97 100644
--- a/src/profiles/formats/gnac-profiles-wavpack.c
+++ b/src/profiles/formats/gnac-profiles-wavpack.c
@@ -314,7 +314,6 @@ static AudioProfileWavpack *
 gnac_profiles_wavpack_audio_profile_new(void)
 {
   AudioProfileWavpack *profile = g_malloc(sizeof(AudioProfileWavpack));
-  if (!profile) return NULL;
   
   profile->mode = NULL;
   profile->bitrate = -1;
diff --git a/src/profiles/gnac-profiles-utils.c b/src/profiles/gnac-profiles-utils.c
index bf26865..c8fefef 100755
--- a/src/profiles/gnac-profiles-utils.c
+++ b/src/profiles/gnac-profiles-utils.c
@@ -733,7 +733,6 @@ AudioProfileGeneric *
 gnac_profiles_utils_audio_profile_generic_new(void)
 {
   AudioProfileGeneric *profile = g_malloc(sizeof(AudioProfileGeneric));
-  if (!profile) return NULL;
 
   profile->generic = profile;
   profile->name = NULL;



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