#!/bin/sh
# <BEGIN COPYRIGHT>
# @2000 by Antonio Gallo - agx@linux.it - www.badpenguin.org
# This file is part of the BAD PENGUIN distribution
# This program is distributed under the GNU General Public License
# You are not allowed to remove the copyright notice
# <END COPYRIGHT>

# Programma di scelta per il background di default
# 2000-01-20, Versione 0.0.1 by AGX

# Temps
TEMPDIR="$HOME/tmp"
[ ! -d $TEMPDIR ] && mkdir -p $TEMPDIR
TEMPSCRIPT=$TEMPDIR/tempscript.$$
TEMPDATA=$TEMPDIR/tempdata.$$
trap 'rm -f $TEMPSCRIPT $TEMPDATA ; exit $USCITA' 0

# Prepare View
echo "Lettura della directory backgrounds in corso ..."
>$TEMPDATA
for i in /usr/share/backgrounds/*
do
  [ ! -f $i ] && continue
  echo -n "`basename $i`::"  >>$TEMPDATA
done

# Hot fix: no SM Installed
if [ "`cat $TEMPDATA`" = "" ]; then
  echoc YELLOW "Nessun background e' disponibile !"
  exit 1
fi

# Show dialog
IFS=":"
dialog \
  --title "Scelta del Session Manager" \
  --menu "\nScegli il tuo Session Manager preferito \n" 0 0 0 `cat $TEMPDATA` \
  2>$TEMPSCRIPT
if [ $? -ne 0 ]; then
  echo "- Nessuna scelta operata"
  exit
fi

# Save data
SM_NAME=`cat $TEMPSCRIPT`
echo "/usr/share/background/$SM_NAME" > $HOME/.BACKGROUND
echoc GREEN "- Il background e' ora $SM_NAME"
