Results 1 to 13 of 13

Thread: MIME database and QMimedata

  1. #1
    Join Date
    Mar 2006
    Posts
    172
    Thanks
    30
    Thanked 2 Times in 2 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Lightbulb MIME database and QMimedata

    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...) 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
    Last edited by nupul; 10th April 2006 at 08:27. Reason: "reason for use" not specified!

  2. #2
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: MIME database and QMimedata

    Quote Originally Posted by nupul
    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.

  3. #3
    Join Date
    Mar 2006
    Posts
    172
    Thanks
    30
    Thanked 2 Times in 2 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Red face Re: MIME database and QMimedata

    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 ) you could perhaps offer me a way to implement the above "reason"

    thanks

  4. #4
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: MIME database and QMimedata

    Quote Originally Posted by nupul
    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 ) 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.

  5. #5
    Join Date
    Mar 2006
    Posts
    172
    Thanks
    30
    Thanked 2 Times in 2 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Exclamation Re: MIME database and QMimedata

    Quote Originally Posted by wysota
    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

    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 )

    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

  6. #6
    Join Date
    Mar 2006
    Posts
    172
    Thanks
    30
    Thanked 2 Times in 2 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Post Re: MIME database and QMimedata

    If any of you are willing please visit the following website:

    http://freedesktop.org/wiki/Standard..._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!!!

    Nupul

  7. #7
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: MIME database and QMimedata

    Quote Originally Posted by nupul
    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.

  8. #8
    Join Date
    Mar 2006
    Posts
    172
    Thanks
    30
    Thanked 2 Times in 2 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Arrow Re: MIME database and QMimedata

    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

  9. #9
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: MIME database and QMimedata

    I was there. xdgmime should be easy to use. Did you try it?

  10. #10
    Join Date
    Mar 2006
    Posts
    172
    Thanks
    30
    Thanked 2 Times in 2 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Unhappy Re: MIME database and QMimedata

    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

  11. #11
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: MIME database and QMimedata

    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.

  12. #12
    Join Date
    Feb 2006
    Location
    Stockholm
    Posts
    5
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: MIME database and QMimedata

    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.

  13. #13
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: MIME database and QMimedata

    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.

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.