diff options
author | Tor Lillqvist <tml@novell.com> | 2008-02-21 12:47:45 +0000 |
---|---|---|
committer | Tor Lillqvist <tml@src.gnome.org> | 2008-02-21 12:47:45 +0000 |
commit | 7a9bbf551f525a25cf4f9dd824b3fb7c1073e995 (patch) | |
tree | a61f871385ec934c5495d93a65743c9cdacaa2da /gtk | |
parent | fbe4c4f8b61a6255125f7512b33e2100557812b4 (diff) | |
download | gtk+-7a9bbf551f525a25cf4f9dd824b3fb7c1073e995.tar.gz |
Must pass the format string to strftime in the C library's locale's
2008-02-21 Tor Lillqvist <tml@novell.com>
* gtk/gtkfilechooserdefault.c (list_mtime_data_func) [Win32]: Must
pass the format string to strftime in the C library's locale's
charset, not the system's. Correspondingly, the return value from
strftime() is in the C library's locale's charset. (#509885)
svn path=/trunk/; revision=19625
Diffstat (limited to 'gtk')
-rw-r--r-- | gtk/gtkfilechooserdefault.c | 48 |
1 files changed, 45 insertions, 3 deletions
diff --git a/gtk/gtkfilechooserdefault.c b/gtk/gtkfilechooserdefault.c index d45043b333..d4bb4dddd9 100644 --- a/gtk/gtkfilechooserdefault.c +++ b/gtk/gtkfilechooserdefault.c @@ -73,6 +73,7 @@ #if defined (G_OS_UNIX) #include "gtkfilesystemunix.h" #elif defined (G_OS_WIN32) +#include <windows.h> #include "gtkfilesystemwin32.h" #endif @@ -10974,6 +10975,11 @@ list_mtime_data_func (GtkTreeViewColumn *tree_column, time_t time_mtime; gchar *date_str = NULL; gboolean sensitive = TRUE; +#ifdef G_OS_WIN32 + const char *locale, *dot = NULL; + gint64 codepage = -1; + char charset[20]; +#endif impl = data; @@ -11092,10 +11098,46 @@ list_mtime_data_func (GtkTreeViewColumn *tree_column, format = "%x"; /* Any other date */ } +#ifdef G_OS_WIN32 + /* g_locale_from_utf8() returns a string in the system + * code-page, which is not always the same as that used by the C + * library. For instance when running a GTK+ program with + * LANG=ko on an English version of Windows, the system + * code-page is 1252, but the code-page used by the C library is + * 949. (It's GTK+ itself that sets the C library locale when it + * notices the LANG environment variable. See gtkmain.c The + * Microsoft C library doesn't look at any locale environment + * variables.) We need to pass strftime() a string in the C + * library's code-page. See bug #509885. + */ + locale = setlocale (LC_ALL, NULL); + if (locale != NULL) + dot = strchr (locale, '.'); + if (dot != NULL) + { + codepage = g_ascii_strtoll (dot+1, NULL, 10); + + /* All codepages should fit in 16 bits AFAIK */ + if (codepage > 0 && codepage < 65536) + { + sprintf (charset, "CP%u", (guint) codepage); + locale_format = g_convert (format, -1, charset, "UTF-8", NULL, NULL, NULL); + } + } +#else locale_format = g_locale_from_utf8 (format, -1, NULL, NULL, NULL); - - if (strftime (buf, sizeof (buf), locale_format, &tm_mtime) != 0) - date_str = g_locale_to_utf8 (buf, -1, NULL, NULL, NULL); +#endif + if (locale_format != NULL && + strftime (buf, sizeof (buf), locale_format, &tm_mtime) != 0) + { +#ifdef G_OS_WIN32 + /* As above but in opposite direction... */ + if (codepage > 0 && codepage < 65536) + date_str = g_convert (buf, -1, "UTF-8", charset, NULL, NULL, NULL); +#else + date_str = g_locale_to_utf8 (buf, -1, NULL, NULL, NULL); +#endif + } else date_str = g_strdup (_("Unknown")); |