GNOME Bugzilla – Bug 141844
gtk_file_chooser_set_current_name() takes UTF-8, not a filename
Last modified: 2005-07-29 00:09:51 UTC
Please see gedit-file.c:374: 373 tmpstr = gedit_document_get_uri (doc); 374 fname = g_filename_from_utf8 (tmpstr, -1, NULL, NULL, NULL); If the document is untitled, tmpstr is _("Untitled N"). In Portugese, this becomes "Sem título N". When the file chooser is actually invoked, you get the warnings described in bug #138158. The problem is that 'fname' above gets passed to gtk_file_chooser_set_current_name(). However, as the documentation indicates, the passed string should be in UTF-8, not in filename encoding. That is, you should not call g_filename_from_utf8() in gedit-file.c:374.
*** Bug 138158 has been marked as a duplicate of this bug. ***
To reproduce this bug: - export LANG=pt_PT.UTF-8 - export G_FILENAME_ENCODING=ISO8859-1 - gedit - type stuff, hit C-s - see warnings appear
I cannot reproduce it in gedit 2.7.1. Federico: are you still able to reproduce it?
With HEAD as of 2004-07-19: - I don't get warnings from the Save dialog. The "Sem título N" appears correctly in the file chooser's name entry. So, this bug in particular is fixed. - However, after saving, the document's notebook tab says "Sem t?tulo N (Unicode inválido)". This means that whoever sets the notebook tab's title is screwing up the conversion. Some notes about the last point: gedit-file.c:417 - right after getting the filename from the file chooser, you call eel_make_uri_from_shell_arg(). This is not necessary for two reasons. First, the file chooser gives you a full filename, which you can simply pass to g_filename_to_uri(); it is not necessary to use _from_shell_arg()'s heuristics. Second, if you really wanted a URI in the first place, you could simply call gtk_file_chooser_get_uri() rather than _get_filename(). gedit-file.c:420 - I see that eel_format_uri_for_display() doesn't pay attention to G_FILENAME_ENCODING, just to the deprecated G_BROKEN_FILENAMES. See this for reference: http://developer.gnome.org/doc/API/2.0/glib/glib-running.html#G_FILENAME_ENCODING (I don't know if there's a bug filed for eel about this.) gedit-document.c:659 - This gets called when the GeditDocument emits its "name_changed" signal after being saved. This calls eel_uri_get_basename(), which calls gnome_vfs_uri_extract_short_name(). The latter function is useless because you get the unescaped base name, *for which you don't know the encoding*: you get a raw chunk of bytes. If it's from a file:// URI, that chunk of bytes will hopefully be in the charset specified by G_FILENAME_ENCODING; if it comes from a non-file URI, it could be anything, so you can't really make use of it. A few lines down, in gedit-document.c:663, you try to convert this chunk of bytes into an UTF-8 base name. However, you use G_BROKEN_FILENAMES, rather than G_FILENAME_ENCODING. You should just use g_filename_to_utf8() instead. See this for reference: http://developer.gnome.org/doc/API/2.0/glib/glib-Character-Set-Conversion.html#file-name-encodings The culprit for the invalid notebook tab label is gedit-document.c:683, where you call eel_make_valid_utf8(). RECOMMENDATIONS: The problem you have in gedit is as follows. You can open any URI, but you can only save to local files (this makes sense). However, the code uses a mixture of raw filenames and URIs, and it doesn't always get the conversions right. You only need to convert filenames to UTF-8 when you want to display those filenames. You should use g_filename_to_utf8() to accomplish that. You only need to convert UTF-8 to a filename when the user types a filename in a GTK+ widget and you want to save that file using Unix calls. You should use g_filename_from_utf8() for that. To go between filenames and file:// URIs and back, you should use g_filename_to_uri() and g_filename_from_uri(). The latter does not work for non-file URIs; you should use the gnome-vfs functions instead.
Created attachment 30133 [details] [review] first small step in the right direction (hopefully) make the file_selector utils return the uri and thus remove the eel_make_uri_from_shell_arg (file) call.
Created attachment 30135 [details] [review] updated there was a blatant mistake in the previous patch.
Comment on attachment 30135 [details] [review] updated (the above patch was alreday committed a long time ago, some of the problems are still valid, but they'll probably wayt for the switch to gnome-vfs for saving)
After the last fixes for bug #166903 and #311187, I think this bug can be closed. federico: please, reopen it if you still see some problems.
Yup, this is fixed now.