Re: Filename encoding in FileChooser
- From: muppet <scott asofyet org>
- To: Gtk-Perl-List <gtk-perl-list gnome org>
- Subject: Re: Filename encoding in FileChooser
- Date: Wed, 11 Aug 2004 18:46:26 -0400
On Aug 11, 2004, at 5:38 PM, Ross McFarland wrote:
On Wed, 2004-08-11 at 15:15, Daniel Flemming wrote:
Hmmm, that's interesting reading, and relevant, but it doesn't really
answer my question. :) I have a FileChooserDialog set to
GTK_FILE_CHOOSER_ACTION_SAVE, and I read its filename with a
get_filename method call after running it with a run method call.
What I want to know is, what encoding is put into the resulting
scalar (from the get_filename call)? I thought it was probably
Unicode because that's what gtk uses in general, and also the
resulting filenames kinda looked like Unicode. But I wanted to make
sure.
have you actually run into any problems, or are you just looking for
what's the right thing up front?
i don't know, but from what i read and seem to remember from past
dealings with the stuff is that the filename encoding isn't anything
in particular (depends on what the system's encoding is) and these
functions help you make sense of that. once again this is all 'i
thinks' and no 'i knows.'
that was certainly the case for the GtkFileSelection --- the filenames
are in local encoding. i do not know about GtkFileChooser. let's have
a look:
the gtk_file_path_* functions which actually manipulate paths in the
file chooser are currently implemented just as macros, and they are
compared with strcmp(). also, in gtk_file_system_unix_create_folder()
(an internal function), the GtkFilePath is passed directly to mkdir(),
and if mkdir() fails, it is converted to utf8 for display in an error
message (actually a GError). so, the GtkFilePath is most likely in a
local encoding (the same as what's on disk).
gtk_file_chooser_get_file_name() returns the result of
gtk_file_system_path_to_filename(), which invokes a vtable method;
choosing the GtkFileSystemUnix implementation, that function is
gtk_file_system_unix_path_to_filename(), which does this:
static gchar *
gtk_file_system_unix_path_to_filename (GtkFileSystem *file_system,
const GtkFilePath *path)
{
return g_strdup (gtk_file_path_get_string (path));
}
based on this reading, i would expect that the result of
gtk_file_chooser_get_filename() is in local encoding (the same as on
your disk, not utf8).
however, at the binding level, since gtk_file_chooser_get_filename()
returns a gchar, we run that through the T_GCHAR typemap, which results
in this code:
XS(XS_Gtk2__FileChooser_get_filename)
{
dXSARGS;
if (items != 1)
Perl_croak(aTHX_ "Usage: Gtk2::FileChooser::get_filename(chooser)");
{
gchar_own * RETVAL;
GtkFileChooser * chooser = SvGtkFileChooser (ST(0));
RETVAL = gtk_file_chooser_get_filename(chooser);
ST(0) = sv_newmortal();
/* used when we can directly own the returned string. */
/* we have to copy in the case when perl's malloc != gtk's malloc,
* so best copy all the time. */
sv_setpv ((SV*)ST(0), RETVAL);
SvUTF8_on (ST(0));
g_free (RETVAL);
}
XSRETURN(1);
}
we're setting the sv's utf8 flag on, which means perl will treat it as
utf8, but since it probably is *not* utf8, this may be a bug in the
bindings.
can anyone confirm this?
--
The door is locked. I tried to open it, but the lock is harder to pick
than a broken nose.
-- Sensei, on 'I, Ninja'
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]