Re: Can someone please comment on this short program
- From: Federico Mena Quintero <federico ximian com>
- To: Murray Cumming <murrayc murrayc com>
- Cc: gnome-vfs-list gnome org, Alexander Larsson <alexl redhat com>, Matthias Kaeppler <matthias finitestate org>
- Subject: Re: Can someone please comment on this short program
- Date: Thu, 15 Dec 2005 11:40:46 -0600
On Thu, 2005-12-15 at 11:46 +0100, Murray Cumming wrote:
> So, we can use the result of gtk_file_chooser_get_uri() directly as the
> parameter to gnome_vfs_uri_new(), because GtkFileChooser gives us an
> escaped ASCII URI?
Yes. These are correct:
/* get a URI from the file chooser and turn it into a GnomeVFSURI */
char *str_uri = gtk_file_chooser_get_uri (chooser);
GnomeVFSURI *vfs_uri = gnome_vfs_uri_new (str_uri);
/* Get a filename from the file chooser and turn it into a GnomeVFSURI */
char *filename_on_disk = gtk_file_chooser_get_filename (chooser);
GnomeVFSURI *vfs_uri = gnome_vfs_get_uri_from_local_path (filename_on_disk);
/* Get a filename from the file chooser and display it in a widget */
char *filename_on_disk = gtk_file_chooser_get_filename (chooser);
GError *error = NULL;
char *utf8_filename = g_filename_to_utf8 (filename_on_disk, -1, NULL, NULL, &error);
if (utf8_filename == NULL)
g_error ("Could not convert on-disk filename to UTF-8: %s", error->message);
else
gtk_entry_set_text (entry, utf8_filename);
/* Get a filename from the user and turn it into a GnomeVFSURI */
const char *utf8_filename = gtk_entry_get_text (entry);
GnomeVFSURI *vfs_uri;
/* The long way */
GError *error = NULL;
char *filename = g_filename_from_utf8 (utf8_filename, -1, NULL, NULL, &error);
if (!g_path_is_absolute (filename))
g_error ("Please type a full pathname");
if (filename == NULL)
g_error ("Could not convert UTF-8 filename to on-disk representation: %s", error->message);
else
vfs_uri = gnome_vfs_get_uri_from_local_path (filename);
/* The short way */
vfs_uri = gnome_vfs_make_uri_from_input (utf8_filename);
We should sprinkle all the relevant docs with examples...
References:
File name conversions:
http://developer.gnome.org/doc/API/2.0/glib/glib-Character-Set-Conversion.html#file-name-encodings
(n.b. the figures are missing; please see this as well:
http://primates.ximian.com/~federico/news-2004-06.html#15
File names in GtkFileChooser:
http://developer.gnome.org/doc/API/2.0/gtk/GtkFileChooser.html#gtkfilechooser-encodings
Federico
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]