[CentOS] kghostview and xdg-open. Need to fix problem across whole system

Thu May 7 16:20:22 UTC 2009
Paul Johnson <pauljohn32 at gmail.com>

On Wed, May 6, 2009 at 11:49 AM, Rex Dieter <rdieter at math.unl.edu> wrote:
> Paul Johnson wrote:
>
>> In Centos 5.3, a bad problem has surfaced in user land. We want to use
>> either Evince or Adobe acroread as the pdf view, but the update of
>> kdegraphics has somehow screwed up these systems so that the odious,
>> horrible, awful pdf viewer kghostview is used.
>
> It's most likely Acrobat Reader that f#$#$#d up here.  It mucks with system
> copies of mimetypes, etc...
>
> My guess is that kdegraphics update simply replaced the muck'd system copies
> with known good ones.
>
> Now, opening pdf's from where is causing problems?  Say, opening in
> nautilus, a webbrowser, what?
>
> -- Rex
>

Same result in opening pdf from nautilus or LyX (via pdflatex).
kghostview refuses to open the pdf file, saying its type is
application/octet-stream. evince or acroread can open same without
trouble. I have not bothered with this because I'm not using kde
anymore, but the kdegraphics update with Centos-5.3 caused this by
installing the program and re-configuring (explanation next).

I've tracked down the problem, though, so I can stop kghostview from
being invoked.

When RPMS install, they often have a post script call to execute
"update-desktop-database" which scans the desktop files under
/usr/share/applications and it builds
/usr/share/applications/mimeinfo.cache.

To my surprise/astonishment, the update-desktop-database function is
completely undocumented, not even a man page or a mention in the
README file from the xdg group that provides it.  To my even greater
surprise, there is apparently no way to predict which programs will be
at the front of the list for each mime type.  The mimeinfo.cache is
used by programs like nautilus to know what programs are available.
update-desktop-database, for reasons I don't know, places ghostview
first among pdf opener programs.

More and more programs are relying on the "xdg-open" script to select
viewers for files. xdg-open ends up scanning for the desktop framework
in use, in my case Gnome, and then it passes off the pdf file to the
program gnome-open, which is supposed to check for "defaults.list" in
the user's config and in the system at /usr/share/applications.  The
mimeinfo.cache file is not supposed to be dominant setting here
because the preferred viewer is supposed to be specified in
defaults.list.  We have AdobeReader.desktop specified there.

However, when the config in defaults.list is broken, then xdg-open
(hence gnome-open) don't know what to do, and they consult
mimeinfo.cache and they take the first program listed.

Our config was broken because Adobe was installed incorrectly.
The RPM that installed AdobeReader did not copy AdobeReader.desktop
into /usr/share/applications.  As a result, when the user tries to
configure "xdg-open" (via xdg-mime) or use "gnome-open", both try to
use AdobeReader.desktop, and fail, and then they fall back to use the
things in /usr/share/applications/mimeinfo.cache. One can just copy
AdobeReader.desktop from /opt/Adobe/... into /usr/share/applications
to fix this. To be fancier, one can run "

To protect my systems from ever using kghostview, I ended up deleting
the Mime line in all of the relevant desktop files in
/usr/share/applicaitons/kde.  After that, "update-desktop-database"
can be called and kghostview is never listed as a pdf opener.


-- 
Paul E. Johnson
Professor, Political Science
1541 Lilac Lane, Room 504
University of Kansas