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



commit 821b4d90df65d993cfed757219489d2777dcef69
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 |   39 +++++++++++++++++++++++++++++++++++----
 src/setting.c            |   11 +----------
 src/setting.h            |    1 -
 5 files changed, 38 insertions(+), 17 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 158f713..4cb2bc0 100644
--- a/src/preferences_dialog.c
+++ b/src/preferences_dialog.c
@@ -102,6 +102,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
  */
@@ -899,12 +928,14 @@ create_preferences_dialog (EtPreferencesDialog *self)
                                    " - 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);
+    g_settings_bind_with_mapping (MainSettings, "id3v2-version-4",
+                                  FileWritingId3v2VersionCombo, "active",
+                                  G_SETTINGS_BIND_DEFAULT,
+                                  et_preferences_id3v2_version_get,
+                                  et_preferences_id3v2_version_set, self,
+                                  NULL);
     gtk_grid_attach (GTK_GRID (Table), FileWritingId3v2VersionCombo, 2, 1, 2,
                      1);
-    g_signal_connect_after (FileWritingId3v2VersionCombo, "changed",
-                            G_CALLBACK (Change_Id3_Settings_Toggled), self);
 #endif
 
 
diff --git a/src/setting.c b/src/setting.c
index e2fd44d..2bd65ef 100644
--- a/src/setting.c
+++ b/src/setting.c
@@ -120,7 +120,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},
@@ -215,11 +214,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");
@@ -346,10 +340,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 2a084e0..b486dfa 100644
--- a/src/setting.h
+++ b/src/setting.h
@@ -164,7 +164,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]