Mercurial > gftp.yaz
changeset 291:265244924868
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
author | masneyb |
---|---|
date | Sun, 19 Oct 2003 12:28:26 +0000 |
parents | 6e255984c0b0 |
children | e5ce6f15290f |
files | ChangeLog lib/gftp.h lib/protocols.c src/gtk/misc-gtk.c |
diffstat | 4 files changed, 140 insertions(+), 22 deletions(-) [+] |
line wrap: on
line diff
--- a/ChangeLog Sat Oct 18 15:21:39 2003 +0000 +++ b/ChangeLog Sun Oct 19 12:28:26 2003 +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(). @@ -1577,7 +1589,7 @@ * cvsclean - added this script - * *.[ch] - added $Id: ChangeLog,v 1.152 2003/10/18 15:21:37 masneyb Exp $ tags + * *.[ch] - added $Id: ChangeLog,v 1.153 2003/10/19 12:28:24 masneyb Exp $ tags * debian/* - updated files from Debian maintainer
--- a/lib/gftp.h Sat Oct 18 15:21:39 2003 +0000 +++ b/lib/gftp.h Sun Oct 19 12:28:26 2003 +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,
--- a/lib/protocols.c Sat Oct 18 15:21:39 2003 +0000 +++ b/lib/protocols.c Sun Oct 19 12:28:26 2003 +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); }
--- a/src/gtk/misc-gtk.c Sat Oct 18 15:21:39 2003 +0000 +++ b/src/gtk/misc-gtk.c Sun Oct 19 12:28:26 2003 +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) {