Overview of previous systems

KDE

KDE uses .desktop files, with Type=MimeType, one file per file. The files are arranges in the filesystem to mirror the two-level MIME type hierarchy. The syntax is very similar to other .desktop files, with Name=, Comment= etc.

Example file:

[Desktop Entry]
Encoding=UTF-8
MimeType=application/x-kword
Comment=KWord
Comment[af]=kword
[... etc. other translations ]
Icon=kword
Type=MimeType
Patterns=*.kwd;*.kwt;
X-KDE-AutoEmbed=false

[Property::X-KDE-NativeExtension]
Type=QString
Value=.kwd

KDE does not have a separate system for specifying extension matches, but uses glob patterns for everything.

GNOME

GNOME uses the gnome-vfs library to determine the MIME type of a file. This library loads name-to-type rules from files with a '.mime' extenstion in a system-wide directory (set at install time), and merged with those in the user's directory. It loads textual descriptions for the types from files in the same directories, ending with '.keys'. The file gnome-vfs.mime in the system directory is always loaded first (allowing everything else to override it). The file user.mime in the user's directory is always loaded last, making these settings take precedence over all others.

The format of the .mime files are described as follows:

# Mime types as provided by the GNOME libraries for GNOME.
#
# Applications can provide more mime types by installing other
# .mime files in the PREFIX/share/mime-info directory.
#
# The format of this file is:
#
# mime-type
#	ext[,prio]:	list of extensions for this mime-type
#	regex[,prio]:	a regular expression that matches the filename
#
# more than one ext: and regex: fields can be present.
#
# prio is the priority for the match, the default is 1. This is required
# to distinguish composed filenames, for example .gz has a priority of 1
# and .tar.gz has a priority of 2 (thus a file having the filename
# something.tar.gz will match the mime-type for tar.gz before the mime-type
# for .gz
#
# The values in this file are kept in alphabetical order for convenience.
# Please maintain this when adding new types. Also consider adding a
# human-readable description to gnome-vfs.keys when adding a new type here.
#
# Also do please not add illegal mime types, observe the mime standard when
# adding new types.
			

When looking up the type for a file, gnome-vfs looks first for an exact-case match, then an all upper-case match, then an all lower-case match. If no matches are found, or there is no '.' in the name, then the regular expression matches are checked. It does this first for rules with priority 2, then for those with priority 1. The modification time on the mime-info directories is used to detect changes.

The .keys files contain type-to-description rules, eg:

application/msword
	description=Microsoft Word document
	[de]description=Microsoft Word-Dokument
	...
			

Guidelines for writing descriptions can be found in the mime-descriptions-guidelines.txt file.

ROX

ROX searches MIME-info directories in CHOICESPATH (~/Choices/MIME-info:/usr/local/share/Choices/MIME-info:/usr/share/Choices/MIME-info by default). Files from earlier directories override those in later ones, but the order within a directory is not specified.

The files are in the same format as GNOME, except:

  • There are no .keys files, so files of all extensions are loaded.

  • The priority is ignored.

  • A case-sensitive match is tried first, then a lower-case match. No upper-case match is tried.

  • Multiple extensions are allowed. Eg:

    application/x-compressed-postscript
    	ext: ps.gz eps.gz
    					

When looking up the type for a file, ROX starts with the first '.' and tries a case-sensitive match of the remaining text against the extensions. The it tries again with the filename in lower-case. It then tries again from the second '.', and so on. If no type is found, it tries the regular expressions.