edelib
2.0.0
|
Mime handling class. More...
#include <edelib/MimeType.h>
Public Member Functions | |
MimeType () | |
~MimeType () | |
bool | set (const char *filename) |
const String & | type (void) const |
const String & | comment (void) |
bool | subclass_of (const char *mime) |
const String & | icon_name (void) |
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).
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?
MimeType | ( | ) |
Empty constructor
~MimeType | ( | ) |
Cleans internal data
Lookup for description described at the beggining of this document. If file with description does not exists, it will return empty string.
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
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.
filename | is full path to file |
bool subclass_of | ( | const char * | mime | ) |
Returns true if current mime type is subclass of given parameter name.