Editing Documentation/Maemo 5 Developer Guide/Application Development/MIME type mapping
Warning: You are not logged in.
Your IP address will be recorded in this page's edit history.
The edit can be undone.
Please check the comparison below to verify that this is what you want to do, and then save the changes below to finish undoing the edit.
Latest revision | Your text | ||
Line 1: | Line 1: | ||
- | MIME types 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 [https://garage.maemo.org/svn/maemoexamples/trunk/maemo-examples/example_libosso.desktop example_libosso.desktop] file for the application looks like the following: | |
- | == | + | <code>[Desktop Entry] |
+ | Encoding=UTF-8 | ||
+ | Version=1.0 | ||
+ | Type=Application | ||
+ | Name=Example libOSSO | ||
+ | Exec=/usr/bin/example_libosso | ||
+ | X-Osso-Service=org.maemo.example_libosso | ||
+ | Icon=qgn_list_gene_default_app | ||
+ | MimeType=application/x-example;</code> | ||
- | 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 | + | <nowiki> The last line is the most important one, and specifies that this application can handle the MIME type ``application/x-example''. </nowiki> |
- | < | + | |
- | + | =New MIME type with OSSO category extension = | |
- | <mime-info xmlns="http://www.freedesktop.org/standards/shared-mime-info" | + | |
- | + | 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: | |
- | + | ||
- | + | <tt><span>'''<span><font color="#000080"><?xml</font></span>'''</span> <span><font color="#009900">version</font></span><span><font color="#990000"><nowiki>=</nowiki></font></span><span><font color="#FF0000">"1.0"</font></span> <span><font color="#009900">encoding</font></span><span><font color="#990000"><nowiki>=</nowiki></font></span><span><font color="#FF0000">"UTF-8"</font></span><span>'''<span><font color="#000080">?></font></span>'''</span> | |
- | + | <span>'''<span><font color="#0000FF"><mime-info</font></span>'''</span> <span><font color="#009900">xmlns</font></span><span><font color="#990000"><nowiki>=</nowiki></font></span><span><font color="#FF0000">"http://www.freedesktop.org/standards/shared-mime-info"</font></span> | |
- | + | <span><font color="#009900">xmlns:osso</font></span><span><font color="#990000"><nowiki>=</nowiki></font></span><span><font color="#FF0000">"http://nokia.com/osso/mime-categories"</font></span><span>'''<span><font color="#0000FF">></font></span>'''</span> | |
- | + | <span>'''<span><font color="#0000FF"><mime-type</font></span>'''</span> <span><font color="#009900">type</font></span><span><font color="#990000"><nowiki>=</nowiki></font></span><span><font color="#FF0000">"application/x-example"</font></span><span>'''<span><font color="#0000FF">></font></span>'''</span> | |
- | + | <span>'''<span><font color="#0000FF"><comment></font></span>'''</span>Example application file<span>'''<span><font color="#0000FF"></comment></font></span>'''</span> | |
- | + | <span>'''<span><font color="#0000FF"><osso:category</font></span>'''</span> <span><font color="#009900">name</font></span><span><font color="#990000"><nowiki>=</nowiki></font></span><span><font color="#FF0000">"images"</font></span><span>'''<span><font color="#0000FF">/></font></span>'''</span> | |
- | + | <span>'''<span><font color="#0000FF"><magic</font></span>'''</span> <span><font color="#009900">priority</font></span><span><font color="#990000"><nowiki>=</nowiki></font></span><span><font color="#FF0000">"50"</font></span><span>'''<span><font color="#0000FF">></font></span>'''</span> | |
- | </mime-info> | + | <span>'''<span><font color="#0000FF"><match</font></span>'''</span> <span><font color="#009900">type</font></span><span><font color="#990000"><nowiki>=</nowiki></font></span><span><font color="#FF0000">"string"</font></span> <span><font color="#009900">value</font></span><span><font color="#990000"><nowiki>=</nowiki></font></span><span><font color="#FF0000">"FOO"</font></span> <span><font color="#009900">offset</font></span><span><font color="#990000"><nowiki>=</nowiki></font></span><span><font color="#FF0000">"0"</font></span><span>'''<span><font color="#0000FF">/></font></span>'''</span> |
- | </ | + | <span>'''<span><font color="#0000FF"></magic></font></span>'''</span> |
- | This entry maps one extension and a | + | <span>'''<span><font color="#0000FF"><glob</font></span>'''</span> <span><font color="#009900">pattern</font></span><span><font color="#990000"><nowiki>=</nowiki></font></span><span><font color="#FF0000">"*.foo"</font></span><span>'''<span><font color="#0000FF">/></font></span>'''</span> |
+ | <span>'''<span><font color="#0000FF"></mime-type></font></span>'''</span> | ||
+ | <span>'''<span><font color="#0000FF"></mime-info></font></span>'''</span> | ||
+ | </tt> | ||
+ | |||
+ | <nowiki> This entry maps one extension and a ``magic'' string to the ``application/x-example'' MIME type. </nowiki> | ||
'''N.B.''' The glob pattern should be given in lowercase. | '''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: | The platform has a notion of file categories for the user's data files. The available categories are: | ||
Line 58: | Line 60: | ||
/usr/share/mime/packages/ | /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: | To introduce the newly defined MIME type(s) to the platform, do the following: | ||
- | + | # Copy the mime-information XML under /usr/share/mime/packages: | |
- | + | ||
- | Copy the mime-information XML under | + | [sbox-FREMANTLE_X86: ~] > cp example-mime.xml /usr/share/mime/packages |
- | + | ||
- | [sbox-FREMANTLE_X86: ~] | + | |
- | + | ||
- | + | ||
- | + | ||
- | + | ||
- | + | ||
- | + | ||
- | + | ||
- | + | ||
- | + | ||
- | + | ||
- | + | ||
- | + | ||
- | + | ||
- | + | ||
- | + | ||
- | + | ||
- | + | ||
- | + | # Update the MIME and desktop database: | |
+ | |||
+ | [sbox-FREMANTLE_X86: ~] > update-mime-database /usr/share/mime | ||
+ | [sbox-FREMANTLE_X86: ~] > update-desktop-database /usr/share/applications | ||
+ | |||
+ | # Update the OSSO category database: | ||
+ | |||
+ | [sbox-FREMANTLE_X86: ~] > hildon-update-category-database /usr/share/mime | ||
+ | |||
+ | |||
+ | 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. | Because most of the applications are installed on the platform via pre-compiled packages, the MIME type registration has to be performed as well. | ||
Line 93: | Line 87: | ||
The steps are similar to the ones shown above. | The steps are similar to the ones shown above. | ||
- | To install the MIME information XML under | + | 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: |
* in the '''rules''' file under install section, add the following lines: | * in the '''rules''' file under install section, add the following lines: | ||
- | mkdir -p $(CURDIR)/debian/tmp/usr/share/mime/packages | + | <tt>mkdir -p <span><font color="#009900">$(CURDIR)</font></span>/debian/tmp/usr/share/mime/packages |
- | cp $(CURDIR)/example-mime.xml $(CURDIR)/debian/tmp/usr/share/mime/packages | + | cp <span><font color="#009900">$(CURDIR)</font></span>/example-mime<span><font color="#990000">.</font></span>xml <span><font color="#009900">$(CURDIR)</font></span>/debian/tmp/usr/share/mime/packages</tt> |
- | * and in .install we need to add< | + | * and in .install we need to add |
+ | <tt>usr/share/mime/packages/example-mime<span><font color="#990000">.</font></span>xml</tt> | ||
- | This way, it can be assured that the mime information XML is being installed under | + | 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: | Add the following lines to both the postinst and postrm files of the package: | ||
- | |||
- | |||
- | |||
- | |||
- | |||
- | |||
- | |||
- | |||
- | |||
- | |||
- | |||
- | |||
- | == | + | <tt><span>'''<span><font color="#0000FF">if</font></span>'''</span> <span><font color="#990000">[</font></span> -x /usr/bin/update-mime-database <span><font color="#990000">];</font></span> <span>'''<span><font color="#0000FF">then</font></span>'''</span> |
+ | update-mime-database /usr/share/mime | ||
+ | <span>'''<span><font color="#0000FF">fi</font></span>'''</span> | ||
+ | <span>'''<span><font color="#0000FF">if</font></span>'''</span> <span><font color="#990000">[</font></span> -x /usr/bin/update-desktop-database <span><font color="#990000">];</font></span> <span>'''<span><font color="#0000FF">then</font></span>'''</span> | ||
+ | update-desktop-database /usr/share/applications | ||
+ | <span>'''<span><font color="#0000FF">fi</font></span>'''</span> | ||
+ | <span>'''<span><font color="#0000FF">if</font></span>'''</span> <span><font color="#990000">[</font></span> -x /usr/bin/hildon-update-category-database <span><font color="#990000">];</font></span> <span>'''<span><font color="#0000FF">then</font></span>'''</span> | ||
+ | hildon-update-category-database /usr/share/mime | ||
+ | <span>'''<span><font color="#0000FF">fi</font></span>'''</span></tt> | ||
- | + | This keeps the platform mime information and OSSO category databases up-to-date. | |
- | + | ||
- | This | + | |
- | + | ||
- | + | ||
- | + | ||
- | + | ||
- | + | ||
- | + | ||
- | + | ||
- | + | ||
- | + | ||
- | + | ||
- | + | ||
- | + | ||
- | + | ||
- | + | ||
- | + | ||
- | + | ||
- | + | ||
- | + | ||
- | + | ||
- | + | ||
- | + | ||
- | + | ||
- | + | ||
- | + | ||
- | + | ||
- | + | ||
- | + | ||
- | + | ||
- | + | ||
- | + | ||
- | + | ||
- | + | ||
- | + | ||
- | + | ||
- | + | ||
- | + | ||
- | + | ||
- | + | ||
- | + | ||
- | + | ||
- | + |
Learn more about Contributing to the wiki.