[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]
[gftp] Re: i18n problems in gFTP 2.0.15
- To: gftp-users@seul.org
- Subject: [gftp] Re: i18n problems in gFTP 2.0.15
- From: Brian Masney <masneyb@gftp.org>
- Date: Sun, 19 Oct 2003 08:33:37 -0400
- Delivered-to: archiver@seul.org
- Delivered-to: gftp-users-outgoing@seul.org
- Delivered-to: gftp-users@seul.org
- Delivery-date: Sun, 19 Oct 2003 08:33:47 -0400
- In-reply-to: <20030827001332.GA20580@liling-coral>; from liling@bit.edu.cn on Wed, Aug 27, 2003 at 08:13:32AM +0800
- References: <20030827001332.GA20580@liling-coral>
- Reply-to: gftp-users@seul.org
- Sender: owner-gftp-users@seul.org
- User-agent: Mutt/1.2.5.1i
Hi,
Here is a patch that should fix these issues. I also put my latest code
online at http://www.gftp.org/gftp-test.tar.bz2.
Brian
On Wed, Aug 27, 2003 at 08:13:32AM +0800, Ling Li wrote:
> I noticed that gFTP 2.0.15 has been released and I have installed it on my
> machine. It's now more stable than before! :-)
>
> I have found some i18n problem with it, and I hope this message will help.
>
> 1. When creating new directory with a Chinese name on local machine or
> remote server, the directory is created in UTF-8 name. In gFTP it's
> displayed no problem, but in some other programs such as shell, it can't
> be displayed. My LC_CTYPES is set to zh_CN.GBK.
>
> I have read the code of gFTP, there's no encoding conversation when
> creating directories, but I think when creating directories, the encoding
> of directory name should be converted from UTF-8 to default locales. And,
> when creating directories on remote server, the directory name should be
> converted from UTF-8 to remote charset setting in options dialog.
>
> This problem not only exists in creating directories, when rename files,
> it's also happen.
>
> 2. When entering a directory with a Chinese name in zh_CN.GBK encoding,
> the directory name can't be displayed correctly in the directory edit box.
> I notice this happened in both local machine or remote server.
>
> 3. Sometimes Chinese Words in zh_CN.GBK encoding can also pass UTF-8
> validation, so I think it's not a good idea using UTF-8 validation function
> provide by GTK to judge whether the encoding of a string should be converted.
> Although UTF-8 can be used to store any language, we seldom use it on FTP
> server or local files. So I think the filename and directory name should be
> convert to remote or local locale with out UTF-8 validation.
>
>
> Thanks a lot for your great work on gFTP!
>
> --
>
> Ling Li,
> Beijing Institute of Technology
Index: ChangeLog
===================================================================
RCS file: /cvs/gnome/gftp/ChangeLog,v
retrieving revision 1.152
diff -u -r1.152 ChangeLog
--- ChangeLog 18 Oct 2003 15:21:37 -0000 1.152
+++ ChangeLog 19 Oct 2003 12:27:28 -0000
@@ -1,3 +1,15 @@
+2003-10-19 Brian Masney <masneyb@gftp.org>
+ * lib/protocols.c lib/gftp.h - added gftp_string_from_utf8(). Also, make
+ gftp_string_{to,from}_utf8() be defined all the time. When using
+ glib 1.2, the functions will always return NULL.
+
+ * lib/protocols.c - when creating a directory or renaming files, make
+ sure the new name is converted from UTF8 to the local character set
+ or the charset specified in the remote_charsets option.
+
+ * src/gtk/misc-gtk.c (update_window_info) - when showing the directory
+ we are currently in, make sure it is converted to UTF8
+
2003-10-18 Brian Masney <masneyb@gftp.org>
* lib/misc.c lib/gftp.h src/text/gftp-text.c src/gtk/gftp-gtk.c - added
gftp_locale_init().
Index: lib/gftp.h
===================================================================
RCS file: /cvs/gnome/gftp/lib/gftp.h,v
retrieving revision 1.60
diff -u -r1.60 gftp.h
--- lib/gftp.h 18 Oct 2003 15:21:37 -0000 1.60
+++ lib/gftp.h 19 Oct 2003 12:27:29 -0000
@@ -811,10 +811,11 @@
int gftp_list_files ( gftp_request * request );
-#if GLIB_MAJOR_VERSION > 1
char * gftp_string_to_utf8 ( gftp_request * request,
- char *str );
-#endif
+ const char *str );
+
+char * gftp_string_from_utf8 ( gftp_request * request,
+ const char *str );
int gftp_parse_bookmark ( gftp_request * request,
gftp_request * local_request,
Index: lib/protocols.c
===================================================================
RCS file: /cvs/gnome/gftp/lib/protocols.c,v
retrieving revision 1.66
diff -u -r1.66 protocols.c
--- lib/protocols.c 4 Oct 2003 14:45:38 -0000 1.66
+++ lib/protocols.c 19 Oct 2003 12:27:30 -0000
@@ -339,6 +339,7 @@
#if GLIB_MAJOR_VERSION > 1
+
static char *
_gftp_get_next_charset (char *remote_charsets, char *orig_str, char **curpos)
{
@@ -379,7 +380,7 @@
char *
-gftp_string_to_utf8 (gftp_request * request, char *str)
+gftp_string_to_utf8 (gftp_request * request, const char *str)
{
char *ret, *remote_charsets, *stpos, *cur_charset, orig_str;
gsize bread, bwrite;
@@ -391,6 +392,8 @@
if (request->iconv_initialized)
return (g_convert_with_iconv (str, -1, request->iconv, &bread, &bwrite,
&error));
+ else if (g_utf8_validate (str, -1, NULL))
+ return (NULL);
gftp_lookup_request_option (request, "remote_charsets", &remote_charsets);
if (*remote_charsets == '\0')
@@ -428,6 +431,76 @@
return (ret);
}
+
+
+char *
+gftp_string_from_utf8 (gftp_request * request, const char *str)
+{
+ char *ret, *remote_charsets, *stpos, *cur_charset, orig_str;
+ gsize bread, bwrite;
+ GError * error;
+
+ if (request == NULL)
+ return (NULL);
+
+ if (request->iconv_initialized)
+ return (g_convert_with_iconv (str, -1, request->iconv, &bread, &bwrite,
+ &error));
+ else if (g_utf8_validate (str, -1, NULL))
+ return (NULL);
+
+ gftp_lookup_request_option (request, "remote_charsets", &remote_charsets);
+ if (*remote_charsets == '\0')
+ {
+ error = NULL;
+ if ((ret = g_locale_from_utf8 (str, -1, &bread, &bwrite, &error)) != NULL)
+ return (ret);
+
+ return (NULL);
+ }
+
+ ret = NULL;
+ stpos = remote_charsets;
+ while ((cur_charset = _gftp_get_next_charset (remote_charsets, &orig_str,
+ &stpos)) != NULL)
+ {
+ if ((request->iconv = g_iconv_open (cur_charset, "UTF-8")) == (GIConv) -1)
+ continue;
+
+ error = NULL;
+ if ((ret = g_convert_with_iconv (str, -1, request->iconv, &bread, &bwrite,
+ &error)) == NULL)
+ {
+ g_iconv_close (request->iconv);
+ request->iconv = NULL;
+ continue;
+ }
+ else
+ {
+ request->iconv_initialized = 1;
+ _gftp_restore_charset_string (&remote_charsets, *cur_charset, &stpos);
+ break;
+ }
+ }
+
+ return (ret);
+}
+
+#else
+
+char *
+gftp_string_to_utf8 (gftp_request * request, const char *str)
+{
+ return (NULL);
+}
+
+
+char *
+gftp_string_from_utf8 (gftp_request * request, const char *str)
+{
+ return (NULL);
+}
+
#endif
@@ -452,10 +525,8 @@
gftp_file_destroy (fle);
ret = request->get_next_file (request, fle, fd);
-#if GLIB_MAJOR_VERSION > 1
- if (ret >= 0 && fle->file != NULL && !g_utf8_validate (fle->file, -1, NULL))
+ if (ret >= 0 && fle->file != NULL)
fle->utf8_file = gftp_string_to_utf8 (request, fle->file);
-#endif
if (ret >= 0 && !request->cached && request->cachefd > 0 &&
request->last_dir_entry != NULL)
@@ -824,11 +895,24 @@
int
gftp_make_directory (gftp_request * request, const char *directory)
{
+ char *utf8;
+ int ret;
+
g_return_val_if_fail (request != NULL, GFTP_EFATAL);
if (request->mkdir == NULL)
return (GFTP_EFATAL);
- return (request->mkdir (request, directory));
+
+ utf8 = gftp_string_from_utf8 (request, directory);
+ if (utf8 != NULL)
+ {
+ ret = request->mkdir (request, utf8);
+ g_free (utf8);
+ }
+ else
+ ret = request->mkdir (request, directory);
+
+ return (ret);
}
@@ -836,11 +920,24 @@
gftp_rename_file (gftp_request * request, const char *oldname,
const char *newname)
{
+ char *utf8;
+ int ret;
+
g_return_val_if_fail (request != NULL, GFTP_EFATAL);
if (request->rename == NULL)
return (GFTP_EFATAL);
- return (request->rename (request, oldname, newname));
+
+ utf8 = gftp_string_from_utf8 (request, newname);
+ if (utf8 != NULL)
+ {
+ ret = request->rename (request, oldname, utf8);
+ g_free (utf8);
+ }
+ else
+ ret = request->rename (request, oldname, newname);
+
+ return (ret);
}
Index: src/gtk/misc-gtk.c
===================================================================
RCS file: /cvs/gnome/gftp/src/gtk/misc-gtk.c,v
retrieving revision 1.32
diff -u -r1.32 misc-gtk.c
--- src/gtk/misc-gtk.c 12 Aug 2003 01:05:02 -0000 1.32
+++ src/gtk/misc-gtk.c 19 Oct 2003 12:27:30 -0000
@@ -50,10 +50,10 @@
gftp_color * color;
GdkColor fore;
#else
- char *utf8_str;
GtkTextBuffer * textbuf;
GtkTextIter iter, iter2;
const char *descr;
+ char *utf8_str;
#endif
va_start (argp, string);
@@ -70,17 +70,14 @@
va_end (argp);
#if GTK_MAJOR_VERSION > 1
- if (!g_utf8_validate (logstr, -1, NULL))
+ if ((utf8_str = gftp_string_to_utf8 (request, logstr)) != NULL)
{
- if ((utf8_str = gftp_string_to_utf8 (request, logstr)) != NULL)
- {
- if (free_logstr)
- g_free (logstr);
- else
- free_logstr = 1;
+ if (free_logstr)
+ g_free (logstr);
+ else
+ free_logstr = 1;
- logstr = utf8_str;
- }
+ logstr = utf8_str;
}
#endif
@@ -294,7 +291,7 @@
void
update_window (gftp_window_data * wdata)
{
- char *dir, *tempstr, *temp1str, *fspec;
+ char *dir, *tempstr, *temp1str, *fspec, *utf8_directory;
int connected, start;
connected = GFTP_IS_CONNECTED (wdata->request);
@@ -312,12 +309,23 @@
gtk_label_set (GTK_LABEL (wdata->hoststxt), tempstr);
g_free (tempstr);
+ utf8_directory = NULL;
if ((dir = wdata->request->directory) == NULL)
temp1str = "";
else
- temp1str = dir;
+ {
+ utf8_directory = gftp_string_to_utf8 (wdata->request,
+ wdata->request->directory);
+ if (utf8_directory != NULL)
+ temp1str = utf8_directory;
+ else
+ temp1str = dir;
+ }
gtk_entry_set_text (GTK_ENTRY (GTK_COMBO (wdata->combo)->entry),temp1str);
+
+ if (utf8_directory != NULL)
+ g_free (utf8_directory);
}
else if (wdata->hoststxt != NULL)
{