[easytag/wip/gerror: 2/6] Use GError in FLAC tagging code



commit edcce9dbb59f6aa2fcc67b69c912046d25e40cdf
Author: David King <amigadave amigadave com>
Date:   Tue Sep 23 22:28:36 2014 +0100

    Use GError in FLAC tagging code
    
    Avoid several uses of Log_Print().

 src/et_core.c       |    8 +++++-
 src/tags/flac_tag.c |   39 +++++++++++++++++++++++--------------
 src/tags/flac_tag.h |   52 +++++++++++++++++++++-----------------------------
 3 files changed, 52 insertions(+), 47 deletions(-)
---
diff --git a/src/et_core.c b/src/et_core.c
index 1588650..0a9dd23 100644
--- a/src/et_core.c
+++ b/src/et_core.c
@@ -546,7 +546,11 @@ GList *ET_Add_File_To_File_List (gchar *filename)
 #endif
 #ifdef ENABLE_FLAC
         case FLAC_TAG:
-            Flac_Tag_Read_File_Tag(filename,FileTag);
+            if (!flac_tag_read_file_tag (filename, FileTag, &error))
+            {
+                Log_Print (LOG_ERROR, "%s", error->message);
+                g_clear_error (&error);
+            }
             break;
 #endif
         case APE_TAG:
@@ -3435,7 +3439,7 @@ ET_Save_File_Tag_To_HD (ET_File *ETFile, GError **error)
 #endif
 #ifdef ENABLE_FLAC
         case FLAC_TAG:
-            state = Flac_Tag_Write_File_Tag(ETFile);
+            state = flac_tag_write_file_tag (ETFile, error);
             break;
 #endif
         case APE_TAG:
diff --git a/src/tags/flac_tag.c b/src/tags/flac_tag.c
index ec0ccb2..8976d91 100644
--- a/src/tags/flac_tag.c
+++ b/src/tags/flac_tag.c
@@ -99,9 +99,12 @@ static gboolean Flac_Set_Tag (FLAC__StreamMetadata *vc_block, const gchar *tag_n
  *  - if field is found but contains no info (strlen(str)==0), we don't read it
  */
 gboolean
-Flac_Tag_Read_File_Tag (const gchar *filename, File_Tag *FileTag)
+flac_tag_read_file_tag (const gchar *filename,
+                        File_Tag *FileTag,
+                        GError **error)
 {
     FLAC__Metadata_SimpleIterator *iter;
+    const gchar *flac_error_msg;
     gchar *string = NULL;
     gchar *filename_utf8 = filename_to_display(filename);
     guint i;
@@ -109,8 +112,7 @@ Flac_Tag_Read_File_Tag (const gchar *filename, File_Tag *FileTag)
     //gint j = 1;
 
     g_return_val_if_fail (filename != NULL && FileTag != NULL, FALSE);
-
-    flac_error_msg = NULL;
+    g_return_val_if_fail (error == NULL || *error == NULL, FALSE);
 
     // Initialize the iterator for the blocks
     iter = FLAC__metadata_simple_iterator_new();
@@ -129,9 +131,10 @@ Flac_Tag_Read_File_Tag (const gchar *filename, File_Tag *FileTag)
             FLAC__metadata_simple_iterator_delete(iter);
         }
 
-        Log_Print (LOG_ERROR, _("Error while opening file ‘%s’ as FLAC: %s"),
-                   filename_utf8, flac_error_msg);
-        g_free(filename_utf8);
+        g_set_error (error, G_FILE_ERROR, G_FILE_ERROR_FAILED,
+                     _("Error while opening file ‘%s’ as FLAC: %s"),
+                     filename_utf8, flac_error_msg);
+        g_free (filename_utf8);
         return FALSE;
     }
     
@@ -817,22 +820,24 @@ static gboolean Flac_Set_Tag (FLAC__StreamMetadata *vc_block, const gchar *tag_n
 /*
  * Write Flac tag, using the level 2 flac interface
  */
-gboolean Flac_Tag_Write_File_Tag (ET_File *ETFile)
+gboolean
+flac_tag_write_file_tag (ET_File *ETFile, GError **error)
 {
     File_Tag *FileTag;
     gchar *filename_utf8, *filename;
     gchar *basename_utf8;
+    const gchar *flac_error_msg;
     FLAC__Metadata_Chain *chain;
     FLAC__Metadata_Iterator *iter;
     FLAC__StreamMetadata_VorbisComment_Entry vce_field_vendor_string; // To save vendor string
     gboolean vce_field_vendor_string_found = FALSE;
 
     g_return_val_if_fail (ETFile != NULL && ETFile->FileTag != NULL, FALSE);
+    g_return_val_if_fail (error == NULL || *error == NULL, FALSE);
 
     FileTag       = (File_Tag *)ETFile->FileTag->data;
     filename      = ((File_Name *)ETFile->FileNameCur->data)->value;
     filename_utf8 = ((File_Name *)ETFile->FileNameCur->data)->value_utf8;
-    flac_error_msg = NULL;
 
     /* libFLAC is able to detect (and skip) ID3v2 tags by itself */
     
@@ -853,8 +858,9 @@ gboolean Flac_Tag_Write_File_Tag (ET_File *ETFile)
             FLAC__metadata_chain_delete(chain);
         }
         
-        Log_Print (LOG_ERROR, _("Error while opening file ‘%s’ as FLAC: %s"),
-                   filename_utf8, flac_error_msg);
+        g_set_error (error, G_FILE_ERROR, G_FILE_ERROR_FAILED,
+                     _("Error while opening file ‘%s’ as FLAC: %s"),
+                     filename_utf8, flac_error_msg);
         return FALSE;
     }
     
