#
# 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
#
#
# cdlabelgen plugin

syntax_cdlabelgen () {
  echo "  --cdlabelgen <item-file>"
  echo "    Makes a CD cover with cdlabelgen reading song's titles from <item-file>"
  echo "    Default item filename: $DEF_LABEL_FILENAME"
  echo "  --cat <category>"
  echo "    Set the category (title) for the CD"
  echo "    Default category: $DEF_LABEL_CAT"
  echo "  --subcat <subcategory>"
  echo "    Set the subcategory (subtitle) for the CD"
  echo "    Default subcategory: $DEF_LABEL_SUBCAT"
  echo "  --psout <output_file>"
  echo "    Output postscript file"
  echo "    Default output filename: $DEF_LABEL_PSOUT"
  echo "  --print"
  echo "    Print directly psout file (print command: $LABEL_PRINTCMD)"
}

parse_param_cdlabelgen () {
  case "$1" in
    --cdlabelgen)
           if [ -z "$2" ] || [ "${2:0:1}" = "-" ]; then 
             LABEL_FILENAME=$DEF_LABEL_FILENAME
             SHIFT=1
           else
             if [ -r "$2" ]; then
               LABEL_FILENAME=$2
               SHIFT=2
             else
               STRERR="File $2 is not readable!"
               return -1
             fi
           fi
           LABEL_CAT=$DEF_LABEL_CAT
           LABEL_SUBCAT=$DEF_LABEL_SUBCAT
           LABEL_PSOUT=$DEF_LABEL_PSOUT
           return 1
           ;;
    --cat)
          if [ -z "$2" ] || [ "${2:0:1}" = "-" ]; then
            SHIFT=1
          else
            LABEL_CAT="$2"
            SHIFT=2
          fi
          return 1
          ;;
    --subcat)
          if [ -z "$2" ] || [ "${2:0:1}" = "-" ]; then
            SHIFT=1
          else
            LABEL_SUBCAT="$2"
            SHIFT=2
          fi
          return 1
          ;;
     --psout)
          if [ -z "$2" ] || [ "${2:0:1}" = "-" ]; then
            SHIFT=1
          else
            if [ -r "$2" ]; then
              echoc GREEN "WARNING: $2 already exist. Overwriting..."
            fi
            LABEL_PSOUT="$2"
            SHIFT=2
          fi
          return 1
          ;;
     --print)
          LABEL_PRINT=1
          ;;
  esac
}

end_cdlabelgen () {
  if [ -z "$LABEL_FILENAME" ]; then
    return
  fi
  echo
  echoc CYAN -n "Making cover..."
  $CDLABELGEN -c "$LABEL_CAT" -s "$LABEL_SUBCAT" -f "$LABEL_FILENAME" -o "$LABEL_PSOUT"
  if [ ! -z "$LABEL_PRINT" ]; then
    echoc CYAN " Printing..."
    $LABEL_PRINTCMD $LABEL_PSOUT
  fi
  echoc CYAN "Done"
  echo
}

