#!bin/sh
#
# Qnext Linux Environment Detection Script
# 1.00

detect_kde_running() 
{
    RETVAL=$(echo $KDE_FULL_SESSION | grep -c "true")
    echo IS_KDE_RUNNING:$RETVAL
    return $RETVAL
}


exec_konqueror()
{
    RETVAL=$(find /usr/bin -name "konqueror" | grep -c "konqueror")
    if [ $RETVAL -gt 0 ] ; then
	konqueror "$1" &
	exit 0
    fi
    return 127
}


exec_mozilla() 
{
    RETVAL=$(find /usr/bin -name "mozilla" | grep -c "mozilla")
    if [ $RETVAL -gt 0 ] ; then
	mozilla "$1" &
	exit 0
    fi
    return 127
}


exec_htmlview() 
{
    RETVAL=$(find /usr/bin -name "htmlview" | grep -c "htmlview")
    if [ $RETVAL -gt 0 ] ; then
	htmlview "$1" &
	exit 0
    fi
    return 127
}


exec_kfmclient()
{
    RETVAL=$(find /usr/bin -name "kfmclient" | grep -c "kfmclient")
    if [ $RETVAL -gt 0 ] ; then
	kfmclient exec "$1" &
	exit 0
    fi
    return 127
}


exec_nautilus()
{
    RETVAL=$(find /usr/bin -name "nautilus" | grep -c "nautilus")
    if [ $RETVAL -gt 0 ] ; then
	nautilus "$1" &
	exit 0
    fi
    return 127
}


#
# check our parameter count
#
if [ $# -eq 0 ] ; then
    echo "too few parameters"
    exit 1
fi

# 
# check if KDE is running
#
detect_kde_running


# 
# if KDE was detected we launch konqueror first for consistency
#
if [ $? -gt 0 ] ; then
     exec_konqueror "$1"
fi

#
# if KDE was not running we try htmlview
#
exec_htmlview "$1"

#
# if htmlview was not found, we try looking for mozilla
#
exec_mozilla "$1"

#
# finally we try konqueror regardless of KDE running
#
exec_konqueror "$1"

#
# if we got this far it's time for a last ditch effort
# so we launch mozilla even if we didn't find it in case
# it's in a funny place, but still in the path
#
mozilla "$1" &




