[easytag/wip/application-window: 17/98] Store character set preferences in GSettings



commit 30f87f95264178603dbaf4e5f3492b62c160c7cf
Author: David King <amigadave amigadave com>
Date:   Sat Jun 21 12:15:18 2014 +0100

    Store character set preferences in GSettings

 data/org.gnome.EasyTAG.gschema.xml |   14 ++--
 src/charset.c                      |   25 ++++--
 src/charset.h                      |    9 +-
 src/id3_tag.c                      |   88 ++++++++++++++----
 src/id3v24_tag.c                   |   91 ++++++++++++++-----
 src/preferences_dialog.c           |  170 +++++++++++++++++++++++++++---------
 src/preferences_dialog.h           |    6 --
 src/setting.c                      |   33 -------
 src/setting.h                      |   57 ++++++++++--
 9 files changed, 343 insertions(+), 150 deletions(-)
---
diff --git a/data/org.gnome.EasyTAG.gschema.xml b/data/org.gnome.EasyTAG.gschema.xml
index 0d0f014..013f646 100644
--- a/data/org.gnome.EasyTAG.gschema.xml
+++ b/data/org.gnome.EasyTAG.gschema.xml
@@ -242,13 +242,11 @@
       <default>true</default>
     </key>
 
-    <!-- TODO: Generate enums with glib-mkenums.
     <key name="id3v1-charset" enum="org.gnome.EasyTAG.EtCharset">
       <summary>The character set for writing ID3v1 tags</summary>
       <description>Choose the character set to be used when writing ID3v1 tags</description>
-      <default>'ISO-8859-1'</default>
+      <default>'iso-8859-1'</default>
     </key>
-    -->
 
     <key name="id3v1-encoding-option" enum="org.gnome.EasyTAG.EtTagEncoding">
       <summary>Encoding options when writing ID3v1 tags</summary>
@@ -256,6 +254,12 @@
       <default>'none'</default>
     </key>
 
+    <key name="id3v1v2-charset" enum="org.gnome.EasyTAG.EtCharset">
+      <summary>The character set for reading ID3v1 and ID3v2 tags</summary>
+      <description>Choose the character set to be used when reading ID3v1 and ID3v2 tags</description>
+      <default>'utf-8'</default>
+    </key>
+
     <key name="id3v2-enabled" type="b">
       <summary>Write ID3v2 tags</summary>
       <description>Whether to write ID3v2 tags when writing ID3 tags into audio files</description>
@@ -308,13 +312,11 @@
       <default>'UTF-8'</default>
     </key>
 
-    <!-- TODO: Generate enums with glib-mkenums.
     <key name="id3v2-no-unicode-charset" enum="org.gnome.EasyTAG.EtCharset">
       <summary>The character set for writing ID3v2 tags</summary>
       <description>Override the typical Unicode character set to be used when writing ID3v2 
tags</description>
-      <default>'ISO-8859-1'</default>
+      <default>'iso-8859-1'</default>
     </key>
-    -->
 
     <key name="id3v2-encoding-option" enum="org.gnome.EasyTAG.EtTagEncoding">
       <summary>Encoding options when writing ID3v2 tags</summary>
diff --git a/src/charset.c b/src/charset.c
index 07cc8dc..554faf6 100644
--- a/src/charset.c
+++ b/src/charset.c
@@ -695,24 +695,26 @@ gchar *Try_To_Validate_Utf8_String (const gchar *string)
 
 
 
-void Charset_Populate_Combobox (GtkComboBox *combo, gchar *select_charset)
+void
+Charset_Populate_Combobox (GtkComboBox *combo, gint select_charset)
 {
-    guint i;
+    gsize i;
 
-    for (i=0; i<CHARSET_TRANS_ARRAY_LEN; i++)
+    for (i = 0; i < CHARSET_TRANS_ARRAY_LEN; i++)
     {
-        gtk_combo_box_text_append_text(GTK_COMBO_BOX_TEXT(combo), _(charset_trans_array[i].charset_title));
+        gtk_combo_box_text_append_text (GTK_COMBO_BOX_TEXT (combo),
+                                        _(charset_trans_array[i].charset_title));
 
-        if (select_charset && strcmp(charset_trans_array[i].charset_name, select_charset) == 0)
-            gtk_combo_box_set_active(combo, i);
     }
+
+    gtk_combo_box_set_active (combo, select_charset);
 }
 
 
 /*
  * Return charset_name from charset_title
  */
-gchar *
+const gchar *
 Charset_Get_Name_From_Title (const gchar *charset_title)
 {
     guint i;
@@ -730,3 +732,12 @@ Charset_Get_Name_From_Title (const gchar *charset_title)
 
     return NULL;
 }
+
+const gchar *
+et_charset_get_name_from_index (gint index)
+{
+    g_return_val_if_fail (index >= 0 && index <= CHARSET_TRANS_ARRAY_LEN,
+                          NULL);
+
+    return charset_trans_array[index].charset_name;
+}
diff --git a/src/charset.h b/src/charset.h
index a5c629d..7809f14 100644
--- a/src/charset.h
+++ b/src/charset.h
@@ -28,8 +28,8 @@ G_BEGIN_DECLS
 
 typedef struct
 {
-    gchar *charset_title;
-    gchar *charset_name;
+    const gchar *charset_title;
+    const gchar *charset_name;
 } CharsetInfo;
 
 
@@ -52,8 +52,9 @@ gchar *filename_from_display (const gchar *string);
 
 gchar *Try_To_Validate_Utf8_String (const gchar *string);
 
