#!/bin/bash

#  Sparky Screenshot is a GUI frontend for scrot
#  This script requires yad to run
#
#  Created by Paweł "pavroo" Pijanowski 2013/06/30
#  Copyright 2013-2024 under the GNU GPL2 License
#  Last update 2024/07/29 by pavroo

# get default's locale file
DEFLOCDIR="/usr/share/sparky/sparky-screenshot"
if [ "`cat /etc/default/locale | grep LANG= | grep de`" != "" ]; then
. $DEFLOCDIR/de
elif [ "`cat /etc/default/locale | grep LANG= | grep el`" != "" ]; then
. $DEFLOCDIR/el
elif [ "`cat /etc/default/locale | grep LANG= | grep es`" != "" ]; then
	if [ "`cat /etc/default/locale | grep LANG= | grep es_AR`" != "" ]; then
. $DEFLOCDIR/es_AR
	else
. $DEFLOCDIR/es_ES
	fi
elif [ "`cat /etc/default/locale | grep LANG= | grep fi`" != "" ]; then
. $DEFLOCDIR/fi
elif [ "`cat /etc/default/locale | grep LANG= | grep fr`" != "" ]; then
. $DEFLOCDIR/fr
elif [ "`cat /etc/default/locale | grep LANG= | grep hu`" != "" ]; then
. $DEFLOCDIR/hu
elif [ "`cat /etc/default/locale | grep LANG= | grep id_ID`" != "" ]; then
. $DEFLOCDIR/id_ID
elif [ "`cat /etc/default/locale | grep LANG= | grep it`" != "" ]; then
. $DEFLOCDIR/it
elif [ "`cat /etc/default/locale | grep LANG= | grep ja`" != "" ]; then
. $DEFLOCDIR/ja
elif [ "`cat /etc/default/locale | grep LANG= | grep pl`" != "" ]; then
. $DEFLOCDIR/pl
elif [ "`cat /etc/default/locale | grep LANG= | grep pt_BR`" != "" ]; then
. $DEFLOCDIR/pt_BR
elif [ "`cat /etc/default/locale | grep LANG= | grep pt_PT`" != "" ]; then
. $DEFLOCDIR/pt_PT
elif [ "`cat /etc/default/locale | grep LANG= | grep ru`" != "" ]; then
. $DEFLOCDIR/ru
elif [ "`cat /etc/default/locale | grep LANG= | grep uk`" != "" ]; then
. $DEFLOCDIR/uk
else
. $DEFLOCDIR/en
fi

DIALOG="yad --window-icon=applets-screenshooter --width=500 --height=300 --center"
TITLE="--always-print-result --dialog-sep --image=applets-screenshooter --title="
TEXT="--text="
MENU="--list --column=$LOCAL1 --column=$LOCAL2"
OKEXIT=" --button=Ok:0 --button=$LOCAL3:1 "
TITLETEXT="$LOCAL4"

mainmenu () {
CHOICES=`$DIALOG $TITLE"$TITLETEXT" $OKEXIT $MENU $TEXT"$LOCAL5" \
Screenshot_0 "$LOCAL6" \
Screenshot_10 "$LOCAL7" \
Screenshot_S "$LOCAL8"`

if [ "$?" = "0" ]; then
	CHOICE=`echo $CHOICES | cut -d "|" -f 1`
else
	exit 1
fi

if [ "$CHOICE" = "Screenshot_0" ]; then
	screenshot0menu
elif [ "$CHOICE" = "Screenshot_10" ]; then
	screenshot10menu
elif [ "$CHOICE" = "Screenshot_S" ]; then
	screenshotSmenu
else
	exit 0
fi
}

screenshot0menu () {
scrot 'screenshot_%Y-%m-%d-%s_$wx$h.png' -e 'mv $f ~/ &amp; gpicview ~/$f'

mainmenu
}

screenshot10menu () {
scrot -d 10 'screenshot_%Y-%m-%d-%s_$wx$h.png' -e 'mv $f ~/ &amp; gpicview ~/$f'

mainmenu
}

screenshotSmenu () {
scrot -s 'screenshot_%Y-%m-%d-%s_$wx$h.png' -e 'mv $f ~/ &amp; gpicview ~/$f'

mainmenu
}

mainmenu
