#!/bin/bash

# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.

# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.

# You should have received a copy of the GNU General Public License
# along with this program.  If not, see <http://www.gnu.org/licenses/>

# (c) Antonio Sánchez León <introlinux[fix@]gmail[fix.]com>
# (c) Miguel Anxo Bouzada <mbouzada[fix@]gmail[fix.]com>
# (c) GALPon MinNo Team <minino[fix@]galpon[fix.]org>
# july 2012

## -

# Script para capturas de pantalla
# Este script depende de "scrot" y de "yad"
# Para instalarlos, en Debian y derivadas, ejecute:
# # (ó sudo) apt-get intall scrot yad
# Es probable que para «yad» tenga que configurar un repositorio

case $LANG in
    ca*)
        TITLE1="Captura de pantalla"
        TITLE2="Trieu el mode de captura"
        TITLE3="Trieu el temps de retard.
		\nEn les captures a <b>pantalla complerta</b> el temps comença a comptar
quant premi <b>Acceptar</b>
		\nEn les captures de <b>Finestra en focus AMB marc</b> el temps comença
a comptar quant premi <b>finestra</b>
		\nLa selecció de <b>Finestra en focus SENSE marc</b> o <b>Àrea seleccionada</b>
té dues opcions:
			<b>Prémer amb el punter a la finestra</b>:
				Obtindrà una captura d'aquesta finestra sense marc,
				el temps comença a comptar després de prémer.
			<b>Seleccionar un àrea rectangular</b>. Prémer en un
                                punt de la pantalla arrossegant el punter sobre
                                la pantalla, veureu una selecció rectangular.
				Es realitzarà una captura d'aquesta àrea seleccionada,
                                El temps comença a comptar quan deixi anar el
                                botó del ratolí"
        SEL1="Pantalla complerta."
	SEL2="Finestra en focus AMB marc"
        SEL3="Finestra en focus SENSE marc
ó Àrea seleccionada"
	SEL4="Captura de vídeo"
	SAVE="Desa com..."
	CAP="Captura_"
	DIR="Imatges"
    ;;
    es*)
        TITLE1="Captura de pantalla"
        TITLE2="Escoja el modo de captura"
        TITLE3="Escoja el tiempo de retardo
en segundos."
        SEL1="Pantalla completa."
	SEL2="Ventana CON marco"
        SEL3="Área seleccionada"
	SEL4="Captura de vídeo"
	SAVE="Guardar como..."
	CAP="Captura_"
	DIR="Imágenes"
        ;;
    gl*)
        TITLE1="Captura de pantalla"
        TITLE2="Escolla o modo de captura"
        TITLE3="Escolla o tempo de retardo.
		\nNas capturas a <b>Pantalla completa</b> o tempo comeza a contar ao
premer en <b>Aceptar</b>
		\nNas capturas de <b>Xanela en foco CON marco</b> o tempo comeza a contar ao
premer na <b>xanela</b>
		\nA selección de <b>Xanela en foco SEN marco</b> ou <b>Área seleccionada</b>
ten dúas opcións:
			<b>Premer co punteiro na xanela</b>:
				Obterá unha captura desa xanela sen marco.
				O tempo comeza a contar despois de premer.
			<b>Seleccionar unha área rectangular</b>:
				Prema nun punto da pantalla e arrastre o punteiro
				sobre a pantalla, verá unha selección rectangular.
				Realizaráse unha captura desa área seleccionada,
				o tempo comeza a contar ao soltar o botón do rato"
        SEL1="Pantalla completa."
	SEL2="Xanela en foco CON marco"
        SEL3="Xanela en foco SEN marco
ou Área seleccionada"
	SEL4="Captura de vídeo"
	SAVE="Gardar como..."
	CAP="Captura_"
	DIR="Imaxes"
        ;;
    *)
        TITLE1="Screenshot"
        TITLE2="Choose Capture Mode"
        TITLE3="Choose Delay Time.
		\nIn the <b>Full Screen</b> mode, timeout starts as soon as you
press <b>OK</b>
		\nIn the <b>Window in focus WITH frame</b> timeout starts when you click the <b>window</b>
		\nYou have two options for <b>Window in focus whithout frame</b> or
<b>Selected area</b>:
			<b>To click in the window</b>
				You will get an screenshot of that window without
				frame, the time starts counting as soon as you
				click on it.
			<b>To select a rectangular area</b>. Drag &amp; drop the pointer
				over the area you want. It will be captured the area you
				chose.
				The time starts counting as soon as you free the mouse"
        SEL1="Full Screen"
	SEL2="Window in focus Whith frame"
        SEL3="Area selected"
	SEL4="Video capture"
	SAVE="Save as..."
	CAP="Capture_"
	DIR="Images"
        ;;
esac

function Guardar(){
    cd $HOME

    # Asignamos valor fecha/hora para nombrar capturas
    /bin/date > /tmp/hora.txt
    HORA=`cat /tmp/hora.txt | cut -c1-19; echo`

    captura=$(yad --window-icon applets-screenshooter \
	--title "$SAVE" --file-selection \
	--filename "$HOME/$DIR/$CAP$HORA" \
	--width 640  --height 480 \
	--save --confirm-overwrite || exit )
    mv /tmp/captura.png  "$captura.png"
}

MODE=$(yad --window-icon applets-screenshooter \
	--title "$TITLE1" --text "$TITLE2" \
	--list --print-column 1 --no-headers \
	--image applets-screenshooter --width 300 --height 180 \
	--column "control" --column "acción":tip --hide-column 1 \
    C "$SEL1" \
    B "$SEL2" \
    A "$SEL3" \
    D "$SEL4" )

case $? in
      0)
        if [ "$MODE" = "C|" ]; then
    TIME=$(yad --window-icon applets-screenshooter --scale --title "$TITLE1" --text "$TITLE3" \
    --image applets-screenshooter --min-value=0 --max-value=30 --value=0 --step 1)

          scrot -q 1 -d $TIME /tmp/captura.png ; Guardar
        elif [ "$MODE" = "A|" ]; then
    TIME=$(yad --window-icon applets-screenshooter --scale --title "$TITLE1" --text "$TITLE3" \
    --image applets-screenshooter --min-value=0 --max-value=30 --value=0 --step 1)

          scrot -q 1 -s -d $TIME /tmp/captura.png ; Guardar
        elif [ "$MODE" = "B|" ]; then
    TIME=$(yad --window-icon applets-screenshooter --scale --title "$TITLE1" --text "$TITLE3" \
    --image applets-screenshooter --min-value=0 --max-value=30 --value=0 --step 1)

          scrot -q 1 -s -b -d $TIME /tmp/captura.png ; Guardar
        elif [ "$MODE" = "D|" ]; then
    #minino-kazam
    minino-simplescreenrecorder
        else
          exit
        fi
        ;;
      1) exit ;;
      255) exit ;;
    esac