-void   Charset_Populate_Combobox   (GtkComboBox *combo, gchar *select_charset);
-gchar *Charset_Get_Name_From_Title (const gchar *charset_title);
+void Charset_Populate_Combobox (GtkComboBox *combo, gint select_charset);
+const gchar *Charset_Get_Name_From_Title (const gchar *charset_title);
+const gchar * et_charset_get_name_from_index (gint index);
 
 
 void Charset_Insert_Locales_Init    (void);
diff --git a/src/id3_tag.c b/src/id3_tag.c
index 0ca261d..a7b2c29 100644
--- a/src/id3_tag.c
+++ b/src/id3_tag.c
@@ -906,6 +906,7 @@ gchar *Id3tag_Get_Field (const ID3Frame *id3_frame, ID3_FieldID id3_fieldid)
 
     //g_print("Id3tag_Get_Field - ID3Frame '%s'\n",ID3FrameInfo_ShortName(ID3Frame_GetID(id3_frame)));
 
+    /* FIXME: Disentangle and avoid compiler warning (9999 in switch). */
     if ( (id3_field = ID3Frame_GetField(id3_frame,id3_fieldid)) )
     {
         ID3_TextEnc enc = ID3TE_NONE;
@@ -934,18 +935,27 @@ gchar *Id3tag_Get_Field (const ID3Frame *id3_frame, ID3_FieldID id3_fieldid)
             if (g_settings_get_boolean (MainSettings,
                                         "id3-override-read-encoding"))
             {
-                // Encoding set by user to ???.
-                if ( strcmp(FILE_READING_ID3V1V2_CHARACTER_SET,"ISO-8859-1") == 0 )
+                /* Encoding set by user to ???. */
+                gint id3v1v2_charset;
+                const gchar *charset;
+
+                id3v1v2_charset = g_settings_get_enum (MainSettings,
+                                                       "id3v1v2-charset");
+                charset = et_charset_get_name_from_index (id3v1v2_charset);
+                if (strcmp (charset, "ISO-8859-1") == 0)
                 {
                     enc = ID3TE_ISO8859_1;
-                }else if ( strcmp(FILE_READING_ID3V1V2_CHARACTER_SET,"UTF-16BE") == 0
-                      ||   strcmp(FILE_READING_ID3V1V2_CHARACTER_SET,"UTF-16LE") == 0 )
+                }
+                else if (strcmp (charset, "UTF-16BE") == 0
+                         || strcmp (charset, "UTF-16LE") == 0)
                 {
                     enc = ID3TE_UTF16;
-                }else if ( strcmp(FILE_READING_ID3V1V2_CHARACTER_SET,"UTF-8") == 0 )
+                }
+                else if (strcmp (charset, "UTF-8") == 0)
                 {
                     enc = ID3TE_UTF8;
-                }else
+                }
+                else
                 {
                     enc = 9999;
                 }
@@ -986,10 +996,18 @@ gchar *Id3tag_Get_Field (const ID3Frame *id3_frame, ID3_FieldID id3_fieldid)
                 break;
 
             case 9999:
+            {
+                gint id3v1v2_charset;
+                const gchar *charset;
+
                 string = g_malloc0(sizeof(char)*ID3V2_MAX_STRING_LEN+1);
                 num_chars = ID3Field_GetASCII_1(id3_field,string,ID3V2_MAX_STRING_LEN,0);
-                string1 = convert_string(string,FILE_READING_ID3V1V2_CHARACTER_SET,"UTF-8",FALSE);
+                id3v1v2_charset = g_settings_get_enum (MainSettings,
+                                                       "id3v1v2-charset");
+                charset = et_charset_get_name_from_index (id3v1v2_charset);
+                string1 = convert_string (string, charset, "UTF-8", FALSE);
                 break;
+            }
 
             default:
                 string = g_malloc0(sizeof(char)*4*ID3V2_MAX_STRING_LEN+1);
@@ -1061,7 +1079,7 @@ Id3tag_Set_Field (const ID3Frame *id3_frame,
             return ID3TE_NONE;
         }
 
-        /*
+        /* FIXME: Disentangle and avoid compiler warning (9999 in switch).
          * We prioritize the rule selected in options. If the encoding of the
          * field is ISO-8859-1, we can write it to another single byte encoding.
          */
@@ -1078,21 +1096,31 @@ Id3tag_Set_Field (const ID3Frame *id3_frame,
                 // Force to UTF-16 as UTF-8 isn't supported
                 enc = ID3TE_UTF16;
             }
-        } else
+        }
+        else
         {
-            // Other encoding selected
-            // Encoding set by user to ???.
-            if ( strcmp(FILE_WRITING_ID3V2_NO_UNICODE_CHARACTER_SET,"ISO-8859-1") == 0 )
+            gint id3v2_charset;
+            const gchar *charset;
+
+            id3v2_charset = g_settings_get_enum (MainSettings,
+                                                 "id3v2-no-unicode-charset");
+            charset = et_charset_get_name_from_index (id3v2_charset);
+
+            /* Other encoding selected. Encoding set by user to ???. */
+            if (strcmp (charset, "ISO-8859-1") == 0)
             {
                 enc = ID3TE_ISO8859_1;
-            }else if ( strcmp(FILE_WRITING_ID3V2_NO_UNICODE_CHARACTER_SET,"UTF-16BE") == 0
-                  ||   strcmp(FILE_WRITING_ID3V2_NO_UNICODE_CHARACTER_SET,"UTF-16LE") == 0 )
+            }
+            else if (strcmp (charset, "UTF-16BE") == 0
+                     || strcmp (charset, "UTF-16LE") == 0)
             {
                 enc = ID3TE_UTF16;
-            }else if ( strcmp(FILE_WRITING_ID3V2_NO_UNICODE_CHARACTER_SET,"UTF-8") == 0 )
+            }
+            else if (strcmp (charset, "UTF-8") == 0)
             {
                 enc = ID3TE_UTF8;
-            }else
+            }
+            else
             {
                 enc = 9999;
             }
