After an evaluation, GNOME has moved from Bugzilla to GitLab. Learn more about GitLab.
No new issues can be reported in GNOME Bugzilla anymore.
To report an issue in a GNOME project, go to GNOME GitLab.
Do not go to GNOME Gitlab for: Bluefish, Doxygen, GnuCash, GStreamer, java-gnome, LDTP, NetworkManager, Tomboy.
Bug 141844 - gtk_file_chooser_set_current_name() takes UTF-8, not a filename
gtk_file_chooser_set_current_name() takes UTF-8, not a filename
Status: RESOLVED FIXED
Product: gedit
Classification: Applications
Component: general
2.6.x
Other All
: High major
: 2.12.0
Assigned To: Gedit maintainers
gedit QA volunteers
: 138158 (view as bug list)
Depends on:
Blocks:
 
 
Reported: 2004-05-04 20:22 UTC by Federico Mena Quintero
Modified: 2005-07-29 00:09 UTC
See Also:
GNOME target: ---
GNOME version: 2.9/2.10


Attachments
first small step in the right direction (hopefully) (2.71 KB, patch)
2004-08-01 12:32 UTC, Paolo Borelli
none Details | Review
updated (2.77 KB, patch)
2004-08-01 12:59 UTC, Paolo Borelli
committed Details | Review

Description Federico Mena Quintero 2004-05-04 20:22:49 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.
Comment 1 Federico Mena Quintero 2004-05-04 20:24:01 UTC
*** Bug 138158 has been marked as a duplicate of this bug. ***
Comment 2 Federico Mena Quintero 2004-05-04 20:31:12 UTC
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
Comment 3 Paolo Maggi 2004-07-14 16:20:32 UTC
I cannot reproduce it in gedit 2.7.1.

Federico: are you still able to reproduce it?
Comment 4 Federico Mena Quintero 2004-07-19 17:59:04 UTC
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.
Comment 5 Paolo Borelli 2004-08-01 12:32:06 UTC
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.
Comment 6 Paolo Borelli 2004-08-01 12:59:21 UTC
Created attachment 30135 [details] [review]
updated

there was a blatant mistake in the previous patch.
Comment 7 Paolo Borelli 2005-01-13 15:13:54 UTC
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)
Comment 8 Paolo Maggi 2005-07-28 16:55:04 UTC
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.
Comment 9 Federico Mena Quintero 2005-07-29 00:09:51 UTC
Yup, this is fixed now.