Associating Applications with MIME types

After you have associated files with MIME types, you need to associate those MIME types with the applications who can open them. KDE and Gnome 2.8 and above use .desktop files to achieve this and Gnome prior to 2.8 use .applications files.

.desktop file

If your program already has a .desktop file (for menu items), you can add a MimeType key to the file. For example, acroread.desktop could become this:

                    
[Desktop Entry]
Version=1.0
Type=Application
Encoding=UTF-8
Name=Acrobat Reader
Comment=Read PDF files
Exec=acroread %f
Icon=acroread.png
MimeType=application/pdf;image/png; # note final semi-colon
Categories=Viewer;Office;
                     

A list of valid Exec variables  is available from FreeDesktop.org.

You can install this file with the installMenuItem() API call. If you don't want your application to appear in the menu, but need to associate it with a MIME type, then use the installMimeDesktop().

Gnome .applications file

Gnome uses their own file format for associating MIME types with applications. It is fully documented here .

The first line ("acroread" in this case), is called the "Application Identifier". It does not need to be the same at the executable name, but that is the convention. This is used to map short_list_application_ids_for_*_user_level to its entry in a .applications file.

                    
acroread
        command=acroread # note tabs!
        name=Acrobat Reader
        can_open_multiple_files=false
        expects_uris=false
        requires_terminal=false
        startup_notify=true
        mime_types=application/pdf,image/png

This file can be called acroread.applications and can be installed with installGnome2AppEntry().