[easytag/wip/application-window: 24/72] Store disc padding preferences in GSettings



commit a3e6becc9a45a280271333dd9a3cc3b9326c1b3a
Author: David King <amigadave amigadave com>
Date:   Fri May 9 21:18:26 2014 +0100

    Store disc padding preferences in GSettings

 data/org.gnome.EasyTAG.gschema.xml |   15 +++++++++++++++
 src/misc.c                         |    7 +++++--
 src/preferences_dialog.c           |   31 ++++++++++++-------------------
 src/preferences_dialog.h           |    3 ---
 src/setting.c                      |    6 ------
 src/setting.h                      |    3 ---
 6 files changed, 32 insertions(+), 33 deletions(-)
---
diff --git a/data/org.gnome.EasyTAG.gschema.xml b/data/org.gnome.EasyTAG.gschema.xml
index de1e5d4..d4f530e 100644
--- a/data/org.gnome.EasyTAG.gschema.xml
+++ b/data/org.gnome.EasyTAG.gschema.xml
@@ -370,6 +370,21 @@
       <default>true</default>
     </key>
 
+    <key name="tag-disc-padded" type="b">
+      <summary>Pad the disc number tag field</summary>
+      <description>Whether the disc number tag field should be padded with
+      leading zeroes</description>
+      <default>true</default>
+    </key>
+
+    <key name="tag-disc-length" type="u">
+      <summary>The length of the disc number field</summary>
+      <description>The length of the disc number field, which controls if the
+      field is padded with leading zeroes</description>
+      <default>2</default>
+      <range min="0" max="6" />
+    </key>
+
     <key name="tag-number-padded" type="b">
       <summary>Pad the track number tag field</summary>
       <description>Whether the track number tag field should be padded with
