### Copyright (C) 1995, 1996, 1997 Jeppe Buk (buk@imada.sdu.dk)
### 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 2 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, write to the Free Software
### Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.

proc FvwmAudio {} {
  # Modules / FvwmAudio
  Desc "Configuration of the FvwmAudio module"
  ShortDesc "FvwmAudio"

  Header h -text "FvwmAudio" -frame:relief flat \
      -help "On this page you configure the FvwmAudio module. This"\
      "module is used for associating sounds to window manager events."
  Line l
  CheckBox spawn -text "Spawn this module when Fvwm2 starts" \
      -help "If you check this option the module will be spawned from"\
      "the two functions 'InitFunction' and 'RestartFunction'. You will"\
      "not have to insert them yourself then."

  CheckBox explay -text "Specify external play command" -help "If your"\
      "Fvwm2 hasn't been compiled with built-in support for rplay you"\
      "can specify any external command to use for playing sounds."
  Entry playcmd -help "If your"\
      "Fvwm2 hasn't been compiled with built-in support for rplay you"\
      "can specify any external command to use for playing sounds."
  Frame playF -entries { explay playcmd } 
  CheckBox rplay -text "Use built-in rplay to play sounds" -help "If"\
      "your Fvwm2 has been compiled with built-in support for rplay you"\
      "can use this support for playing sound files (probably faster"\
      "than spawning an external program)."
  Entry rplayhost -text "     Specify rplay host" -help "Here you can"\
      "specify what host the sounds will play on. The hostname can also"\
      "be an environment variable such as \$RPLAYHOST."
  Int rplaypriority -text "     Specify rplay priority" -help "This"\
      "specifies what priority will be assigned to the sounds when they"\
      "are played (sorry, I don't know more about this setting)."
  Int rplayvolume -text "     Specify rplay volume" -help "This"\
      "specifies the volume assigned to the sounds when they are"\
      "played."
  Dir-Browser dir -text "Directory to look for sound files"

  foreach widget { dir com_dir } {
    Help $widget "Here"\
	"you can specify the directory in which FvwmAudio will look for"\
	"sound files.  This directory will be used for the file browser"\
	"below too."
  }
  Int delay -text "Minimum delay between sounds" -textafter seconds -help \
      "Here you specify the minimum delay between sound events. If you set"\
      "this to e.g. 5 seconds events occuring during the first 5"\
      "seconds after an event will be ignored. This is useful if you"\
      "want to avoid too many sounds playing at the same time."\
      ""

  Label lab -text "Sounds to play" -help "In this extended entry you"\
      "can specify a sound file to play for every existing event."
  Entry event -text Event -help "Select an event from this index entry,"\
      "and associate to it a sound file."
  File-Browser file -text "Sound file" -dir \$dir

  foreach widget { file com_file } {
    Help $widget "Using this"\
	"file browser you can select a file from the directory you"\
	"specified above. You can also enter a file name yourself."
  }

  ExtEntry events -entries { event frame_file } -default {
    startup shutdown unknown add_window raise_window lower_window
    focus_change destroy_window iconify deiconify toggle_paging
    new_page new_desk configure_window window_name icon_name
    res_class res_name end_windowlist
  } -maxentries 19 -index event -noscissor 1

  Change {
    if { $changeElm == "rplay" } {
      if { $rplay == 1 } {
	set explay 0
	Disable playcmd
	Enable rplayhost
	Enable rplaypriority
	Enable rplayvolume
      } else {
	Disable rplayhost
	Disable rplaypriority
	Disable rplayvolume
      }
    }
    if { $changeElm == "explay" } {
      if { $explay == 1 } {
	set rplay 0
	Enable playcmd
	Disable rplayhost
	Disable rplaypriority
	Disable rplayvolume
      } else {
	Disable playcmd
      }
    }
  }

  Save {
    if {$explay == 1} {if {$playcmd != ""} {print "*FvwmAudioPlayCmd\t$playcmd"
    } else { error "Invalid external play command in FvwmAudio" }}
    if {$rplay         ==  1} {print "*FvwmAudioPlayCmd\tbuiltin-rplay"}
    if {$rplayhost     != ""} {print "*FvwmAudioRplayHost\t$rplayhost"}
    if {$rplaypriority != ""} {print "*FvwmAudioRplayPriority\t$rplaypriority"}
    if {$rplayvolume   != ""} {print "*FvwmAudioRplayVolume\t$rplayvolume"}
    if {$dir           != ""} {print "*FvwmAudioDir\t$dir"}
    if {$delay         != ""} {print "*FvwmAudioDelay\t$delay"}
    forevery events {
      if {$file != ""} {print "*FvwmAudio $event\t$file"}
    }
    if {$spawn == 1} {
      print "AddToFunc InitFunction \"I\" Module FvwmAudio"
      print "AddToFunc RestartFunction \"I\" Module FvwmAudio"
    }
  }
}
