#!/bin/bash
# This script is called by ACEDB Pick_me_to_call records.
# It chooses a viewer, depending on the file extension.
# Mime might be the 'right' way to do this, but it's
# immensly easier to just write a short script, and probably
# more reliable.

# In most cases the file extension tells us what to do with
# the file. However, we also want to be able to correctly handle
# a URL, so URL tells us if $1 is a URL, rather than a local
# file name. 
echo 'chooseviewer: Filename: '$1

EXT=${1##*.}

URLFLAG=`echo $1 | egrep -e '^http:|^https:|^ftp:|^ftps:'`
if [ ! -z "$URLFLAG" ]
   then
   EXT="html"
fi

case $EXT in

  # -------- Web pages
  "html" | "shtml" | "HTML" | "htm" | "HTM")
        browser.csh $1 &
    ;;

  # -------- PDF, PostScript
  "pdf" | "PDF" )
        acePDFviewer $1 &
    ;;  
  "ps" | "PS" )
        acePSviewer $1 &
    ;;  

  # -------- Spreadsheet
  "xls" | "XLS" | "ods" | "sxc" | "csv" | "tsv" | "CSV" | "dif" | "DBF")
        acespreadsheet $1 &
    ;;


  # -------- Bitmap graphics
  "GIF")
    aceviewer $1 &
    ;;  
  "gif")
    aceviewer $1 &
    ;;  
  "JPG")
    aceviewer $1 &
    ;;  
  "jpg")
    aceviewer $1 &
    ;;  
  "JPEG")
    aceviewer $1 &
    ;;  
  "jpeg")
    aceviewer $1 &
    ;;  
  "PNG")
    aceviewer $1 &
    ;;  
  "png")
    aceviewer $1 &
    ;;  
  "BMP")
    aceviewer $1 &
    ;;  
  "bmp")
    aceviewer $1 &
    ;;  
  "TIF")
    aceviewer $1 &
    ;;  
  "tif")
    aceviewer $1 &
    ;;    
  "TIFF")
    aceviewer $1 &
    ;;  
  "tiff")
    aceviewer $1 &
    ;; 
       
  # -------- Default is text editor
  *) 
    acetextedit $1 &
    ;;
esac