Gnome Library Reference Manual
<<< Previous Page | Home | Up | Next Page >>>

# gnome-mime-info

## Name

gnome-mime-info — Routines to get information bound to a MIME type.

## Synopsis

    #include <gnome.h>

    const char* gnome_mime_get_value            (const char *mime_type,
                                                 char *key);
    GList*      gnome_mime_get_keys             (const char *mime_type);
    const char* gnome_mime_program              (const char *mime_type);
    const char* gnome_mime_description          (const char *mime_type);
    const char* gnome_mime_nametemplate         (const char *mime_type);
    const char* gnome_mime_test                 (const char *mime_type);
    const char* gnome_mime_composetyped         (const char *mime_type);
    gboolean    gnome_mime_copiousoutput        (const char *mime_type,
                                                 char *key);
    gboolean    gnome_mime_needsterminal        (const char *mime_type,
                                                 char *key);

## Description

The routines in the `gnome-mime-info` allow retrieval of information that has been bound to a given MIME type. There are a number of standard keys used in GNOME to provide default actions and behaviour.

To add keys to a MIME type, it is necessary to install a file with the extension `.keys` in the `$gnome/share/mime-info` directory or in the `~/.gnome/mime-info directory` directory. The former is for system-provided MIME information and the latter is to enable the user to extend the actions as provided by the system.

The file `$gnome/share/mime-info/gnome.keys` is special, as it contains the defaults for gnome, and is read first. In addition, the file `~/.gnome/mime-info/user.keys` is read last. This will guarantee that there is a way to set system defaults, and there is a way for the user to override them. There is currently no way to tell anything about the order of the other files in those directories, nor is there any way to override system defaults yet.

The `.keys` files have the following format:

Example 1. Format of a .keys file

    mime-type-match:
    	[\[LANG\]]key=value

Above, the `key` is the key that is being defined, and `value` is the value we bind to it. The optional `[LANG]` represents a language in which this definition is valid. If this part is specified, then the definition will only be valid if LANG matches the setting of the environment variable LANG. The LANG setting is used to provide keys which can be displayed to the user in a localized way.

This is an example to bind the key open to all of the MIME types matching image/* and the icon-filename key is bound to the `/opt/gimp/share/xcf.png` value:

Example 2. Sample gimp.keys file

    image/*:
    	open=gimp f

    image/x-xcf:
            icon-filename=/opt/gimp/share/xcf.png

This will make the GIMP the handler for the open action. Files of type xcf would use the filename pointed to in the icon-filename key.

`f` gets interpolated with the file name or the list of file names that matched this MIME type.

As you can see from the example above, a `.keys` file does not need to provide all of the values, it can just provide or override some of the actions.

User defined bindings in `.keys` file will take precedence over system installed files.

The following keys are currently used in the GNOME desktop:

- open: Open the file with this command.

- icon-filename: The filename with the icon that should be used to represent files of this type.

- view: Command to view the file contents.

- ascii-view: A command that should be used to do an ascii-rendering of the file. Used as a fallback by the filemanager if a view action does not exist.

- fm-open:file-manager open. If present, the file manager will use this action instead of the value in open to perform this action (the filemanager for example will open archive files as if they were directories by using the VFS).

- fm-view: file-manager view. If present, invoking the view opertion on the file manager will use the value defined here instead of the value in "view".

- fm-ascii-view:Fallback operation for the file manager as well.

Those keys are also queried on the metadata (except in the cases where the lookup would be too expensive).

## Details

### gnome_mime_get_value ()

    const char* gnome_mime_get_value            (const char *mime_type,
                                                 char *key);

`mime_type` : |
`key` : |
Returns : |

### gnome_mime_get_keys ()

    GList*      gnome_mime_get_keys             (const char *mime_type);

`mime_type` : | the mime type to lookup.
Returns : | a GList that contains private strings with all of the keys associated with the `mime_type`.

### gnome_mime_program ()

    const char* gnome_mime_program              (const char *mime_type);

`mime_type` : | the mime_type
Returns : | the program intended to be loaded for this given mime-type

### gnome_mime_description ()

    const char* gnome_mime_description          (const char *mime_type);

`mime_type` : | the mime type
Returns : | the description for this mime-type

### gnome_mime_nametemplate ()

    const char* gnome_mime_nametemplate         (const char *mime_type);

`mime_type` : |
Returns : |

### gnome_mime_test ()

    const char* gnome_mime_test                 (const char *mime_type);

`mime_type` : | the mime type
Returns : | the command to be executed on the file before considering the file to match this mime_type.

### gnome_mime_composetyped ()

    const char* gnome_mime_composetyped         (const char *mime_type);

`mime_type` : | the mime type
Returns : | the command to be executed to compose a message of the given mime_type

### gnome_mime_copiousoutput ()

    gboolean    gnome_mime_copiousoutput        (const char *mime_type,
                                                 char *key);

`mime_type` : | the mime type
`key` : | the key used to open the command.
Returns : | a boolean value, whether the mime_type open command will produce lots of output

### gnome_mime_needsterminal ()

    gboolean    gnome_mime_needsterminal        (const char *mime_type,
                                                 char *key);

`mime_type` : | the mime type
`key` : | the key used to open the command.
Returns : | a boolean value, whether the mime_type open command will required a terminal.

<<< Previous Page | Home | Up | Next Page >>>
gnome-metadata | gnome-mime