#!/bin/bash
# Copyright (C) 2007 Pâris Quentin
#  		     Cassarin-Grand Arthur

# 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.,
# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. 
message () 
{
	if [ ! "$2" ]
	then
		TITRE_FENETRE="Message"
	else
		TITRE_FENETRE="$2"
	fi
	
	if [ ! "$3" ]
	then
		N1=0
	else
		N1=$3
	fi

	if [ ! "$4" ]
	then
		N2=0
	else
		N2=$4
	fi

	if [ ! "$5" ]
	then
		CANCEL=0
	else
		CANCEL=$5
	fi
	message=${1//"\n"/
}

	if [ ! "$6" ]
	then
		IMAGE="info.png"
	else
		IMAGE=$6
	fi
	WINDOW=$(python2.5 "$PLAYONLINUX/python/message.py" "$TITRE_FENETRE" "$message" $N1 $N2 $CANCEL $IMAGE)
	if [ "$WINDOW" = "Canceled" ]
	then
		exit
	fi
}
erreur () 
{
	if [ ! "$2" ]
	then
		TITRE_FENETRE="Erreur"
	else
		TITRE_FENETRE="$2"
	fi
	
	if [ ! "$3" ]
	then
		N1=0
	else
		N1=$3
	fi

	if [ ! "$4" ]
	then
		N2=0
	else
		N2=$4
	fi

	if [ ! "$5" ]
	then
		CANCEL=0
	else
		CANCEL=$5
	fi
	message=${1//"\n"/
}
	if [ ! "$6" ]
	then
		IMAGE="error.png"
	else
		IMAGE=$6
	fi
	WINDOW=$(python2.5 "$PLAYONLINUX/python/message.py" "$TITRE_FENETRE" "$message" $N1 $N2 $CANCEL $IMAGE)
	if [ "$WINDOW" = "Canceled" ]
	then
		exit
	fi
}
attention () 
{
	if [ ! "$2" ]
	then
		TITRE_FENETRE="Attention"
	else
		TITRE_FENETRE="$2"
	fi
	
	if [ ! "$3" ]
	then
		N1=0
	else
		N1=$3
	fi

	if [ ! "$4" ]
	then
		N2=0
	else
		N2=$4
	fi

	if [ ! "$5" ]
	then
		CANCEL=0
	else
		CANCEL=$5
	fi
	message=${1//"\n"/
}
	if [ ! "$6" ]
	then
		IMAGE="warning.png"
	else
		IMAGE=$6
	fi
	WINDOW=$(python2.5 "$PLAYONLINUX/python/message.py" "$TITRE_FENETRE" "$message" $N1 $N2 $CANCEL $IMAGE)
	if [ "$WINDOW" = "Canceled" ]
	then
		exit
	fi
}


question () 
{
	if [ ! "$2" ]
	then
		TITRE_FENETRE="Question"
	else
		TITRE_FENETRE="$2"
	fi
	
	if [ ! "$3" ]
	then
		N1=0
	else
		N1=$3
	fi

	if [ ! "$4" ]
	then
		N2=0
	else
		N2=$4
	fi

	if [ ! "$5" ]
	then
		CANCEL=0
	else
		CANCEL=$5
	fi
	message=${1//"\n"/
}
	if [ ! "$6" ]
	then
		IMAGE="question.png"
	else
		IMAGE=$6
	fi
	WINDOW=$(python2.5 "$PLAYONLINUX/python/question.py" "$TITRE_FENETRE" "$message" $N1 $N2 $CANCEL $IMAGE)
	if [ "$WINDOW" = "Canceled" ]
	then
		exit
	else 
		echo "$WINDOW"
	fi
}

champ () 
{
	if [ ! $6 ]
	then
		TITRE_FENETRE="Champ"
	else
		TITRE_FENETRE="$6"
	fi
	
	if [ ! "$3" ]
	then
		N1=0
	else
		N1=$3
	fi

	if [ ! "$4" ]
	then
		N2=0
	else
		N2=$4
	fi

	if [ ! "$5" ]
	then
		CANCEL=1
	else
		CANCEL=$5
	fi
	message=${1//"\n"/
}
	if [ ! "$7" ]
	then
		IMAGE="question.png"
	else
		IMAGE=$7
	fi
	python2.5 "$PLAYONLINUX/python/champ.py" "$TITRE_FENETRE" "$message" $N1 $N2 $CANCEL $IMAGE "$2"
	
}