@@ -1160,8 +1188,18 @@ Id3tag_Set_Field (const ID3Frame *id3_frame,
 
             case 9999:
             default:
-                //string_converted = 
convert_string(string,"UTF-8",FILE_WRITING_ID3V2_NO_UNICODE_CHARACTER_SET,TRUE);
-                string_converted = 
Id3tag_Rules_For_ISO_Fields(string,"UTF-8",FILE_WRITING_ID3V2_NO_UNICODE_CHARACTER_SET);
+            {
+                //string_converted = convert_string(string,"UTF-8",charset,TRUE);
+                gint id3v2_charset;
+                const gchar *charset;
+
+                id3v2_charset = g_settings_get_enum (MainSettings,
+                                                     "id3v2-no-unicode-charset");
+                charset = et_charset_get_name_from_index (id3v2_charset);
+
+                string_converted = Id3tag_Rules_For_ISO_Fields (string,
+                                                                "UTF-8",
+                                                                charset);
                 ID3Field_SetEncoding(id3_field,ID3TE_ISO8859_1);
                 ID3Field_SetASCII(id3_field,string_converted);
                 g_free(string_converted);
@@ -1172,6 +1210,7 @@ Id3tag_Set_Field (const ID3Frame *id3_frame,
 
                 return ID3TE_NONE;
                 break;
+            }
         }
     }
 
