[easytag/wip/gerror: 2/8] Use GError in APE tagging code
- From: David King <davidk src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [easytag/wip/gerror: 2/8] Use GError in APE tagging code
- Date: Mon, 29 Sep 2014 17:06:18 +0000 (UTC)
commit 35cd27c9d04b5d7344642a39fdc43e718e6cee70
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 | 26 ++++++++++++++++++---
src/tags/ape_tag.c | 47 +++++++++++++++++++++++++++------------
src/tags/ape_tag.h | 4 +-
src/tags/id3_tag.c | 2 +-
src/tags/libapetag/apetaglib.c | 2 +-
src/tags/libapetag/apetaglib.h | 2 +-
src/tags/monkeyaudio_header.c | 18 +++++++++------
src/tags/monkeyaudio_header.h | 4 +-
src/tags/musepack_header.c | 16 ++++++++-----
src/tags/musepack_header.h | 2 +-
10 files changed, 83 insertions(+), 40 deletions(-)
---
diff --git a/src/et_core.c b/src/et_core.c
index 31fa6bb..6a3a524 100644
--- a/src/et_core.c
+++ b/src/et_core.c
@@ -556,7 +556,13 @@ 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,
+ _("Error reading APE tag from file ‘%s’: %s"),
+ filename_utf8, error->message);
+ g_clear_error (&error);
+ }
break;
#ifdef ENABLE_MP4
case MP4_TAG:
@@ -619,10 +625,22 @@ GList *ET_Add_File_To_File_List (gchar *filename)
break;
#endif
case MPC_FILE:
- Mpc_Header_Read_File_Info(filename,ETFileInfo);
+ if (!mpc_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;
case MAC_FILE:
- Mac_Header_Read_File_Info(filename,ETFileInfo);
+ if (!mac_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;
#ifdef ENABLE_WAVPACK
case WAVPACK_FILE:
@@ -3451,7 +3469,7 @@ ET_Save_File_Tag_To_HD (ET_File *ETFile, GError **error)
break;
#endif
case APE_TAG:
- state = Ape_Tag_Write_File_Tag(ETFile);
+ state = ape_tag_write_file_tag (ETFile, error);
break;
#ifdef ENABLE_MP4
case MP4_TAG:
diff --git a/src/tags/ape_tag.c b/src/tags/ape_tag.c
index c251d9b..34d72b3 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,13 @@ 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);
+ g_set_error (error, G_FILE_ERROR, g_file_error_from_errno (errno),
+ _("Error while opening file: %s"),
+ g_strerror (errno));
return FALSE;
}
@@ -201,25 +203,33 @@ Ape_Tag_Read_File_Tag (const gchar *filename, File_Tag *FileTag)
return TRUE;
}
-
-
-gboolean Ape_Tag_Write_File_Tag (ET_File *ETFile)
+gboolean
+ape_tag_write_file_tag (ET_File *ETFile,
+ GError **error)
{
- File_Tag *FileTag;
- gchar *filename_in;
+ const File_Tag *FileTag;
+ const gchar *filename_in;
//FILE *file_in;
gchar *string;
//GList *list;
apetag *ape_mem;
- if (!ETFile || !ETFile->FileTag)
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_in = ((File_Name *)ETFile->FileNameCur->data)->value;
- ape_mem = apetag_init();
+ ape_mem = apetag_init ();
+
+ /* TODO: Pointless, as g_set_error() will try to malloc. */
+ if (!ape_mem)
+ {
+ g_set_error (error, G_FILE_ERROR, G_FILE_ERROR_NOMEM, "%s",
+ g_strerror (ENOMEM));
+ return FALSE;
+ }
/*********
* Title *
@@ -347,9 +357,16 @@ gboolean Ape_Tag_Write_File_Tag (ET_File *ETFile)
else
apefrm_remove(ape_mem,"Encoded By");
-
/* reread all tag-type again excl. changed frames by apefrm_remove() */
- apetag_save(filename_in,ape_mem,APE_TAG_V2+SAVE_NEW_OLD_APE_TAG);
+ if (apetag_save (filename_in, ape_mem, APE_TAG_V2 + SAVE_NEW_OLD_APE_TAG)
+ != 0)
+ {
+ g_set_error (error, G_FILE_ERROR, G_FILE_ERROR_FAILED, "%s",
+ _("Failed to write APE tag"));
+ apetag_free (ape_mem);
+ return FALSE;
+ }
+
apetag_free(ape_mem);
return TRUE;
diff --git a/src/tags/ape_tag.h b/src/tags/ape_tag.h
index 45ee30e..f09a178 100644
--- a/src/tags/ape_tag.h
+++ b/src/tags/ape_tag.h
@@ -25,8 +25,8 @@
G_BEGIN_DECLS
-gboolean Ape_Tag_Read_File_Tag (const gchar *filename, File_Tag *FileTag);
-gboolean Ape_Tag_Write_File_Tag (ET_File *ETFile);
+gboolean ape_tag_read_file_tag (const gchar *filename, File_Tag *FileTag, GError **error);
+gboolean ape_tag_write_file_tag (ET_File *ETFile, GError **error);
G_END_DECLS
diff --git a/src/tags/id3_tag.c b/src/tags/id3_tag.c
index 71e3183..756b5dd 100644
--- a/src/tags/id3_tag.c
+++ b/src/tags/id3_tag.c
@@ -569,7 +569,7 @@ Id3tag_Write_File_v23Tag (ET_File *ETFile)
// With empty tag...
ETFile_tmp->FileTagList = g_list_append(NULL,FileTag_tmp);
ETFile_tmp->FileTag = ETFile_tmp->FileTagList;
- Ape_Tag_Write_File_Tag(ETFile_tmp);
+ ape_tag_write_file_tag (ETFile_tmp, NULL);
ET_Free_File_List_Item(ETFile_tmp);
}
diff --git a/src/tags/libapetag/apetaglib.c b/src/tags/libapetag/apetaglib.c
index fbb0a66..57533d8 100644
--- a/src/tags/libapetag/apetaglib.c
+++ b/src/tags/libapetag/apetaglib.c
@@ -884,7 +884,7 @@ libapetag_qsort (struct tag **a, struct tag **b)
*/
int
-apetag_save (char *filename, apetag *mem_cnt, int flag)
+apetag_save (const char *filename, apetag *mem_cnt, int flag)
{
FILE *fp;
struct _id3v1Tag id3v1_tag;
diff --git a/src/tags/libapetag/apetaglib.h b/src/tags/libapetag/apetaglib.h
index e8ac4cd..41bc007 100644
--- a/src/tags/libapetag/apetaglib.h
+++ b/src/tags/libapetag/apetaglib.h
@@ -207,7 +207,7 @@ apetag_free (apetag *mem_cnt) ;
/* save apetag to file */
int
-apetag_save (char *filename, apetag *mem_cnt, int flag) ;
+apetag_save (const char *filename, apetag *mem_cnt, int flag) ;
/* Add text frame */
diff --git a/src/tags/monkeyaudio_header.c b/src/tags/monkeyaudio_header.c
index cb38872..1d90fd5 100644
--- a/src/tags/monkeyaudio_header.c
+++ b/src/tags/monkeyaudio_header.c
@@ -1,7 +1,7 @@
/* EasyTAG - Tag editor for audio files
* Copyright (C) 2014 David King <amigadave amigadave com>
* Copyright (C) 2001-2003 Jerome Couderc <easytag gmail com>
- * Copyright (C) 2002-2003 Artur Polaczy�ski <artii o2 pl>
+ * Copyright (C) 2002-2003 Artur Polaczyñski <artii o2 pl>
*
* 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
@@ -42,18 +42,22 @@
***************/
gboolean
-Mac_Header_Read_File_Info (const gchar *filename,
- ET_File_Info *ETFileInfo)
+mac_header_read_file_info (const gchar *filename,
+ ET_File_Info *ETFileInfo,
+ GError **error)
{
StreamInfoMac Info;
- if (info_mac_read(filename, &Info))
+ g_return_val_if_fail (filename != NULL && ETFileInfo != NULL, FALSE);
+ g_return_val_if_fail (error == NULL || *error == NULL, FALSE);
+
+ if (info_mac_read (filename, &Info))
{
- gchar *filename_utf8 = filename_to_display(filename);
- fprintf(stderr,"MAC header not found for file '%s'\n", filename_utf8);
- g_free(filename_utf8);
+ g_set_error (error, G_FILE_ERROR, G_FILE_ERROR_FAILED, "%s",
+ _("Error opening Monkey’s Audio file"));
return FALSE;
}
+
ETFileInfo->mpc_profile = g_strdup(Info.CompresionName);
ETFileInfo->version = Info.Version;
ETFileInfo->bitrate = Info.Bitrate/1000.0;
diff --git a/src/tags/monkeyaudio_header.h b/src/tags/monkeyaudio_header.h
index e1f904d..d0b95d2 100644
--- a/src/tags/monkeyaudio_header.h
+++ b/src/tags/monkeyaudio_header.h
@@ -1,7 +1,7 @@
/* EasyTAG - Tag editor for audio files
* Copyright (C) 2014 David King <amigadave amigadave com>
* Copyright (C) 2000-2003 Jerome Couderc <easytag gmail com>
- * Copyright (C) 2002-2003 Artur Polaczy�ski <artii o2 pl>
+ * Copyright (C) 2002-2003 Artur Polaczyñski <artii o2 pl>
*
* 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
@@ -25,7 +25,7 @@
G_BEGIN_DECLS
-gboolean Mac_Header_Read_File_Info (const gchar *filename, ET_File_Info *ETFileInfo);
+gboolean mac_header_read_file_info (const gchar *filename, ET_File_Info *ETFileInfo, GError **error);
EtFileHeaderFields * Mac_Header_Display_File_Info_To_UI (const gchar *filename, ET_File *ETFile);
void et_mac_file_header_fields_free (EtFileHeaderFields *fields);
diff --git a/src/tags/musepack_header.c b/src/tags/musepack_header.c
index 05e2279..0ee84b7 100644
--- a/src/tags/musepack_header.c
+++ b/src/tags/musepack_header.c
@@ -42,18 +42,22 @@
***************/
gboolean
-Mpc_Header_Read_File_Info (const gchar *filename, ET_File_Info *ETFileInfo)
+mpc_header_read_file_info (const gchar *filename,
+ ET_File_Info *ETFileInfo,
+ GError **error)
{
StreamInfoMpc Info;
- if (info_mpc_read(filename, &Info))
+ g_return_val_if_fail (filename != NULL && ETFileInfo != NULL, FALSE);
+ g_return_val_if_fail (error == NULL || *error == NULL, FALSE);
+
+ if (info_mpc_read (filename, &Info))
{
- gchar *filename_utf8 = filename_to_display(filename);
- fprintf(stderr,"MPC header not found for file '%s'\n", filename_utf8);
- g_free(filename_utf8);
+ g_set_error (error, G_FILE_ERROR, G_FILE_ERROR_FAILED, "%s",
+ _("Error opening Musepack file"));
return FALSE;
}
- //printf("%",Info.fields);
+
ETFileInfo->mpc_profile = g_strdup(Info.ProfileName);
ETFileInfo->version = Info.StreamVersion;
ETFileInfo->bitrate = Info.Bitrate/1000.0;
diff --git a/src/tags/musepack_header.h b/src/tags/musepack_header.h
index 40ad0f7..05d3c7d 100644
--- a/src/tags/musepack_header.h
+++ b/src/tags/musepack_header.h
@@ -25,7 +25,7 @@
G_BEGIN_DECLS
-gboolean Mpc_Header_Read_File_Info (const gchar *filename, ET_File_Info *ETFileInfo);
+gboolean mpc_header_read_file_info (const gchar *filename, ET_File_Info *ETFileInfo, GError **error);
EtFileHeaderFields * Mpc_Header_Display_File_Info_To_UI (const gchar *filename, ET_File *ETFile);
void et_mpc_file_header_fields_free (EtFileHeaderFields *fields);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]