# !/bin/sh
#
# streamtuner-theme-convert
# A script converting streamtuner and Galeon themes to GTK+ themes.
#
# Generated automatically from streamtuner-theme-convert.m4.
# Do not edit this file directly.
#
# Copyright (c) 2003, 2004 Jean-Yves Lefort
# All rights reserved.
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions
# are met:
# 1. Redistributions of source code must retain the above copyright
#    notice, this list of conditions and the following disclaimer.
# 2. Redistributions in binary form must reproduce the above copyright
#    notice, this list of conditions and the following disclaimer in the
#    documentation and/or other materials provided with the distribution.
# 3. Neither the name of Jean-Yves Lefort nor the names of its contributors
#    may be used to endorse or promote products derived from this software
#    without specific prior written permission.
#
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND
# CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
# INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
# MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
# DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS
# BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
# EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED
# TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
# ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
# OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
# OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
# POSSIBILITY OF SUCH DAMAGE.

if test $# -ne 2; then
	echo "Usage: streamtuner-theme-convert SOURCE_DIRECTORY TARGET_DIRECTORY"
	exit 1
fi

indir="$1"
outdir="$2"

gtkdir="$outdir/gtk-2.0"
gtkrc="$gtkdir/gtkrc"

# sanity checks

if test -e "$indir"; then :; else
	echo "streamtuner-theme-convert: $indir not found"
	exit 1
fi
if test -d "$indir"; then :; else
	echo "streamtuner-theme-convert: $indir is not a directory"
	exit 1
fi
if test -e "$outdir"; then
	echo "streamtuner-theme-convert: $outdir exists, refusing to overwrite"
	exit 1
fi

# find images

img_tune_in=
img_tune_in_prelight=
test -f "$indir/Forward.png" && img_tune_in="$indir/Forward.png"
test -f "$indir/Forward-prelight.png" && img_tune_in_prelight="$indir/Forward-prelight.png"
test -f "$indir/tune_in.png" && img_tune_in="$indir/tune_in.png"
test -f "$indir/tune_in-prelight.png" && img_tune_in_prelight="$indir/tune_in-prelight.png"
img_record=
img_record_prelight=
test -f "$indir/New.png" && img_record="$indir/New.png"
test -f "$indir/New-prelight.png" && img_record_prelight="$indir/New-prelight.png"
test -f "$indir/record.png" && img_record="$indir/record.png"
test -f "$indir/record-prelight.png" && img_record_prelight="$indir/record-prelight.png"
img_browse=
img_browse_prelight=
test -f "$indir/Home.png" && img_browse="$indir/Home.png"
test -f "$indir/Home-prelight.png" && img_browse_prelight="$indir/Home-prelight.png"
test -f "$indir/browse.png" && img_browse="$indir/browse.png"
test -f "$indir/browse-prelight.png" && img_browse_prelight="$indir/browse-prelight.png"

# convert theme

if mkdir -p "$gtkdir"; then :; else
	echo "streamtuner-theme-convert: unable to create $gtkdir"
	exit 1
fi

cat <<EOF > "$gtkrc"
style "streamtuner"
{
EOF

if test -z "$img_tune_in"; then :; else
	cp -f "$img_tune_in" "$gtkdir/st-tune-in.png"
	cat <<EOF >> "$gtkrc"
	stock["st-tune-in"] =
	{
EOF

	if test -z "$img_tune_in_prelight"; then
		cat <<EOF >> "$gtkrc"
		{ "st-tune-in.png",		*, *,		* }
	}
EOF
	else
		cp -f "$img_tune_in_prelight" "$gtkdir/st-tune-in-prelight.png"
		cat <<EOF >> "$gtkrc"
		{ "st-tune-in.png",		*, *,		* },
		{ "st-tune-in-prelight.png",	*, PRELIGHT,	* }
	}
EOF
	fi
fi
if test -z "$img_record"; then :; else
	cp -f "$img_record" "$gtkdir/st-record.png"
	cat <<EOF >> "$gtkrc"
	stock["st-record"] =
	{
EOF

	if test -z "$img_record_prelight"; then
		cat <<EOF >> "$gtkrc"
		{ "st-record.png",		*, *,		* }
	}
EOF
	else
		cp -f "$img_record_prelight" "$gtkdir/st-record-prelight.png"
		cat <<EOF >> "$gtkrc"
		{ "st-record.png",		*, *,		* },
		{ "st-record-prelight.png",	*, PRELIGHT,	* }
	}
EOF
	fi
fi
if test -z "$img_browse"; then :; else
	cp -f "$img_browse" "$gtkdir/st-browse.png"
	cat <<EOF >> "$gtkrc"
	stock["st-browse"] =
	{
EOF

	if test -z "$img_browse_prelight"; then
		cat <<EOF >> "$gtkrc"
		{ "st-browse.png",		*, *,		* }
	}
EOF
	else
		cp -f "$img_browse_prelight" "$gtkdir/st-browse-prelight.png"
		cat <<EOF >> "$gtkrc"
		{ "st-browse.png",		*, *,		* },
		{ "st-browse-prelight.png",	*, PRELIGHT,	* }
	}
EOF
	fi
fi

cat <<EOF >> "$gtkrc"
}

widget_class "*" style "streamtuner"
EOF