@@ -1224,13 +1263,22 @@ void Id3tag_Prepare_ID3v1 (ID3Tag *id3_tag)
             if ( (id3_field_text != NULL)
             &&   (enc != ID3TE_ISO8859_1) )
             {
-                // Read UTF-16 frame
+                gint id3v1_charset;
+                const gchar *charset;
+
+                /* Read UTF-16 frame. */
                 string = g_malloc0(sizeof(unicode_t)*ID3V2_MAX_STRING_LEN+1);
                 num_chars = ID3Field_GetUNICODE_1(id3_field_text,(unicode_t *)string,ID3V2_MAX_STRING_LEN,0);
                 // "convert_string_1" as we need to pass length for UTF-16
                 string1 = convert_string_1(string,num_chars,"UTF-16BE","UTF-8",FALSE);
 
-                string_converted = 
Id3tag_Rules_For_ISO_Fields(string1,"UTF-8",FILE_WRITING_ID3V1_CHARACTER_SET);
+                id3v1_charset = g_settings_get_enum (MainSettings,
+                                                     "id3v1-charset");
+                charset = et_charset_get_name_from_index (id3v1_charset);
+
+                string_converted = Id3tag_Rules_For_ISO_Fields (string1,
+                                                                "UTF-8",
+                                                                charset);
 
                 if (string_converted)
                 {
diff --git a/src/id3v24_tag.c b/src/id3v24_tag.c
index 0776cd6..9c00297 100644
--- a/src/id3v24_tag.c
+++ b/src/id3v24_tag.c
@@ -557,11 +557,13 @@ etag_guess_byteorder(const id3_ucs4_t *ustr, gchar **ret) /* XXX */
 
     if (g_settings_get_boolean (MainSettings, "id3-override-read-encoding"))
     {
-        charset = FILE_READING_ID3V1V2_CHARACTER_SET;
+        charset = g_settings_get_string (MainSettings,
+                                         "id3v1v2-charset");
     }
     else if (!g_settings_get_boolean (MainSettings, "id3v2-enable-unicode"))
     {
-        charset = FILE_WRITING_ID3V2_NO_UNICODE_CHARACTER_SET; /* XXX */
+        charset = g_settings_get_string (MainSettings,
+                                         "id3v2-no-unicode-charset"); /* XXX */
     }
     else
     {
@@ -665,7 +667,13 @@ etag_ucs42gchar(const id3_ucs4_t *usrc, unsigned is_latin,
     {
         if ((latinstr = (gchar *)id3_ucs4_latin1duplicate(usrc)))
         {
-            retstr = convert_string(latinstr, FILE_READING_ID3V1V2_CHARACTER_SET, "UTF-8", FALSE);
+            gint id3v1v2_charset;
+            const gchar * charset;
+
+            id3v1v2_charset = g_settings_get_enum (MainSettings,
+                                                   "id3v1v2-charset");
+            charset = et_charset_get_name_from_index (id3v1v2_charset);
+            retstr = convert_string (latinstr, charset, "UTF-8", FALSE);
             free(latinstr);
         }
     }else
@@ -743,9 +751,13 @@ libid3tag_Get_Frame_Str (const struct id3_frame *frame,
                 if (g_settings_get_boolean (MainSettings,
                                             "id3-override-read-encoding"))
                 {
-                    tmpstr = convert_string (latinstr,
-                                             FILE_READING_ID3V1V2_CHARACTER_SET,
-                                             "UTF-8", FALSE);
+                    gint id3v1v2_charset;
+                    const gchar * charset;
+
+                    id3v1v2_charset = g_settings_get_enum (MainSettings,
+                                                           "id3v1v2-charset");
+                    charset = et_charset_get_name_from_index (id3v1v2_charset);
+                    tmpstr = convert_string (latinstr, charset, "UTF-8", FALSE);
                     g_free (latinstr);
                 }
                 else
@@ -1241,46 +1253,77 @@ id3taglib_set_field(struct id3_frame *frame,
             /* id3v1 fields converted using its own character set and iconv options */
             if ( id3v1 )
             {
-                EtTagEncoding iconv_option = g_settings_get_enum (MainSettings,
-                                                                  "id3v1-encoding-option");
+                gint id3v1_charset;
+                const gchar *charset;
+                EtTagEncoding iconv_option;
+
+                id3v1_charset = g_settings_get_enum (MainSettings,
+                                                     "id3v1-charset");
+                charset = et_charset_get_name_from_index (id3v1_charset);
+                iconv_option = g_settings_get_enum (MainSettings,
+                                                    "id3v1-encoding-option");
+
                 if (iconv_option != ET_TAG_ENCODING_NONE)
-                    encname = g_strconcat(
-                        FILE_WRITING_ID3V1_CHARACTER_SET,
-                        iconv_option == ET_TAG_ENCODING_TRANSLITERATE ? "//TRANSLIT" : "//IGNORE",
-                        NULL);
+                {
+                    encname = g_strconcat (charset,
+                                           iconv_option == ET_TAG_ENCODING_TRANSLITERATE ? "//TRANSLIT" : 
"//IGNORE",
+                                           NULL);
+                }
                 else
-                    encname = g_strdup(FILE_WRITING_ID3V1_CHARACTER_SET);
-            } else
+                {
+                    encname = g_strdup (charset);
+                }
+            }
+            else
             {
                 /* latin1 fields (such as URL) always converted with ISO-8859-1*/
                 if ((type != ID3_FIELD_TYPE_LATIN1) && (type != ID3_FIELD_TYPE_LATIN1FULL))
                 {
-                    EtTagEncoding iconv_option = g_settings_get_enum (MainSettings,
-                                                                      "id3v2-encoding-option");
+                    gint id3v2_charset;
+                    const gchar *charset;
+                    EtTagEncoding iconv_option;
+
+                    id3v2_charset = g_settings_get_enum (MainSettings,
+                                                         "id3v2-no-unicode-charset");
+                    charset = et_charset_get_name_from_index (id3v2_charset);
+                    iconv_option = g_settings_get_enum (MainSettings,
+                                                        "id3v2-encoding-option");
                     if (iconv_option != ET_TAG_ENCODING_NONE)
-                        encname = g_strconcat(
-                            FILE_WRITING_ID3V2_NO_UNICODE_CHARACTER_SET,
-                            iconv_option == ET_TAG_ENCODING_TRANSLITERATE ? "//TRANSLIT" : "//IGNORE",
-                            NULL);
+                    {
+                        encname = g_strconcat (charset,
+                                               iconv_option == ET_TAG_ENCODING_TRANSLITERATE ? "//TRANSLIT" 
: "//IGNORE",
+                                               NULL);
+                    }
                     else
-                        encname = g_strdup(FILE_WRITING_ID3V2_NO_UNICODE_CHARACTER_SET);
+                    {
+                        encname = g_strdup (charset);
+                    }
                 }
             }
 
             latinstr = convert_string(str, "UTF-8", encname ? encname : "ISO-8859-1//IGNORE", TRUE);
             g_free (encname);
             buf = id3_latin1_ucs4duplicate((id3_latin1_t const *)latinstr);
-        } else
+        }
+        else
         {
-            if (!strcmp(FILE_WRITING_ID3V2_UNICODE_CHARACTER_SET, "UTF-16"))
+            gchar *charset;
+
+            charset = g_settings_get_string (MainSettings,
+                                             "id3v2-unicode-charset");
+
+            if (!strcmp (charset, "UTF-16"))
             {
                 enc_field = ID3_FIELD_TEXTENCODING_UTF_16;
                 buf = id3_utf8_ucs4duplicate((id3_utf8_t const *)str);
-            }else
+            }
+            else
             {
                 enc_field = ID3_FIELD_TEXTENCODING_UTF_8;
                 buf = id3_utf8_ucs4duplicate((id3_utf8_t const *)str);
             }
+
+            g_free (charset);
         }
     }
 
diff --git a/src/preferences_dialog.c b/src/preferences_dialog.c
index 7c9c2dd..995294b 100644
--- a/src/preferences_dialog.c
+++ b/src/preferences_dialog.c
@@ -64,6 +64,12 @@ struct _EtPreferencesDialogPrivate
     GtkWidget *FileWritingId3v2VersionCombo;
     GtkWidget *FileWritingId3v2UseUnicodeCharacterSet;
     GtkWidget *FileWritingId3v2UseNoUnicodeCharacterSet;
+
+    GtkWidget *FileWritingId3v2UnicodeCharacterSetCombo;
+    GtkWidget *FileWritingId3v2NoUnicodeCharacterSetCombo;
+    GtkWidget *FileWritingId3v1CharacterSetCombo;
+    GtkWidget *FileReadingId3v1v2CharacterSetCombo;
+
     GtkWidget *ConvertOldId3v2TagVersion;
     GtkWidget *FileWritingId3v2UseCrc32;
     GtkWidget *FileWritingId3v2UseCompression;
@@ -168,6 +174,53 @@ id3_settings_changed (GtkComboBox *combo,
     notify_id3_settings_active (NULL, NULL, self);
 }
 
+static gboolean
+et_preferences_id3v2_unicode_charset_get (GValue *value,
+                                          GVariant *variant,
+                                          gpointer user_data)
+{
+    const gchar *charset;
+
+    charset = g_variant_get_string (variant, NULL);
+
+    if (strcmp (charset, "UTF-8") == 0)
+    {
+        g_value_set_int (value, 0);
+    }
+    else if (strcmp (charset, "UTF-16") == 0)
+    {
+        g_value_set_int (value, 1);
+    }
+    else
+    {
+        return FALSE;
+    }
+
+    return TRUE;
+}
+
+static GVariant *
+et_preferences_id3v2_unicode_charset_set (const GValue *value,
+                                          const GVariantType *variant_type,
+                                          gpointer user_data)
+{
+    gint active_row;
+
+    active_row = g_value_get_int (value);
+
+    switch (active_row)
+    {
+        case 0:
+            return g_variant_new_string ("UTF-8");
+            break;
+        case 1:
+            return g_variant_new_string ("UTF-16");
+            break;
+        default:
+            g_assert_not_reached ();
+    }
+}
+
 /*
  * The window for options
  */
@@ -910,18 +963,22 @@ create_preferences_dialog (EtPreferencesDialog *self)
     gtk_grid_attach (GTK_GRID (Table), priv->FileWritingId3v2UseUnicodeCharacterSet,
                      1, 3, 1, 1);
 
-    FileWritingId3v2UnicodeCharacterSetCombo = gtk_combo_box_text_new();
-    gtk_widget_set_tooltip_text(FileWritingId3v2UnicodeCharacterSetCombo,
-                                _("Unicode type to use"));
-    gtk_combo_box_text_append_text(GTK_COMBO_BOX_TEXT(FileWritingId3v2UnicodeCharacterSetCombo), "UTF-8");
-    gtk_combo_box_text_append_text(GTK_COMBO_BOX_TEXT(FileWritingId3v2UnicodeCharacterSetCombo), "UTF-16");
-    if ( FILE_WRITING_ID3V2_UNICODE_CHARACTER_SET == NULL )
-        gtk_combo_box_set_active(GTK_COMBO_BOX(FileWritingId3v2UnicodeCharacterSetCombo), 0); // Set UTF-8 
by default
-    else
-        gtk_combo_box_set_active(GTK_COMBO_BOX(FileWritingId3v2UnicodeCharacterSetCombo),
-            strcmp(FILE_WRITING_ID3V2_UNICODE_CHARACTER_SET, "UTF-8") ? 1 : 0);
+    priv->FileWritingId3v2UnicodeCharacterSetCombo = gtk_combo_box_text_new ();
+    gtk_widget_set_tooltip_text (priv->FileWritingId3v2UnicodeCharacterSetCombo,
+                                 _("Unicode type to use"));
+    gtk_combo_box_text_append_text (GTK_COMBO_BOX_TEXT (priv->FileWritingId3v2UnicodeCharacterSetCombo),
+                                    "UTF-8");
+    gtk_combo_box_text_append_text (GTK_COMBO_BOX_TEXT (priv->FileWritingId3v2UnicodeCharacterSetCombo),
+                                    "UTF-16");
+    g_settings_bind_with_mapping (MainSettings, "id3v2-unicode-charset",
+                                  priv->FileWritingId3v2UnicodeCharacterSetCombo,
+                                  "active", G_SETTINGS_BIND_DEFAULT,
+                                  et_preferences_id3v2_unicode_charset_get,
+                                  et_preferences_id3v2_unicode_charset_set,
+                                  NULL, NULL);
     gtk_grid_attach (GTK_GRID (Table),
-                     FileWritingId3v2UnicodeCharacterSetCombo, 2, 3, 2, 1);
+                     priv->FileWritingId3v2UnicodeCharacterSetCombo, 2, 3, 2,
+                     1);
     g_signal_connect (priv->FileWritingId3v2UseUnicodeCharacterSet,
                       "notify::active",
                       G_CALLBACK (notify_id3_settings_active), self);
