[easytag/wip/gsettings: 25/29] Store the file extension case mode in GSettings
- From: David King <davidk src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [easytag/wip/gsettings: 25/29] Store the file extension case mode in GSettings
- Date: Fri, 29 Mar 2013 12:51:13 +0000 (UTC)
commit d37bdc601766427cae3ce0625482acacea3779c2
Author: David King <amigadave amigadave com>
Date: Sun Mar 24 19:50:39 2013 +0000
Store the file extension case mode in GSettings
data/org.gnome.EasyTAG.gschema.xml | 2 +
src/et_core.c | 21 ++++++----
src/prefs.c | 30 +++++++++++++-
src/prefs.h | 3 -
src/setting.c | 72 ++++++++++++++++++++++++++++++-----
src/setting.h | 15 +++++--
6 files changed, 114 insertions(+), 29 deletions(-)
---
diff --git a/data/org.gnome.EasyTAG.gschema.xml b/data/org.gnome.EasyTAG.gschema.xml
index 56f6094..a6c59f2 100644
--- a/data/org.gnome.EasyTAG.gschema.xml
+++ b/data/org.gnome.EasyTAG.gschema.xml
@@ -771,6 +771,7 @@
files</description>
<default>'spaces'</default>
</key>
+ -->
<key name="rename-extension-mode" enum="org.gnome.EasyTAG.EtFilenameExtensionMode">
<summary>How to modify filename extensions when renaming</summary>
@@ -779,6 +780,7 @@
<default>'lower-case'</default>
</key>
+ <!-- TODO: Generate enums with glib-mkenums.
<key name="rename-encoding" enum="org.gnome.EasyTAG.EtRenameEncoding">
<summary>Encoding options when renaming files</summary>
<description>If the encoding of the filename does not match the
diff --git a/src/et_core.c b/src/et_core.c
index b5dd02f..7f58717 100644
--- a/src/et_core.c
+++ b/src/et_core.c
@@ -4635,18 +4635,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 2e65b62..78e8fc8 100644
--- a/src/prefs.c
+++ b/src/prefs.c
@@ -46,6 +46,11 @@
#include "win32/win32dep.h"
#endif /* G_OS_WIN32 */
+
+static GtkWidget *FilenameExtensionNoChange;
+static GtkWidget *FilenameExtensionLowerCase;
+static GtkWidget *FilenameExtensionUpperCase;
+
/**************
* Prototypes *
**************/
@@ -452,22 +457,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_settings_enum_radio_get,
+ et_settings_enum_radio_set,
+ FilenameExtensionLowerCase, NULL);
+ g_settings_bind_with_mapping (ETSettings, "rename-extension-mode",
+ FilenameExtensionUpperCase, "active",
+ G_SETTINGS_BIND_DEFAULT,
+ et_settings_enum_radio_get,
+ et_settings_enum_radio_set,
+ FilenameExtensionUpperCase, NULL);
+ g_settings_bind_with_mapping (ETSettings, "rename-extension-mode",
+ FilenameExtensionNoChange, "active",
+ G_SETTINGS_BIND_DEFAULT,
+ et_settings_enum_radio_get,
+ et_settings_enum_radio_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);
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 e08eb0b..66024f6 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));
@@ -1259,3 +1248,64 @@ et_settings_enum_set (const GValue *value, const GVariantType *expected_type,
return g_variant_new (g_variant_type_peek_string (expected_type),
enum_value->value_nick);
}
+
+/*
+ * et_settings_enum_radio_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 convert an enum-type GSettings key state to the active
+ * radio button.
+ *
+ * Returns: %TRUE
+ */
+gboolean
+et_settings_enum_radio_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_settings_enum_radio_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 convert the active radiobutton to the value of an
+ * enum-type GSettings key.
+ *
+ * Returns: a new GVariant containing the mapped value, or %NULL upon failure
+ */
+GVariant *
+et_settings_enum_radio_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;
+}
diff --git a/src/setting.h b/src/setting.h
index 53c8c32..88a7b83 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;
/*
* The mode for the scanner window. See the GSettings key "scanner-type".
@@ -118,10 +124,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;
@@ -289,6 +291,11 @@ gboolean et_settings_enum_get (GValue *value, GVariant *variant,
GVariant *et_settings_enum_set (const GValue *value,
const GVariantType *expected_type,
gpointer user_data);
+gboolean et_settings_enum_radio_get (GValue *value, GVariant *variant,
+ gpointer user_data);
+GVariant *et_settings_enum_radio_set (const GValue *value,
+ const GVariantType *expected_type,
+ gpointer user_data);
#endif /* __CONFIG_H__ */
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]