#!/bin/bash

# This example requires bash.

GTKDIALOG=gtkdialog

progress() {
	for i in $(seq 0 10 100); do
		echo $i
		[ "$i" -le 30 ] && echo "Start..."
		[ "$i" -le 60 -a "$i" -gt 30 ] && echo "Middle..."
		[ "$i" -gt 60 ] && echo "End..."
		sleep 0.3
	done;
}; export -f progress

export BAR_DIALOG='
<window>
	<vbox>
		<frame Progress>
			<text>
				<label>Some text describing what is happening.</label>
			</text>
			<progressbar>
				<label>Some Text</label>
				<input>bash -c progress</input>
				<action function="closewindow">BAR_DIALOG</action>
			</progressbar>
		</frame>
		<hbox>
			<button cancel>
				<action function="closewindow">BAR_DIALOG</action>
			</button>
		</hbox>
	</vbox>
	<variable>BAR_DIALOG</variable>
</window>
'

export MAIN_DIALOG='
<window>
	<hbox>
		<button cancel></button>
		<button>
			<label>Launch</label>
			<action function="launch">BAR_DIALOG</action>
		</button>
	</hbox>
</window>
'

case $1 in
	-d | --dump) echo "$MAIN_DIALOG" "$BAR_DIALOG" ;;
	*) $GTKDIALOG --program=MAIN_DIALOG ;;
esac
