gnome-commander r2105 - in branches/gcmd-1-3: . doc/C src



Author: epiotr
Date: Wed Sep 24 17:37:49 2008
New Revision: 2105
URL: http://svn.gnome.org/viewvc/gnome-commander?rev=2105&view=rev

Log:
Fixed problem #548947 (non-UTF8 locale date problem)

Modified:
   branches/gcmd-1-3/ChangeLog
   branches/gcmd-1-3/doc/C/gnome-commander.xml
   branches/gcmd-1-3/src/gnome-cmd-data.cc
   branches/gcmd-1-3/src/gnome-cmd-options-dialog.cc
   branches/gcmd-1-3/src/utils.cc

Modified: branches/gcmd-1-3/doc/C/gnome-commander.xml
==============================================================================
--- branches/gcmd-1-3/doc/C/gnome-commander.xml	(original)
+++ branches/gcmd-1-3/doc/C/gnome-commander.xml	Wed Sep 24 17:37:49 2008
@@ -5948,6 +5948,9 @@
                             <para>Fixed problem #548961 (support for input method when rename or quicksearch)</para>
                         </listitem>
                         <listitem>
+                            <para>Fixed problem #548947 (non-UTF8 locale date problem)</para>
+                        </listitem>
+                        <listitem>
                             <para>Fixed problem #548948 (crash when home directory contains non-UTF8 characters)</para>
                         </listitem>
                         <listitem>

Modified: branches/gcmd-1-3/src/gnome-cmd-data.cc
==============================================================================
--- branches/gcmd-1-3/src/gnome-cmd-data.cc	(original)
+++ branches/gcmd-1-3/src/gnome-cmd-data.cc	Wed Sep 24 17:37:49 2008
@@ -51,7 +51,7 @@
     GList                *fav_apps;
     GnomeCmdSizeDispMode size_disp_mode;
     GnomeCmdPermDispMode perm_disp_mode;
-    GnomeCmdDateFormat   date_format;
+    GnomeCmdDateFormat   date_format;           // NOTE: internally stored as locale (which not always defaults to UTF8), needs converting from/to UTF8 for editing and cfg load/save
     GnomeCmdLayout       layout;
     GnomeCmdColorTheme   color_themes[GNOME_CMD_NUM_COLOR_MODES];
     gchar                *list_font;
@@ -1226,10 +1226,12 @@
     priv->perm_disp_mode = (GnomeCmdPermDispMode) gnome_cmd_data_get_int ("/options/perm_disp_mode", GNOME_CMD_PERM_DISP_MODE_TEXT);
 
 #ifdef HAVE_LOCALE_H
-    priv->date_format = gnome_cmd_data_get_string ("/options/date_disp_mode", "%x %R");
+    gchar *utf8_date_format = gnome_cmd_data_get_string ("/options/date_disp_mode", "%x %R");
 #else
-    priv->date_format = gnome_cmd_data_get_string ("/options/date_disp_mode", "%D %R");
+    gchar *utf8_date_format = gnome_cmd_data_get_string ("/options/date_disp_mode", "%D %R");
 #endif
+    priv->date_format = g_locale_from_utf8 (utf8_date_format, -1, NULL, NULL, NULL);
+    g_free (utf8_date_format);
 
     priv->layout = (GnomeCmdLayout) gnome_cmd_data_get_int ("/options/layout", GNOME_CMD_LAYOUT_MIME_ICONS);
 
@@ -1596,10 +1598,13 @@
 
     gnome_cmd_data_set_int    ("/options/size_disp_mode", priv->size_disp_mode);
     gnome_cmd_data_set_int    ("/options/perm_disp_mode", priv->perm_disp_mode);
-    gnome_cmd_data_set_string ("/options/date_disp_mode", priv->date_format);
     gnome_cmd_data_set_int    ("/options/layout", priv->layout);
     gnome_cmd_data_set_int    ("/options/list_row_height", list_row_height);
 
+    gchar *utf8_date_format = g_locale_to_utf8 (priv->date_format, -1, NULL, NULL, NULL);
+    gnome_cmd_data_set_string ("/options/date_disp_mode", utf8_date_format);
+    g_free (utf8_date_format);
+
     gnome_cmd_data_set_bool   ("/confirm/delete", confirm_delete);
     gnome_cmd_data_set_int    ("/confirm/copy_overwrite", confirm_copy_overwrite);
     gnome_cmd_data_set_int    ("/confirm/move_overwrite", confirm_move_overwrite);

Modified: branches/gcmd-1-3/src/gnome-cmd-options-dialog.cc
==============================================================================
--- branches/gcmd-1-3/src/gnome-cmd-options-dialog.cc	(original)
+++ branches/gcmd-1-3/src/gnome-cmd-options-dialog.cc	Wed Sep 24 17:37:49 2008
@@ -172,12 +172,16 @@
     GtkWidget *test_label = lookup_widget (options_dialog, "date_format_test_label");
 
     const char *format = gtk_entry_get_text (GTK_ENTRY (format_entry));
+    gchar *locale_format = g_locale_from_utf8 (format, -1, NULL, NULL, NULL);
 
     char s[256];
     time_t t = time (NULL);
-    strftime (s, sizeof(s), format, localtime (&t));
+    strftime (s, sizeof(s), locale_format, localtime (&t));
+    gchar *utf8_str = g_locale_to_utf8 (s, -1, NULL, NULL, NULL);
 
-    gtk_label_set_text (GTK_LABEL (test_label), s);
+    gtk_label_set_text (GTK_LABEL (test_label), utf8_str);
+    g_free (utf8_str);
+    g_free (locale_format);
 }
 
 
@@ -245,8 +249,9 @@
     label = create_label (parent, _("Format:"));
     table_add (table, label, 0, 0, GTK_FILL);
 
-    entry = create_entry (parent, "date_format_entry", gnome_cmd_data_get_date_format());
-    gtk_entry_set_text (GTK_ENTRY (entry), gnome_cmd_data_get_date_format ());
+    gchar *utf8_date_format = g_locale_to_utf8 (gnome_cmd_data_get_date_format(), -1, NULL, NULL, NULL);
+    entry = create_entry (parent, "date_format_entry", utf8_date_format);
+    g_free (utf8_date_format);
     gtk_widget_grab_focus (entry);
     table_add (table, entry, 1, 0, GTK_FILL);
 
@@ -293,7 +298,7 @@
     else
         gnome_cmd_data_set_perm_disp_mode (GNOME_CMD_PERM_DISP_MODE_NUMBER);
 
-    gnome_cmd_data_set_date_format (g_strdup (format));
+    gnome_cmd_data_set_date_format (g_locale_from_utf8 (format, -1, NULL, NULL, NULL));
 }
 
 

Modified: branches/gcmd-1-3/src/utils.cc
==============================================================================
--- branches/gcmd-1-3/src/utils.cc	(original)
+++ branches/gcmd-1-3/src/utils.cc	Wed Sep 24 17:37:49 2008
@@ -420,12 +420,21 @@
 
 const gchar *time2string (time_t t, const gchar *date_format)
 {
+    // NOTE: date_format is passed in current locale format
+
     static gchar buf[64];
     struct tm lt;
 
     localtime_r (&t, &lt);
     strftime (buf, sizeof(buf), date_format, &lt);
 
+    // convert formatted date from current locale to UTF8
+    gchar *loc_date = g_locale_to_utf8 (buf, -1, NULL, NULL, NULL);
+    if (loc_date)
+        strncpy (buf, loc_date, sizeof(buf)-1);
+
+    g_free (loc_date);
+
     return buf;
 }
 



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