[easytag/wip/gerror: 3/6] Use GError in APE tagging code



commit 4b38bb79cfa9fd20cb2821ce3f003afd5bae0d01
Author: David King <amigadave amigadave com>
Date:   Tue Sep 23 22:34:59 2014 +0100

    Use GError in APE tagging code
    
    Avoid a use of Log_Print().

 src/et_core.c      |    6 +++++-
 src/tags/ape_tag.c |   16 ++++++++++------
 src/tags/ape_tag.h |    2 +-
 3 files changed, 16 insertions(+), 8 deletions(-)
---
diff --git a/src/et_core.c b/src/et_core.c
index 0a9dd23..4897e45 100644
--- a/src/et_core.c
+++ b/src/et_core.c
@@ -554,7 +554,11 @@ GList *ET_Add_File_To_File_List (gchar *filename)
             break;
 #endif
         case APE_TAG:
-            Ape_Tag_Read_File_Tag(filename,FileTag);
+            if (!ape_tag_read_file_tag (filename, FileTag, &error))
+            {
+                Log_Print (LOG_ERROR, "%s", error->message);
+                g_clear_error (&error);
+            }
             break;
 #ifdef ENABLE_MP4
         case MP4_TAG:
diff --git a/src/tags/ape_tag.c b/src/tags/ape_tag.c
index c251d9b..c8c0d9d 100644
--- a/src/tags/ape_tag.c
+++ b/src/tags/ape_tag.c
@@ -46,7 +46,9 @@
  *  - if field is found but contains no info (strlen(str)==0), we don't read it
  */
 gboolean
-Ape_Tag_Read_File_Tag (const gchar *filename, File_Tag *FileTag)
+ape_tag_read_file_tag (const gchar *filename,
+                       File_Tag *FileTag,
+                       GError **error)
 {
     FILE *file;
     gchar *string = NULL;
@@ -54,13 +56,15 @@ Ape_Tag_Read_File_Tag (const gchar *filename, File_Tag *FileTag)
     apetag *ape_cnt;
 
     g_return_val_if_fail (filename != NULL && FileTag != NULL, FALSE);
+    g_return_val_if_fail (error == NULL || *error == NULL, FALSE);
 
-    if ((file = fopen(filename, "rb")) == NULL)
+    if ((file = fopen (filename, "rb")) == NULL)
     {
-        gchar *filename_utf8 = filename_to_display(filename);
-        Log_Print (LOG_ERROR, _("Error while opening file ā€˜%sā€™: %s"),
-                   filename_utf8, g_strerror (errno));
-        g_free(filename_utf8);
+        gchar *filename_utf8 = filename_to_display (filename);
+        g_set_error (error, G_FILE_ERROR, g_file_error_from_errno (errno),
+                     _("Error while opening file ā€˜%sā€™: %s"),
+                     filename_utf8, g_strerror (errno));
+        g_free (filename_utf8);
         return FALSE;
     }
 
diff --git a/src/tags/ape_tag.h b/src/tags/ape_tag.h
index 45ee30e..752abc2 100644
--- a/src/tags/ape_tag.h
+++ b/src/tags/ape_tag.h
@@ -25,7 +25,7 @@
 
 G_BEGIN_DECLS
 
-gboolean Ape_Tag_Read_File_Tag (const gchar *filename, File_Tag *FileTag);
+gboolean ape_tag_read_file_tag (const gchar *filename, File_Tag *FileTag, GError **error);
 gboolean Ape_Tag_Write_File_Tag (ET_File *ETFile);
 
 G_END_DECLS


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