Wednesday 4 February 2009

Things you shouldn't do

Things you shouldn't ever be doing.
  • Transform a filename into a URI like that:
uri = g_strdup_printf ("file:///%s", filename);

Use g_filename_to_uri() instead. Same goes for the opposite direction, where stripping "file://" isn't good enough to transform a URI into a local filename. Use g_filename_from_uri(), or g_file_get_path() if you're actually going to be opening the files.

  • Use GStreamer to play a single small pop sound:
Use libcanberra instead. It's portable, might use GStreamer in some cases, and very certainly requires less code for a simple use like this.

Bruno, you should get a Bugzilla component for Garfunkel.

6 comments:

Vitaly Babiy said...

Is there a python binding for this

Anonymous said...

Heh - I was just going to ask the same Python-binding question :-)

Also: in one case I want to check if a file name is on a local directory (ie. not on gvfs mount) and then get the directory of the file... Currently I use this:

if theUri.startswith("file:///"):
theDir = os.path.dirname(theUri[7:])

Not elegant, and uses a hardcoded file:/ prefix... Any suggestion how to improve this?

Anonymous said...

oliver:
use g_file_is_native()

/ Alex

Anonymous said...

You can also use g_file_get_path() if it returns Non-NULL its a local path. If you do it this way it can return local paths for gvfs mounts too, via fuse. (but is_native() will return FALSE even if fuse is availible).

Anonymous said...

Thank you, Bastien!

Kevin Kofler said...

> Use libcanberra instead.

Or Phonon. :-)