Ticket #391 (history is broken).

Reason:
glib ini-function works only with UTF-8 in files. Bug raised if system charset not UTF-8.

Issue:
 * recode to utf-8 before saving values of ini-params and
 * recode from utf-8 after reading values of ini-params

Also fixed:
 * if system codepage is not UTF-8, panelize named is always in utf-8 and seems as non-sense string.
 * Recode panelize command names into system codepage from utf-8
 * global variable utf8_display now initialized in any case (non-relative to ENABLE_CHARSET)

Signed-off-by: Slava Zanko <slavazanko@gmail.com>
This commit is contained in:
Slava Zanko 2009-07-08 15:17:10 +03:00
parent 944d1cf961
commit cf363ad022
5 changed files with 85 additions and 8 deletions

View File

@ -1457,8 +1457,8 @@ setup_dummy_mc ()
static void check_codeset()
{
#ifdef HAVE_CHARSET
const char *_system_codepage = NULL;
#ifdef HAVE_CHARSET
const char *_source_codepage = NULL;
const char *_display_codepage = NULL;
int profile_changed = 0;
@ -1519,7 +1519,10 @@ static void check_codeset()
if ( profile_changed )
save_configure ();
}
#endif
#else /* HAVE_CHARSET */
_system_codepage = str_detect_termencoding();
utf8_display = str_isutf8 (_system_codepage);
#endif /* HAVE_CHARSET */
}
static void

View File

@ -46,12 +46,13 @@ extern int mouse_move_pages;
#ifdef HAVE_CHARSET
extern int source_codepage;
extern int display_codepage;
extern int utf8_display;
#else
extern int eight_bit_clean;
extern int full_eight_bits;
#endif /* !HAVE_CHARSET */
extern int utf8_display;
extern int confirm_view_dir;
extern int fast_refresh;
extern int navigate_with_arrows;

View File

@ -22,8 +22,12 @@
#include "global.h"
#include "mcconfig.h"
#include "../src/strutil.h"
/*** global variables **************************************************/
extern int utf8_display;
/*** file scope macro definitions **************************************/
/*** file scope type declarations **************************************/
@ -80,7 +84,10 @@ gchar *
mc_config_get_string (mc_config_t * mc_config, const gchar * group,
const gchar * param, const gchar * def)
{
GIConv conv;
GString *buffer;
gchar *ret;
if (!mc_config || !group || !param)
return def ? g_strdup (def) : NULL;
@ -94,7 +101,27 @@ mc_config_get_string (mc_config_t * mc_config, const gchar * group,
if (!ret)
ret = def ? g_strdup (def) : NULL;
return ret;
if (utf8_display)
return ret;
conv = str_crt_conv_from ("UTF-8");
if (conv == INVALID_CONV)
return ret;
buffer = g_string_new ("");
if (str_convert (conv, ret, buffer) == ESTR_FAILURE)
{
g_string_free(buffer, TRUE);
str_close_conv (conv);
return ret;
}
str_close_conv (conv);
g_free(ret);
return g_string_free(buffer, FALSE);
}
/* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */

View File

@ -22,8 +22,12 @@
#include "global.h"
#include "mcconfig.h"
#include "../src/strutil.h"
/*** global variables **************************************************/
extern int utf8_display;
/*** file scope macro definitions **************************************/
/*** file scope type declarations **************************************/
@ -38,10 +42,35 @@ void
mc_config_set_string (mc_config_t * mc_config, const gchar * group,
const gchar * param, const gchar * value)
{
GIConv conv;
GString *buffer;
if (!mc_config || !group || !param || !value)
return;
g_key_file_set_string (mc_config->handle, group, param, value);
if (utf8_display)
{
buffer = g_string_new(value);
}
else
{
conv = str_crt_conv_to ("UTF-8");
if (conv == INVALID_CONV)
return;
buffer = g_string_new ("");
if (str_convert (conv, value, buffer) == ESTR_FAILURE)
{
g_string_free(buffer, TRUE);
buffer = g_string_new(value);
}
str_close_conv (conv);
}
g_key_file_set_string (mc_config->handle, group, param, buffer->str);
g_string_free(buffer, TRUE);
}
/* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */

View File

@ -314,7 +314,11 @@ void load_panelize (void)
{
gchar **profile_keys, **keys;
gsize len;
GIConv conv;
GString *buffer;
conv = str_crt_conv_from ("UTF-8");
profile_keys = keys = mc_config_get_keys (mc_main_config, panelize_section,&len);
add2panelize (g_strdup (_("Other command")), g_strdup (""));
@ -325,15 +329,28 @@ void load_panelize (void)
add2panelize (g_strdup (_("Find SUID and SGID programs")), g_strdup ("find . \\( \\( -perm -04000 -a -perm +011 \\) -o \\( -perm -02000 -a -perm +01 \\) \\) -print"));
return;
}
while (*profile_keys){
if (utf8_display || conv == INVALID_CONV){
buffer = g_string_new (*profile_keys);
} else {
buffer = g_string_new ("");
if (str_convert (conv, *profile_keys, buffer) == ESTR_FAILURE)
{
g_string_free(buffer, TRUE);
buffer = g_string_new (*profile_keys);
}
}
add2panelize (
g_strdup (*profile_keys),
g_string_free(buffer, FALSE),
mc_config_get_string(mc_main_config,panelize_section,*profile_keys,"")
);
profile_keys++;
}
g_strfreev(keys);
str_close_conv (conv);
}
void save_panelize (void)