#!/bin/sh
#Lesser GPL licence v2 (/usr/share/doc/legal/lgpl-2.1.txt). 2007 www.puppylinux.com
#120201 internationalized.
#120226 01micko: test screensize and set SCROLLABLE variable.
#120706 change gtkdialog3 to gtkdialog4.
#120724 alsaconf does not work on arm boards. refer 3builddistro.
#151105 change gtkdialog4 to gtkdialog.

export TEXTDOMAIN=alsawizard
export OUTPUT_CHARSET=UTF-8

. /etc/rc.d/BOOTCONSTRAINED #120724

#if [ "`/etc/rc.d/rc.alsa status | grep "not loaded"`" = "" ];then
# Xdialog --title "ALSA sound Wizard" --yesno "ALSA sound modules are currently loaded and active.\n
#If you answer Yes here, modules will be unloaded,\nand the Wizard will continue.\nAnswer No, Wizard will exit..." 0 0
# [ ! $? -eq 0 ] && exit
# /etc/rc.d/rc.alsa stop
#fi

#...above not necessary, alsaconf does it.

#100501 weird, nvidia xorg pet pkg seems to need the files created by busybox depmod,
#however alsaconf has been modified to run depmod-FULL. so, rerun busybox depmod after...

#120226 01micko: test screensize and set SCROLLABLE variable
SCRNSIZE="`xwininfo -root|grep -iE "height"|cut -d ':' -f2`"
if [ "$SCRNSIZE" -le "600" ];then #kicks in at 800x600resolution, eee-701 is 800x480
 SCROLLABLE=" scrollable=\"true\" height=\"340\" width=\"450\"" #leading space is essential
else
 SCROLLABLE=" scrollable=\"false\""
fi

#110513 put up a preliminary dlg...
AUDIOICON='/usr/local/lib/X11/mini-icons/mini-speaker.xpm'
[ -f /usr/share/retrovol/images/working.png ] && AUDIOICON='/usr/share/retrovol/images/working.png'
#/usr/local/apps/ROX-Filer/ROX/MIME/audio.png

#   <frame THREE: Reboot>
#    <text><label>It is unusual, but presuming that you have booted Puppy for the first time, sometimes you have to shutdown (and create a session save-file) and reboot for sound to work. Various peripherals, especially modems, may have conflicting kernel sound driver requirements, which might not get sorted out until the second boot. If you played with the mixer settings but your sound is still not working, it is recommended that you still do not run the ALSA Wizard, instead choose to reboot (see menu). Recommend click 'EXIT' button below.</label></text>
#   </frame>

#120724 alsaconf does not work on arm boards. refer 3builddistro.
if [ "$BOOT_DISABLEALSACONF" = "yes" ];then #see /etc/rc.d/BOOTCONSTRAINED
 AC1_XML=""
 AC2_XML=""
else
 AC1_XML="<text><label>`gettext \"FOUR: After trying ONE, TWO, THREE above, sound still not working, click 'ALSA Wizard' button:\"`</label></text>"
 AC2_XML="
     <button>
       <label>$(gettext 'ALSA Wizard')</label>
       <action type=\"exit\">RUNALSA</action>
     </button>"
fi

export ASKDIALOG="
<window title=\"$(gettext 'Sound Wizard')\" window_position=\"1\">
  <vbox${SCROLLABLE}>

   <text use-markup=\"true\"><label>\"<big>$(gettext 'Welcome to the Sound Wizard')</big>\"</label></text>
   <text><label>$(gettext 'Presumably you are here because sound does not work? If so, here are steps to follow, to hopefully fix sound...')</label></text>

   <frame $(gettext 'ONE: Adjust levels')>
    <hbox>
     <text><label>$(gettext 'Often non-working sound is just a matter of unmuting (tick a checkbox) and/or bring up a level in the audio mixer. Click this button to run the mixer:')</label></text>
     <vbox><button><input file>${AUDIOICON}</input><action>/usr/local/bin/defaultaudiomixer & </action></button></vbox>
    </hbox>
   </frame>
  
   <frame $(gettext 'TWO: Play test sound')>
    <hbox>
     <text><label>$(gettext 'Having adjusted the levels, click this button to play a test sound:')</label></text>
     <vbox><button><input file>${AUDIOICON}</input><action>/usr/bin/aplay /usr/share/audio/2barks.au & </action></button></vbox>
    </hbox>
    <hbox>
     <text><label>$(gettext 'On some hardware (very rare fortunately) sound plays but does not always stop! If your Puppy will not stop barking, click this button:')</label></text>
     <vbox><button><input file>/usr/local/lib/X11/mini-icons/mini-stop.xpm</input><action>/usr/bin/killall aplay</action></button></vbox>
    </hbox>
   </frame>
   
   <frame $(gettext 'THREE: Multiple cards')>
    <hbox>
     <text><label>`gettext \"Linux may have detected more than one audio interface or 'card', and has set the wrong one as default. Run Kirk's Multiple Sound Card Wizard to investigate this (note, a reboot is required for change to take effect):\"`</label></text>
     <vbox><button><input file>${AUDIOICON}</input><action>/usr/bin/Multiple-Sound-Card-Wizard & </action></button></vbox>
    </hbox>
   </frame>
  
   ${AC1_XML}
  
    <hbox>
     ${AC2_XML}
     <button>
       <label>$(gettext 'EXIT')</label>
       <action type=\"exit\">EXIT</action>
     </button>
    </hbox>

  </vbox>
</window>
"
RETVAL="`gtkdialog --program=ASKDIALOG 2>/dev/null`"
eval "$RETVAL"
[ "$EXIT" != "RUNALSA" ] && exit

#/usr/sbin/alsaconf #101015
rxvt -geometry 60x3 -bg orange -e /usr/sbin/alsaconf

#depmod
