#!/usr/bin/env bash

# Set state as unchanged
BB_CURRENT_STATE=0

# Read in variables
source ${BBROOTDIR}/misc/variables.idx

# Read in language
source ${BBROOTDIR}/lang/${BBLANG}/configure.lang

# Read in functions
source ${BBROOTDIR}/misc/commonfunctions.sh
source ${BBROOTDIR}/func/configfunc.sh


#####PROGRAM START#####
while true; do
        # This is for the numbering of the menu choices. It is
        # updated once before each entry printout in the menu
        # except exit which should always be 0. The variable must
	# be reset within this while loop or bad things will happen.
        (( bb_m_c = 0 ))
	# <colors>
	#source "$BBROOTDIR"/misc/colors.idx
	# </colors>
	# Top and bottom lines for Information
	BBINFOLINE="${BBTABLECOLOR}${BBDECOLINE}${BBSUBCOLOR} INFORMATION ${BBTABLECOLOR}${BBDECOLINE}${BBCOLOROFF}"
	BBDECOLIN3="${BBTABLECOLOR}${BBDECOLINE}-------------${BBDECOLINE}${BBCOLOROFF}"
	# <table>
	pretty_top
	echo -e "${BBTABLECOLOR}|-(${BBSUBCOLOR}$bb_conf_menu_toptext1${BBTABLECOLOR})\t\t\t${BBTABLECOLOR}(${BBSUBCOLOR}$bb_conf_menu_toptext2${BBTABLECOLOR})"
		(( bb_m_c += 1 ))
	echo -e "${BBTABLECOLOR}|${BBMAINCOLOR} $bb_m_c) $bb_conf_menu1(${BBOPTIONCOLOR}$BBCDWRITER${BBMAINCOLOR})"
		(( bb_m_c += 1 ))
	echo -e "${BBTABLECOLOR}|${BBMAINCOLOR} $bb_m_c) $bb_conf_menu2(${BBOPTIONCOLOR}$BBCDROM${BBMAINCOLOR})"
		(( bb_m_c += 1 ))
	echo -e "${BBTABLECOLOR}|${BBMAINCOLOR} $bb_m_c) $bb_conf_menu3(${BBOPTIONCOLOR}$BBCDMNT${BBMAINCOLOR})"
		(( bb_m_c += 1 ))
	echo -e "${BBTABLECOLOR}|${BBMAINCOLOR} $bb_m_c) $bb_conf_menu4(${BBOPTIONCOLOR}$BBSPEED${BBMAINCOLOR})"
		(( bb_m_c += 1 ))
	echo -e "${BBTABLECOLOR}|${BBMAINCOLOR} $bb_m_c) $bb_conf_menu5(${BBOPTIONCOLOR}$BBBLANKING${BBMAINCOLOR})"
		(( bb_m_c += 1 ))
	echo -e "${BBTABLECOLOR}|${BBMAINCOLOR} $bb_m_c) $bb_conf_menu6(${BBOPTIONCOLOR}$BBNUMDEV${BBMAINCOLOR})"
		(( bb_m_c += 1 ))
	echo -e "${BBTABLECOLOR}|${BBMAINCOLOR} $bb_m_c) $bb_conf_menu7(${BBOPTIONCOLOR}$BBROOTDIR${BBMAINCOLOR})"
		(( bb_m_c += 1 ))
	echo -e "${BBTABLECOLOR}|${BBMAINCOLOR} $bb_m_c) $bb_conf_menu8(${BBOPTIONCOLOR}$BBBURNDIR${BBMAINCOLOR})" 
		(( bb_m_c += 1 ))
	echo -e "${BBTABLECOLOR}|${BBMAINCOLOR} $bb_m_c) $bb_conf_menu9(${BBOPTIONCOLOR}$BBLABEL${BBMAINCOLOR})" 
		(( bb_m_c += 1 ))
	echo -e "${BBTABLECOLOR}|${BBMAINCOLOR} $bb_m_c) $bb_conf_menu10(${BBOPTIONCOLOR}$BBCOPYRIGHT${BBMAINCOLOR})" 
		(( bb_m_c += 1 ))
	echo -e "${BBTABLECOLOR}|${BBMAINCOLOR} $bb_m_c) $bb_conf_menu11(${BBOPTIONCOLOR}$BBAUTHOR${BBMAINCOLOR})" 
		(( bb_m_c += 1 ))
	echo -e "${BBTABLECOLOR}|${BBMAINCOLOR} $bb_m_c) $bb_conf_menu12(${BBOPTIONCOLOR}$BBPUBLISHER${BBMAINCOLOR})" 
		(( bb_m_c += 1 ))
	echo -e "${BBTABLECOLOR}|${BBMAINCOLOR} $bb_m_c) $bb_conf_menu13(${BBOPTIONCOLOR}$BBDESCRIPTION${BBMAINCOLOR})" 
		(( bb_m_c += 1 ))
	echo -e "${BBTABLECOLOR}|${BBMAINCOLOR} $bb_m_c) $bb_conf_menu14(${BBOPTIONCOLOR}$BBNAMEOFPACKAGE${BBMAINCOLOR})" 
		(( bb_m_c += 1 ))
	echo -e "${BBTABLECOLOR}|${BBMAINCOLOR} $bb_m_c) $bb_conf_menu15(${BBOPTIONCOLOR}$BBNORMALIZE${BBMAINCOLOR})"
		(( bb_m_c += 1 ))
	echo -e "${BBTABLECOLOR}|${BBMAINCOLOR} $bb_m_c) $bb_conf_menu16(${BBOPTIONCOLOR}$BBOPT_ONE${BBMAINCOLOR})"
		(( bb_m_c += 1 ))
	echo -e "${BBTABLECOLOR}|${BBMAINCOLOR} $bb_m_c) $bb_conf_menu17(${BBOPTIONCOLOR}$BBFIFODIR${BBMAINCOLOR})"	
		(( bb_m_c += 1 ))
	echo -e "${BBTABLECOLOR}|${BBMAINCOLOR} $bb_m_c) $bb_conf_menu18(${BBOPTIONCOLOR}$BBDELTEMPBURN${BBMAINCOLOR})"
		(( bb_m_c += 1 ))
	echo -e "${BBTABLECOLOR}|${BBMAINCOLOR} $bb_m_c) $bb_conf_menu19(${BBOPTIONCOLOR}$BBOVERBURN${BBMAINCOLOR})"
		(( bb_m_c += 1 ))
	echo -e "${BBTABLECOLOR}|${BBMAINCOLOR} $bb_m_c) $bb_conf_menu20(${BBOPTIONCOLOR}$BBCOPY_PROTECT${BBMAINCOLOR})"
		(( bb_m_c += 1 ))
	echo -e "${BBTABLECOLOR}|${BBMAINCOLOR} $bb_m_c) $bb_conf_menu21(${BBOPTIONCOLOR}$BBBITRATE${BBMAINCOLOR})"
		(( bb_m_c += 1 ))
	echo -e "${BBTABLECOLOR}|${BBMAINCOLOR} $bb_m_c) $bb_conf_menu22(${BBOPTIONCOLOR}$BBLANG${BBMAINCOLOR})"
		(( bb_m_c += 1 ))
	echo -e "${BBTABLECOLOR}|${BBMAINCOLOR} $bb_m_c) $bb_conf_menu23(${BBOPTIONCOLOR}$BBDTAO${BBMAINCOLOR})"
		(( bb_m_c += 1 ))
	echo -e "${BBTABLECOLOR}|${BBMAINCOLOR} $bb_m_c) $bb_conf_menu24(${BBOPTIONCOLOR}$BBPADDING${BBMAINCOLOR})"
	echo -e "${BBTABLECOLOR}|"
	#echo -e "${BBTABLECOLOR}|-(${BBSUBCOLOR}Actions${BBTABLECOLOR})"
		(( bb_m_c += 1 ))
        echo -n -e "${BBTABLECOLOR}  |- #${BBMAINCOLOR} $bb_m_c) $bb_conf_menu25 ${BBTABLECOLOR}"
	 (( bb_m_c += 1 )) 
	echo -n -e "${BBTABLECOLOR} #${BBMAINCOLOR} $bb_m_c) $bb_conf_menu26 ${BBTABLECOLOR}"
	echo -e "${BBTABLECOLOR} #${BBMAINCOLOR} 0) $bb_conf_menu0 ${BBTABLECOLOR}"
	echo -e ""

	echo -n -e "${BBINPUTCOLOR}$bb_conf_menu_entry |>${BBMAINCOLOR} "
	read action
	echo -e "${BBCOLOROFF}"
	# </table>

	case $action in
  		1)	#Change writer device
			change_writer_device
		;;	
		2)	#Change cdrom device file
			change_cdrom_device
		;;
		3)	#Change cdrom mount point
			change_cd_mount_point
		;;
		4)	#Change writer speed
			change_writer_speed
		;;
		5)	#Change type of blanking
			change_blanking
		;;
		6)	#Number of devices
			set_num_devices
		;;
		7)	#Change of ROOTDIR. Be careful!
			change_rootdir
		;;
		8)	#Change of BBBURNDIR. Default usually ok.
			change_burndir
		;;			
		9)	#Label of the cd
			change_label
		;;					
		10)	#Copyright notice (If any)
			change_copyright_cd
		;;
		11)	#Author
			set_author
		;;
		12)	#Publisher
			set_publisher
		;;
		13)	#Content description
			set_description
		;;
		14)	#Name of package
			set_package_name
		;;
		15)	#Use normalize
			set_normalize
		;;
		16)	#Driver options
			set_driver_options
		;;
		17)	#FIFO dir for direct audio burning
			set_fifo_dir
		;;
		18)	# Delete tempdir?
			delete_temp
		;;
		19)	#Overburn
			set_overburn
		;;
		20)	#Audio set Copy Protection 
			set_audio_copyprotect
		;;
		21)	#BITRATE OPTION
			set_bitrate
		;;
		22)	#Language Option
			set_language
		;;
		23)	#DAO/TAO
			set_dtao
		;;
		24)	#Gaps between tracks
			set_gaps
		;;
		25)	#Apply changes
			pretty_top
			echo -e "${BBINFOLINE}"
			if get_new_settings ; then
				continue
			fi
			${BBROOTDIR}/config/apply_options.sh
			source ${BBROOTDIR}/misc/variables.idx
			BB_CURRENT_STATE=0
		;;
		26)	#Apply default values
			pretty_top
			echo -e "${BBINFOLINE}"
			if get_really_sure ; then
				continue
			fi
			${BBROOTDIR}/config/reset_options.sh
			source ${BBROOTDIR}/misc/variables.idx
		;;
  		0)	#Back to main menu
			if get_confirm ; then 
				continue
			fi
  				break
		;;
  		*)	#You did a bad bad thing
			pretty_top
		        echo -e "${BBINFOLINE}"
			echo
   			echo -e "     ${BBMAINCOLOR}$bb_conf_err [0-$bb_m_c]${BBCOLOROFF}"
			echo
			echo -e "${BBDECOLIN3}"
			wait_for_enter
			continue
  		;;
 	esac
done
