#!/bin/bash
#this generates xml code for a gtkdialog gui.
#it is NOT a standalone window
#
#the reason for using this template is to control size and source for all popups
#
#usage :
# xml_pixmap ICON SIZE
#
# ICON can either be a gtk stock icon, a normal raster/vector file or no icon. if no path is set, /usr/share/pixmaps/puppy/ is used
# SIZE can be an integer or one of the templates (popup, icon, big or huge). Anything else sets size to buttonsize
#
#Sigmund Berglund, dec 2013
#GPL

#either use Puppy-stock icons (puppy) or Gtk-stock icons (gtk)
STOCK=puppy
#STOCK=gtk

#define icon
case $1 in
	/*svg)
		#icon from svg file
		ICON="<input file>${1}</input>"
		;;
	*.svg)
		#icon from puppy stock
		ICON="<input file>/usr/share/pixmaps/puppy/${1}</input>"
		;;
	/*)
		#icon from file
		ICON="<input file>${1}</input>"
		;;
	0|none|' '|'')
		ICON=""
		;;
	*) 
		#stock icon - use either Gtk-stock or Pyppy-stock
		if [ "$STOCK" = "puppy" ] && [ -s "/usr/share/pixmaps/puppy/${1}.svg" ]; then
			ICON="<input file>/usr/share/pixmaps/puppy/${1}.svg</input>"
		else
			ICON="<input file stock=\"gtk-${1}\"></input>"
		fi
esac

#read config if exist
[ -s $HOME/.config/ptheme/gtkdialog_active ] && . $HOME/.config/ptheme/gtkdialog_active
[ ! "$XML_PIXMAP_HEIGHT_HUGE" ]		&& XML_PIXMAP_HEIGHT_HUGE=100
[ ! "$XML_PIXMAP_HEIGHT_BIG" ]		&& XML_PIXMAP_HEIGHT_BIG=60
[ ! "$XML_PIXMAP_HEIGHT_ICON" ]		&& XML_PIXMAP_HEIGHT_ICON=48
[ ! "$XML_PIXMAP_HEIGHT_NORMAL" ]	&& XML_PIXMAP_HEIGHT_NORMAL=20

if [ "$ICON" ]; then
	case $2 in
		huge)
			HEIGHT="<height>$XML_PIXMAP_HEIGHT_HUGE</height>"
			;;
		popup|big)
			HEIGHT="<height>$XML_PIXMAP_HEIGHT_BIG</height>"
			;;
		icon)
			HEIGHT="<height>$XML_PIXMAP_HEIGHT_ICON</height>"
			;;
		[1-9]*)
			HEIGHT="<height>$2</height>"
			;;
		*)
			HEIGHT="<height>$XML_PIXMAP_HEIGHT_NORMAL</height>"
			;;
	esac
fi
	
#generate XML code
echo "<pixmap space-expand=\"false\" space-fill=\"false\">$ICON $HEIGHT</pixmap>"