@@ -864,8 +870,9 @@ gboolean Flac_Tag_Write_File_Tag (ET_File *ETFile)
     {
         flac_error_msg = 
FLAC__Metadata_ChainStatusString[FLAC__METADATA_CHAIN_STATUS_MEMORY_ALLOCATION_ERROR];
 
-        Log_Print (LOG_ERROR, _("Error while opening file ‘%s’ as FLAC: %s"),
-                   filename_utf8, flac_error_msg);
+        g_set_error (error, G_FILE_ERROR, G_FILE_ERROR_FAILED,
+                     _("Error while opening file ‘%s’ as FLAC: %s"),
+                     filename_utf8, flac_error_msg);
         return FALSE;
     }
     
@@ -1120,10 +1127,12 @@ gboolean Flac_Tag_Write_File_Tag (ET_File *ETFile)
 
         FLAC__metadata_chain_delete(chain);
         
-        Log_Print (LOG_ERROR, _("Failed to write comments to file ‘%s’: %s"),
-                   filename_utf8, flac_error_msg);
+        g_set_error (error, G_FILE_ERROR, G_FILE_ERROR_FAILED,
+                     _("Failed to write comments to file ‘%s’: %s"),
+                     filename_utf8, flac_error_msg);
         return FALSE;
-    }else
+    }
+    else
     {
         basename_utf8 = g_path_get_basename(filename_utf8);
         Log_Print (LOG_OK, _("Wrote tag of ‘%s’"), basename_utf8);
diff --git a/src/tags/flac_tag.h b/src/tags/flac_tag.h
index 9762aea..2ac8e57 100644
--- a/src/tags/flac_tag.h
+++ b/src/tags/flac_tag.h
@@ -1,43 +1,35 @@
-/* flac_tag.h - 2003/12/27 */
-/*
- *  EasyTAG - Tag editor for MP3 and Ogg Vorbis files
- *  Copyright (C) 2001-2003  Jerome Couderc <easytag gmail com>
- *  Copyright (C) 2003       Pavel Minayev <thalion front ru>
+/* EasyTAG - Tag editor for audo files
+ * Copyright (C) 2013  David King <amigadave amigadave com>
+ * Copyright (C) 2001-2003  Jerome Couderc <easytag gmail com>
+ * Copyright (C) 2003       Pavel Minayev <thalion front ru>
  *
- *  This program is free software; you can redistribute it and/or modify
- *  it under the terms of the GNU General Public License as published by
- *  the Free Software Foundation; either version 2 of the License, or
- *  (at your option) any later version.
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
  *
- *  This program is distributed in the hope that it will be useful,
- *  but WITHOUT ANY WARRANTY; without even the implied warranty of
- *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
- *  GNU General Public License for more details.
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
  *
- *  You should have received a copy of the GNU General Public License
- *  along with this program; if not, write to the Free Software
- *  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
  */
 
 
-#ifndef __FLAC_TAG_H__
-#define __FLAC_TAG_H__
-
+#ifndef ET_FLAC_TAG_H_
+#define ET_FLAC_TAG_H_
 
 #include <glib.h>
 #include "et_core.h"
 
-/***************
- * Declaration *
- ***************/
-const gchar *flac_error_msg;
-
+G_BEGIN_DECLS
 
-/**************
- * Prototypes *
- **************/
-gboolean Flac_Tag_Read_File_Tag  (const gchar *filename, File_Tag *FileTag);
-gboolean Flac_Tag_Write_File_Tag (ET_File *ETFile);
+gboolean flac_tag_read_file_tag (const gchar *filename, File_Tag *FileTag, GError **error);
+gboolean flac_tag_write_file_tag (ET_File *ETFile, GError **error);
 
+G_END_DECLS
 
-#endif /* __FLAC_TAG_H__ */
+#endif /* ET_FLAC_TAG_H_ */


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