[easytag/wip/gerror: 5/6] Use GError in MP4 tagging code



commit 676ae9c838373ff8b4fa3b5b9443a853629ed0eb
Author: David King <amigadave amigadave com>
Date:   Wed Sep 24 20:34:24 2014 +0100

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

 src/et_core.c          |   16 ++++++++++--
 src/tags/mp4_header.cc |   23 +++++++++++-------
 src/tags/mp4_header.h  |    2 +-
 src/tags/mp4_tag.cc    |   59 ++++++++++++++++++++++++++++-------------------
 src/tags/mp4_tag.h     |    4 +-
 5 files changed, 65 insertions(+), 39 deletions(-)
---
diff --git a/src/et_core.c b/src/et_core.c
index dac1efc..fee234b 100644
--- a/src/et_core.c
+++ b/src/et_core.c
@@ -566,7 +566,11 @@ GList *ET_Add_File_To_File_List (gchar *filename)
             break;
 #ifdef ENABLE_MP4
         case MP4_TAG:
-            Mp4tag_Read_File_Tag(filename,FileTag);
+            if (!mp4tag_read_file_tag (filename, FileTag, &error))
+            {
+                Log_Print (LOG_ERROR, "%s", error->message);
+                g_clear_error (&error);
+            }
             break;
 #endif
 #ifdef ENABLE_WAVPACK
@@ -631,7 +635,13 @@ GList *ET_Add_File_To_File_List (gchar *filename)
 #endif
 #ifdef ENABLE_MP4
         case MP4_FILE:
-            Mp4_Header_Read_File_Info(filename,ETFileInfo);
+            if (!mp4_header_read_file_info (filename, ETFileInfo, &error))
+            {
+                Log_Print (LOG_ERROR,
+                           _("Error while querying information for file ‘%s’: %s"),
+                           filename_utf8, error->message);
+                g_error_free (error);
+            }
             break;
 #endif
 #ifdef ENABLE_OPUS
@@ -3455,7 +3465,7 @@ ET_Save_File_Tag_To_HD (ET_File *ETFile, GError **error)
             break;
 #ifdef ENABLE_MP4
         case MP4_TAG:
-            state = Mp4tag_Write_File_Tag(ETFile);
+            state = mp4tag_write_file_tag (ETFile, error);
             break;
 #endif
 #ifdef ENABLE_WAVPACK
diff --git a/src/tags/mp4_header.cc b/src/tags/mp4_header.cc
index cdcf1b4..088702e 100644
--- a/src/tags/mp4_header.cc
+++ b/src/tags/mp4_header.cc
@@ -22,12 +22,14 @@
 /* This file is intended to be included directly in mp4_tag.cc */
 
 /*
- * Mp4_Header_Read_File_Info:
+ * mp4_header_read_file_info:
  *
  * Get header info into the ETFileInfo structure
  */
 gboolean
