[easytag/easytag-2-2] Clear empty tag fields when saving WavPack tags
- From: David King <davidk src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [easytag/easytag-2-2] Clear empty tag fields when saving WavPack tags
- Date: Mon, 22 Dec 2014 09:04:52 +0000 (UTC)
commit 5f4d7e2bd0eaf5498c873f5a7bfe2e3450084a11
Author: David King <amigadave amigadave com>
Date: Sun Dec 21 21:17:57 2014 +0000
Clear empty tag fields when saving WavPack tags
Refactor WavPack tag saving to use a new
et_wavpack_append_or_delete_tag_item() helper function. Call
WavpackDeleteTagItem() to delete a tag item if the item is empty.
src/wavpack_tag.c | 159 +++++++++++++++++++++++++++++++----------------------
1 files changed, 93 insertions(+), 66 deletions(-)
---
diff --git a/src/wavpack_tag.c b/src/wavpack_tag.c
index 1bfda08..243cce1 100644
--- a/src/wavpack_tag.c
+++ b/src/wavpack_tag.c
@@ -261,8 +261,37 @@ gboolean Wavpack_Tag_Read_File_Tag (gchar *filename, File_Tag *FileTag)
return TRUE;
}
+/*
+ * et_wavpack_append_or_delete_tag_item:
+ * @wpc: the #WavpackContext of which to modify tags
+ * @tag: the tag item name
+ * @value: the tag value to write, or %NULL to delete
+ *
+ * Appends @value to the @tag item of @wpc, or removes the tag item if @value
+ * is %NULL.
+ *
+ * Returns: %TRUE on success, %FALSE otherwise
+ */
+static gboolean
+et_wavpack_append_or_delete_tag_item (WavpackContext *wpc,
+ const gchar *tag,
+ const gchar *value)
+{
+ if (value)
+ {
+ return WavpackAppendTagItem (wpc, tag, value, strlen (value));
+ }
+ else
+ {
+ WavpackDeleteTagItem (wpc, tag);
-gboolean Wavpack_Tag_Write_File_Tag (ET_File *ETFile)
+ /* It is not an error if there was no tag item to delete. */
+ return TRUE;
+ }
+}
+
+gboolean
+Wavpack_Tag_Write_File_Tag (ET_File *ETFile)
{
WavpackContext *wpc;
@@ -280,44 +309,38 @@ gboolean Wavpack_Tag_Write_File_Tag (ET_File *ETFile)
return FALSE;
}
- /*
- * Title
- */
- if (FileTag->title && WavpackAppendTagItem(wpc, "title", FileTag->title, strlen(FileTag->title)) == 0) {
+ /* Title. */
+ if (!et_wavpack_append_or_delete_tag_item (wpc, "title", FileTag->title))
+ {
return FALSE;
}
- /*
- * Artist
- */
- if (FileTag->artist && WavpackAppendTagItem(wpc, "artist", FileTag->artist, strlen(FileTag->artist)) ==
0) {
+ /* Artist. */
+ if (!et_wavpack_append_or_delete_tag_item (wpc, "artist", FileTag->artist))
+ {
return FALSE;
}
/* Album artist. */
- if (FileTag->album_artist
- && WavpackAppendTagItem (wpc, "album artist", FileTag->album_artist,
- strlen (FileTag->album_artist)) == 0)
+ if (!et_wavpack_append_or_delete_tag_item (wpc, "album artist",
+ FileTag->album_artist))
{
return FALSE;
}
- /*
- * Album
- */
- if (FileTag->album && WavpackAppendTagItem(wpc, "album", FileTag->album, strlen(FileTag->album)) == 0) {
+ /* Album. */
+ if (!et_wavpack_append_or_delete_tag_item (wpc, "album", FileTag->album))
+ {
return FALSE;
}
- /*
- * Discnumber
- */
+ /* Discnumber. */
if (FileTag->disc_number && FileTag->disc_total)
{
buffer = g_strdup_printf ("%s/%s", FileTag->disc_number,
FileTag->disc_total);
- if (WavpackAppendTagItem (wpc, "part", buffer, strlen (buffer)) == 0)
+ if (!et_wavpack_append_or_delete_tag_item (wpc, "part", buffer))
{
g_free (buffer);
return FALSE;
@@ -329,84 +352,88 @@ gboolean Wavpack_Tag_Write_File_Tag (ET_File *ETFile)
}
else
{
- if (FileTag->disc_number && WavpackAppendTagItem (wpc, "part",
- FileTag->disc_number,
- strlen (FileTag->disc_number)) == 0)
+ if (!et_wavpack_append_or_delete_tag_item (wpc, "part",
+ FileTag->disc_number))
{
return FALSE;
}
}
- /*
- * Year
- */
- if (FileTag->year && WavpackAppendTagItem(wpc, "year", FileTag->year, strlen(FileTag->year)) == 0) {
+ /* Year. */
+ if (!et_wavpack_append_or_delete_tag_item (wpc, "year", FileTag->year))
+ {
return FALSE;
}
- /*
- * Tracknumber + tracktotal
- */
- if (FileTag->track_total) {
- buffer = g_strdup_printf("%s/%s", FileTag->track, FileTag->track_total);
- if (FileTag->track && WavpackAppendTagItem(wpc, "track", buffer, strlen(buffer)) == 0) {
- g_free(buffer);
+ /* Tracknumber + tracktotal. */
+ if (FileTag->track_total)
+ {
+ buffer = g_strdup_printf ("%s/%s", FileTag->track,
+ FileTag->track_total);
+
+ if (!et_wavpack_append_or_delete_tag_item (wpc, "track", buffer))
+ {
+ g_free (buffer);
return FALSE;
- } else {
- g_free(buffer);
}
- } else {
- if (FileTag->track && WavpackAppendTagItem(wpc, "track", FileTag->track, strlen(FileTag->track)) ==
0) {
+ else
+ {
+ g_free (buffer);
+ }
+ }
+ else
+ {
+ if (!et_wavpack_append_or_delete_tag_item (wpc, "track",
+ FileTag->track))
+ {
return FALSE;
}
}
- /*
- * Genre
- */
- if (FileTag->genre && WavpackAppendTagItem(wpc, "genre", FileTag->genre, strlen(FileTag->genre)) == 0) {
+ /* Genre. */
+ if (!et_wavpack_append_or_delete_tag_item (wpc, "genre", FileTag->genre))
+ {
return FALSE;
}
- /*
- * Comment
- */
- if (FileTag->comment && WavpackAppendTagItem(wpc, "comment", FileTag->comment, strlen(FileTag->comment))
== 0) {
+ /* Comment. */
+ if (!et_wavpack_append_or_delete_tag_item (wpc, "comment", FileTag->comment))
+ {
return FALSE;
}
- /*
- * Composer
- */
- if (FileTag->composer && WavpackAppendTagItem(wpc, "composer", FileTag->composer,
strlen(FileTag->composer)) == 0) {
+ /* Composer. */
+ if (!et_wavpack_append_or_delete_tag_item (wpc, "composer",
+ FileTag->composer))
+ {
return FALSE;
}
- /*
- * Original artist
- */
- if (FileTag->orig_artist && WavpackAppendTagItem(wpc, "original artist", FileTag->orig_artist,
strlen(FileTag->orig_artist)) == 0) {
+ /* Original artist. */
+ if (!et_wavpack_append_or_delete_tag_item (wpc, "original artist",
+ FileTag->orig_artist))
+ {
return FALSE;
}
- /*
- * Copyright
- */
- if (FileTag->copyright && WavpackAppendTagItem(wpc, "copyright", FileTag->copyright,
strlen(FileTag->copyright)) == 0) {
+ /* Copyright. */
+ if (!et_wavpack_append_or_delete_tag_item (wpc, "copyright",
+ FileTag->copyright))
+ {
return FALSE;
}
- /*
- * URL
- */
- if (FileTag->url && WavpackAppendTagItem(wpc, "copyright url", FileTag->url, strlen(FileTag->url)) == 0)
{
+ /* URL. */
+ if (!et_wavpack_append_or_delete_tag_item (wpc, "copyright url",
+ FileTag->url))
+ {
return FALSE;
}
- /*
- * Encoded by
- */
- if (FileTag->encoded_by && WavpackAppendTagItem(wpc, "encoded by", FileTag->encoded_by,
strlen(FileTag->encoded_by)) == 0) {
+ /* Encoded by. */
+ if (!et_wavpack_append_or_delete_tag_item (wpc, "encoded by",
+ FileTag->encoded_by))
+ {
return FALSE;
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]