diff --git a/src/misc.c b/src/misc.c
index e514df4..041eb76 100644
--- a/src/misc.c
+++ b/src/misc.c
@@ -890,9 +890,12 @@ et_get_file_size (const gchar *filename)
 gchar *
 et_disc_number_to_string (const guint disc_number)
 {
-    if (PAD_DISC_NUMBER)
+    if (g_settings_get_boolean (MainSettings, "tag-disc-padded"))
     {
-        return g_strdup_printf ("%.*d", PAD_DISC_NUMBER_DIGITS, disc_number);
+        return g_strdup_printf ("%.*d",
+                                g_settings_get_uint (MainSettings,
+                                                     "tag-disc-length"),
+                                disc_number);
     }
 
     return g_strdup_printf ("%d", disc_number);
diff --git a/src/preferences_dialog.c b/src/preferences_dialog.c
index 9da28ea..39154e6 100644
--- a/src/preferences_dialog.c
+++ b/src/preferences_dialog.c
@@ -84,7 +84,6 @@ struct _EtPreferencesDialogPrivate
 /* Options window */
 static void Number_Track_Formatted_Spin_Button_Changed (GtkWidget *Label,
                                                         GtkWidget *SpinButton);
-static void et_prefs_on_pad_disc_number_toggled (void);
 static void et_prefs_on_pad_disc_number_spinbutton_changed (GtkWidget *label,
                                                             GtkWidget *spinbutton);
 
@@ -144,6 +143,8 @@ create_preferences_dialog (EtPreferencesDialog *self)
     GtkWidget *DateAutoCompletion;
     GtkWidget *NumberTrackFormated;
     GtkWidget *NumberTrackFormatedSpinButton;
+    GtkWidget *pad_disc_number;
+    GtkWidget *pad_disc_number_spinbutton;
     GtkWidget *SetFocusToSameTagField;
     GtkWidget *VorbisSplitFieldTitle;
     GtkWidget *VorbisSplitFieldArtist;
@@ -643,8 +644,8 @@ create_preferences_dialog (EtPreferencesDialog *self)
 
     pad_disc_number = gtk_check_button_new_with_label (_("Write the disc field with the following number of 
digits:"));
     gtk_box_pack_start (GTK_BOX (hbox), pad_disc_number, FALSE, FALSE, 0);
-    gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (pad_disc_number),
-                                  PAD_DISC_NUMBER);
+    g_settings_bind (MainSettings, "tag-number-padded", pad_disc_number,
+                     "active", G_SETTINGS_BIND_DEFAULT);
     gtk_widget_set_tooltip_text (pad_disc_number,
                                  _("Whether to pad the disc field with leading zeroes"));
 
@@ -652,16 +653,18 @@ create_preferences_dialog (EtPreferencesDialog *self)
                                                                  1.0);
     gtk_box_pack_start (GTK_BOX (hbox), pad_disc_number_spinbutton, FALSE,
                         FALSE, 0);
-    gtk_spin_button_set_value (GTK_SPIN_BUTTON (pad_disc_number_spinbutton),
-                               (gfloat)PAD_DISC_NUMBER_DIGITS);
-    g_signal_connect (G_OBJECT (pad_disc_number), "toggled",
-                      G_CALLBACK (et_prefs_on_pad_disc_number_toggled), NULL);
+    g_settings_bind (MainSettings, "tag-number-length",
+                     pad_disc_number_spinbutton, "value",
+                     G_SETTINGS_BIND_DEFAULT);
+    g_settings_bind (MainSettings, "tag-number-padded",
+                     pad_disc_number_spinbutton, "sensitive",
+                     G_SETTINGS_BIND_GET);
     g_signal_emit_by_name (G_OBJECT (pad_disc_number), "toggled");
 
     /* Label to show the example. */
     Label = gtk_label_new ("");
     gtk_box_pack_start (GTK_BOX (hbox), Label, FALSE, FALSE, BOX_SPACING);
-    g_signal_connect_swapped (G_OBJECT (pad_disc_number_spinbutton), "changed",
+    g_signal_connect_swapped ((pad_disc_number_spinbutton), "changed",
                               G_CALLBACK (et_prefs_on_pad_disc_number_spinbutton_changed),
                               Label);
     g_signal_emit_by_name (G_OBJECT (pad_disc_number_spinbutton), "changed");
@@ -1552,23 +1555,13 @@ Number_Track_Formatted_Spin_Button_Changed (GtkWidget *Label,
 }
 
 static void
-et_prefs_on_pad_disc_number_toggled (void)
-{
-    gtk_widget_set_sensitive (pad_disc_number_spinbutton,
-                              gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (pad_disc_number)));
-    /* Update the example. */
-    g_signal_emit_by_name (G_OBJECT (pad_disc_number_spinbutton), "changed",
-                           NULL);
-}
-
-static void
 et_prefs_on_pad_disc_number_spinbutton_changed (GtkWidget *label,
                                                 GtkWidget *spinbutton)
 {
     gchar *tmp;
     guint val;
 
-    if (gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (pad_disc_number)))
+    if (g_settings_get_boolean (MainSettings, "tag-disc-padded"))
     {
         val = gtk_spin_button_get_value_as_int (GTK_SPIN_BUTTON (spinbutton));
     }
diff --git a/src/preferences_dialog.h b/src/preferences_dialog.h
index 448e1bd..ab073bc 100644
--- a/src/preferences_dialog.h
+++ b/src/preferences_dialog.h
@@ -70,9 +70,6 @@ GtkWidget *FileWritingId3v2NoUnicodeCharacterSetCombo;
 GtkWidget *FileWritingId3v1CharacterSetCombo;
 GtkWidget *FileReadingId3v1v2CharacterSetCombo;
 
-GtkWidget *pad_disc_number;
-GtkWidget *pad_disc_number_spinbutton;
-
 /* Scanner */
 GtkWidget *FTSConvertUnderscoreAndP20IntoSpace;
 GtkWidget *FTSConvertSpaceIntoUnderscore;
diff --git a/src/setting.c b/src/setting.c
index 20bfa2a..368eaa3 100644
--- a/src/setting.c
+++ b/src/setting.c
@@ -111,8 +111,6 @@ static const tConfigVariable Config_Variables[] =
 {
     {"default_path_to_mp3",                 CV_TYPE_STRING,  &DEFAULT_PATH_TO_MP3               },
 
-    {"pad_disc_number", CV_TYPE_BOOL, &PAD_DISC_NUMBER },
-    {"pad_disc_number_digits", CV_TYPE_INT, &PAD_DISC_NUMBER_DIGITS },
     {"sorting_file_case_sensitive",          CV_TYPE_BOOL,    &SORTING_FILE_CASE_SENSITIVE              },
 
     {"file_reading_id3v1v2_character_set",             CV_TYPE_STRING,&FILE_READING_ID3V1V2_CHARACTER_SET},
@@ -194,8 +192,6 @@ void Init_Config_Variables (void)
     /*
      * Misc
      */
-    PAD_DISC_NUMBER = 1;
-    PAD_DISC_NUMBER_DIGITS = 1;
 #ifdef G_OS_WIN32
     SORTING_FILE_CASE_SENSITIVE             = 1;
 #else /* !G_OS_WIN32 */
@@ -312,8 +308,6 @@ Apply_Changes_Of_Preferences_Window (void)
 #endif /* G_OS_WIN32 */
 #endif
         /* Misc */
-        PAD_DISC_NUMBER = gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (pad_disc_number));
-        PAD_DISC_NUMBER_DIGITS = gtk_spin_button_get_value_as_int (GTK_SPIN_BUTTON 
(pad_disc_number_spinbutton));
         SORTING_FILE_CASE_SENSITIVE            = 
gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(SortingFileCaseSensitive));
 
         if (AUDIO_FILE_PLAYER) g_free(AUDIO_FILE_PLAYER);
diff --git a/src/setting.h b/src/setting.h
index 18d5246..361a327 100644
--- a/src/setting.h
+++ b/src/setting.h
@@ -171,9 +171,6 @@ gchar  *FILE_WRITING_ID3V2_NO_UNICODE_CHARACTER_SET;
 
 gchar  *FILE_WRITING_ID3V1_CHARACTER_SET;
 
-gint PAD_DISC_NUMBER;
-gint PAD_DISC_NUMBER_DIGITS;
-
 /* Scanner */
 gint    FTS_CONVERT_UNDERSCORE_AND_P20_INTO_SPACE;
 gint    FTS_CONVERT_SPACE_INTO_UNDERSCORE;


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