#!/bin/sh
#*********************************************************************************************************
#*   __     __               __     ______                __   __                      _______ _______   *
#*  |  |--.|  |.---.-..----.|  |--.|   __ \.---.-..-----.|  |_|  |--..-----..----.    |       |     __|  *
#*  |  _  ||  ||  _  ||  __||    < |    __/|  _  ||     ||   _|     ||  -__||   _|    |   -   |__     |  *
#*  |_____||__||___._||____||__|__||___|   |___._||__|__||____|__|__||_____||__|      |_______|_______|  *
#* http://www.blackpantheros.eu | http://www.blackpanther.hu - kbarcza[]blackpanther.hu * Charles Barcza *
#*************************************************************************************(c)2002-2011********
#---------------------------------------------------------------
# Project         : blackPanther OS default-apps
# Module          : bin
# File            : default-vplayer (videooplayer)
# Version         : 0.1
# Author          : Charles Barcza
# Created On      : Mon Aug 29 2008
# Purpose         : launch a video player
#---------------------------------------------------------------
 . /etc/blackPanther-default-apps.conf
appname=vplayer

if [ -f ~/.personal-$appname ];then
    . ~/.personal-$appname
    echo "Presonal conf found!"
fi

set_a_vplayer() {
echo "VPLAYER=$1" > ~/.personal-$appname
echo "Personal $appname definied, please restart $0 without parameter."
exit
}

strip_vplayer_var() {
    if [[ -n "$VPLAYER" ]]; then
	if [[ `basename "$VPLAYER"` == "default-${appname}" ]]; then
	    unset VPLAYER
	else
	    set $VPLAYER
	    if ! which $1 > /dev/null 2>&1; then
		unset VPLAYER
	    fi
	fi
    fi
}

if [ "$1" = "-s" ];then
    echo "Define user ${appname}.."
    set_a_vplayer $2
elif [ "$1" = "-u" ];then
    rm -f $HOME/.personal-${appname}
    echo "Clear definied personal ${appname} conf.."
    exit
elif [ "$1" = "-h" ];then
    echo ""
    echo -e "${GRN}This is a$BLK blackPanther OS$GRN specific tool"
    echo ""
    echo -e "$MAG  Usage:"
    echo -e "$YEL       `basename $0` -s $DEF Set a personal ${appname} (You conf file: $HOME/.personal-${appname})"
    echo -e "$YEL       `basename $0` -u $DEF Unset definied ${appname} (Remove you conf file: $HOME/.personal-${appname})"
    echo -e "$YEL       `basename $0` -h $DEF This screen"
    echo ""
    echo -e "$CYN  [$RED Example:$CYN `basename $0` -s smplayer$RED OR to autodetect:$CYN `basename $0`]$DEF"
    echo ""
    exit
fi

strip_vplayer_var
if [[ -z "$VPLAYER" ]]; then
 
    #strip_vplayer_var
    [[ -z "$VPLAYER" ]] && VPLAYER=`which smplayer 2> /dev/null` 
    [[ -z "$VPLAYER" ]] && VPLAYER=`which xine 2> /dev/null`
    [[ -z "$VPLAYER" ]] && VPLAYER=`which totem 2> /dev/null`
    [[ -z "$VPLAYER" ]] && VPLAYER=`which vlc 2> /dev/null`
    [[ -z "$VPLAYER" ]] && VPLAYER=`which dragonplayer 2> /dev/null`
    [[ -z "$VPLAYER" ]] && VPLAYER=`which gmplayer 2> /dev/null`
    [[ -z "$VPLAYER" ]] && VPLAYER=`which kmplayer 2> /dev/null`
    [[ -z "$VPLAYER" ]] && VPLAYER=`which mplayer 2> /dev/null`
fi


if [[ -n "$VPLAYER" ]]; then 
    exec $VPLAYER "$@"
else
    xmsg=`which kdialog 2>/dev/null || which zenity 2>/dev/null`
    [ -n "$DISPLAY" ] && $xmsg --error "Sorry. Audio Player applications not detected, please install on PC (etc: installing audacious)"
    [ ! -n "$DISPLAY" ] && echo -n "Sorry. Audio Player not detected! Please install on PC (etc: installing audacious)"
fi
