Mime type to icon script

David Faure dfaure at trolltech.com
Tue Jul 1 04:37:29 PDT 2008


On Monday 19 May 2008, Josh wrote:
> I recently ran into a problem while doing some Qt programming.  The current
> implementation of Qt4's QFileIconProvider does not provide a Linux user with
> icons from their preferred theme.
> 
> I started looking into a way to provide a filetype's icon from its extension. 
> I found out about /etc/mime.types and wrote a cross-DE script.  While writing
> and testing the script I stumbled across the icon theme specification and
> modified my script accordingly.
> 
> The script does not follow the icon lookup pseudo code line for line but does
> not stray from the core ideas.  There are some additions for providing what Qt
> calls standard pixmaps (eg. hd, folder, network, cd drive icons).
> 
> I am looking to get more eyes on this script for improvements.  Possibly this
> script could be included as an xdg utility?  If this is not a an option I plan
> to submit a task tracker report to Trolltech and send a copy of the script. 
> Although I will wait until I get some feedback.

A note: with KDE-4.1 you can also simply do

mime=`kmimetypefinder $1 | head -n 1`
kiconfinder `echo $mime | sed -e 's,/,-,g'`

Example:
mime=`kmimetypefinder freedesktop.org.xml | head -n 1`
kiconfinder `echo $mime | sed -e 's,/,-,g'`
--> /opt/kde4/share/icons/oxygen/48x48/mimetypes/application-xml.png

This has no support for <icon> and <generic-icon> though, but I think your script doesn't either :)

-- 
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 xdg mailing list