[easytag/wip/application-window: 29/33] Store disc padding preferences in GSettings



commit 6d3aefabdf3392ec17aa4b5d72917c2e67ae301b
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 13a67bc..0fff6f9 100644
--- a/src/preferences_dialog.c
+++ b/src/preferences_dialog.c
@@ -85,7 +85,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);
 
@@ -146,6 +145,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;
@@ -721,8 +722,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"));
 
@@ -730,16 +731,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");
@@ -1642,23 +1645,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 b128681..dbcced6 100644
--- a/src/setting.c
+++ b/src/setting.c
@@ -117,8 +117,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},
@@ -200,8 +198,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 */
@@ -321,8 +317,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));
 
         /* FIXME: Port to GSettings? */
diff --git a/src/setting.h b/src/setting.h
index bed6f40..2a084e0 100644
--- a/src/setting.h
+++ b/src/setting.h
@@ -172,9 +172,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]