Find More DocumentationFeatured Support Resources | Download this book in PDF (602 KB)
Chapter 4 MIME TypesThis chapter describes how applications detect MIME types, how to register MIME types, and how to add applications to the GNOME Desktop. Introduction to MIME TypesA Multipurpose Internet Mail Extension (MIME) type identifies the format of a file. The MIME type enables applications to read the file. Applications such as Internet browsers and email applications use the MIME type to handle files of different types. For example, an email application can use the MIME type to detect what type of file is in a file attached to an email. The
If you add a new application, you must ensure that other applications can recognize the files associated with the application. You must perform several tasks to enable other applications to detect the MIME type of the application files. This section describes how applications detect the MIME types of files, and how applications are associated with MIME types. This chapter also describes the procedure that you must follow to add a new application. Detecting the MIME Type for a FileApplications can detect the MIME type of a file as follows:
The following sections provide further information on file content sniffers and the MIME type registry. File Content SniffersFile content sniffers are specified in the file /etc/gnome-vfs-mime-magic. The following is an example of a file content sniffer: 0 string \x89PNG image/png The syntax for file content sniffers is as follows: offset_start[:offset_end] pattern_type pattern [&pattern_mask] type Table 4–1 describes the fields in a file content sniffer. Table 4–1 Fields in a File Content Sniffer
Pattern MasksA pattern mask identifies bits in the pattern to ignore when searching for a pattern in a file. The following is an example of a file content sniffer with a pattern mask: 0 string BMxxxx\000\000 &0xffff00000000ffff image/bmp The pattern and mask in the example are as follows:
The pattern and mask specify a file with the following characteristics:
The file content sniffer specifies that the MIME type of files that match the pattern and mask is image/bmp. MIME Type RegistryThe MIME type registry is located in /usr/share/mime-info. The MIME type registry contains the following files:
The following sections describe MIME information files and MIME keys files. MIME Information FilesMIME information files associate MIME types with one or both of the following:
When an application searches for the MIME type of a file, the application checks the filename against the MIME information files. If a match for the filename is found, the MIME type associated with the extension or pattern is the MIME type of the file. In MIME information files, the filename pattern to search for is written as a regular expression. The format of MIME type entries in MIME information files is as follows: MIME-type ext[,priority]: list-of-extensions regex[,priority]: list-of-regular-expressions You can specify a priority value for the file extension and the regular expression. You can use the priority value to differentiate composite filenames. For example, you can assign a priority of 1 to the .gz extension, and assign a higher priority of 2 to the .tar.gz extension. In this case, the file abc.tar.gz takes the MIME type for .tar.gz. Note – You must indent the ext field and the regex field with a tab character (\t). The following MIME type entries are samples from the gnome-vfs.mime MIME information file: application/x-compressed-tar regex,2: tar\.gz$ ext: tgz audio/x-real-audio ext: rm ra ram image/jpeg ext: jpe jpeg jpg image/png ext: png text/html ext: html htm HTML text/plain ext: asc txt TXT text/x-readme regex: README.* Note – The file manager reads the MIME information files alphabetically. The alphabetical order determines the order in which MIME types are assigned to file extensions or regular expressions. For example, if the same file extension is assigned to different MIME types in the files abc.mime and def.mime, the MIME type in abc.mime is used. MIME Keys FilesMIME keys file provide information about a MIME type that is used in the user interface. For example, the MIME keys file provides a description of a MIME type, and specifies an icon to represent files of that MIME type. The following is a sample from a MIME keys file: text/html description=HTML page icon_filename=gnome-text-html default_action_type=application short_list_application_ids_for_novice_user_level=mozilla,netscape,galeon category=Documents/World Wide Web Note – You must indent the keys in a MIME keys file with a tab character (\t). Table 4–2 describes the most important keys in MIME keys files. Typically, the description key and the category key are localized. Table 4–2 Keys in MIME Keys Files
Registering Applications for MIME TypesThe application registry contains text files that register applications. The application registration files contain a series of key-value pairs that specify details for applications. For example, the application registration files contain the following information:
An application registration file can contain one or more application registrations. Application registration files have a .applications extension. The location of the application registry is /usr/share/application-registry. This directory contains a default application registration file that is called gnome-vfs.applications. To register an application, add a registration file for the application to the application registry. The following is an example of an application registration: eog command=eog name=Eye of Gnome can_open_multiple_files=true expects_uris=false requires_terminal=false mime_types=image/bmp,image/gif,image/jpeg,image/png,image/tiff, image/x-xpixmap,image/x-bmp,image/x-png,image/x-portable-anymap, image/x-portable-bitmap,image/x-portable-graymap, image/x-portable-pixmap Table 4–3 describes the keys in application registration files. Table 4–3 Keys for an Application Registration
Adding an Application to the GNOME DesktopTo add an application to the GNOME Desktop, perform the following steps:
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||