Documentation/Maemo 5 Developer Guide/Application Development/MIME type mapping

= MIME types mapping =

MIME types mapping specifies for the platform which application should handle a given MIME type. A mapping has to be defined in the desktop file of the application by adding to it the MimeType field.

An example_libosso.desktop file for the application looks like the following:

The last line is the most important one, and specifies that this application can handle the MIME type ``application/x-example''.

=New MIME type with OSSO category extension =

If the application is introducing a new MIME type to the system, it is necessary to provide the mime-info XML (see more at http://standards.freedesktop.org/shared-mime-info-spec/) that defines it, in this case an example-mime.xml file for the application looks as follows:

  &lt;?xml  version   =  "1.0"  encoding   =  "UTF-8"   ?&gt;   &lt;mime-info  xmlns   =  "http://www.freedesktop.org/standards/shared-mime-info" xmlns:osso  =  "http://nokia.com/osso/mime-categories"   <font color="#0000FF">&gt;   <font color="#0000FF">&lt;mime-type  <font color="#009900">type  <font color="#990000"> =  <font color="#FF0000">"application/x-example"   <font color="#0000FF">&gt;   <font color="#0000FF">&lt;comment&gt;  Example application file  <font color="#0000FF">&lt;/comment&gt;   <font color="#0000FF">&lt;osso:category  <font color="#009900">name  <font color="#990000"> =  <font color="#FF0000">"images"   <font color="#0000FF">/&gt;   <font color="#0000FF">&lt;magic  <font color="#009900">priority  <font color="#990000"> =  <font color="#FF0000">"50"   <font color="#0000FF">&gt;   <font color="#0000FF">&lt;match  <font color="#009900">type  <font color="#990000"> =  <font color="#FF0000">"string"  <font color="#009900">value  <font color="#990000"> =  <font color="#FF0000">"FOO"  <font color="#009900">offset  <font color="#990000"> =  <font color="#FF0000">"0"   <font color="#0000FF">/&gt;   <font color="#0000FF">&lt;/magic&gt;   <font color="#0000FF">&lt;glob  <font color="#009900">pattern  <font color="#990000"> =  <font color="#FF0000">"*.foo"   <font color="#0000FF">/&gt;   <font color="#0000FF">&lt;/mime-type&gt;   <font color="#0000FF">&lt;/mime-info&gt;  </tt>

This entry maps one extension and a ``magic string to the ``application/x-example MIME type.

N.B. The glob pattern should be given in lowercase.

= What is OSSO category =

The platform has a notion of file categories for the user's data files. The available categories are:


 * Bookmarks
 * Contacts
 * Documents
 * Emails
 * Images
 * Audio
 * Video
 * Other

A mapping is set up between categories and MIME types, so that the MIME type of a file determines its category. The MIME type setup is handled by the shared-mime-info infrastructure, and the category information is added to that same framework.

Adding a mapping between a category and a number of MIME types is performed much like adding or editing the supported MIME types in the system.

Each application or library that adds a category mapping should add a file in

/usr/share/mime/packages/

The file format is the same XML format used for MIME types, with an added tag `` 8.7.3 Updating platform databases

To introduce the newly defined MIME type(s) to the platform, do the following:

[sbox-FREMANTLE_X86: ~] &gt; cp example-mime.xml /usr/share/mime/packages
 * 1) Copy the mime-information XML under /usr/share/mime/packages:

[sbox-FREMANTLE_X86: ~] &gt; update-mime-database /usr/share/mime [sbox-FREMANTLE_X86: ~] &gt; update-desktop-database /usr/share/applications
 * 1) Update the MIME and desktop database:

[sbox-FREMANTLE_X86: ~] &gt; hildon-update-category-database /usr/share/mime
 * 1) Update the OSSO category database:

To remove the MIME from the platform, delete the XML file in /usr/share/mime/packages/ and update the databases as above.

= Registering MIME type with package =

Because most of the applications are installed on the platform via pre-compiled packages, the MIME type registration has to be performed as well.

The steps are similar to the ones shown above.

To install the MIME information XML under /usr/share/mime/packages, edit the package rules and install the files. In this case it looks as follows:

<tt>mkdir -p <font color="#009900">$(CURDIR) /debian/tmp/usr/share/mime/packages cp <font color="#009900">$(CURDIR) /example-mime <font color="#990000">. xml <font color="#009900">$(CURDIR) /debian/tmp/usr/share/mime/packages</tt> <tt>usr/share/mime/packages/example-mime <font color="#990000">. xml</tt>
 * in the rules file under install section, add the following lines:
 * and in .install we need to add

This way, it can be assured that the mime information XML is being installed under /usr/share/mime/packages.

Add the following lines to both the postinst and postrm files of the package:

<tt>  <font color="#0000FF">if  <font color="#990000">[ -x /usr/bin/update-mime-database <font color="#990000">];   <font color="#0000FF">then  update-mime-database /usr/share/mime  <font color="#0000FF">fi   <font color="#0000FF">if  <font color="#990000">[ -x /usr/bin/update-desktop-database <font color="#990000">];   <font color="#0000FF">then  update-desktop-database /usr/share/applications  <font color="#0000FF">fi   <font color="#0000FF">if  <font color="#990000">[ -x /usr/bin/hildon-update-category-database <font color="#990000">];   <font color="#0000FF">then  hildon-update-category-database /usr/share/mime  <font color="#0000FF">fi  </tt>

This keeps the platform mime information and OSSO category databases up-to-date.