Installing (and programming) a new thumbnailer for Gnome.

What it is:

a thumbnail is the little image that Nautilus (the file manager of
Gnome) shows to represent the file. Most of file types has a standard
thumbnailer, and you see a representation of the file such as a little
image or a preview of the contents. This is quite useful, but less
common filetypes do not have a preview, you just see a standard icon,
the same for all of them. 

I will explain how to add a thumbnailer for a new or unsupported file
type. In that case we will add a script to prepare the preview of Xfig
files (.fig). 

How it works: 

When trying to prepare the preview, I deduced that Nautilus do the
following: 

First step: it tries to find a preview computed before. To do this, it
generate a hash for the file and looks into the directories under your
$HOME/.thumbnails. If it find it, or find an entry that said the
generation of the thumbnail failed before, it use it (or a defualt
icon) and stop searching. That means that, if you want to change the
thumbnail generation and see the effects, you have to delete this
"cache" under $HOME/.thumbnails. 

Second step: if the type of the file is known, it generates (and
saves) the preview. To see which is the type of a file, run 

xdg-mime query filetype <file>. 

For example: 

% xdg-mime query filetype xfig-thumbnailer.tar.gz
application/x-compressed-tar

Third step: if all this fail, it needs to generate an image; now there are
difference between gnome 2 and 3. 

In gnome2, it searches the "registry" (gconf
database) for a couple of  entries called after the type; for example: 

/desktop/gnome/thumbnailers/application@x-compressed-tar/command 
/desktop/gnome/thumbnailers/application@x-compressed-tar/enable

with a @ char in the place of the "/". If "enable" is true, it then
call the command to generate the thumbnail. "command" is in the form

my_thumbnailer -s %s %u %o

and %s is substituted for the vertical size of the preview image, %u
for the URL of the file (if it's a local file, in the form of
file:///path/to/file), and %o the output file where the preview (in
PNG format) has to be stored. 

In gnome 3, gconf is deprecated, so it search for a file in
/usr/share/thumbnailers with a structure like that: 

****
[Thumbnailer Entry]
Exec=/usr/bin/xfig-thumb -s %s %i %o
MimeType=image/x-xfig;
*****

and use the "Exec" line to generate (with the same rules as in gnome2) the
image. 


The practical case: adding a thumbnailer for Xfig files. 

Acknowlegment: this mostly extracted from 
http://quirkygba.blogspot.com/2009/11/nds-thumbnail-preview-in-nautilus.html

In the <package> file, you have all you need to add the thumbnails for
your xfig file. Move it in a directory and uncompress it. You will see
4 files:

xfig-thumb-setup.sh : this script moves the script to your $HOME/bin
directory and enables the gconf entry that will run it. 

xfig-thumb-remove.sh: this script undoes what the previous did. Run it
if you want to get rid of the thumbnailer.

The two above mentioned commands, in Gnome3, need superuser credentials, so
you have to run them as: 

    sudo ./xfig-thumb-setup.sh 
    sudo ./xfig-thumb-remove.sh

xfig-thumb: this is the script that create the thumbnailer. It will
need that you have xfig, fig2dev and imagemagick packages installed,
otherwise it will fail (and you can see error messages in your
$HOME/.xsession-errors file). 

If you look at it, you will see that it creates a temporary file
(there are some nice tricks there to safely delete it afterward),
generate a PNG version of the file and then resizes it to the requested
dimension and adds a little watermark text. 

Enjoy!



