#! /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

## -

ICON=applications-development

case $LANG in
  ca*)
    TIT="Restaurar MiniNo"
    WAR="\n\t<big><b>ADVERTÈNCIA</b></big>  \n\n Aquesta és una solució d'emergència per quan un  \n usuari manasses destrossa la configuració de minino.  \n\n Apliqui-la <big>solo</big> si està absolutament segur del  \n que fa, ja que pot perdre alguna configuració  \n que hagi fet vostè.  \n\n Vol restaurar la configuració de l'escriptori als seus  \n <b>valors predeterminats inicials</b>? " 
    CONFIRM="\n<big><b>Per la seva seguretat</b>  \n\n Disculpi que insistim.</big>  \n\n Està segur de voler restaurar la  \n configuració del escriptori als seus  \n <b>valors predeterminats inicials</b>? "
    MSG="\n Aplicant els canvis.  \n "
    BUT1="_Restaurar"
    BUT2="_Abandonar"
    PTXT="RESTAURAT"
  ;;
  es*)
    TIT="Restaurar MiniNo"
    WAR="\n\t<big><b>ADVERTENCIA</b></big>  \n\n Esta es una solución de emergencia para cuando un  \n usuario manazas destroza la configuración de minino.  \n\n Aplíquela <big>solo</big> si está absolutamente seguro de lo  \n que hace, ya que puede perder alguna configuración  \n que haya hecho usted.  \n\n ¿Quiere restaurar la configuración del escritorio a sus  \n <b>valores predeterminados iniciales</b>? " 
    CONFIRM="\n<big><b>Por su seguridad</b>  \n\n Disculpe que insistamos.</big>  \n\n Está seguro de que quiere restaurar la  \n configuración del escritorio a sus  \n <b>valores predeterminados iniciales</b>? "
    MSG="\n Aplicando los cambios.  \n "
    BUT1="_Restaurar"
    BUT2="_Abandonar"
    PTXT="RESTAURADO"
  ;;
  gl*)
    TIT="Restaurar MiniNo"
    WAR="\n\t<big><b>ADVERTENCIA</b></big>  \n\n Esta é unha solución de emerxencia para cando un  \n usuario zoupón escangalla a configuración do minino.  \n\n Aplíquea <big>só</big> se está absolutamente seguro do que  \n fai, xa que pode perder algunha configuración que  \n teña feito vostede.  \n\n Quere restaurar a configuración do escritorio aos  \n seus <b>valores predeterminados iniciais</b>?  " 
    CONFIRM="\n<big><b>Pola súa seguranza</b>  \n\n Desculpe que insistamos.</big>  \n\n Esta seguro de que quere restaurar a  \n configuración do escritorio aos seus  \n <b>valores predeterminados iniciais</b>?  "
    MSG="\n Aplicando os cambios.  \n "
    BUT1="_Restaurar"
    BUT2="_Abandonar"
    PTXT="RESTAURADO"
  ;;
  *)
    TIT="MiniNo Restore"
    WAR="\n\t<big><b>WARNIG</b></big>  \n\n This is an emergency solution when a butterfingers  \n user destroys the minino configuration.  \n\n Apply it <big>only</big> if you are absolutely sure what it does,  \n as you may lose some settings that yo have made.  \n\n He wants to restore your desktop settings to their  \n <b>out of the box default values</b>?  " 
    CONFIRM="\n<big><b>For your safety</b>  \n\n Sorry to insist.</big>  \n\n Are you sure to want restore your  \n desktop settings to their  \n <b>Out of the box default values</b>?  "
    MSG="\n Applying the changes.  \n "
    BUT1="_Restore"
    BUT2="_Abort"
    PTXT="RESTORED"
  ;;
esac

function progressBar(){
#    tail -f $0 | \
    yad --progress --pulsate --progress-text $PTXT \
	--window-icon $ICON --image $ICON \
	--title "$TIT" --text "$MSG" 
}

function restoreConfig(){
    rsync -a /etc/skel/ $HOME/ |progressBar
# sustituir rutina de prueba por la orden correcta a ejecutar
#    x=1
#    while [ $x -le 60000 ]; do x=$((x + 1)); echo $x; done
}

yad --window-icon $ICON --image $ICON \
    --button "$BUT1":0 --button "$BUT2":1 --title "$TIT" --text "$WAR"
  ret=$?
  [ $ret = 1 ] && exit 0

yad --window-icon $ICON --image $ICON \
    --button "$BUT1":0 --button "$BUT2":1 --title "$TIT" --text "$CONFIRM"
  ret=$?
  [ $ret = 1 ] && exit 0 || restoreConfig