menu () 
{
	# 1 = Message
	# 2 = Items
	# 3 = Titre
	# 4 = Numéro de l'étape
	# 5 = Nombre d'étapes
	# 6 = Bouton annuler [ 1 = Oui, 0 = Non ]
	# 7 = Image
	# 8 = Where To Cut
	if [ ! "$3" ]
	then
		TITRE_FENETRE="Veuillez faire un choix"
	else
		TITRE_FENETRE="$3"
	fi
	
	if [ ! "$4" ]
	then
		N1=0
	else
		N1=$4
	fi

	if [ ! "$5" ]
	then
		N2=0
	else
		N2=$5
	fi

	if [ ! "$6" ]
	then
		CANCEL=1
	else
		CANCEL=$6
	fi
	message=${1//"\n"/
}
	if [ ! "$7" ]
	then
		IMAGE="question.png"
	else
		IMAGE=$7
	fi

	if [ ! "$8" ]
	then
		WHERE_TO_CUT=" "
	else
		WHERE_TO_CUT="$8"
	fi

	python2.5 "$PLAYONLINUX/python/menu.py" "$TITRE_FENETRE" "$message" $N1 $N2 $CANCEL $IMAGE "$2" "$WHERE_TO_CUT"
}



attendre ()
{
	# 1 = Message
	# 2 = Commande
	# 3 = Titre
	# 4 = Numéro de l'étape
	# 5 = Nombre d'étapes
	# 6 = Bouton annulé [1 = Oui, 0 = Non]
	# 7 = Image 
	# 8 = Quitter automatiquement lorsque la commande est achevé [1 = Oui, 0 = Non]
	# 9 = Message lorsque la commande est terminée

	if [ ! "$3" ]
	then
		TITRE_FENETRE="$LNG_WAIT"
	else
		TITRE_FENETRE="$3"
	fi
	
	if [ ! "$4" ]
	then
		N1=0
	else
		N1=$4
	fi

	if [ ! "$5" ]
	then
		N2=0
	else
		N2=$5
	fi

	if [ ! "$6" ]
	then
		CANCEL=1
	else
		CANCEL=$6
	fi

	if [ ! "$7" ]
	then
		IMAGE="question.png"
	else
		IMAGE=$7
	fi
	WINDOW=$(python2.5 "$PLAYONLINUX/python/attendre.py" "$TITRE_FENETRE" "$1" "$N1" "$N2" "$CANCEL" "$IMAGE" "$2" "$8" "$9")
	if [ "$WINDOW" = "Canceled" ]
	then
		exit
	fi
}

telecharger ()
{
	# 1 = Message
	# 2 = Fichier
	# 3 = Titre
	# 4 = Numéro de l'étape
	# 5 = Nombre d'étapes
	# 6 = Bouton annulé [1 = Oui, 0 = Non]
	# 7 = Image 
	# 8 = Autoexit ?
	if [ ! "$3" ]
	then
		TITRE_FENETRE="$LNG_WAIT"
	else
		TITRE_FENETRE="$3"
	fi
	
	if [ ! "$4" ]
	then
		N1=0
	else
		N1=$4
	fi

	if [ ! "$5" ]
	then
		N2=0
	else
		N2=$5
	fi

	if [ ! "$6" ]
	then
		CANCEL=1
	else
		CANCEL=$6
	fi

	if [ ! "$7" ]
	then
		IMAGE="question.png"
	else
		IMAGE=$7
	fi

	if [ ! "$8" ]
	then
		AUTOEXIT="0"
	else
		AUTOEXIT="1"
	fi
	WINDOW=$(python2.5 "$PLAYONLINUX/python/telecharger.py" "$TITRE_FENETRE" "$2" "$(pwd)/" "$1" $N1 $N2 $CANCEL $IMAGE $AUTOEXIT)
	if [ "$WINDOW" = "Canceled" ]
	then
		exit
	fi
}
selectionner_fichier ()
{
	if [ ! $6 ]
	then
		TITRE_FENETRE="Parcourir"
	else
		TITRE_FENETRE="$6"
	fi
	
	if [ ! "$3" ]
	then
		N1=0
	else
		N1=$3
	fi

	if [ ! "$4" ]
	then
		N2=0
	else
		N2=$4
	fi

	if [ ! "$5" ]
	then
		CANCEL=0
	else
		CANCEL=$5
	fi
	message=${1//"\n"/
}
	if [ ! "$7" ]
	then
		IMAGE="question.png"
	else
		IMAGE=$7
	fi
	WINDOW=$(python2.5  "$PLAYONLINUX/python/file.py" "$TITRE_FENETRE" "$message" $N1 $N2 $CANCEL $IMAGE "$2")
	if [ "$WINDOW" = "Canceled" ]
	then
		exit
	fi
}
afficher_fichier ()
{
	 contenu=$(cat $1)
	 message "$contenu"
}
