Qt4 “Freedesktop” MIME Type

August 11, 2008 Matteo Bertozzi | Filed Under Qt4 | No Comments

A couple of weeks ago, i’ve released at Qt Apps a Qt Component called QFreeDesktopMime that is a simple class for determining the MIME type of files using FreeDesktop Specification.

How to use this class? it’s really simple.

Example 1: Get Information about specified MIME Type

QFreeDesktopMime mime;
QString description = mime.description("application/epub+zip");
QString expandedAcronym = mime.expandedAcronym("text/x-xslfo");
QString acronym = mime.acronym("text/x-xslfo");

Example 2: Extract MIME Type and information from File Name (Results based on File Extension)

QFreeDesktopMime mime;
QString mimeType = mime.fromFileName("test.png");
QString mimeDescription = mime.description();

Example 3: Extract MIME Type and information from File (Data)

QFreeDesktopMime mime;
QString mimeType = mime.fromFile("/home/oz/myUnknownFile");
QString mimeDescription = mime.description();

If fromFile() method doesn’t find the matching data it tries to use fromFileName() method to get the MIME Type. In all cases if file’s MIME Type wasn’t found it returns an empty QString.

No Comments yet »

RSS feed for comments on this post. TrackBack URI

Leave a comment

XHTML: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>