#!/bin/sh

#C- This program is free software; you can redistribute it and/or
#C- modify it under the terms of the GNU General Public License,
#C- either Version 2 of the License or (at your option) any later
#C- version.  The license should have accompanied the program 
#C- or you may obtain a copy of the license from the Free Software
#C- Foundation at http://www.fsf.org.
#C-
#C- This program is distributed in the hope that it will be useful,
#C- but WITHOUT ANY WARRANTY; without even the implied warranty of
#C- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
#C- GNU General Public License for more details.
#C-
#C- $Id: register-djvu-mime.in,v 1.9 2008/02/21 20:08:20 leonb Exp $


xdg_mime=
xdg_icon_resource=
xdg_desktop_menu=
datadir=/usr/local/share
mydir=/usr/local/share/djvu/osi/desktop

# test directory
if test -d "$mydir" 
then
  cd $mydir
else
  echo 1>&2 "Unable to find directory ${mydir}"
  exit 10
fi


# check presence of xdg utils
test -n "$xdg_mime" || xdg_mime=`which xdg-mime`
test -n "$xdg_icon_resource" || xdg_icon_resource=`which xdg-icon-resource`
test -n "$xdg_desktop_menu" || xdg_desktop_menu=`which xdg-desktop-menu`

if test -x "$xdg_mime" &&
   test -x "$xdg_icon_resource" &&
   test -x "$xdg_desktop_menu" 
then
   true
else
   echo 1>&2 "Unable to find the Xdg Portland utils"
   echo 1>&2 " These are needed to run $0".
   echo 1>&2 " Please check http://portland.freedesktop.org."
   exit 10
fi

if test -n "$XDG_DATA_DIRS" ; then
    XDG_DATA_DIRS="$datadir:$XDG_DATA_DIRS"
else
    XDG_DATA_DIRS="$datadir:/usr/local/share:/usr/share"
fi
export XDG_DATA_DIRS

# proceed
case "$1" in
install)
   "$xdg_icon_resource" install --noupdate --context mimetypes \
       --size 22 ./hi22-djvu.png image-vnd.djvu
   "$xdg_icon_resource" install --noupdate --context mimetypes \
       --size 32 ./hi32-djvu.png image-vnd.djvu
   "$xdg_icon_resource" install --noupdate --context mimetypes \
       --size 48 ./hi48-djvu.png image-vnd.djvu
   "$xdg_icon_resource" forceupdate
   ## This is disabled to avoid conflicting with the
   ## djvu information provided by freedesktop.org
   ## "$xdg_mime" install ./djvulibre-mime.xml
   ;;
uninstall)
   "$xdg_icon_resource" uninstall --noupdate --context mimetypes \
       --size 22 image-vnd.djvu
   "$xdg_icon_resource" uninstall --noupdate --context mimetypes \
       --size 32 image-vnd.djvu
   "$xdg_icon_resource" uninstall --noupdate --context mimetypes \
       --size 48 image-vnd.djvu
   "$xdg_icon_resource" forceupdate
   ## This is disabled to avoid conflicting with the
   ## djvu information provided by freedesktop.org
   ## "$xdg_mime" uninstall ./djvulibre-mime.xml
   ;;
*)
   echo 1>&2 "Usage: $0 {install|uninstall}"
   exit 10
   ;;
esac
