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

Daniel Leidert daniel.leidert.spam at gmx.net
Sun Feb 18 20:50:07 GMT 2007


Am Sonntag, den 18.02.2007, 20:52 +0100 schrieb David Faure:
> 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 know :) I read your mail to xdg-list.

> > 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?

I did not.

> 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".

Ok. I will have this in mind. So both need to have this line or no
pattern, if I understand you.

> > 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?

Yes. It searches from a given offset in the given offset-range length.

> Interesting; especially since xdg mime doesn't support that, does it?

It supports. But it doesn't use the search type. Instead it allows to
give an offset range "x:y" in the offset attribute of the match element.
I used the search-type of file's magic.mime file syntax, because the
file syntax does not contain something like offset_start:offset_end. The
only thing, that fits this idea, is the search type.

> (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.

But also byte|short|long|leshort|lelong|beshort|belong?

> 
> > 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.

Ah. In Debian /etc/kde3/magic for system files. Many thanks. Didn't know
that. I always thought, you cannot extend the database. I should add
this information to the freedesktop.org Wiki, so it will not be lost :)

> > 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.

So, I should create .desktop files for the aliases too and simply add
the X-KDE-IsAlso there, without any pattern?

> 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.

Ok. Understood. This is, how it should work.

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

Agreed.

BTW, is there somewhere an official documentation of the X-KDE keys
in .desktop files? I mostly found discussion on this list, but no
complete documentation.

Thanks for the information you gave.
Regards, Daniel





More information about the kde-core-devel mailing list