-Mp4_Header_Read_File_Info (const gchar *filename, ET_File_Info *ETFileInfo)
+mp4_header_read_file_info (const gchar *filename,
+                           ET_File_Info *ETFileInfo,
+                           GError **error)
 {
     const TagLib::MP4::Properties *properties;
 
@@ -42,9 +44,10 @@ Mp4_Header_Read_File_Info (const gchar *filename, ET_File_Info *ETFileInfo)
     if (!stream.isOpen ())
     {
         gchar *filename_utf8 = filename_to_display (filename);
-        const GError *error = stream.getError ();
-        Log_Print (LOG_ERROR, _("Error while opening file ‘%s’: %s"),
-                   filename_utf8, error->message);
+        const GError *tmp_error = stream.getError ();
+        g_set_error (error, G_FILE_ERROR, G_FILE_ERROR_FAILED,
+                     _("Error while opening file ‘%s’: %s"), filename_utf8,
+                     tmp_error->message);
         g_free (filename_utf8);
         return FALSE;
     }
@@ -56,8 +59,9 @@ Mp4_Header_Read_File_Info (const gchar *filename, ET_File_Info *ETFileInfo)
     if (!mp4file.isOpen ())
     {
         gchar *filename_utf8 = filename_to_display (filename);
-        Log_Print (LOG_ERROR, _("Error while opening file ‘%s’: %s"),
-                   filename_utf8, _("MP4 format invalid"));
+        g_set_error (error, G_FILE_ERROR, G_FILE_ERROR_FAILED,
+                     _("Error while opening file ‘%s’: %s"), filename_utf8,
+                     _("MP4 format invalid"));
         g_free (filename_utf8);
         return FALSE;
     }
@@ -67,8 +71,9 @@ Mp4_Header_Read_File_Info (const gchar *filename, ET_File_Info *ETFileInfo)
     if (properties == NULL)
     {
         gchar *filename_utf8 = filename_to_display (filename);
-        Log_Print (LOG_ERROR, _("Error reading properties from file ‘%s’"),
-                   filename_utf8);
+        g_set_error (error, G_FILE_ERROR, G_FILE_ERROR_FAILED,
+                     _("Error reading properties from file ‘%s’"),
+                     filename_utf8);
         g_free (filename_utf8);
         return FALSE;
     }
diff --git a/src/tags/mp4_header.h b/src/tags/mp4_header.h
index 35d04f0..ca04cde 100644
--- a/src/tags/mp4_header.h
+++ b/src/tags/mp4_header.h
@@ -25,7 +25,7 @@
 
 G_BEGIN_DECLS
 
-gboolean Mp4_Header_Read_File_Info (const gchar *filename, ET_File_Info *ETFileInfo);
+gboolean mp4_header_read_file_info (const gchar *filename, ET_File_Info *ETFileInfo, GError **error);
 EtFileHeaderFields * Mp4_Header_Display_File_Info_To_UI (const gchar *filename, ET_File *ETFile);
 void et_mp4_file_header_fields_free (EtFileHeaderFields *fields);
 
diff --git a/src/tags/mp4_tag.cc b/src/tags/mp4_tag.cc
index 2316a2b..38b9fe2 100644
--- a/src/tags/mp4_tag.cc
+++ b/src/tags/mp4_tag.cc
@@ -52,7 +52,9 @@
  * Read tag data into an Mp4 file.
  */
 gboolean
-Mp4tag_Read_File_Tag (const gchar *filename, File_Tag *FileTag)
+mp4tag_read_file_tag (const gchar *filename,
+                      File_Tag *FileTag,
+                      GError **error)
 {
     TagLib::MP4::Tag *tag;
     guint year;
@@ -66,9 +68,10 @@ Mp4tag_Read_File_Tag (const gchar *filename, File_Tag *FileTag)
     if (!stream.isOpen ())
     {
         gchar *filename_utf8 = filename_to_display (filename);
-        const GError *error = stream.getError ();
-        Log_Print (LOG_ERROR, _("Error while opening file ‘%s’: %s"),
-                   filename_utf8, error->message);
+        const GError *tmp_error = stream.getError ();
+        g_set_error (error, G_FILE_ERROR, G_FILE_ERROR_FAILED,
+                     _("Error while opening file ‘%s’: %s"), filename_utf8,
+                     tmp_error->message);
         g_free (filename_utf8);
         return FALSE;
     }
@@ -79,17 +82,19 @@ Mp4tag_Read_File_Tag (const gchar *filename, File_Tag *FileTag)
     if (!mp4file.isOpen ())
     {
         gchar *filename_utf8 = filename_to_display (filename);
-        const GError *error = stream.getError ();
+        const GError *tmp_error = stream.getError ();
 
-        if (error)
+        if (tmp_error)
         {
-            Log_Print (LOG_ERROR, _("Error while opening file ‘%s’: %s"),
-                       filename_utf8, error->message);
+            g_set_error (error, G_FILE_ERROR, G_FILE_ERROR_FAILED,
+                         _("Error while opening file ‘%s’: %s"), filename_utf8,
+                         tmp_error->message);
         }
         else
         {
-            Log_Print (LOG_ERROR, _("Error while opening file ‘%s’: %s"),
-                       filename_utf8, _("MP4 format invalid"));
+            g_set_error (error, G_FILE_ERROR, G_FILE_ERROR_FAILED,
+                         _("Error while opening file ‘%s’: %s"), filename_utf8,
+                         _("MP4 format invalid"));
         }
 
         g_free (filename_utf8);
@@ -99,8 +104,8 @@ Mp4tag_Read_File_Tag (const gchar *filename, File_Tag *FileTag)
     if (!(tag = mp4file.tag ()))
     {
         gchar *filename_utf8 = filename_to_display (filename);
-        Log_Print (LOG_ERROR, _("Error reading tags from file ‘%s’"),
-                   filename_utf8);
+        g_set_error (error, G_FILE_ERROR, G_FILE_ERROR_FAILED,
+                     _("Error reading tags from file ‘%s’"), filename_utf8);
         g_free (filename_utf8);
         return FALSE;
     }
@@ -238,7 +243,9 @@ Mp4tag_Read_File_Tag (const gchar *filename, File_Tag *FileTag)
  *
  * Write tag data into an Mp4 file.
  */
-gboolean Mp4tag_Write_File_Tag (ET_File *ETFile)
+gboolean
+mp4tag_write_file_tag (ET_File *ETFile,
+                       GError **error)
 {
     File_Tag *FileTag;
     gchar    *filename;
@@ -259,9 +266,10 @@ gboolean Mp4tag_Write_File_Tag (ET_File *ETFile)
     if (!stream.isOpen ())
     {
         gchar *filename_utf8 = filename_to_display (filename);
-        const GError *error = stream.getError ();
-        Log_Print (LOG_ERROR, _("Error while opening file ‘%s’: %s"),
-                   filename_utf8, error->message);
+        const GError *tmp_error = stream.getError ();
+        g_set_error (error, G_FILE_ERROR, G_FILE_ERROR_FAILED,
+                     _("Error while opening file ‘%s’: %s"), filename_utf8,
+                     tmp_error->message);
         g_free (filename_utf8);
         return FALSE;
     }
@@ -272,27 +280,30 @@ gboolean Mp4tag_Write_File_Tag (ET_File *ETFile)
 
     if (!mp4file.isOpen ())
     {
-        const GError *error = stream.getError ();
+        const GError *tmp_error = stream.getError ();
 
-        if (error)
+        if (tmp_error)
         {
-            Log_Print (LOG_ERROR, _("Error while opening file ‘%s’: %s"),
-                       filename_utf8, error->message);
+            g_set_error (error, G_FILE_ERROR, G_FILE_ERROR_FAILED,
+                         _("Error while opening file ‘%s’: %s"), filename_utf8,
+                         tmp_error->message);
         }
         else
         {
-            Log_Print (LOG_ERROR, _("Error while opening file ‘%s’: %s"),
-                       filename_utf8, _("MP4 format invalid"));
+            g_set_error (error, G_FILE_ERROR, G_FILE_ERROR_FAILED,
+                         _("Error while opening file ‘%s’: %s"), filename_utf8,
+                         _("MP4 format invalid"));
         }
 
+
         return FALSE;
     }
 
     if (!(tag = mp4file.tag ()))
     {
         gchar *filename_utf8 = filename_to_display (filename);
-        Log_Print (LOG_ERROR, _("Error reading tags from file ‘%s’"),
-                   filename_utf8);
+        g_set_error (error, G_FILE_ERROR, G_FILE_ERROR_FAILED,
+                     _("Error reading tags from file ‘%s’"), filename_utf8);
         g_free (filename_utf8);
         return FALSE;
     }
diff --git a/src/tags/mp4_tag.h b/src/tags/mp4_tag.h
index 82e1bd5..74a5195 100644
--- a/src/tags/mp4_tag.h
+++ b/src/tags/mp4_tag.h
@@ -25,8 +25,8 @@
 
 G_BEGIN_DECLS
 
-gboolean Mp4tag_Read_File_Tag (const gchar *filename, File_Tag *FileTag);
-gboolean Mp4tag_Write_File_Tag (ET_File *ETFile);
+gboolean mp4tag_read_file_tag (const gchar *filename, File_Tag *FileTag, GError **error);
+gboolean mp4tag_write_file_tag (ET_File *ETFile, GError **error);
 
 G_END_DECLS
 


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