@@ -933,18 +990,25 @@ create_preferences_dialog (EtPreferencesDialog *self)
     gtk_grid_attach (GTK_GRID (Table),
                      priv->FileWritingId3v2UseNoUnicodeCharacterSet, 1, 4, 1, 1);
 
-    FileWritingId3v2NoUnicodeCharacterSetCombo = gtk_combo_box_text_new();
-    gtk_widget_set_tooltip_text (FileWritingId3v2NoUnicodeCharacterSetCombo,
+    priv->FileWritingId3v2NoUnicodeCharacterSetCombo = gtk_combo_box_text_new();
+    gtk_widget_set_tooltip_text (priv->FileWritingId3v2NoUnicodeCharacterSetCombo,
                                  _("Character set used to write the tag data in the file."));
 
-    Charset_Populate_Combobox(GTK_COMBO_BOX(FileWritingId3v2NoUnicodeCharacterSetCombo), 
-        FILE_WRITING_ID3V2_NO_UNICODE_CHARACTER_SET);
+    Charset_Populate_Combobox (GTK_COMBO_BOX (priv->FileWritingId3v2NoUnicodeCharacterSetCombo), 
+                               g_settings_get_enum (MainSettings,
+                                                    "id3v2-no-unicode-charset"));
     gtk_grid_attach (GTK_GRID (Table),
-                     FileWritingId3v2NoUnicodeCharacterSetCombo, 2, 4, 3, 1);
+                     priv->FileWritingId3v2NoUnicodeCharacterSetCombo, 2, 4, 3,
+                     1);
+    g_settings_bind_with_mapping (MainSettings, "id3v2-no-unicode-charset",
+                                  priv->FileWritingId3v2NoUnicodeCharacterSetCombo,
+                                  "active", G_SETTINGS_BIND_DEFAULT,
+                                  et_settings_enum_get, et_settings_enum_set,
+                                  GSIZE_TO_POINTER (ET_TYPE_CHARSET), NULL);
     g_signal_connect (priv->FileWritingId3v2UseNoUnicodeCharacterSet,
                       "notify::active",
                       G_CALLBACK (notify_id3_settings_active), self);
