views:

79

answers:

1

i need to open a viewer for a given mime type. how to do that in linux. i suppose the method would be specific to desktop environment in use. i want to do this through a C program.

+1  A: 

There are Gnome APIs that deal with mime-types for you (declared in headers such as <libgnomevfs/gnome-vfs-mime-handlers.h>) but I think that understanding what's happening under the covers is also useful.

The functions in question essentially read, parse and present certain configuration files' contents to you, and here is a clear explanation of the files that Gnome uses to associate mime types with files, i.e.:

extension .mime in the $gnome/share/mime-info directory or from the ~/.gnome/mime-info directory.

The file $gnome/share/mime-info/gnome.mime is special, as it contains the defaults for gnome, and is read first. In addition, the file ~/.gnome/mime-info/user.mime is read last.

As explain in the section "Default Keys" of this URL, keys such as open, view etc are what gives you the commands to use for various generic actions (and, via "tags", for specific named actions too).

For a C code example using the API, see e.g. the end of this thread.

Alex Martelli
i am not able to get the program given in the thread mentioned to compile. it includes a file config.h which is not present in my /usr/include/.in addition i get a lot of compiler errors in the included header files. how to fix this?like these:/usr/include/glib/gconvert.h:108: error: expected declaration specifiers or ‘...’ before ‘gssize’another error:/usr/include/glib/gi18n-lib.h:27:2: error: #error You must define GETTEXT_PACKAGE before including gi18n-lib.h.
iamrohitbanga