[easytag/wip/gsettings: 22/22] Store the file extension case mode in GSettings



commit 80ab64a3703cd2e0943ff0b44bbf357f24e6681b
Author: David King <amigadave amigadave com>
Date:   Sun Mar 24 19:50:39 2013 +0000

    Store the file extension case mode in GSettings

 src/et_core.c |   21 +++++++-----
 src/prefs.c   |   98 +++++++++++++++++++++++++++++++++++++++++++++++++++++++--
 src/prefs.h   |    3 --
 src/setting.c |   11 ------
 src/setting.h |   10 +++--
 5 files changed, 114 insertions(+), 29 deletions(-)
---
diff --git a/src/et_core.c b/src/et_core.c
index a81cab8..aa24577 100644
--- a/src/et_core.c
+++ b/src/et_core.c
@@ -4633,18 +4633,23 @@ gchar *ET_File_Name_Generate (ET_File *ETFile, gchar *new_file_name_utf8)
 #endif
 
 
+/* Convert filename extension (lower/upper/no change). */
 static gchar *
 ET_File_Name_Format_Extension (ET_File *ETFile)
 {
-    // Convert filename extension (lower/upper/no change)
-    if (FILENAME_EXTENSION_LOWER_CASE)
-        return g_utf8_strdown(ETFile->ETFileDescription->Extension,-1);
+    EtFilenameExtensionMode mode;
 
-    else if (FILENAME_EXTENSION_UPPER_CASE)
-        return g_utf8_strup(ETFile->ETFileDescription->Extension,-1);
-
-    else // FILENAME_EXTENSION_NO_CHANGE
-        return g_strdup(ETFile->ETFileExtension);
+    mode = g_settings_get_enum (ETSettings, "rename-extension-mode");
+    switch (mode)
+    {
+        case ET_FILENAME_EXTENSION_LOWER_CASE:
+            return g_utf8_strdown (ETFile->ETFileDescription->Extension, -1);
+        case ET_FILENAME_EXTENSION_UPPER_CASE:
+            return g_utf8_strup (ETFile->ETFileDescription->Extension, -1);
+        case ET_FILENAME_EXTENSION_NO_CHANGE:
+        default:
+            return g_strdup (ETFile->ETFileExtension);
+    };
 }
 
 
diff --git a/src/prefs.c b/src/prefs.c
index acccffa..70b29ae 100644
--- a/src/prefs.c
+++ b/src/prefs.c
@@ -45,6 +45,11 @@
 #include "win32/win32dep.h"
 #endif /* G_OS_WIN32 */
 
+
+static GtkWidget *FilenameExtensionNoChange;
+static GtkWidget *FilenameExtensionLowerCase;
+static GtkWidget *FilenameExtensionUpperCase;
+
 /**************
  * Prototypes *
  **************/
@@ -73,6 +78,13 @@ static GVariant * et_prefs_sortmode_set (const GValue *value,
                                          const GVariantType *expected_type,
                                          gpointer user_data);
 
