#!/bin/sh
#
# Small GTK boxes to TazPKG for deep desktop integration. PcmanFM 0.5.x has a
# patch to extract a TazPKG file but not Thunar and other FM. TazPKGbox tries
# to follow freedesktop standards.
#
# Copyright (C) 2012 SliTaz GNU/Linux - GNU gpl v2
#
# Authors : Christophe Lincoln <pankso@slitaz.org>
#

icon="/usr/share/pixmaps/tazpkg.png"

# Main GUI box function with pure Yad spec
actions_main() {
	title=$(gettext "TazPKG actions")
	text=$(gettext "Package name:")
	yad --text="$text <b>${pkg%.tazpkg}</b>" \
		--title="$title" --width=480 --height=100 \
		--center --on-top --window-icon=$icon \
		--image="tazpkg" --image-on-top \
		--button="Install:3" --button="Extract:2" \
		--button="gtk-close:1"
}

# Actions user can do when clicking on a package.
actions() {
	# Store box results
	main=$(actions_main)
	ret=$?
	# Deal with --button values
	case $ret in
		1) exit 0 ;;
		2) tazpkg extract $pkg | $0 output ;;
		3) tazpkg -i $pkg --forced | $0 output ;;
	esac
}

#
# Script commands
#

case "$1" in
	usage|help|-u|-h)
		echo "Usage: $(basename $0) [command] [pkg|cmd]" ;;
	output)
		# Nice GTK output for install and extract.
		sed	-e s'/\[^Gm]*./ /g' -e s'/^=.*//' | \
		yad --text-info \
			--width=480 --height=260 --center --on-top \
			--title="TazPKG" --window-icon=$icon \
			--margins=4 --button="gtk-close:0" ;;
	actions)
		pkg=$(basename $2)
		cd $(dirname $2)
		actions ;;
esac

exit 0

