[easytag/wip/application-window: 12/55] Store ID3v2.4/2.3 preference in GSettings



commit a6c0a244d8ee6b92e7440f348b919dda156c383c
Author: David King <amigadave amigadave com>
Date:   Fri May 9 21:28:28 2014 +0100

    Store ID3v2.4/2.3 preference in GSettings

 src/id3_tag.c            |    2 +-
 src/id3v24_tag.c         |    2 +-
 src/preferences_dialog.c |   56 ++++++++++++++++++++++++++++++++++++----------
 src/preferences_dialog.h |    1 -
 src/setting.c            |   11 +--------
 src/setting.h            |    1 -
 6 files changed, 47 insertions(+), 26 deletions(-)
---
diff --git a/src/id3_tag.c b/src/id3_tag.c
index b04df6a..0ca261d 100644
--- a/src/id3_tag.c
+++ b/src/id3_tag.c
@@ -1480,7 +1480,7 @@ gboolean Id3tag_Check_If_Id3lib_Is_Bugged (void)
 gboolean Id3tag_Write_File_Tag (ET_File *ETFile)
 {
 #ifdef ENABLE_ID3LIB
-    if (FILE_WRITING_ID3V2_VERSION_4)
+    if (g_settings_get_boolean (MainSettings, "id3v2-version-4"))
         return Id3tag_Write_File_v24Tag(ETFile);
     else
         return Id3tag_Write_File_v23Tag(ETFile);
diff --git a/src/id3v24_tag.c b/src/id3v24_tag.c
index c30d4fc..0776cd6 100644
--- a/src/id3v24_tag.c
+++ b/src/id3v24_tag.c
@@ -154,7 +154,7 @@ gboolean Id3tag_Read_File_Tag (const gchar *filename, File_Tag *FileTag)
                 unsigned version = id3_tag_version(tag);
 #ifdef ENABLE_ID3LIB
                 /* Besides upgrade old tags we will downgrade id3v2.4 to id3v2.3 */
-                if ( FILE_WRITING_ID3V2_VERSION_4 )
+                if (g_settings_get_boolean (MainSettings, "id3v2-version-4"))
                 {
                     update = (ID3_TAG_VERSION_MAJOR(version) < 4);
                 }else
diff --git a/src/preferences_dialog.c b/src/preferences_dialog.c
index 39154e6..d45bde1 100644
--- a/src/preferences_dialog.c
+++ b/src/preferences_dialog.c
@@ -61,6 +61,7 @@ struct _EtPreferencesDialogPrivate
     GtkWidget *LabelId3v2Charset;
     GtkWidget *LabelId3v1Charset;
     GtkWidget *LabelId3v2Version;
+    GtkWidget *FileWritingId3v2VersionCombo;
     GtkWidget *FileWritingId3v2UseUnicodeCharacterSet;
     GtkWidget *FileWritingId3v2UseNoUnicodeCharacterSet;
     GtkWidget *ConvertOldId3v2TagVersion;
@@ -111,6 +112,35 @@ DefaultPathToMp3_Combo_Add_String (EtPreferencesDialog *self)
     Add_String_To_Combo_List(GTK_LIST_STORE(priv->default_path_model), path);
 }
 
+static gboolean
+et_preferences_id3v2_version_get (GValue *value,
+                                  GVariant *variant,
+                                  gpointer user_data)
+{
+    gboolean id3v24;
+
+    id3v24 = g_variant_get_boolean (variant);
+
+    g_value_set_int (value, id3v24 ? 0 : 1);
+
+    return TRUE;
+}
+
+static GVariant *
+et_preferences_id3v2_version_set (const GValue *value,
+                                  const GVariantType *variant_type,
+                                  gpointer user_data)
+{
+    GVariant *id3v24;
+    gint active_row;
+
+    active_row = g_value_get_int (value);
+
+    id3v24 = g_variant_new_boolean (active_row == 0);
+
+    return id3v24;
+}
+
 /*
  * The window for options
  */
@@ -831,19 +861,21 @@ create_preferences_dialog (EtPreferencesDialog *self)
     gtk_grid_attach (GTK_GRID (Table), priv->LabelId3v2Version, 0, 1, 2, 1);
     gtk_misc_set_alignment (GTK_MISC (priv->LabelId3v2Version), 0, 0.5);
 
