#!/bin/sh

export TEXTDOMAIN=pburn

[ "$(grep -F delay <<< "$*")" ] && sleep 1

case $1 in
-yesno)
	[ -z "$FRAME" ] && FRAME="$(gettext 'Information')"
	[ -z "$IMG" ] && IMG="dialog-question"
	BUTTONS="<button no></button><button yes></button>"
	;;
-input) #rename / new dir in burnlist
	BUTTONS="<button cancel></button>
			<button can-default=\"true\" has-default=\"true\" use-stock=\"true\">
			 <input file stock=\"gtk-apply\"></input>
			 <label>$(gettext 'Apply')</label>
			 <action>EXIT:Apply</action>
			</button>"
	EXTENDED_GTKDIALOG="<entry activates-default=\"true\"><variable>INPUT</variable><input>cat $WORKDIR/input</input></entry>"
	;;
-quest_overburn) #option to set burn-command to overwrite/overburn before burning  
	[ "`grep -iE "Blu-ray|DVD" <<< "$MEDIATYPE"`" ] && TXT3="$(gettext 'Since the inserted disc is a DVD/BD, you can solve this by overwriting existing data on the disc. If not, read on...')

..."
	TXT3=$TXT3"`echo "$HLPTXT32" | grep -B 1 -A 10 -C 1 '(88'`"
	IMG=dialog-question; FRAME="$(gettext 'Overburn')"; TXT1="<b>$(gettext 'The size of burn content is more than the official media size.')</b>"; TXT2="$TXT3

$(gettext 'Minimum size'): $NEEDED_SPACE_HUMAN"
	BUTTONS="<button><input file>$APPDIR/pburn20.png</input><label>$(gettext 'Allow overburning')</label><action>EXIT:overburn</action></button>
			<button><input file>$APPDIR/pburn20.png</input><label>$(gettext 'Overwrite existing data')</label><action>EXIT:overwrite</action></button>
			<button cancel></button>"
	;;
-quest_blank) #option to blank not-empty-disc before burning  
	FRAME="$(gettext 'Blank (Erase) disc')"
 	IMG="dialog-question"
	TXT1="$(gettext '<b>Inserted disc is not blank or writable</b>

- Burning <b>Audio/Video</b> requires a blank disc.
- Burning <b>Data</b> requires a writeable or blank disc.')
- $(gettext "Burning <b>Image (iso/nrg)</b> may require a blank disc. You can mix data from the chosen image with the content on the disc, but if burning a bootable disc it might be corupted. An exception is when updating the LIVE-disc to a newer version. Files in the new image will replace similar files on the disc. Press 'Continue' to add more data from the image to the disc.")" 
	if [ "$2" != "CD" ]; then
		TMP="<button><label>$(gettext 'Overwrite existing data on disc')</label><input file>$APPDIR/pburn20.png</input><action>EXIT:overwrite</action></button>"
		TXT2="<span color='"'#FF0000'"'>
$(gettext '<b>Notes for DVD/Blu-ray</b>
Blanking a DVD or Blu-ray can give issues. The quick way (and sometimes the only way) is to <i>overwrite existing data on the disc</i>. pBurn will set the overwrite-flag, but if this fails, please consider to <b>Blank from the main gui</b>.')</span>"

	else	
		TMP="<button><label>$(gettext 'Blank (Erase) CD')</label><input file>$APPDIR/pburn20.png</input><action>EXIT:blank</action></button>"
	fi
	BUTTONS="$TMP
			<button><input file stock=\"gtk-cdrom\"></input><label>$(gettext 'Continue with valid disc')</label></button>
			<text><label>\"    \"</label></text>
			<button><input file stock=\"gtk-info\"></input><label>$(gettext 'Disc info')</label><action>. $APPDIR/func -disc_info</action></button>
			<button cancel></button>"
	;;
-quest_isolevel) #isolevel is not detected - and there is data on the disc
	FRAME="$(gettext 'Blank (Erase) disc')"
 	IMG="dialog-question"
	TXT1="$(gettext '<b>Inserted disc contains data, and is not initialized by pBurn.</b>')
