Default Program | File Association
Alexander Larsson
alexl at redhat.com
Fri Jan 25 01:32:28 PST 2008
On Wed, 2008-01-23 at 10:13 +0000, David Faure wrote:
> Here's how it worked in KDE3:
> If I add the application gwenview to the mimetype image/svg+xml, then kde3 will
> copy /usr/share/applications/kde/gwenview.desktop into
> ~/.local/share/applications/kde-gwenview.desktop and add the new mimetype to
> the MimeType key.
> In a sense this works well, because it only uses the existing specifications...
> except the small detail that kde/gwenview.desktop is associated with the name
> kde-gwenview.desktop internally so the local file hide the global one (on
> purpose, we don't want both to show up in menus).
Let me explain how this works in gnome (this is how gio does it, but
gnome-vfs is similar):
The apps files list the mime types they support in their desktop files,
this info is extractted out into a "mimeinfo.cache" file in each
directory with desktop files listing for each mimetype a list of desktop
files. The order of the lists in this file is to my knowledge
essentially random.
In each directory with desktop files we also have a "defaults.list" file
which is similar to the mimeinfo.cache file. It lists for each mimetype
the default apps to use for it as a list of desktop file names that are
to be looked up in the order specified (as some might not exist, or be
marked as ignored for one particular desktop or in general). This file
looks something like:
[Default Applications]
application/x-dia-diagram=fedora-dia.desktop
application/x-bzip=gnome-file-roller.desktop
image/jpeg=gnome-eog.desktop;gthumb.desktop;
...
Now, the way we pick the default for a mimetype is (in pseudo code):
for each $mimetype in [mimetype, mimetype parent, grandparent,...]:
for each $dir with desktop files (from XDG_DATA_DIRS etc):
lookup $desktopids by $mimetype in $dir/defaults.list
for each $desktopid in $desktopids:
if $desktopid exists and is not ignored:
return $desktopid
for each $dir with desktop files (from XDG_DATA_DIRS etc):
lookup $desktopids by $mimetype in $dir/mimetype.cache
for each $desktopid in $desktopids:
if $desktopid exists and is not ignored:
return $desktopid
I.E. we first look up from defaults.list in all dirs, then from
mimetype.cache in all dirs and we return the first that exists
and is not hidden. If none are found we then start over with the parent
mimetype.
For the "open with" menu functionallity we do the same, only we don't
stop at the first desktop file that works, but list all the hits.
To change the default app for a mimetype, all we have to do is update
~/.local/share/applications/defaults.list, adding the desktop id at the
front of the list for the mimetype (and deleting any previous mention of
it in the rest of the list.
To add support for a new mimetype to a desktop file we at the moment
make a copy of the desktop file in
~/.local/share/applications/defaults.list and add the new mimetype to
the MimeTypes line.
This way to add new mimetype has all the problems you mentioned with
updates to the original desktop file. One possible solution would be to
instead add the desktop id to the end of the list in the defaults.list
file. Then it would show up in the open with menu, but only for desktops
that look at the defaults.list file...
More information about the xdg
mailing list