On Thursday 11 September 2014 07:14:54 Emmanuel Thomas-Maurin wrote:
> I've had a similar problem previously, with non-ascii (for instance
> cyrillic) user names in app data dir on windows. The trick was to use
> 'wide char' win32 API functions which all return UTF-16 encoded strings,
> then convert to UTF-8 (with g_utf16_to_utf8()).
>
>
> On 09/11/2014 03:25 AM, Fernando Rodriguez wrote:
> > On Wednesday 10 September 2014 5:07:03 PM Fernando Rodriguez wrote:
> >> On Wednesday 10 September 2014 7:37:28 PM Geert Janssens wrote:
> >>> Hi,
> >>>
> >>> I'm stuck on the following issue. Program is GnuCash on Windows.
> >>>
> >>> Consider the following code snippet:
> >>>
> >>> struct stat statbuf;
> >>> gchar* dirname = g_strdup(g_getenv("GNC_DOTGNUCASH_DIR");
> >>> gint rc = g_stat (dirname, &statbuf);
> >>>
> >>> switch (errno)
> >>> {
> >>>
> >>> case ENOENT:
> >>> // Directory doesn't exist
> >>> // Here is code to create it which I cut for brevity
> >>> break;
> >>>
> >>> case EACCES:
> >>> // Directory can't be accessed
> >>> exit(1);
> >>>
> >>> case ENOTDIR:
> >>> // Not a directory
> >>> exit(1);
> >>>
> >>> default:
> >>> // Unknown error
> >>> exit(1);
> >>>
> >>> }
> >>>
> >>> // Continue code with valid, existing directory
> >>> ...
> >>>
> >>> So this snippet reads the value of environment variable GNC_DOTGNUCASH_DIR
> >>> and tests whether this is a valid directory.
> >>>
> >>> This works fine when GNC_DOTGNUCASH_DIR uses a limited character set like
> >>> ascii. For example when set to "c:\gcdev\geert" this works well and the
> >>> code continues.
> >>>
> >>> However if set to for example:
> >>> c:\gcdev\Łukasz
> >>> Things go wrong (note the unusual Ł).
> >>>
> >>> In this case the code branches into case ENOENT and creates a directory
> >>> named c:\gcdev\Lukasz (note the plain L now)
> >>> Before it continues.
> >>>
> >>> Setting a breakpoint at rc=g_stat... and examining the value of dirname at
> >>> that point also shows it to have a value of c:\gcdev\Lukasz (with plain
> >>> L).
> >>>
> >>> So it seems I'm losing diacritical information here and I can't pass the
> >>> right directory to my code to use.
> >>>
> >>> What should I do to get the real value from the environment to be able to
> >>> access the true directory ?
> >>>
> >>> Thanks,
> >>>
> >>> Geert
> >>>
> >>> P.S. my locale settings are all "Dutch_Belgium.1252" except for LC_ALL
> >>> which is empty. _______________________________________________
> >>> gtk-app-devel-list mailing list
> >>> [email protected]
> >>> https://mail.gnome.org/mailman/listinfo/gtk-app-devel-list
> >>
> >> Well gchar is a typedef for char so it only supports ascii. I think you'll
> >> probably have to use Win32 API calls on Windows to access multibyte file
> >> names.
> >>
> >> Also according to the documentation you should use GStatBuf instead of
> >> struct stat on Windows to get consistent behaviour on different compilers.
> >>
> >>
> >>
> >> _______________________________________________
> >> gtk-app-devel-list mailing list
> >> [email protected]
> >> https://mail.gnome.org/mailman/listinfo/gtk-app-devel-list
> >
> > Actually try using g_utf8_strncpy() instead of g_strdup(). I'm not sure if
> > that'll get you all the way as the docs say g_stat calls the standard
> > library
> > functions and AFAIK those dont support unicode/multibyte filenames.
> >
> >
> >
> > _______________________________________________
> > gtk-app-devel-list mailing list
> > [email protected]
> > https://mail.gnome.org/mailman/listinfo/gtk-app-devel-list
> >
>
>
>
Hi,
take a look at this code, maybe it helps:
ZZ
char *file_selector(char *title, GtkFileChooserAction fs_action, gboolean
local_only, gboolean show_hidden,
char *name, char *folder, char
*shortcut_folder)
{
GtkWidget *dialog;
char *tmp;
char *filename = NULL;;
tmp = g_locale_to_utf8((title) ? title : "", -1,NULL,NULL,NULL);
dialog = gtk_file_chooser_dialog_new (tmp,
/*parent_window*/ NULL,
fs_action,
GTK_STOCK_CANCEL,
GTK_RESPONSE_CANCEL,
GTK_STOCK_OPEN,
GTK_RESPONSE_ACCEPT,
NULL);
xfree(&tmp);
gtk_file_chooser_set_local_only(GTK_FILE_CHOOSER(dialog), local_only);
gtk_file_chooser_set_show_hidden(GTK_FILE_CHOOSER(dialog), show_hidden);
/* Returns a GsList *, not a char * */
/*gtk_file_chooser_set_select_multiple(GTK_FILE_CHOOSER(dialog),
select_multiple);*/
if (name) {
tmp = g_locale_to_utf8((name) , -1,NULL,NULL,NULL);
gtk_file_chooser_set_current_name(GTK_FILE_CHOOSER(dialog),
tmp);
xfree(&tmp);
}
if (folder) {
tmp = g_locale_to_utf8((folder) , -1,NULL,NULL,NULL);
gtk_file_chooser_set_current_folder(GTK_FILE_CHOOSER(dialog),
tmp);
xfree(&tmp);
}
if (shortcut_folder) {
tmp = g_locale_to_utf8((shortcut_folder) , -1,NULL,NULL,NULL);
gtk_file_chooser_add_shortcut_folder(GTK_FILE_CHOOSER(dialog),
tmp, NULL);
xfree(&tmp);
}
if (gtk_dialog_run (GTK_DIALOG (dialog)) == GTK_RESPONSE_ACCEPT) {
filename = gtk_file_chooser_get_filename(GTK_FILE_CHOOSER
(dialog));
}
gtk_widget_destroy (dialog);
return filename;
}
_______________________________________________
gtk-app-devel-list mailing list
[email protected]
https://mail.gnome.org/mailman/listinfo/gtk-app-devel-list