[easytag/wip/application-window: 9/98] Store rename filename encoding in GSettings
- From: David King <davidk src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [easytag/wip/application-window: 9/98] Store rename filename encoding in GSettings
- Date: Sat, 6 Sep 2014 10:11:23 +0000 (UTC)
commit f0270a6923f1e3754031c285f517118e66286b5f
Author: David King <amigadave amigadave com>
Date: Fri May 9 19:12:52 2014 +0100
Store rename filename encoding in GSettings
data/org.gnome.EasyTAG.gschema.xml | 2 -
src/charset.c | 58 +++++++++++++++++++++--------------
src/preferences_dialog.c | 28 +++++++++++++++--
src/preferences_dialog.h | 5 ---
src/setting.c | 16 ----------
src/setting.h | 13 +++++---
6 files changed, 67 insertions(+), 55 deletions(-)
---
diff --git a/data/org.gnome.EasyTAG.gschema.xml b/data/org.gnome.EasyTAG.gschema.xml
index 2e71dbc..943991d 100644
--- a/data/org.gnome.EasyTAG.gschema.xml
+++ b/data/org.gnome.EasyTAG.gschema.xml
@@ -611,13 +611,11 @@
<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 filesystem encoding, choose whether to
try another encoding, approximate the filesystem encoding with transliteration or discard the offending
characters</description>
<default>'try-alternative'</default>
</key>
- -->
<key name="rename-replace-illegal-chars" type="b">
<summary>Replace illegal characters when renaming</summary>
diff --git a/src/charset.c b/src/charset.c
index 09ded37..07cc8dc 100644
--- a/src/charset.c
+++ b/src/charset.c
@@ -546,32 +546,44 @@ gchar *filename_from_display (const gchar *string)
char_encoding = char_encoding+1; // Skip the '.'
if (char_encoding)
{
+ EtRenameEncoding enc_option = g_settings_get_enum (MainSettings,
+ "rename-encoding");
error = NULL;
- if (FILENAME_CHARACTER_SET_OTHER)
+ switch (enc_option)
{
- ret = g_convert(string, -1, char_encoding, "UTF-8", NULL, NULL, &error);
-
- }else if (FILENAME_CHARACTER_SET_APPROXIMATE)
- {
- // iconv_open (3):
- // When the string "//TRANSLIT" is appended to tocode, transliteration
- // is activated. This means that when a character cannot be represented
- // in the target character set, it can be approximated through one or
- // several similarly looking characters.
- gchar *enc = g_strconcat(char_encoding, "//TRANSLIT", NULL);
- ret = g_convert(string, -1, enc, "UTF-8", NULL, NULL, &error);
- g_free(enc);
-
- }else if (FILENAME_CHARACTER_SET_DISCARD)
- {
- // iconv_open (3):
- // When the string "//IGNORE" is appended to tocode, characters that
- // cannot be represented in the target character set will be silently
- // discarded.
- gchar *enc = g_strconcat(char_encoding, "//IGNORE", NULL);
- ret = g_convert(string, -1, enc, "UTF-8", NULL, NULL, &error);
- g_free(enc);
+ case ET_RENAME_ENCODING_TRY_ALTERNATIVE:
+ ret = g_convert (string, -1, char_encoding, "UTF-8", NULL,
+ NULL, &error);
+ break;
+ case ET_RENAME_ENCODING_TRANSLITERATE:
+ {
+ /* iconv_open (3):
+ * When the string "//TRANSLIT" is appended to tocode,
+ * transliteration is activated. This means that when a
+ * character cannot be represented in the target character set,
+ * it can be approximated through one or several similarly
+ * looking characters.
+ */
+ gchar *enc = g_strconcat (char_encoding, "//TRANSLIT", NULL);
+ ret = g_convert (string, -1, enc, "UTF-8", NULL, NULL, &error);
+ g_free (enc);
+ break;
+ }
+ case ET_RENAME_ENCODING_IGNORE:
+ {
+ /* iconv_open (3):
+ * When the string "//IGNORE" is appended to tocode, characters
+ * that cannot be represented in the target character set will
+ * be silently discarded.
+ */
+ gchar *enc = g_strconcat (char_encoding, "//IGNORE", NULL);
+ ret = g_convert (string, -1, enc, "UTF-8", NULL, NULL, &error);
+ g_free (enc);
+ break;
+ }
+ default:
+ g_assert_not_reached ();
}
}
diff --git a/src/preferences_dialog.c b/src/preferences_dialog.c
index c98c85f..c81a8e5 100644
--- a/src/preferences_dialog.c
+++ b/src/preferences_dialog.c
@@ -145,6 +145,9 @@ create_preferences_dialog (EtPreferencesDialog *self)
GtkWidget *ReplaceIllegalCharactersInFilename;
GtkWidget *PreserveModificationTime;
GtkWidget *UpdateParentDirectoryModificationTime;
+ GtkWidget *FilenameCharacterSetOther;
+ GtkWidget *FilenameCharacterSetApproximate;
+ GtkWidget *FilenameCharacterSetDiscard;
GtkWidget *DateAutoCompletion;
GtkWidget *NumberTrackFormated;
GtkWidget *NumberTrackFormatedSpinButton;
@@ -545,7 +548,7 @@ create_preferences_dialog (EtPreferencesDialog *self)
FilenameCharacterSetOther = gtk_radio_button_new_with_label(NULL,_("Try another "
"character encoding"));
gtk_grid_attach (GTK_GRID (Table), FilenameCharacterSetOther, 1, 1, 1, 1);
- gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(FilenameCharacterSetOther),FILENAME_CHARACTER_SET_OTHER);
+ gtk_widget_set_name (FilenameCharacterSetOther, "try-alternative");
gtk_widget_set_tooltip_text(FilenameCharacterSetOther,_("With this option, it will "
"try the conversion to the encoding associated to your locale (for example: "
"ISO-8859-1 for 'fr', KOI8-R for 'ru', ISO-8859-2 for 'ro'). If it fails, it "
@@ -556,7 +559,7 @@ create_preferences_dialog (EtPreferencesDialog *self)
_("Force using the system character encoding and activate the transliteration"));
gtk_grid_attach (GTK_GRID (Table), FilenameCharacterSetApproximate, 1, 2,
1, 1);
-
gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(FilenameCharacterSetApproximate),FILENAME_CHARACTER_SET_APPROXIMATE);
+ gtk_widget_set_name (FilenameCharacterSetApproximate, "transliterate");
gtk_widget_set_tooltip_text(FilenameCharacterSetApproximate,_("With this option, when "
"a character cannot be represented in the target character set, it can be "
"approximated through one or several similarly looking characters."));
@@ -566,12 +569,29 @@ create_preferences_dialog (EtPreferencesDialog *self)
_("Force using the system character encoding and silently discard some characters"));
gtk_grid_attach (GTK_GRID (Table), FilenameCharacterSetDiscard, 1, 3, 1,
1);
-
gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(FilenameCharacterSetDiscard),FILENAME_CHARACTER_SET_DISCARD);
+ gtk_widget_set_name (FilenameCharacterSetDiscard, "ignore");
gtk_widget_set_tooltip_text(FilenameCharacterSetDiscard,_("With this option, when "
"a character cannot be represented in the target character set, it will "
"be silently discarded."));
-
+ g_settings_bind_with_mapping (MainSettings, "rename-encoding",
+ FilenameCharacterSetOther, "active",
+ G_SETTINGS_BIND_DEFAULT,
+ et_settings_enum_radio_get,
+ et_settings_enum_radio_set,
+ FilenameCharacterSetOther, NULL);
+ g_settings_bind_with_mapping (MainSettings, "rename-encoding",
+ FilenameCharacterSetApproximate,
+ "active", G_SETTINGS_BIND_DEFAULT,
+ et_settings_enum_radio_get,
+ et_settings_enum_radio_set,
+ FilenameCharacterSetApproximate, NULL);
+ g_settings_bind_with_mapping (MainSettings, "rename-encoding",
+ FilenameCharacterSetDiscard, "active",
+ G_SETTINGS_BIND_DEFAULT,
+ et_settings_enum_radio_get,
+ et_settings_enum_radio_set,
+ FilenameCharacterSetDiscard, NULL);
/*
* Tag Settings
diff --git a/src/preferences_dialog.h b/src/preferences_dialog.h
index 1169700..448e1bd 100644
--- a/src/preferences_dialog.h
+++ b/src/preferences_dialog.h
@@ -63,11 +63,6 @@ GtkWidget *SortingFileCaseSensitive;
GtkWidget *FilePlayerCombo;
-/* File Settings */
-GtkWidget *FilenameCharacterSetOther;
-GtkWidget *FilenameCharacterSetApproximate;
-GtkWidget *FilenameCharacterSetDiscard;
-
/* Tag Settings */
GtkWidget *FileWritingId3v2VersionCombo;
GtkWidget *FileWritingId3v2UnicodeCharacterSetCombo;
diff --git a/src/setting.c b/src/setting.c
index a04257a..8560405 100644
--- a/src/setting.c
+++ b/src/setting.c
@@ -115,10 +115,6 @@ static const tConfigVariable Config_Variables[] =
{"pad_disc_number_digits", CV_TYPE_INT, &PAD_DISC_NUMBER_DIGITS },
{"sorting_file_case_sensitive", CV_TYPE_BOOL, &SORTING_FILE_CASE_SENSITIVE },
- {"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
},
-
{"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},
@@ -225,13 +221,6 @@ void Init_Config_Variables (void)
#endif /* !G_OS_WIN32 */
/*
- * File Settings
- */
- FILENAME_CHARACTER_SET_OTHER = 1;
- FILENAME_CHARACTER_SET_APPROXIMATE = 0;
- FILENAME_CHARACTER_SET_DISCARD = 0;
-
- /*
* Tag Settings
*/
FILE_READING_ID3V1V2_CHARACTER_SET = g_strdup("UTF-8");
@@ -355,11 +344,6 @@ Apply_Changes_Of_Preferences_Window (void)
if (AUDIO_FILE_PLAYER) g_free(AUDIO_FILE_PLAYER);
AUDIO_FILE_PLAYER =
g_strdup(gtk_entry_get_text(GTK_ENTRY(gtk_bin_get_child(GTK_BIN(FilePlayerCombo)))));
- /* File Settings */
- 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));
-
/* Tag Settings */
#ifdef ENABLE_ID3LIB
active = gtk_combo_box_get_active(GTK_COMBO_BOX(FileWritingId3v2VersionCombo));
diff --git a/src/setting.h b/src/setting.h
index 0d97fb5..cdc4a26 100644
--- a/src/setting.h
+++ b/src/setting.h
@@ -58,6 +58,14 @@ typedef enum
ET_PLAYLIST_CONTENT_EXTENDED_MASK
} EtPlaylistContent;
+/* Encoding options when renaming files. */
+typedef enum
+{
+ ET_RENAME_ENCODING_TRY_ALTERNATIVE,
+ ET_RENAME_ENCODING_TRANSLITERATE,
+ ET_RENAME_ENCODING_IGNORE
+} EtRenameEncoding;
+
/*
* The mode for the scanner window.
*/
@@ -137,11 +145,6 @@ gint SORTING_FILE_CASE_SENSITIVE;
gchar *AUDIO_FILE_PLAYER;
-/* File Settings */
-gint FILENAME_CHARACTER_SET_OTHER;
-gint FILENAME_CHARACTER_SET_APPROXIMATE;
-gint FILENAME_CHARACTER_SET_DISCARD;
-
/* Tag Settings */
gint FILE_WRITING_ID3V2_VERSION_4;
gchar *FILE_READING_ID3V1V2_CHARACTER_SET;
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]