#
# Copyright (C) by Stefano Falsetto
# e-mail contact ....: mailto:stefko5@inwind.it
#
#    This program is free software; you can redistribute it and/or modify
#    it under the terms of the GNU General Public License as published by
#    the Free Software Foundation; either version 2 of the License, or
#    (at your option) any later version.
#
#    This program is distributed in the hope that it will be useful,
#    but WITHOUT ANY WARRANTY; without even the implied warranty of
#    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
#    GNU General Public License for more details.
#
#    You should have received a copy of the GNU General Public License
#    along with this program; if not, write to the Free Software
#    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
#
#
# disc-cover plugin

syntax_disc_cover () {
  echo "  --disc-cover"
  echo "    Makes a CD cover with disc-cover"
  echo "  --save-cddbfile"
  echo "    Don't remove cddb file (his name will be something like $$-disk.cddb"
  echo "  --casetype <jewel|slim>"
  echo "    Set type of case"
  echo "    Default: $DEF_COVER_TYPE"
  echo "  --out-type"
  echo "    File type for output"
  echo "    Default: $DEF_COVER_FILETYPE"
  echo "  --out-name <output_file>"
  echo "    Output file"
  echo "    Default output filename: $DEF_COVER_FILENAME"
  echo "  --device <device>"
  echo "    Specify the CD-ROM device"
  echo "    Default: $DEF_COVER_DEVICE"
  #echoc WHITE "  --print"
  #echoc WHITE "    Print directly psout file (print command: $LABEL_PRINTCMD)"
}

parse_param_disc_cover () {
  case "$1" in
    --disc-cover)
          DISCCOVER=$DEF_DISCCOVER
          COVER_SAVE_CDDBFILE=
          COVER_TYPE=$DEF_COVER_TYPE
          COVER_FILETYPE=$DEF_COVER_FILETYPE
          COVER_FILENAME=$DEF_COVER_FILENAME
          COVER_DEVICE=$DEF_COVER_DEVICE
          return 1
          ;;
    --save-cddbfile)
          COVER_SAVE_CDDBFILE=1
          SHIFT=1
          return 1
          ;;
    --casetype)
          if [ -z "$2" ] || [ "${2:0:1}" = "-" ]; then
            SHIFT=1
          else
            case "$2" in
              jewel|slim)
                 COVER_TYPE=$2
                 ;;
              *)
                 STRERR="Invalid case type"
                 return -1
                 ;;
            esac
            SHIFT=2
          fi
          return 1
          ;;
     --out-type)
          if [ -z "$2" ] || [ "${2:0:1}" = "-" ]; then
            SHIFT=1
          else
            case "$2" in
              txt|dvi|tex|ps|pdf|cddb|lbl|html)
                COVER_FILETYPE="$2"
                ;;
              *)
                STRERR="Invalid output file format"
                return -1
                ;;
            esac
            SHIFT=2
          fi
          return 1
          ;;
     --out-name)
          if [ -z "$2" ] || [ "${2:0:1}" = "-" ]; then
            SHIFT=1
          else
            if [ -r "$2" ]; then
              echoc GREEN "WARNING: $2 already exist. Overwriting..."
            fi
            COVER_FILENAME="$2"
            SHIFT=2
          fi
          return 1
          ;;
     --device)
          if [ -z "$2" ] || [ "${2:0:1}" = "-" ]; then
            SHIFT=1
          else
            if [ ! -r "$2" ]; then
              STRERR="Device file is not readable!"
              return -1
            fi
            COVER_DEVICE="$2"
            SHIFT=2
          fi
          return 1
          ;;
  esac
}

end_disc_cover () {
  if [ -z "$DISCCOVER" ]; then
    return
  fi
  echo
  echoc CYAN "Making cover..."
  (
  CDDBFILE="$$-cover.cddb"
  echoc CYAN "Now will edit cddbfile $CDDBFILE with vi. Press ENTER"
  read X
  $DISCCOVER -D $COVER_DEVICE -n -t cddb -o $CDDBFILE
  vi $CDDBFILE
  $DISCCOVER -D $COVER_DEVICE -f $CDDBFILE -c "$COVER_TYPE" \
             -t "$COVER_FILETYPE" -o $COVER_FILENAME
  if [ -z "$COVER_SAVE_CDDBFILE" ]; then
    rm -f $CDDBFILE
  fi
  )
  echoc CYAN "Done"
  echo
}

