gtk+ r19625 - in trunk: . gtk



Author: tml
Date: Thu Feb 21 12:47:45 2008
New Revision: 19625
URL: http://svn.gnome.org/viewvc/gtk+?rev=19625&view=rev

Log:
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)



Modified:
   trunk/ChangeLog
   trunk/gtk/gtkfilechooserdefault.c

Modified: trunk/gtk/gtkfilechooserdefault.c
==============================================================================
--- trunk/gtk/gtkfilechooserdefault.c	(original)
+++ trunk/gtk/gtkfilechooserdefault.c	Thu Feb 21 12:47:45 2008
@@ -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 @@
   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 @@
 	    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"));
 



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]