-    
+
     /* ID3v2 Additional iconv() options. */
     priv->LabelAdditionalId3v2IconvOptions = gtk_label_new (_("Additional settings for iconv():"));
     gtk_grid_attach (GTK_GRID (Table), priv->LabelAdditionalId3v2IconvOptions,
@@ -1027,12 +1091,19 @@ create_preferences_dialog (EtPreferencesDialog *self)
     gtk_grid_attach (GTK_GRID (Table), priv->LabelId3v1Charset, 0, 1, 4, 1);
     gtk_misc_set_alignment (GTK_MISC (priv->LabelId3v1Charset), 0, 0.5);
 
-    FileWritingId3v1CharacterSetCombo = gtk_combo_box_text_new();
-    gtk_grid_attach (GTK_GRID (Table), FileWritingId3v1CharacterSetCombo, 1, 2,
-                     3, 1);
-    gtk_widget_set_tooltip_text (FileWritingId3v1CharacterSetCombo,
+    priv->FileWritingId3v1CharacterSetCombo = gtk_combo_box_text_new();
+    gtk_grid_attach (GTK_GRID (Table), priv->FileWritingId3v1CharacterSetCombo,
+                     1, 2, 3, 1);
+    gtk_widget_set_tooltip_text (priv->FileWritingId3v1CharacterSetCombo,
                                  _("Character set used to write ID3v1 tag data in the file."));
-    Charset_Populate_Combobox(GTK_COMBO_BOX(FileWritingId3v1CharacterSetCombo), 
FILE_WRITING_ID3V1_CHARACTER_SET);
+    Charset_Populate_Combobox (GTK_COMBO_BOX (priv->FileWritingId3v1CharacterSetCombo),
+                               g_settings_get_enum (MainSettings,
+                                                    "id3v1-charset"));
+    g_settings_bind_with_mapping (MainSettings, "id3v1-charset",
+                                  priv->FileWritingId3v1CharacterSetCombo,
+                                  "active", G_SETTINGS_BIND_DEFAULT,
+                                  et_settings_enum_get, et_settings_enum_set,
+                                  GSIZE_TO_POINTER (ET_TYPE_CHARSET), NULL);
 
     /* ID3V1 Additional iconv() options*/
     priv->LabelAdditionalId3v1IconvOptions = gtk_label_new (_("Additional settings for iconv():"));
@@ -1122,17 +1193,23 @@ create_preferences_dialog (EtPreferencesDialog *self)
         "'Windows-1251' to load tags written under Windows. And 'KOI8-R' to load tags "
         "written under Unix systems."));
 
-    FileReadingId3v1v2CharacterSetCombo = gtk_combo_box_text_new();
-    gtk_grid_attach (GTK_GRID (Table), FileReadingId3v1v2CharacterSetCombo, 2,
-                     0, 1, 1);
+    priv->FileReadingId3v1v2CharacterSetCombo = gtk_combo_box_text_new();
+    gtk_grid_attach (GTK_GRID (Table),
+                     priv->FileReadingId3v1v2CharacterSetCombo, 2, 0, 1, 1);
 
