#!/bin/bash
#
#Copyright 2012 CurlyMo <development@xbian.org>
#
#This file is part of XBian - XBMC on the Raspberry Pi.
#
#XBian 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 3 of the License, or (at your option) any later
#version.
#
#XBian 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 XBian. If not, see <http://www.gnu.org/licenses/>

function showRetrievingCurrentTZDlg() {
	wrapTxtFn "$(_ timezone.loading.timezone)" $(($DEFAULTWIDTH-4));
	centerTxtFn "$WRAPPEDTXT" $(($DEFAULTWIDTH-4));
	valignTxtFn "$CENTEREDTXT" 
	showInfoDlg "$ALIGNEDTXT" $HEIGHT;
}

function showTZNoTimezoneSelectedDlg() {
	wrapTxtFn "$(_ timezone.no_timezone_selected)" $(($DEFAULTWIDTH-4));
	centerTxtFn "$WRAPPEDTXT" $(($DEFAULTWIDTH-4));
	valignTxtFn "$CENTEREDTXT" 
	showMsgDlg "$ALIGNEDTXT" $HEIGHT;
}

function showTZNoLocationSelectedDlg() {
	wrapTxtFn "$(_ timezone.no_location_selected)" $(($DEFAULTWIDTH-4));
	centerTxtFn "$WRAPPEDTXT" $(($DEFAULTWIDTH-4));
	valignTxtFn "$CENTEREDTXT" 
	showMsgDlg "$ALIGNEDTXT" $HEIGHT;
}

function showTZLoadingLocationsDlg() {
	wrapTxtFn "$(_ timezone.loading.location)" $(($DEFAULTWIDTH-4));
	centerTxtFn "$WRAPPEDTXT" $(($DEFAULTWIDTH-4));
	valignTxtFn "$CENTEREDTXT" 
	showInfoDlg "$ALIGNEDTXT" $HEIGHT;
}

function showTZCategoryDlg() {
	MENU=();
	X=0;
	
	for TZCATEGORY in ${TZCATEGORIES[@]}; do
		X=$(($X+1));
		if [ "$TZCATEGORY" == "${CURRENTTZ[0]}" ]; then
			STATUS="on";
		else
			STATUS="off";
		fi
		MENU+=($X,"\Zn"$TZCATEGORY","$STATUS);
	done;
	TBLCOLUMNCENTER=0;
	createTableFn "radio" \
	"#;\Zb"$(_ timezone.label.timezone) \
	"${MENU[@]}"
	TBLCOLUMNCENTER=1;
	centerTxtFn "$HEADER" $(($DEFAULTWIDTH+6)); 
	showRadioDlg "$CENTEREDTXT" "$ROWS" ${#MENU[@]} 15;
}


function showTZLocationDlg() {
	CURRENTTZ=($1);
	IFS=" ";
	TZLOCATIONS=($2);
	IFS=$ORIGINALIFS;
	
	MENU=();
	X=0;
	for TZLOCATION in ${TZLOCATIONS[@]}; do
		X=$(($X+1));
		if [ "$TZLOCATION" == "${CURRENTTZ[1]}" ]; then
			STATUS="on";
		else
			STATUS="off";
		fi
		MENU+=($X,"\Zn"$TZLOCATION","$STATUS);
	done;

	if [ $X -gt 100 ]; then
		NRSIGN="# ";
	else
		NRSIGN="#";
	fi
	TBLCOLUMNCENTER=0;
	createTableFn "radio" \
	"$NRSIGN;\Zb"$(_ timezone.label.location) \
	"${MENU[@]}"
	TBLCOLUMNCENTER=1;
	centerTxtFn "$HEADER" $(($DEFAULTWIDTH+6));  
	showRadioDlg "$CENTEREDTXT" "$ROWS" ${#MENU[@]} 15;
}

function showCurrentDateTimeDlg() {
	TEXT=$(printf "$(_ timezone.old)" "$2")
	TEXT+="\n";
	TEXT+=$(printf "$(_ timezone.new)" "$1")

	centerTxtFn "$TEXT"  $(($DEFAULTWIDTH-4));
	valignTxtFn "$CENTEREDTXT" 
	showMsgDlg "$ALIGNEDTXT" 8;
}