#942011 xdg-utils should be smarter when selecting from multiple .desktop files for a mime-type

#942011#5
Date:
2019-10-09 01:39:11 UTC
From:
To:
different apps install .desktop files that contain a MimeType entry
that includes the same mime-types.

for example:

0 dkg@alice:~$ grep -l '^MimeType=.*application/pdf' /usr/share/applications/*.desktop
/usr/share/applications/gimp.desktop
/usr/share/applications/libreoffice-draw.desktop
/usr/share/applications/mupdf.desktop
/usr/share/applications/okularApplication_pdf.desktop
/usr/share/applications/org.gnome.Evince.desktop
/usr/share/applications/org.inkscape.Inkscape.desktop
/usr/share/applications/pdf-presenter-console.desktop
0 dkg@alice:~$

Since all of these applications *can* handle a pdf file, they are all
right in doing so (i believe it makes it possible for drag-and-drop to
target an icon derived from the .desktop file based on the mime-type
of the dragged object, for example).

Then, /usr/bin/update-desktop-database (from desktop-file-utils)
gathers all these together and makes a list of them in
/usr/share/applications/mimeinfo.cache.  When it does so, it sorts
them ASCIIbetically (for lack of any better sorting technique):

https://sources.debian.org/src/desktop-file-utils/0.24-1/src/update-desktop-database.c/?hl=43#L310

Then, xdg-open reads this file and picks the first one.

This means that on my system, "xdg-open foo.pdf" will launch
/usr/bin/gimp.

That's clearly the wrong choice.

Presumably, on a desktop system like mine, a sensible priority is
something like:

  * evince or ocular (dedicated, full-fledged pdf viewer apps)
  * pdf-presenter-console or mupdf (specialized custom pdf renderers)
  * libreoffice-draw or inkscape or gimp (apps capable of editing single pages of a pdf)

The current default (having "xdg-open foo.pdf" launch gimp) is just
not credible or user-friendly (as evident in the now decade-old and
resolved https://bugs.debian.org/525077.  It also affects new projects
like xapers, which delegates opening of pdfs to xdg-open.

I don't know where else these priorities should live if not in
xdg-utils.  In the absence of some more sensible distributed priority
system, i think xdg-utils needs to step up and maintain these
mappings.

This doesn't sound like a fun task, but it's looks like the only way
for xdg-open to do a sensible thing by default, which is presumably
what it is supposed to do.

Thanks for maintaining xdg-utils in debian!