-    gtk_widget_set_tooltip_text (FileReadingId3v1v2CharacterSetCombo,
+    gtk_widget_set_tooltip_text (priv->FileReadingId3v1v2CharacterSetCombo,
                                  _("Character set used to read tag data in the file."));
 
-    Charset_Populate_Combobox(GTK_COMBO_BOX(FileReadingId3v1v2CharacterSetCombo), 
-        FILE_READING_ID3V1V2_CHARACTER_SET);
+    Charset_Populate_Combobox (GTK_COMBO_BOX (priv->FileReadingId3v1v2CharacterSetCombo),
+                               g_settings_get_enum (MainSettings,
+                                                    "id3v1v2-charset"));
+    g_settings_bind_with_mapping (MainSettings, "id3v1v2-charset",
+                                  priv->FileReadingId3v1v2CharacterSetCombo,
+                                  "active", G_SETTINGS_BIND_DEFAULT,
+                                  et_settings_enum_get, et_settings_enum_set,
+                                  GSIZE_TO_POINTER (ET_TYPE_CHARSET), NULL);
     g_settings_bind (MainSettings, "id3-override-read-encoding",
-                     FileReadingId3v1v2CharacterSetCombo, "sensitive",
+                     priv->FileReadingId3v1v2CharacterSetCombo, "sensitive",
                      G_SETTINGS_BIND_GET);
     notify_id3_settings_active (NULL, NULL, self);
 
@@ -1677,23 +1754,30 @@ notify_id3_settings_active (GObject *object,
 #ifdef ENABLE_ID3LIB
         gtk_widget_set_sensitive (priv->LabelId3v2Version, TRUE);
         gtk_widget_set_sensitive (priv->FileWritingId3v2VersionCombo, TRUE);
-        if (gtk_combo_box_get_active (GTK_COMBO_BOX (priv->FileWritingId3v2VersionCombo)) == 1)
+
+        if (!g_settings_get_boolean (MainSettings, "id3v2-version-4"))
         {
-            // When "ID3v2.3" is selected
-            gtk_combo_box_set_active(GTK_COMBO_BOX(FileWritingId3v2UnicodeCharacterSetCombo), 1);
-            gtk_widget_set_sensitive(FileWritingId3v2UnicodeCharacterSetCombo, FALSE);
-        }else
+            /* When "ID3v2.3" is selected. */
+            gtk_combo_box_set_active (GTK_COMBO_BOX (priv->FileWritingId3v2UnicodeCharacterSetCombo), 1);
+            gtk_widget_set_sensitive (priv->FileWritingId3v2UnicodeCharacterSetCombo,
+                                      FALSE);
+        }
+        else
         {
-            // When "ID3v2.4" is selected
-            gtk_combo_box_set_active(GTK_COMBO_BOX(FileWritingId3v2UnicodeCharacterSetCombo), 0); // Set 
"UTF-8" as default value for this version of tag
-            gtk_widget_set_sensitive(FileWritingId3v2UnicodeCharacterSetCombo, active);
+            /* When "ID3v2.4" is selected, set "UTF-8" as default value. */
+            gtk_combo_box_set_active (GTK_COMBO_BOX (priv->FileWritingId3v2UnicodeCharacterSetCombo),
+                                      0);
+            gtk_widget_set_sensitive (priv->FileWritingId3v2UnicodeCharacterSetCombo,
+                                      active);
         }
 #else 
-        gtk_widget_set_sensitive(FileWritingId3v2UnicodeCharacterSetCombo, active);
+        gtk_widget_set_sensitive (priv->FileWritingId3v2UnicodeCharacterSetCombo,
+                                  active);
 #endif
         gtk_widget_set_sensitive(priv->FileWritingId3v2UseUnicodeCharacterSet, TRUE);
         gtk_widget_set_sensitive(priv->FileWritingId3v2UseNoUnicodeCharacterSet, TRUE);
-        gtk_widget_set_sensitive(FileWritingId3v2NoUnicodeCharacterSetCombo, !active);
+        gtk_widget_set_sensitive (priv->FileWritingId3v2NoUnicodeCharacterSetCombo,
+                                  !active);
         gtk_widget_set_sensitive (priv->LabelAdditionalId3v2IconvOptions, !active);
         gtk_widget_set_sensitive (priv->FileWritingId3v2IconvOptionsNo, !active);
         gtk_widget_set_sensitive (priv->FileWritingId3v2IconvOptionsTranslit, !active);
@@ -1712,8 +1796,10 @@ notify_id3_settings_active (GObject *object,
 #endif
         gtk_widget_set_sensitive (priv->FileWritingId3v2UseUnicodeCharacterSet, FALSE);
         gtk_widget_set_sensitive (priv->FileWritingId3v2UseNoUnicodeCharacterSet, FALSE);
-        gtk_widget_set_sensitive(FileWritingId3v2UnicodeCharacterSetCombo, FALSE);
-        gtk_widget_set_sensitive(FileWritingId3v2NoUnicodeCharacterSetCombo, FALSE);
+        gtk_widget_set_sensitive (priv->FileWritingId3v2UnicodeCharacterSetCombo,
+                                  FALSE);
+        gtk_widget_set_sensitive (priv->FileWritingId3v2NoUnicodeCharacterSetCombo,
+                                  FALSE);
         gtk_widget_set_sensitive (priv->LabelAdditionalId3v2IconvOptions, FALSE);
         gtk_widget_set_sensitive (priv->FileWritingId3v2IconvOptionsNo, FALSE);
         gtk_widget_set_sensitive (priv->FileWritingId3v2IconvOptionsTranslit, FALSE);
@@ -1727,7 +1813,7 @@ notify_id3_settings_active (GObject *object,
     active = g_settings_get_boolean (MainSettings, "id3v1-enabled");
 
     gtk_widget_set_sensitive (priv->LabelId3v1Charset, active);
-    gtk_widget_set_sensitive(FileWritingId3v1CharacterSetCombo, active);
+    gtk_widget_set_sensitive (priv->FileWritingId3v1CharacterSetCombo, active);
     gtk_widget_set_sensitive (priv->LabelAdditionalId3v1IconvOptions, active);
     gtk_widget_set_sensitive (priv->FileWritingId3v1IconvOptionsNo, active);
     gtk_widget_set_sensitive (priv->FileWritingId3v1IconvOptionsTranslit, active);
diff --git a/src/preferences_dialog.h b/src/preferences_dialog.h
index 6ae3836..705d681 100644
--- a/src/preferences_dialog.h
+++ b/src/preferences_dialog.h
@@ -56,12 +56,6 @@ G_END_DECLS
 /* Misc */
 GtkWidget *FilePlayerCombo;
 
-/* Tag Settings */
-GtkWidget *FileWritingId3v2UnicodeCharacterSetCombo;
-GtkWidget *FileWritingId3v2NoUnicodeCharacterSetCombo;
-GtkWidget *FileWritingId3v1CharacterSetCombo;
-GtkWidget *FileReadingId3v1v2CharacterSetCombo;
-
 /* CDDB */
 GtkWidget *CddbLocalPath;
 
diff --git a/src/setting.c b/src/setting.c
index b3efa26..1ee692d 100644
--- a/src/setting.c
+++ b/src/setting.c
@@ -108,11 +108,6 @@ static gboolean Create_Easytag_Directory (void);
 static const tConfigVariable Config_Variables[] =
 {
 
-    {"file_reading_id3v1v2_character_set",             CV_TYPE_STRING,&FILE_READING_ID3V1V2_CHARACTER_SET},
-    {"file_writing_id3v2_unicode_character_set",       
CV_TYPE_STRING,&FILE_WRITING_ID3V2_UNICODE_CHARACTER_SET},
-    {"file_writing_id3v2_no_unicode_character_set",    
CV_TYPE_STRING,&FILE_WRITING_ID3V2_NO_UNICODE_CHARACTER_SET},
-    {"file_writing_id3v1_character_set",               CV_TYPE_STRING,&FILE_WRITING_ID3V1_CHARACTER_SET},
-
     {"audio_file_player",                       CV_TYPE_STRING,&AUDIO_FILE_PLAYER                        },
 
     {"playlist_name",                           CV_TYPE_STRING,  &PLAYLIST_NAME                          },
@@ -174,18 +169,6 @@ void Init_Config_Variables (void)
 #endif /* !G_OS_WIN32 */
 
     /*
-     * Tag Settings
-     */
-    FILE_READING_ID3V1V2_CHARACTER_SET              = g_strdup("UTF-8");
-#ifdef G_OS_WIN32
-    FILE_WRITING_ID3V2_UNICODE_CHARACTER_SET        = g_strdup("UTF-16");
-#else /* !G_OS_WIN32 */
-    FILE_WRITING_ID3V2_UNICODE_CHARACTER_SET        = g_strdup("UTF-8");
-#endif /* !G_OS_WIN32 */
-    FILE_WRITING_ID3V2_NO_UNICODE_CHARACTER_SET     = g_strdup("ISO-8859-1");
-    FILE_WRITING_ID3V1_CHARACTER_SET                = g_strdup("ISO-8859-1");
-
-    /*
      * Playlist window
      */
     PLAYLIST_NAME                   = g_strdup("playlist_%a_-_%b");
@@ -216,8 +199,6 @@ Apply_Changes_Of_Preferences_Window (void)
 {
     EtApplicationWindow *window;
     GtkWidget *dialog;
-    gchar *temp;
-    int active;
 
     window = ET_APPLICATION_WINDOW (MainWindow);
     dialog = et_application_window_get_preferences_dialog (window);
@@ -232,20 +213,6 @@ Apply_Changes_Of_Preferences_Window (void)
 #ifdef ENABLE_ID3LIB
         g_settings_set_boolean (MainSettings, "id3v2-version-4", TRUE);
 #endif
-        temp = Get_Active_Combo_Box_Item(GTK_COMBO_BOX(FileReadingId3v1v2CharacterSetCombo));
-        FILE_READING_ID3V1V2_CHARACTER_SET = Charset_Get_Name_From_Title(temp);
-        g_free(temp);
-
-        active = gtk_combo_box_get_active(GTK_COMBO_BOX(FileWritingId3v2UnicodeCharacterSetCombo));
-        FILE_WRITING_ID3V2_UNICODE_CHARACTER_SET     = (active == 1) ? "UTF-16" : "UTF-8";
-
-        temp = Get_Active_Combo_Box_Item(GTK_COMBO_BOX(FileWritingId3v2NoUnicodeCharacterSetCombo));
-        FILE_WRITING_ID3V2_NO_UNICODE_CHARACTER_SET  = Charset_Get_Name_From_Title(temp);
-        g_free(temp);
-
-        temp = Get_Active_Combo_Box_Item(GTK_COMBO_BOX(FileWritingId3v1CharacterSetCombo));
-        FILE_WRITING_ID3V1_CHARACTER_SET             = Charset_Get_Name_From_Title(temp);
-        g_free(temp);
 
         /* CDDB */
         if (CDDB_LOCAL_PATH) g_free(CDDB_LOCAL_PATH);
diff --git a/src/setting.h b/src/setting.h
index 8c87109..f30b7ec 100644
--- a/src/setting.h
+++ b/src/setting.h
@@ -80,6 +80,55 @@ typedef enum
     ET_CDDB_SET_FIELD_FILENAME = 1 << 7
 } EtCddbSetField;
 
+/* Character set for passing to iconv. */
+typedef enum
+{
+    ET_CHARSET_IBM864,
+    ET_CHARSET_ISO_8859_6,
+    ET_CHARSET_WINDOWS_1256,
+    ET_CHARSET_ISO_8859_13,
+    ET_CHARSET_ISO_8859_4,
+    ET_CHARSET_WINDOWS_1257,
+    ET_CHARSET_ISO_8859_14,
+    ET_CHARSET_IBM852,
+    ET_CHARSET_ISO_8859_2,
+    ET_CHARSET_WINDOWS_1250,
+    ET_CHARSET_GB18030,
+    ET_CHARSET_GB2312,
+    ET_CHARSET_BIG5,
+    ET_CHARSET_BIG5_HKSCS,
+    ET_CHARSET_IBM855,
+    ET_CHARSET_ISO_8859_5,
+    ET_CHARSET_ISO_IR_111,
+    ET_CHARSET_ISO_KOI8_R,
+    ET_CHARSET_WINDOWS_1251,
+    ET_CHARSET_IBM866,
+    ET_CHARSET_KOI8_U,
+    ET_CHARSET_US_ASCII,
+    ET_CHARSET_ISO_8859_7,
+    ET_CHARSET_WINDOWS_1253,
+    ET_CHARSET_IBM862,
+    ET_CHARSET_WINDOWS_1255,
+    ET_CHARSET_EUC_JP,
+    ET_CHARSET_ISO_2022_JP,
+    ET_CHARSET_SHIFT_JIS,
+    ET_CHARSET_EUC_KR,
+    ET_CHARSET_ISO_8859_10,
+    ET_CHARSET_ISO_8859_3,
+    ET_CHARSET_TIS_620,
+    ET_CHARSET_IBM857,
+    ET_CHARSET_ISO_8859_9,
+    ET_CHARSET_WINDOWS_1254,
+    ET_CHARSET_UTF_8,
+    ET_CHARSET_VISCII,
+    ET_CHARSET_WINDOWS_1258,
+    ET_CHARSET_ISO_8859_8,
+    ET_CHARSET_IBM850,
+    ET_CHARSET_ISO_8859_1,
+    ET_CHARSET_ISO_8859_15,
+    ET_CHARSET_WINDOWS_1252
+} EtCharset;
+
 /* Method for processing spaces when updating tags. */
 typedef enum
 {
@@ -211,14 +260,6 @@ GSettings *MainSettings;
 /* Misc */
 gchar  *AUDIO_FILE_PLAYER;
 
-/* Tag Settings */
-gchar  *FILE_READING_ID3V1V2_CHARACTER_SET;
-
-gchar  *FILE_WRITING_ID3V2_UNICODE_CHARACTER_SET;
-gchar  *FILE_WRITING_ID3V2_NO_UNICODE_CHARACTER_SET;
-
-gchar  *FILE_WRITING_ID3V1_CHARACTER_SET;
-
 /* Playlist window */
 gchar  *PLAYLIST_NAME;
 gchar  *PLAYLIST_CONTENT_MASK_VALUE;



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