KDE's MIME magic (KMimeMagic) database (format)

David Faure faure at kde.org
Sun Feb 18 19:52:24 GMT 2007


On Saturday 17 February 2007, Daniel Leidert wrote:
> For KDE 3 (4 will hopefully support the shared-mime-info db) 
Yes, it will, I'm working on this as we speak ;)

> I already implemented to 
> output .desktop files for every (supported) MIME type. Now I wanted to
> extend the magic database (mimelnk/magic) to solve possible conflicts
> (e.g. chemical/x-daxlight-smiles and application/smil use the same file
> extension, ditto for e.g. chemical/x-pdb and application/vnd.palm). 
You know that in KDE 3, extensions are always considered first, right?
So this will only work if both conflicting mimetypes don't have Patterns=,
or if they have X-KDE-PatternsAccuracy=50 (any number < 100).
Feel free to submit a patch for kdelibs/mimetypes which adds the latter to all
the mimetypes with "not so deterministic extensions".

> So I 
> wrote a stylesheet, that produces an output, usable as file(1)'s
> magic.mime database (works perfectly for `file -i'). From what I read I
> thought, that the KMimeMagic uses the same format. But that seems to be
> wrong. I can make konqueror crash with such a magic-database. I get the
> following errors on command line (just a few of them):
> 
> kio (KMimeMagic): ERROR: parse: type search/76  NOTE    chemical/x-cmtx invalid

Well, KMimeMagic is based upon an old version of file(1). That version didn't have support
for "search/". I never saw that before; it's for searching from a given offset instead of expecting
data at that offset? Interesting; especially since xdg mime doesn't support that, does it?
(I haven't looked into the "magic" part of xdg mime yet).

> So what is supported in the KMimeMagic database format compared to
> file's magic(.mime) database? 
string, but not search.

> I've attached the current database to this 
> mail, so that you can have a look at your own for the used syntax. To
> test, I simply copied it to ~/.kde/share/mimelnk.
You can put it under <prefix or kdehome>/share/config/magic/chemical.magic (filename doesn't matter, extension does), instead.
This is how to install kmimemagic snippets.

> And a second problem: What is 'X-KDE-IsAlso' compared to the
> shared-mime-info database format? From what I read, I think it's similar
> to <sub-class-of type="..."/>. 
Yes.

> But how do you handle aliases then?
The same way. Choose which one is the "canonical" type, and declare the other type
as a subclass (X-KDE-IsAlso) of it.
I know, this isn't really like aliases - if an application declares that it supports only the 
subclass/alias then it won't be launched for a file that has the canonical type.
This is why we use the chosen canonical type in all application desktop files,
and the alias is really only for the case where the 'wrong mimetype name' is being found,
e.g. as returned by apache.

> CCing the freedesktop.org xdg-list
CC removed since this discussion is mostly about the kde-specific stuff ;)

-- 
David Faure, faure at kde.org, sponsored by Trolltech to work on KDE,
Konqueror (http://www.konqueror.org), and KOffice (http://www.koffice.org).




More information about the kde-core-devel mailing list