[easytag] Remove last remnants of GTK+ usage from tag code
- From: David King <davidk src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [easytag] Remove last remnants of GTK+ usage from tag code
- Date: Thu, 31 Dec 2015 16:06:36 +0000 (UTC)
commit 8e343337a81227314760370c4fbcd48a0da42d67
Author: David King <amigadave amigadave com>
Date: Wed Dec 30 20:44:02 2015 +0000
Remove last remnants of GTK+ usage from tag code
Rather than opening a GTK+ dialog from the ID3 writing code when
detecting a buggy implementation, simply return a new
ET_ID3_ERROR_BUGGY_ID3LIB error. Handle the error and show the dialog in
the UI code.
src/easytag.c | 53 ++++++++++++++++++++++++------
src/tags/id3_tag.c | 91 +++++++++++++++++++++++++--------------------------
src/tags/id3_tag.h | 18 ++++++++++
3 files changed, 106 insertions(+), 56 deletions(-)
---
diff --git a/src/easytag.c b/src/easytag.c
index deb851d..662ffc1 100644
--- a/src/easytag.c
+++ b/src/easytag.c
@@ -1,5 +1,5 @@
/* EasyTAG - Tag editor for audio files
- * Copyright (C) 2014 David King <amigadave amigadave com>
+ * Copyright (C) 2014-2015 David King <amigadave amigadave com>
* Copyright (C) 2000-2003 Jerome Couderc <easytag gmail com>
*
* This program is free software; you can redistribute it and/or modify
@@ -29,6 +29,7 @@
#include "browser.h"
#include "file_description.h"
#include "file_list.h"
+#include "id3_tag.h"
#include "log.h"
#include "misc.h"
#include "cddb_dialog.h"
@@ -755,15 +756,47 @@ Write_File_Tag (ET_File *ETFile, gboolean hide_msgbox)
if (!hide_msgbox)
{
- msgdialog = gtk_message_dialog_new(GTK_WINDOW(MainWindow),
- GTK_DIALOG_MODAL | GTK_DIALOG_DESTROY_WITH_PARENT,
- GTK_MESSAGE_ERROR,
- GTK_BUTTONS_CLOSE,
- _("Cannot write tag in file ā%sā"),
- basename_utf8);
- gtk_message_dialog_format_secondary_text (GTK_MESSAGE_DIALOG (msgdialog),
- "%s", error->message);
- gtk_window_set_title(GTK_WINDOW(msgdialog),_("Tag Write Error"));
+ if (g_error_matches (error, ET_ID3_ERROR, ET_ID3_ERROR_BUGGY_ID3LIB))
+ {
+ msgdialog = gtk_message_dialog_new (GTK_WINDOW (MainWindow),
+ GTK_DIALOG_MODAL | GTK_DIALOG_DESTROY_WITH_PARENT,
+ GTK_MESSAGE_ERROR,
+ GTK_BUTTONS_CLOSE,
+ "%s",
+ _("You have tried to save "
+ "this tag to Unicode but it "
+ "was detected that your "
+ "version of id3lib is buggy"));
+ gtk_message_dialog_format_secondary_text (GTK_MESSAGE_DIALOG (msgdialog),
+ _("If you reload this "
+ "file, some characters "
+ "in the tag may not be "
+ "displayed correctly. "
+ "Please, apply the "
+ "patch "
+ "src/id3lib/patch_id3lib_3.8.3_UTF16_writing_bug.diff "
+ "to id3lib, which is "
+ "available in the "
+ "EasyTAG package "
+ "sources.\nNote that "
+ "this message will "
+ "appear only "
+ "once.\n\nFile: %s"),
+ basename_utf8);
+ }
+ else
+ {
+ msgdialog = gtk_message_dialog_new (GTK_WINDOW (MainWindow),
+ GTK_DIALOG_MODAL | GTK_DIALOG_DESTROY_WITH_PARENT,
+ GTK_MESSAGE_ERROR,
+ GTK_BUTTONS_CLOSE,
+ _("Cannot write tag in file ā%sā"),
+ basename_utf8);
+ gtk_message_dialog_format_secondary_text (GTK_MESSAGE_DIALOG (msgdialog),
+ "%s", error->message);
+ gtk_window_set_title (GTK_WINDOW (msgdialog),
+ _("Tag Write Error"));
+ }
gtk_dialog_run(GTK_DIALOG(msgdialog));
gtk_widget_destroy(msgdialog);
diff --git a/src/tags/id3_tag.c b/src/tags/id3_tag.c
index a79a336..a639cb9 100644
--- a/src/tags/id3_tag.c
+++ b/src/tags/id3_tag.c
@@ -75,6 +75,18 @@ static gboolean id3tag_check_if_id3lib_is_buggy (GError **error);
* Functions *
*************/
+/* et_id3_error_quark:
+ *
+ * Quark for EtID3Error domain.
+ *
+ * Returns: a GQuark for the EtID3Error domain
+ */
+GQuark
+et_id3_error_quark (void)
+{
+ return g_quark_from_static_string ("et-id3-error-quark");
+}
+
/**
* et_id3tag_get_tpos_from_file_tag:
* @FileTag: File_Tag to get disc_number and disc_total from
@@ -646,52 +658,6 @@ id3tag_write_file_v23tag (const ET_File *ETFile,
Id3tag_Get_Error_Message (error_update_id3v2));
success = FALSE;
}
- else
- {
- /* See known problem on the top : [ 1016290 ] Unicode16 writing bug.
- * When we write the tag in Unicode, we try to check if it was correctly
- * written. So to test it : we read again the tag, and then compare
- * with the previous one. We check up to find an error (as only some
- * characters are affected).
- * If the patch to id3lib was applied to fix the problem (tested
- * by id3tag_check_if_id3lib_is_buggy) we didn't make the following
- * test => OK */
- if (flag_id3lib_bugged
- && g_settings_get_boolean (MainSettings,
- "id3v2-enable-unicode"))
- {
- File_Tag *FileTag_tmp = et_file_tag_new ();
-
- if (id3tag_read_file_tag (file, FileTag_tmp, NULL) == TRUE
- && et_file_tag_detect_difference (FileTag,
- FileTag_tmp) == TRUE)
- {
- GtkWidget *msgdialog;
-
- msgdialog = gtk_message_dialog_new(GTK_WINDOW(MainWindow),
- GTK_DIALOG_MODAL | GTK_DIALOG_DESTROY_WITH_PARENT,
- GTK_MESSAGE_ERROR,
- GTK_BUTTONS_CLOSE,
- "%s",
- _("You have tried to save this tag to Unicode but
it was detected that your version of id3lib is buggy"));
- gtk_message_dialog_format_secondary_text(GTK_MESSAGE_DIALOG(msgdialog),
- _("If you reload this file, some characters
in the tag may not be displayed "
- "correctly. Please, apply the patch "
-
"src/id3lib/patch_id3lib_3.8.3_UTF16_writing_bug.diff to id3lib, which is "
- "available in the EasyTAG package
sources.\nNote that this message will "
- "appear only once.\n\nFile: %s"),
- filename_utf8);
-
- gtk_window_set_title(GTK_WINDOW(msgdialog),_("Buggy id3lib"));
- gtk_dialog_run(GTK_DIALOG(msgdialog));
- gtk_widget_destroy(msgdialog);
- flag_id3lib_bugged = FALSE; // To display the message only one time
- }
-
- et_file_tag_free (FileTag_tmp);
- }
-
- }
}
else
{
@@ -744,6 +710,39 @@ id3tag_write_file_v23tag (const ET_File *ETFile,
}
}
+ /* Do a one-time check that the id3lib version is not buggy. */
+ if (g_settings_get_boolean (MainSettings, "id3v2-enabled")
+ && number_of_frames != 0 && success)
+ {
+ /* See known problem on the top : [ 1016290 ] Unicode16 writing bug.
+ * When we write the tag in Unicode, we try to check if it was
+ * correctly written. So to test it : we read again the tag, and then
+ * compare with the previous one. We check up to find an error (as only
+ * some characters are affected).
+ * If the patch to id3lib was applied to fix the problem (tested
+ * by id3tag_check_if_id3lib_is_buggy) we didn't make the following
+ * test => OK */
+ if (flag_id3lib_bugged
+ && g_settings_get_boolean (MainSettings,
+ "id3v2-enable-unicode"))
+ {
+ File_Tag *FileTag_tmp = et_file_tag_new ();
+
+ if (id3tag_read_file_tag (file, FileTag_tmp, NULL) == TRUE
+ && et_file_tag_detect_difference (FileTag,
+ FileTag_tmp) == TRUE)
+ {
+ flag_id3lib_bugged = FALSE; /* Report the error only once. */
+ success = FALSE;
+ g_set_error (error, ET_ID3_ERROR,
+ ET_ID3_ERROR_BUGGY_ID3LIB, "%s",
+ _("Buggy id3lib"));
+ }
+
+ et_file_tag_free (FileTag_tmp);
+ }
+ }
+
/* Free allocated data */
ID3Tag_Delete(id3_tag);
g_object_unref (file);
diff --git a/src/tags/id3_tag.h b/src/tags/id3_tag.h
index ff26cb9..13ffda4 100644
--- a/src/tags/id3_tag.h
+++ b/src/tags/id3_tag.h
@@ -27,6 +27,24 @@ G_BEGIN_DECLS
#define ID3_INVALID_GENRE 255
+/*
+ * Error domain and codes for errors while reading/writing ID3 tags.
+ */
+GQuark et_id3_error_quark (void);
+
+#define ET_ID3_ERROR et_id3_error_quark ()
+
+/*
+ * EtID3Error:
+ * @ET_ID3_ERROR_BUGGY_ID3LIB: Buggy id3lib implementation found
+ *
+ * Errors that can occur when dealing with ID3 tags.
+ */
+typedef enum
+{
+ ET_ID3_ERROR_BUGGY_ID3LIB
+} EtID3Error;
+
gboolean id3tag_read_file_tag (GFile *file, File_Tag *FileTag, GError **error);
gboolean id3tag_write_file_v24tag (const ET_File *ETFile, GError **error);
gboolean id3tag_write_file_tag (const ET_File *ETFile, GError **error);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]