-    FileWritingId3v2VersionCombo = gtk_combo_box_text_new();
-    gtk_widget_set_tooltip_text (FileWritingId3v2VersionCombo,
+    priv->FileWritingId3v2VersionCombo = gtk_combo_box_text_new ();
+    gtk_widget_set_tooltip_text (priv->FileWritingId3v2VersionCombo,
                                  _("Select the ID3v2 tag version to write:\n"
                                    " - ID3v2.3 is written using id3lib,\n"
                                    " - ID3v2.4 is written using libid3tag (recommended)."));
-    gtk_combo_box_text_append_text(GTK_COMBO_BOX_TEXT(FileWritingId3v2VersionCombo), "ID3v2.4");
-    gtk_combo_box_text_append_text(GTK_COMBO_BOX_TEXT(FileWritingId3v2VersionCombo), "ID3v2.3");
-    gtk_combo_box_set_active(GTK_COMBO_BOX(FileWritingId3v2VersionCombo),
-        FILE_WRITING_ID3V2_VERSION_4 ? 0 : 1);
-    gtk_grid_attach (GTK_GRID (Table), FileWritingId3v2VersionCombo, 2, 1, 2,
+    gtk_combo_box_text_append_text (GTK_COMBO_BOX_TEXT (priv->FileWritingId3v2VersionCombo), "ID3v2.4");
+    gtk_combo_box_text_append_text (GTK_COMBO_BOX_TEXT (priv->FileWritingId3v2VersionCombo), "ID3v2.3");
+    g_settings_bind_with_mapping (MainSettings, "id3v2-version-4",
+                                  priv->FileWritingId3v2VersionCombo, "active",
+                                  G_SETTINGS_BIND_DEFAULT,
+                                  et_preferences_id3v2_version_get,
+                                  et_preferences_id3v2_version_set, self,
+                                  NULL);
+    gtk_grid_attach (GTK_GRID (Table), priv->FileWritingId3v2VersionCombo, 2, 1, 2,
                      1);
-    g_signal_connect_after (FileWritingId3v2VersionCombo, "changed",
-                            G_CALLBACK (Change_Id3_Settings_Toggled), self);
 #endif
 
 
@@ -1594,8 +1626,8 @@ Change_Id3_Settings_Toggled (GtkWidget *blah, EtPreferencesDialog *self)
 
 #ifdef ENABLE_ID3LIB
         gtk_widget_set_sensitive (priv->LabelId3v2Version, TRUE);
-        gtk_widget_set_sensitive (FileWritingId3v2VersionCombo, TRUE);
-        if (gtk_combo_box_get_active(GTK_COMBO_BOX(FileWritingId3v2VersionCombo)) == 1)
+        gtk_widget_set_sensitive (priv->FileWritingId3v2VersionCombo, TRUE);
+        if (gtk_combo_box_get_active (GTK_COMBO_BOX (priv->FileWritingId3v2VersionCombo)) == 1)
         {
             // When "ID3v2.3" is selected
             gtk_combo_box_set_active(GTK_COMBO_BOX(FileWritingId3v2UnicodeCharacterSetCombo), 1);
@@ -1626,7 +1658,7 @@ Change_Id3_Settings_Toggled (GtkWidget *blah, EtPreferencesDialog *self)
         gtk_widget_set_sensitive (priv->LabelId3v2Charset, FALSE);
 #ifdef ENABLE_ID3LIB
         gtk_widget_set_sensitive (priv->LabelId3v2Version, FALSE);
-        gtk_widget_set_sensitive (FileWritingId3v2VersionCombo, FALSE);
+        gtk_widget_set_sensitive (priv->FileWritingId3v2VersionCombo, FALSE);
 #endif
         gtk_widget_set_sensitive (priv->FileWritingId3v2UseUnicodeCharacterSet, FALSE);
         gtk_widget_set_sensitive (priv->FileWritingId3v2UseNoUnicodeCharacterSet, FALSE);
diff --git a/src/preferences_dialog.h b/src/preferences_dialog.h
index ab073bc..f6494e1 100644
--- a/src/preferences_dialog.h
+++ b/src/preferences_dialog.h
@@ -64,7 +64,6 @@ GtkWidget *SortingFileCaseSensitive;
 GtkWidget *FilePlayerCombo;
 
 /* Tag Settings */
-GtkWidget *FileWritingId3v2VersionCombo;
 GtkWidget *FileWritingId3v2UnicodeCharacterSetCombo;
 GtkWidget *FileWritingId3v2NoUnicodeCharacterSetCombo;
 GtkWidget *FileWritingId3v1CharacterSetCombo;
diff --git a/src/setting.c b/src/setting.c
index 368eaa3..bf22762 100644
--- a/src/setting.c
+++ b/src/setting.c
@@ -114,7 +114,6 @@ static const tConfigVariable Config_Variables[] =
     {"sorting_file_case_sensitive",          CV_TYPE_BOOL,    &SORTING_FILE_CASE_SENSITIVE              },
 
     {"file_reading_id3v1v2_character_set",             CV_TYPE_STRING,&FILE_READING_ID3V1V2_CHARACTER_SET},
-    {"file_writing_id3v2_version_4",                   CV_TYPE_BOOL,  &FILE_WRITING_ID3V2_VERSION_4   },
     {"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},
@@ -209,11 +208,6 @@ void Init_Config_Variables (void)
      */
     FILE_READING_ID3V1V2_CHARACTER_SET              = g_strdup("UTF-8");
 #ifdef G_OS_WIN32
-    FILE_WRITING_ID3V2_VERSION_4                    = 0;
-#else /* !G_OS_WIN32 */
-    FILE_WRITING_ID3V2_VERSION_4                    = 1;
-#endif /* !G_OS_WIN32 */
-#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");
@@ -315,10 +309,7 @@ Apply_Changes_Of_Preferences_Window (void)
 
         /* Tag Settings */
 #ifdef ENABLE_ID3LIB
-        active = gtk_combo_box_get_active(GTK_COMBO_BOX(FileWritingId3v2VersionCombo));
-        FILE_WRITING_ID3V2_VERSION_4 = !active;
-#else
-        FILE_WRITING_ID3V2_VERSION_4 = 1;
+        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);
diff --git a/src/setting.h b/src/setting.h
index 361a327..9cf1d49 100644
--- a/src/setting.h
+++ b/src/setting.h
@@ -163,7 +163,6 @@ gint    SORTING_FILE_CASE_SENSITIVE;
 gchar  *AUDIO_FILE_PLAYER;
 
 /* Tag Settings */
-gint    FILE_WRITING_ID3V2_VERSION_4;
 gchar  *FILE_READING_ID3V1V2_CHARACTER_SET;
 
 gchar  *FILE_WRITING_ID3V2_UNICODE_CHARACTER_SET;


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