PDA

View Full Version : MIME database and QMimedata



nupul
10th April 2006, 08:09
Most linux installations have a mime database to determine which app to use to open a particular type of file.

Now, does Qt have a provision to query this database? (honestly i don't know the path of this database...:p) Or can qt decipher all MIME types as set by freedesktop's mime-specs?

Can QMimeData be used for the above purpose?

Reason for use: I am displaying the contents of a folder in my widget...I want the user to be able to launch the corresponding app from my widget itself...you are free to suggest an alternative method....

Thanks

Nupul

wysota
10th April 2006, 08:54
Most linux installations have a mime database to determine which app to use to open a particular type of file.

Now, does Qt have a provision to query this database?
No.


Or can qt decipher all MIME types as set by freedesktop's mime-specs?
Sure, as it can read a file, you can implement a parser for it.


Can QMimeData be used for the above purpose?
No.


Reason for use: I am displaying the contents of a folder in my widget...I want the user to be able to launch the corresponding app from my widget itself...you are free to suggest an alternative method....
Well... Look at KDE sources (again) :) The database is in few separate places... ~/.local/share/mime, /usr/share/mime and /usr/share/mimelnk being good places to start looking.

nupul
10th April 2006, 09:06
Sure, as it can read a file, you can implement a parser for it.


can you exemplify this on a file say myfile.pdf?



Well... Look at KDE sources (again) :) The database is in few separate places... ~/.local/share/mime, /usr/share/mime and /usr/share/mimelnk being good places to start looking.


I've been practically exhausting myself referring the sources....rather than directing me to the sources directly (a hectic task in it's own right :eek: ) you could perhaps offer me a way to implement the above "reason"

thanks

wysota
10th April 2006, 09:17
can you exemplify this on a file say myfile.pdf?

I'm sorry, I'll redirect you again :) If you have Apache server installed, take a look at conf/magic file which resides in its configuration directory (/etc/httpd/ on my system). It contains information how to discover mime types based on file contents.



I've been practically exhausting myself referring the sources....rather than directing me to the sources directly (a hectic task in it's own right :eek: ) you could perhaps offer me a way to implement the above "reason"

You know, generally I'm against reinventing wheels, that's why I redirect you to sources which already implement the thing you need. This is the beauty of Open Source -- you can reuse some code you didn't even write.

How much would be an academic project worth if someone tells you how to do everything? You have to learn using tools (in this case "Open Source" being a tool too) and making architectural decisions. And this is one of them. The easiest way is to judge a file by its extension. It's an awful one, but works in many cases. It is your choice if you want to use your time on mime recognition or something which you think is more important.

BTW. With PDF files it is fairly easy -- all PDF documents begin with a "%PDF-" string.

nupul
10th April 2006, 09:31
I'm sorry, I'll redirect you again. If you have Apache server installed, take a look at conf/magic file which resides in its configuration directory (/etc/httpd/ on my system). It contains information how to discover mime types based on file contents.


Thanks for this...I'll look it up...it's at another site...8 computers away :D



You know, generally I'm against reinventing wheels, that's why I redirect you to sources which already implement the thing you need. This is the beauty of Open Source -- you can reuse some code you didn't even write.


To tell you the truth...i too am against it...and i don't feel a wee bit bad when you direct me to the sources...am actually glad that someone reimburses what i do :)



How much would be an academic project worth if someone tells you how to do everything?


Worthless!!! ( I am not asking for everything :rolleyes:)



You have to learn using tools (in this case "Open Source" being a tool too) and making architectural decisions. And this is one of them. The easiest way is to judge a file by its extension. It's an awful one, but works in many cases. It is your choice if you want to use your time on mime recognition or something which you think is more important.


Trust me, I use them to their fullest potential!. The reason to be more keen on MIME is :

1. to know and understand how the underlying system does it
2. freedesktop specs suggest it
3. I thought I can adapt it to my project

I have been sifting through the KDE source for some hints regarding this, but still in vain. I did think about the extension mapping....but it's an exhaustive task!! That's why I'd prefer to use MIME....it's takes care of most of the problems.



BTW. With PDF files it is fairly easy -- all PDF documents begin with a "%PDF-" string.

I was expecting this answer ;)

nupul
10th April 2006, 09:34
If any of you are willing please visit the following website:

http://freedesktop.org/wiki/Standards_2fshared_2dmime_2dinfo_2dspec

under that there is a section of "Current Implementors" which actually query the mime-database and find that apt app for the file...the problem being...i just don't/can't run ANY of them!!! :crying:

Nupul

wysota
10th April 2006, 09:49
I have been sifting through the KDE source for some hints regarding this, but still in vain. I did think about the extension mapping....but it's an exhaustive task!! That's why I'd prefer to use MIME....it's takes care of most of the problems.

Again apache, /etc/httpd/conf/mime.types this time.

BTW. mime-magic is also present in /etc/mime-magic.

nupul
10th April 2006, 11:59
well wysota, if possible...do me a favour....pls visit the link in my prev reply, and see if you can figure out how to make it work

Thanks

Nupul

wysota
10th April 2006, 13:43
I was there. xdgmime should be easy to use. Did you try it?

nupul
12th April 2006, 05:50
I just couldn't figure out how to use it....as the link to me to an ftp site...just listing the source files....I even downloaded the libsharedmime... but it just installed a lib and no where is it mentioned how to query it!!! maybe you could help ;)

Thanks nupul

wysota
12th April 2006, 11:47
xdgmime looks better. There is an example in its sources how to use it. It should be enough to include its files directly into your project.

Funklord
12th April 2006, 12:38
I use the file command to determine file types, it has a huge database.

Usage: file [OPTION]... [FILE]...

Pardon me, I don't know which package installs this binary, it is very useful nevertheless.
You probably already have it.

wysota
12th April 2006, 14:36
The problem with file is that it returns a non-uniform and non-parsable data. Its output is readable for a human but not for a computer.

EDIT: I see it has a -i option which outputs mime-type instead of human readable strings. That's more interesting.