$(gettext "Adding data to an already used disc, recommends that the burn-options are equal to the first session. pBurn can't determine the settings of this disc, and further burning is risky. 

Please use a pBurn-initialized or blank disc")"

	if [ "$2" != "CD" ]; then
		TMP="<button><label>$(gettext 'Blank DVD/Blu-ray (Overwrite existing data)')</label><input file>$APPDIR/pburn20.png</input><action>EXIT:overwrite</action></button>"
	else	
		TMP="<button><label>$(gettext 'Blank (Erase) CD')</label><input file>$APPDIR/pburn20.png</input><action>EXIT:blank</action></button>"
	fi
	BUTTONS="$TMP
			<button><input file stock=\"gtk-cdrom\"></input><label>$(gettext 'Continue anyway')</label><action>EXIT:do_nothing</action></button>
			<text><label>\"    \"</label></text>
			<button><input file stock=\"gtk-info\"></input><label>$(gettext 'Disc info')</label><action>. $APPDIR/func -disc_info</action></button>
			<button cancel></button>"
	;;
-quest_iso) #option to unpack iso-file or burn as is
	FRAME="$(gettext 'image')"
 	IMG="dialog-question"
	TXT1="$(gettext '<b>You have chosen to burn a filesystem image (*.iso or *.nrg).

Normally the filesystem should be unpacked onto the disc</b>, unless for some reason you want to put the image on the disc as a single file.

What would you like to do?')"
	BUTTONS="<button><label>$(gettext 'Unpack filesystem')</label><input file>$APPDIR/pburn20.png</input><action>EXIT:iso</action></button>
			<button><input file>$APPDIR/pburn20.png</input><label>$(gettext 'Single file')</label></button>
			<text><label>\"    \"</label></text>
			<button cancel></button>"
	;;
-quest_export_iso)
	FRAME="$(gettext 'Export iso')"
 	IMG="dialog-question"
	TXT1="<b>$(gettext 'The file list contains only movie/image files, and are valid for Video-DVD')</b>"	
	TXT2="$(gettext 'Building an iso image for video-DVD requires some extra preparations, - compared to an ordinary iso for optical pc-drives.
Please choose your target.')"
	BUTTONS="<button><label>$(gettext 'Export as-is to iso-image')</label><input file stock=\"gtk-save-as\"></input><action>EXIT:export_iso</action></button>
			<button><input file stock=\"gtk-convert\"></input><label>$(gettext 'Build iso for video-DVD')</label><action>EXIT:export_iso_video</action></button>
			<text><label>\"    \"</label></text>
			<button cancel></button>"
	;;
*) #ok box
	[ -z "$IMG" ] && IMG="dialog-error"
	[ -z "$FRAME" ] && FRAME="$(gettext 'Error')"
	BUTTONS="<button ok></button>"
	;;
esac
export pburn_box="
<window title=\"pBurn\" icon-name=\"media-optical\">
 <vbox>
  <frame $FRAME>
   <pixmap icon_size=\"6\"><input file stock=\"gtk-$IMG\"></input></pixmap>
   <text use-markup=\"true\" wrap=\"true\" width-chars=\"50\"><label>\"$TXT1\"</label></text>
   <text use-markup=\"true\" wrap=\"true\" width-chars=\"50\"><label>\"$TXT2\"</label></text>
   $EXTENDED_GTKDIALOG
  </frame>
  <hbox>
   $BUTTONS
  </hbox>
 </vbox>
</window>"
I=$IFS; IFS=""
for STATEMENTS in  $($GTKDIALOG -p pburn_box --center); do
	eval $STATEMENTS
done
IFS=$I

export EXIT=$EXIT
TXT1=""; TXT2=""; IMG=""; FRAME=""; DEFAULT=""; EXTENDED_GTKDIALOG=""; echo -n > $WORKDIR/input #reset to avoid alien values in next box