From 9b2786d392c7dd0ef1c86c70bf47c02cdafefe77 Mon Sep 17 00:00:00 2001 From: Alexey Yakovenko Date: Sat, 14 Jun 2014 12:08:19 +0200 Subject: made shift-jis detector optional and configurable --- junklib.c | 11 +++++++++++ plugins/gtkui/callbacks.h | 4 ++++ plugins/gtkui/deadbeef.glade | 20 ++++++++++++++++++++ plugins/gtkui/interface.c | 9 +++++++++ plugins/gtkui/prefwin.c | 12 ++++++++++++ 5 files changed, 56 insertions(+) diff --git a/junklib.c b/junklib.c index fe619d1b..d4d82583 100644 --- a/junklib.c +++ b/junklib.c @@ -57,6 +57,7 @@ uint16_t sj_to_unicode[] = { int enable_cp1251_detection = 1; int enable_cp936_detection = 0; +int enable_shift_jis_detection = 0; #define MAX_TEXT_FRAME_SIZE 1024 #define MAX_CUESHEET_FRAME_SIZE 10000 @@ -713,6 +714,9 @@ can_be_chinese (const uint8_t *str, int sz) { static int can_be_shift_jis (const unsigned char *str, int size) { + if (!enable_shift_jis_detection) { + return 0; + } unsigned char out[size*4]; if (size < 2) { @@ -4110,10 +4114,17 @@ junk_enable_cp936_detection (int enable) { enable_cp936_detection = enable; } +void +junk_enable_shift_jis_detection (int enable) { + enable_shift_jis_detection = enable; +} + void junk_configchanged (void) { int cp1251 = conf_get_int ("junk.enable_cp1251_detection", 1); int cp936 = conf_get_int ("junk.enable_cp936_detection", 0); + int shift_jis = conf_get_int ("junk.enable_shift_jis_detection", 0); junk_enable_cp1251_detection (cp1251); junk_enable_cp936_detection (cp936); + junk_enable_shift_jis_detection (shift_jis); } diff --git a/plugins/gtkui/callbacks.h b/plugins/gtkui/callbacks.h index 23745f0f..cd5d35fb 100644 --- a/plugins/gtkui/callbacks.h +++ b/plugins/gtkui/callbacks.h @@ -1301,3 +1301,7 @@ gboolean on_mainwin_button_press_event (GtkWidget *widget, GdkEventButton *event, gpointer user_data); + +void +on_enable_shift_jis_recoding_toggled (GtkToggleButton *togglebutton, + gpointer user_data); diff --git a/plugins/gtkui/deadbeef.glade b/plugins/gtkui/deadbeef.glade index 967b97b3..f4bb6c8e 100644 --- a/plugins/gtkui/deadbeef.glade +++ b/plugins/gtkui/deadbeef.glade @@ -3241,6 +3241,26 @@ Album + + + True + True + Enable Japanese SHIFT-JIS detection and recoding + True + GTK_RELIEF_NORMAL + True + False + False + True + + + + 0 + False + False + + + True diff --git a/plugins/gtkui/interface.c b/plugins/gtkui/interface.c index d75ff742..3f70035a 100644 --- a/plugins/gtkui/interface.c +++ b/plugins/gtkui/interface.c @@ -1539,6 +1539,7 @@ create_prefwin (void) GtkWidget *vbox9; GtkWidget *pref_close_send_to_tray; GtkWidget *hide_tray_icon; + GtkWidget *enable_shift_jis_recoding; GtkWidget *enable_cp1251_recoding; GtkWidget *enable_cp936_recoding; GtkWidget *hbox102; @@ -1943,6 +1944,10 @@ create_prefwin (void) gtk_widget_show (hide_tray_icon); gtk_box_pack_start (GTK_BOX (vbox9), hide_tray_icon, FALSE, FALSE, 0); + enable_shift_jis_recoding = gtk_check_button_new_with_mnemonic (_("Enable Japanese SHIFT-JIS detection and recoding")); + gtk_widget_show (enable_shift_jis_recoding); + gtk_box_pack_start (GTK_BOX (vbox9), enable_shift_jis_recoding, FALSE, FALSE, 0); + enable_cp1251_recoding = gtk_check_button_new_with_mnemonic (_("Enable Russian CP1251 detection and recoding")); gtk_widget_show (enable_cp1251_recoding); gtk_box_pack_start (GTK_BOX (vbox9), enable_cp1251_recoding, FALSE, FALSE, 0); @@ -2700,6 +2705,9 @@ create_prefwin (void) g_signal_connect ((gpointer) hide_tray_icon, "toggled", G_CALLBACK (on_hide_tray_icon_toggled), NULL); + g_signal_connect ((gpointer) enable_shift_jis_recoding, "toggled", + G_CALLBACK (on_enable_shift_jis_recoding_toggled), + NULL); g_signal_connect ((gpointer) enable_cp1251_recoding, "toggled", G_CALLBACK (on_enable_cp1251_recoding_toggled), NULL); @@ -2904,6 +2912,7 @@ create_prefwin (void) GLADE_HOOKUP_OBJECT (prefwin, vbox9, "vbox9"); GLADE_HOOKUP_OBJECT (prefwin, pref_close_send_to_tray, "pref_close_send_to_tray"); GLADE_HOOKUP_OBJECT (prefwin, hide_tray_icon, "hide_tray_icon"); + GLADE_HOOKUP_OBJECT (prefwin, enable_shift_jis_recoding, "enable_shift_jis_recoding"); GLADE_HOOKUP_OBJECT (prefwin, enable_cp1251_recoding, "enable_cp1251_recoding"); GLADE_HOOKUP_OBJECT (prefwin, enable_cp936_recoding, "enable_cp936_recoding"); GLADE_HOOKUP_OBJECT (prefwin, hbox102, "hbox102"); diff --git a/plugins/gtkui/prefwin.c b/plugins/gtkui/prefwin.c index 970dc42b..ed05525a 100644 --- a/plugins/gtkui/prefwin.c +++ b/plugins/gtkui/prefwin.c @@ -231,6 +231,9 @@ gtkui_run_preferences_dlg (void) { // resume last session gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (lookup_widget (w, "resume_last_session")), deadbeef->conf_get_int ("resume_last_session", 0)); + // enable shift-jis recoding + gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (lookup_widget (w, "enable_shift_jis_recoding")), deadbeef->conf_get_int ("junk.enable_shift_jis_detection", 0)); + // enable cp1251 recoding gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (lookup_widget (w, "enable_cp1251_recoding")), deadbeef->conf_get_int ("junk.enable_cp1251_detection", 1)); @@ -923,6 +926,15 @@ on_resume_last_session_toggled (GtkToggleButton *togglebutton, deadbeef->conf_set_int ("resume_last_session", active); } +void +on_enable_shift_jis_recoding_toggled (GtkToggleButton *togglebutton, + gpointer user_data) +{ + int active = gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (togglebutton)); + deadbeef->conf_set_int ("junk.enable_shift_jis_detection", active); + deadbeef->sendmessage (DB_EV_CONFIGCHANGED, 0, 0, 0); +} + void on_enable_cp1251_recoding_toggled (GtkToggleButton *togglebutton, gpointer user_data) -- cgit v1.2.3