+static gboolean et_prefs_renameextensionmode_get (GValue *value,
+                                                  GVariant *variant,
+                                                  gpointer user_data);
+static GVariant * et_prefs_renameextensionmode_set (const GValue *value,
+                                                    const GVariantType *expected_type,
+                                                    gpointer user_data);
+
 
 /*************
  * Functions *
@@ -457,22 +469,41 @@ void Open_OptionsWindow (void)
     gtk_box_pack_start(GTK_BOX(hbox),Label,FALSE,FALSE,0);
 
     FilenameExtensionLowerCase = gtk_radio_button_new_with_label(NULL,_("Lower Case"));
+    gtk_widget_set_name (FilenameExtensionLowerCase, "lower-case");
     gtk_box_pack_start(GTK_BOX(hbox),FilenameExtensionLowerCase,FALSE,FALSE,2);
-    
gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(FilenameExtensionLowerCase),FILENAME_EXTENSION_LOWER_CASE);
     gtk_widget_set_tooltip_text(FilenameExtensionLowerCase,_("For example, the extension will be converted 
to '.mp3'"));
 
     FilenameExtensionUpperCase = gtk_radio_button_new_with_label(
         gtk_radio_button_get_group(GTK_RADIO_BUTTON(FilenameExtensionLowerCase)),_("Upper Case"));
+    gtk_widget_set_name (FilenameExtensionUpperCase, "upper-case");
     gtk_box_pack_start(GTK_BOX(hbox),FilenameExtensionUpperCase,FALSE,FALSE,2);
-    
gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(FilenameExtensionUpperCase),FILENAME_EXTENSION_UPPER_CASE);
     gtk_widget_set_tooltip_text(FilenameExtensionUpperCase,_("For example, the extension will be converted 
to '.MP3'"));
 
     FilenameExtensionNoChange = gtk_radio_button_new_with_label(
         gtk_radio_button_get_group(GTK_RADIO_BUTTON(FilenameExtensionLowerCase)),_("No Change"));
+    gtk_widget_set_name (FilenameExtensionNoChange, "no-change");
     gtk_box_pack_start(GTK_BOX(hbox),FilenameExtensionNoChange,FALSE,FALSE,2);
-    gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(FilenameExtensionNoChange),FILENAME_EXTENSION_NO_CHANGE);
     gtk_widget_set_tooltip_text(FilenameExtensionNoChange,_("The extension will not be converted"));
 
+    g_settings_bind_with_mapping (ETSettings, "rename-extension-mode",
+                                  FilenameExtensionLowerCase, "active",
+                                  G_SETTINGS_BIND_DEFAULT,
+                                  et_prefs_renameextensionmode_get,
+                                  et_prefs_renameextensionmode_set,
+                                  FilenameExtensionLowerCase, NULL);
+    g_settings_bind_with_mapping (ETSettings, "rename-extension-mode",
+                                  FilenameExtensionUpperCase, "active",
+                                  G_SETTINGS_BIND_DEFAULT,
+                                  et_prefs_renameextensionmode_get,
+                                  et_prefs_renameextensionmode_set,
+                                  FilenameExtensionUpperCase, NULL);
+    g_settings_bind_with_mapping (ETSettings, "rename-extension-mode",
+                                  FilenameExtensionNoChange, "active",
+                                  G_SETTINGS_BIND_DEFAULT,
+                                  et_prefs_renameextensionmode_get,
+                                  et_prefs_renameextensionmode_set,
+                                  FilenameExtensionNoChange, NULL);
+
     /* Preserve modification time */
     PreserveModificationTime = gtk_check_button_new_with_label(_("Preserve modification time of the file"));
     gtk_box_pack_start(GTK_BOX(vbox),PreserveModificationTime,FALSE,FALSE,0);
@@ -1971,6 +2002,67 @@ CddbLocalPath_Combo_Add_String (void)
 }
 
 /*
+ * et_prefs_renameextensionmode_get:
+ * @value: the property value to be set
+ * @variant: the variant to set the @value from
+ * @user_data: the widget on which the setting should be applied
+ *
+ * Wrapper function to bind the "rename-extension-mode" GSettings key state to
+ * the active radio button.
+ *
+ * Returns: %TRUE
+ */
+static gboolean
+et_prefs_renameextensionmode_get (GValue *value, GVariant *variant,
+                                  gpointer user_data)
+{
+    const gchar *name;
+    const gchar *setting;
+
+    name = gtk_widget_get_name (GTK_WIDGET (user_data));
+    setting = g_variant_get_string (variant, NULL);
+
+    /* Only set the radio button which matches the setting to active. */
+    if (g_strcmp0 (name, setting) == 0)
+    {
+        g_value_set_boolean (value, TRUE);
+    }
+
+    return TRUE;
+}
+
+/*
+ * et_prefs_renameextensionmode_set:
+ * @value: the property value to set the @variant from
+ * @expected_type: the expected type of the returned variant
+ * @user_data: the widget which the setting should be taken from
+ *
+ * Wrapper function to bind the active rename mode radiobutton to the value of
+ * "rename-extension-mode" GSettings key.
+ *
+ * Returns: a new GVariant containing the mapped value, or %NULL upon failure
+ */
+static GVariant *
+et_prefs_renameextensionmode_set (const GValue *value,
+                                  const GVariantType *expected_type,
+                                  gpointer user_data)
+{
+    GVariant *variant = NULL;
+    const gchar *name;
+
+    /* Ignore buttons that are not active. */
+    if (!g_value_get_boolean (value))
+    {
+        return variant;
+    }
+
+    name = gtk_widget_get_name (GTK_WIDGET (user_data));
+    variant = g_variant_new_string (name);
+
+    return variant;
+}
+
+/*
  * et_prefs_sortmode_get:
  * @value: the property value to be set (active item on combo box)
  * @variant: the variant to set the @value from
diff --git a/src/prefs.h b/src/prefs.h
index dc1805e..ce20b88 100644
--- a/src/prefs.h
+++ b/src/prefs.h
@@ -63,9 +63,6 @@ GtkListStore *FilePlayerModel;
 
 /* File Settings */
 GtkWidget *ReplaceIllegalCharactersInFilename;
