36ac449
#!/bin/bash
36ac449
## Copyright (C) 2004 Warren Togami <wtogami@redhat.com>
36ac449
## Contributors:   David Hill <djh[at]ii.net>
36ac449
#
36ac449
# This program is free software; you can redistribute it and/or modify
36ac449
# it under the terms of the GNU General Public License as published by
36ac449
# the Free Software Foundation; version 2 of the License.
36ac449
#
36ac449
# This program is distributed in the hope that it will be useful,
36ac449
# but WITHOUT ANY WARRANTY; without even the implied warranty of
36ac449
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
36ac449
# GNU General Public License for more details.
36ac449
#
36ac449
# You should have received a copy of the GNU General Public License
36ac449
# along with this program; if not, write to the Free Software
36ac449
# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
36ac449
36ac449
#
36ac449
# open-browser.sh for MozillaThunderbird
36ac449
# Release 5
36ac449
#
36ac449
# This script is called by MozillaThunderbird in order to launch the web 
36ac449
# browser specified in gconf key /desktop/gnome/url-handlers/http/command
36ac449
#
36ac449
36ac449
# Exit with Error Message
36ac449
function error_exit() {
36ac449
    echo "$1"
36ac449
    if [ -a /usr/bin/zenity ]; then
36ac449
        /usr/bin/zenity --error --text="$1"
36ac449
    else
36ac449
        xmessage "$1" &
36ac449
    fi
36ac449
    exit 1
36ac449
}
36ac449
36ac449
# No URL specified so set to blank
36ac449
url=$1
36ac449
if [ -z $url ]; then
36ac449
    url=about:blank
36ac449
fi
36ac449
36ac449
# Use gnome-open if it exists (Gnome 2.6+ only)
36ac449
if [ -f /usr/bin/gnome-open ]; then
36ac449
    OUTPUT="$(/usr/bin/gnome-open "$url" 2>&1)"
36ac449
    if [ $? -ne 0 ]; then
36ac449
        error_exit "$OUTPUT"
36ac449
    fi
36ac449
    exit 0
36ac449
fi
36ac449
36ac449
# Pull key from gconf, remove %s or "%s", trim leading & trailing spaces
36ac449
GCONF=$(gconftool-2 -g /desktop/gnome/url-handlers/http/command 2>/dev/null | sed -e 's/%s//; s/\"\"//; s/^\ *//; s/\ *$//')
36ac449
NEEDTERM=$(gconftool-2 -g /desktop/gnome/url-handlers/http/need-terminal 2>/dev/null | sed -e 's/^\ *//; s/\ *$//')
36ac449
36ac449
# Check if browser really exists
36ac449
which $GCONF 2> /dev/null > /dev/null
36ac449
if [ $? -ne 0 ]; then
36ac449
    error_exit "ERROR: The browser $GCONF specified in Preferences -> Preferred Applications does not exist."
36ac449
fi
36ac449
36ac449
# Check if text-mode browser
36ac449
if [ "$NEEDTERM" == "true" ]; then
36ac449
    PREFTERM=$(gconftool-2 -g /desktop/gnome/applications/terminal/exec 2>/dev/null | sed -e 's/^\ *//; s/\ *$//')
36ac449
    TERMARGS=$(gconftool-2 -g /desktop/gnome/applications/terminal/exec_arg 2>/dev/null | sed -e 's/^\ *//; s/\ *$//')
36ac449
    # Check if terminal exists
36ac449
    which $PREFTERM 2> /dev/null > /dev/null
36ac449
    if [ $? -ne 0 ]; then
36ac449
        error_exit "ERROR: The terminal $GCONF specified in Preferences -> Preferred Applications does not exist."
36ac449
    fi
36ac449
    # Execute
36ac449
    exec $PREFTERM $TERMARGS $GCONF "$url"
36ac449
fi
36ac449
36ac449
exec $GCONF "$url"
36ac449