#! /bin/sh
#----------------------------------------------------------------------
# Usage: appserverclient options
#    -m: operating mode
#        2X for 2X Application Server client mode (default)
#        MS for Microsoft Terminal Server client mode
#    -s: server[:port] (default port: 3389)
#    -u: user name
#    -p: password
#    -d: domain
#    -a: application to start
#    -f: working folder
#    -w: desktop width (default: 1024)
#    -h: desktop height (default: 768)
#    -c: color depth in bits (default: 24 bits)
#    -e: RDP experience one or more ORed value(s) from:
#        0x00 to disable nothing (default)
#        0x01 to disable wallpapers
#        0x02 to disable full window drag
#        0x04 to disable menu animations
#        0x08 to disable theming
#        0x20 to disable cursor shadow
#        0x40 to disable cursor blinking
#    -k: path to keymap file
#----------------------------------------------------------------------
#

. $TS_GLOBAL
. /etc/2x.defaults
. $HOME/.2x/"$1".2x

# Check for minimal values, and prompts user to enter them.  Currently only value is SERVER

for minimal in "SERVER"
do
	value=`eval echo '$'$minimal`
	if [ -z "$value" ] ; then
		dialog_get_value 2x $minimal |
		( read $minimal
		if [ `eval echo '$'$minimal` = "0" ] ; then
			dialog_no_value 2x
		else
			echo "$minimal=`eval echo '$'$minimal`" >> /tmp/CMD
		fi )
	fi
done

. /tmp/CMD

CMD="appserverclient $OPTIONS"
[ -n "$MODE" ] && CMD="$CMD -m$MODE"
[ -z "$USER" ] && USER="''"
CMD="$CMD -u$USER"

[ -n "$PASSWORD" ] && CMD="$CMD -p$PASSWORD"
[ -n "$DOMAIN" ] && CMD="$CMD -d$DOMAIN"

if [ "`make_caps $FULL_SCREEN`" = "YES" ] 
then
	CMD="$CMD -mMF"
else
	if [ -n "$WIDTH" ]
	then
		CMD="$CMD -w$WIDTH"
	fi
	if [ -n "$HEIGHT" ]
	then
		CMD="$CMD -h$HEIGHT"
	fi
fi

[ -n "$COLOR_DEPTH" ] && \
	CMD="$CMD -c$COLOR_DEPTH"
[ -n "$KEYMAP_PATH" ] && \
	CMD="$CMD -k$KEYMAP_PATH"

if [ "`make_caps $START_PROGRAM_ENABLED`" = "YES" ] ; then
	[ -n "$START_PROGRAM" ] && \
		CMD="$CMD -a$START_PROGRAM"
	[ -n "$START_PROGRAM_FOLDER" ] && \
		CMD="$CMD -f$START_PROGRAM_FOLDER"
fi

if [ -n "$PORT" ]
then
	SERVER="$SERVER:$PORT"
fi

if [ -n "$EXPERIENCE" ]
then
	# hex value
	CMD="$CMD -e$EXPERIENCE"
fi

$CMD -s $SERVER
