#!/bin/bash

# opencocon option menu

SELECT=/tmp/.cocon.menu.select

# If copy-to-ram mode, show eject menu.
if [ "$COCON_COPYTORAM" = "1" ];
then
  menu_eject="EJECT"
  menu_eject_desc="Eject unused boot device"
else
  menu_eject="----"
fi


while :
do

  dialog --no-cancel --menu "Option, Ambient tools" 20 60 25 \
  MIX   "Sound mixer" \
  SNDT  "Sound test (Caution: play noise sound!)" \
  TPAD  "Touchpad calibration" \
  IMAGE "Image viewer (Incomplete)" \
  RANDR "Change resolution, output of screen" \
  KBD   "Change keyboard layout" \
  "$menu_eject" "$menu_eject_desc" \
  RET   "Return to main menu" 2>$SELECT

  select=`cat $SELECT`

  case $select in
  MIX)
    alsamixer
    ;;

  SNDT)
    aplay /usr/share/sounds/alsa/Noise.wav
    ;;

  TPAD)
    xinput_calibrator_once.sh
    ;;

  IMAGE)
    ssdir="/media/cf/media/realroot/coconpic/"
    if [ -d "$ssdir" ];
    then
      echo "Using slideshow directory on realroot"
    else
      echo "Using pre-installed slideshow"
      ssdir="/usr/share/cocon/pic/"
    fi
     
    viewnior --slideshow --fullscreen $ssdir
    ;;

  RANDR)
    lxrandr
    ;;

  KBD)
    cocon-select-kbd
    ;;

  EJECT)
    # TODO: use sudo
    su -c "eject.eject $ROOT_DEVICE"
    ;;

  RET)
    exit 1
    ;;


  esac

done