-GtkWidget *FilenameExtensionNoChange;
-GtkWidget *FilenameExtensionLowerCase;
-GtkWidget *FilenameExtensionUpperCase;
 GtkWidget *PreserveModificationTime;
 GtkWidget *UpdateParentDirectoryModificationTime;
 
diff --git a/src/setting.c b/src/setting.c
index 0b49857..ba5082c 100644
--- a/src/setting.c
+++ b/src/setting.c
@@ -113,9 +113,6 @@ tConfigVariable Config_Variables[] =
 
     {"sorting_file_case_sensitive",          CV_TYPE_BOOL,    &SORTING_FILE_CASE_SENSITIVE              },
 
-    {"filename_extension_lower_case",                  CV_TYPE_BOOL,    &FILENAME_EXTENSION_LOWER_CASE       
     },
-    {"filename_extension_upper_case",                  CV_TYPE_BOOL,    &FILENAME_EXTENSION_UPPER_CASE       
     },
-    {"filename_extension_no_change",                   CV_TYPE_BOOL,    &FILENAME_EXTENSION_NO_CHANGE        
     },
     {"filename_character_set_other",                   CV_TYPE_BOOL,    &FILENAME_CHARACTER_SET_OTHER        
     },
     {"filename_character_set_approximate",             CV_TYPE_BOOL,    &FILENAME_CHARACTER_SET_APPROXIMATE  
     },
     {"filename_character_set_discard",                 CV_TYPE_BOOL,    &FILENAME_CHARACTER_SET_DISCARD      
     },
@@ -235,10 +232,6 @@ void Init_Config_Variables (void)
     /*
      * File Settings
      */
-    FILENAME_EXTENSION_LOWER_CASE               = 1;
-    FILENAME_EXTENSION_UPPER_CASE               = 0;
-    FILENAME_EXTENSION_NO_CHANGE                = 0;
-
     FILENAME_CHARACTER_SET_OTHER                = 1;
     FILENAME_CHARACTER_SET_APPROXIMATE          = 0;
     FILENAME_CHARACTER_SET_DISCARD              = 0;
@@ -372,10 +365,6 @@ Apply_Changes_Of_Preferences_Window (void)
         AUDIO_FILE_PLAYER                       = 
g_strdup(gtk_entry_get_text(GTK_ENTRY(gtk_bin_get_child(GTK_BIN(FilePlayerCombo)))));
 
         /* File Settings */
-        FILENAME_EXTENSION_LOWER_CASE             = 
gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(FilenameExtensionLowerCase));
-        FILENAME_EXTENSION_UPPER_CASE             = 
gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(FilenameExtensionUpperCase));
-        FILENAME_EXTENSION_NO_CHANGE              = 
gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(FilenameExtensionNoChange));
-
         FILENAME_CHARACTER_SET_OTHER              = 
gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(FilenameCharacterSetOther));
         FILENAME_CHARACTER_SET_APPROXIMATE        = 
gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(FilenameCharacterSetApproximate));
         FILENAME_CHARACTER_SET_DISCARD            = 
gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(FilenameCharacterSetDiscard));
diff --git a/src/setting.h b/src/setting.h
index cad6b4a..d78a9ca 100644
--- a/src/setting.h
+++ b/src/setting.h
@@ -44,6 +44,12 @@ struct _tConfigVariable
     void *pointer;              /* Pointer to our variable */
 };
 
+typedef enum
+{
+    ET_FILENAME_EXTENSION_LOWER_CASE,
+    ET_FILENAME_EXTENSION_UPPER_CASE,
+    ET_FILENAME_EXTENSION_NO_CHANGE
+} EtFilenameExtensionMode;
 
 /*
  * Config variables
@@ -60,10 +66,6 @@ gint    SORTING_FILE_CASE_SENSITIVE;
 gchar  *AUDIO_FILE_PLAYER;
 
 /* File Settings */
-gint    FILENAME_EXTENSION_LOWER_CASE;
-gint    FILENAME_EXTENSION_UPPER_CASE;
-gint    FILENAME_EXTENSION_NO_CHANGE;
-
 gint    FILENAME_CHARACTER_SET_OTHER;
 gint    FILENAME_CHARACTER_SET_APPROXIMATE;
 gint    FILENAME_CHARACTER_SET_DISCARD;


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