edelib  2.1.0
Public Member Functions | List of all members
MimeType Class Reference

Mime handling class. More...

#include <edelib/MimeType.h>

Public Member Functions

 MimeType ()
 
 ~MimeType ()
 
bool set (const char *filename)
 
const Stringtype (void) const
 
const Stringcomment (void)
 
bool subclass_of (const char *mime)
 
const Stringicon_name (void)
 

Detailed Description

Mime handling class.

MimeType will handle file types according to specification at http://www.freedesktop.org. This class depends on shared-mime-info package, usually shipped with todays distributions.

It will try to recognize given file looking into $XDG_DATA_DIRS/mime/magic database, consulting $XDG_DATA_DIRS/mime/aliases for potential type * aliasing.

Returned values from type() will be in the form context/file-type, so, for example, for given file foo.tar.gz will be application/x-compressed-tar or for baz.jpg will be image/jpeg.

If file could not be recognized, returned string will be application/octet-stream.

comment() will return full description for recognized file, looking inside $XDG_DATA_DIRS/mime/context/file-type.xml file. This description can be plain english (default) or localized (not implemented yet).

Todo:

add locale during read of comments

Last change in xdgmime.c moved stat-ed code to be executed first so ambiguous directory names (like ".kde" or ".emacs.d" or ".e") doesn't be recognized as files or unknown types; can stat's be delayed?

Constructor & Destructor Documentation

MimeType ( )

Empty constructor

~MimeType ( )

Cleans internal data

Member Function Documentation

const String& comment ( void  )

Lookup for description described at the beggining of this document. If file with description does not exists, it will return empty string.

const String& icon_name ( void  )

Try to guess the name of possible icon (the name can be used for edelib::IconLoader and edelib::IconTheme). Generally the icon used for a mimetype is created based on the mime-type by mapping "/" characters to "-", but it can overriden by writing entry in icons file. This file will be searched in user_data_dir() and system_data_dirs() directories.

icons file looks like:

* # this is comment
* text/plain:icon-name
* application/octet-stream:another-icon
*
* # this is bad and will not be read
* application/octet-stream : icon
*
Note
This rule does not applies for node/xxx (where xxx is folder,socket,fifo, etc.). According to the icon naming specs, icon names should be file,socket,folder,...
For folders icon name will be folder due compatibility with icon naming standard.

If set() failed, it will return empty string.

bool set ( const char *  filename)

Set path to the file for inspection. If file does not exists or is unreadable, it will return false.

Returns
true if manage to access file, otherwise false
Parameters
filenameis full path to file
bool subclass_of ( const char *  mime)

Returns true if current mime type is subclass of given parameter name.

const String& type ( void  ) const

Return context/file-type form for file, given with set(). If set() failed, it will return empty string.


The documentation for this class was generated from the following file: