#!/bin/sh
# the next line restarts using wish \
exec wish "$0" "$@"

# tcl/tk front-end for vgetty allows listening/recording of 
# messages through sound card.
#
# Maintained by: Peter Bruley
# email: pbruley@highstream.net
# The latest version of this script is available from:
# ftp://alpha.greenie.net/pub/mgetty/tools/

###########################################################################

set playPID "notyet"
set tkVoice 1
set TKVREV "TKVOICE v1.2a"
set TKVDATE "March 8, 2002"
set font {Helvetica 14}


wm title . "tkVOICE"


#   READ the user preferences into the program and
#   load in some defaults if the files are not found
##############################################################################
proc startup {} {
# read in the VOICE paths information
global drawvoice tkvoicedir voicedir voicein voiceout greeting userhome
  set USERPREF ""
  set tkvoicedir [pwd]
  set FILENAME tkvoicevoice.dat
  cd ~/
  if { [file isdirectory .tkvoice] == 0} {
       catch [exec mkdir .tkvoice] }
  cd ~/.tkvoice
  set userhome [exec pwd]
  if { [file writable $FILENAME] == 1} {
   catch {set file [open $FILENAME r+]}
     while {[gets $file string] >= 0} {
       append USERPREF $string
      }
    close $file} else {
   set USERPREF "1 $tkvoicedir /var/spool/voice /incoming /messages greeting"
    }
   set drawvoice  [lindex $USERPREF 0]
   set tkvoicedir [lindex $USERPREF 1]
   set voicedir   [lindex $USERPREF 2]
   set voicein    [lindex $USERPREF 3]
   set voiceout   [lindex $USERPREF 4]
   set greeting   [lindex $USERPREF 5]

# read in the modem information
global MODEMTYPE MODEMCOMP pvfsamples
  set USERPREF ""
  set FILENAME tkvoicemodem.dat
   set datinfo [catch {set file [open $FILENAME r+]}]
   if {$datinfo == 0} {
     while {[gets $file string] >= 0} {
       append USERPREF $string
      }
    close $file} else {
   set USERPREF "US_Robotics 1 8000"
    }
   set MODEMTYPE [lindex $USERPREF 0]
   set MODEMCOMP [lindex $USERPREF 1]
   set pvfsamples [lindex $USERPREF 2]

# read in the audio information
global AUTOP playwave
  set USERPREF ""
  set FILENAME tkvoiceplaywave.dat
   set datinfo [catch {set file [open $FILENAME r+]}]
   if {$datinfo == 0} {
     while {[gets $file string] >= 0} {
       append USERPREF $string
      }
    close $file} else {
   set USERPREF "1"
    }
   set AUTOP [lindex $USERPREF 0]
   set playwave [lindex $USERPREF 1]

global AUTOR recordwave
  set USERPREF ""
  set FILENAME tkvoicerecwave.dat
   set datinfo [catch {set file [open $FILENAME r+]}]
   if {$datinfo == 0} {
     while {[gets $file string] >= 0} {
       append USERPREF $string
      }
    close $file} else {
   set USERPREF "1"
    }
   set AUTOR [lindex $USERPREF 0]
   set recordwave [lindex $USERPREF 1]
# record time in seconds (not worth saving this)
global rectime
   set rectime 10

# read in the FAX paths information
global drawfax faxdir faxin faxout faxdpi printcmd printsel
  set USERPREF ""
  set FILENAME tkvoicefax.dat
  cd ~/
  if { [file isdirectory .tkvoice] == 0} {
       catch [exec mkdir .tkvoice] }
  cd ~/.tkvoice
  if { [file writable $FILENAME] == 1} {
   catch {set file [open $FILENAME r+]}
     while {[gets $file string] >= 0} {
       append USERPREF $string
      }
    close $file} else {
   set USERPREF "1 /var/spool/fax /incoming /outgoing 206 {lpr -P} {}"
    }
   set drawfax  [lindex $USERPREF 0]
   set faxdir   [lindex $USERPREF 1]
   set faxin    [lindex $USERPREF 2]
   set faxout   [lindex $USERPREF 3]
   set faxdpi   [lindex $USERPREF 4]
   set printcmd [lindex $USERPREF 5]
   set printsel [lindex $USERPREF 6]
}
################ END proc startup ##################################
# now run the startup proc or the rest of the script will bomb
startup

####################################################################
#   Process to save the paths preferences
proc savevoice {} {
global drawvoice tkvoicedir voicedir voicein voiceout greeting
  set USERPREF ""
  set SAVENAME "tkvoicevoice.dat"
  cd ~/
  if { [file isdirectory .tkvoice] == 0} {
       catch [exec mkdir .tkvoice] }
  cd ~/.tkvoice
  if { [file isfile $SAVENAME] == 1} {
       catch [exec rm $SAVENAME] }
  catch [exec touch $SAVENAME]
  set file [open "$SAVENAME" r+]
  foreach x "$drawvoice $tkvoicedir $voicedir $voicein $voiceout $greeting" {
    append USERPREF "$x\ "
  }
  puts $file $USERPREF
  close $file
}

#   Process to save the Modem preferences
proc savemodem {} {
global MODEMTYPE MODEMCOMP pvfsamples
  set USERPREF ""
  set SAVENAME "tkvoicemodem.dat"
  cd ~/
  if { [file isdirectory .tkvoice] == 0} {
       catch [exec mkdir .tkvoice] }
  cd ~/.tkvoice
  if { [file isfile $SAVENAME] == 1} {
       catch [exec rm $SAVENAME] }
  catch [exec touch $SAVENAME]
  set file [open "$SAVENAME" r+]
  foreach x "$MODEMTYPE $MODEMCOMP $pvfsamples" {
    append USERPREF "$x\ "
  }
  puts $file $USERPREF
  close $file
}

#   Process to save the audio command and arguments
# save the playwave command and arguements
proc saveaudio {} {
global AUTOP playwave
  set USERPREF ""
  set SAVENAME "tkvoiceplaywave.dat"
  cd ~/
  if { [file isdirectory .tkvoice] == 0} {
       catch [exec mkdir .tkvoice] }
  cd ~/.tkvoice
  if { [file isfile $SAVENAME] == 1} {
       catch [exec rm $SAVENAME] }
  catch [exec touch $SAVENAME]
  set file [open "$SAVENAME" r+]
    append USERPREF "{$AUTOP}\ {$playwave}"
  puts $file $USERPREF
  close $file
global AUTOR recordwave
  set USERPREF ""
  set SAVENAME "tkvoicerecwave.dat"
  cd ~/.tkvoice
  if { [file isfile $SAVENAME] == 1} {
       catch [exec rm $SAVENAME] }
  catch [exec touch $SAVENAME]
  set file [open "$SAVENAME" r+]
    append USERPREF "{$AUTOR}\ {$recordwave}"
  puts $file $USERPREF
  close $file
}
#   Process to save the FAX preferences
proc savefax {} {
global drawfax faxdir faxin faxout faxdpi printcmd printsel
  set USERPREF ""
  set SAVENAME "tkvoicefax.dat"
  cd ~/
  if { [file isdirectory .tkvoice] == 0} {
       catch [exec mkdir .tkvoice] }
  cd ~/.tkvoice
  if { [file isfile $SAVENAME] == 1} {
       catch [exec rm $SAVENAME] }
  catch [exec touch $SAVENAME]
  set file [open "$SAVENAME" r+]
append USERPREF "{$drawfax}\ {$faxdir}\ {$faxin}\ {$faxout}\ {$faxdpi}\ {$printcmd}\ {$printsel}"
  puts $file $USERPREF
  close $file
}

################# END proc savevoice ##############################

proc play_audio {} {
global fnlist AUTOP tkvoicedir pvfsamples playwave voicedir voicein playPID userhome

  foreach i [.v.voice.list curselection] {
    set MESSAGE [lindex $fnlist $i]
    exec cat $MESSAGE | rmdtopvf | pvftowav > \
         $userhome/tkvoice.tmp 2>/dev/null
    if {$AUTOP == 1} {
      set playcmd "$tkvoicedir/bin/wavplay -M"
      set playPID [eval exec $playcmd $userhome/tkvoice.tmp > /dev/null 2>&1 &]
      } else {
      set playPID [eval exec $playwave $userhome/tkvoice.tmp > /dev/null 2>&1 &]
      }
    exec touch $MESSAGE.played
    exec chmod 666 $MESSAGE.played
    set z [.v.voice.list get $i]
    set l [string length $z]
    if {$l>19} {
      set z [string range $z 2 $l ]
      set y "\x3E\x20"
      append t $y $z
      .v.voice.list delete $i
      .v.voice.list insert $i $t
    }
  }
}
######################## END proc play_audio ######################

proc stop_audio {} {
global playPID
    catch [exec kill -9 $playPID >/dev/null 2>&1]
}
######################## END proc stop_audio ######################

proc record_g {} {
global recordwave rectime pvfsamples voicedir voiceout greeting AUTOR \
       tkvoicedir

if {$AUTOR == 1} {
    catch [exec ps -ef | grep artsd | grep -v grep | awk {{print $2}} \
           | xargs kill -9 ]
    set recordcmd "$tkvoicedir/bin/wavrec -M -s $pvfsamples -t $rectime"
    catch [eval exec $recordcmd $voicedir/$voiceout/$greeting.wav ]
    } else {
    catch [eval exec $recordwave ]
    }
}
######################## END proc record_g ########################

proc listen_g {} {
global playwave tkvoicedir voicedir voiceout greeting AUTOP
if {$AUTOP == 1} {
    set playcmd "$tkvoicedir/bin/wavplay"
    catch [eval exec $playcmd $voicedir/$voiceout/$greeting.wav ]
   } else {
    catch [eval exec $playwave $voicedir/$voiceout/$greeting.wav ]
   }
}
######################## END proc listen_g ########################

proc convert_g {} {
global MODEMTYPE MODEMCOMP pvfsamples voicedir voiceout greeting
    catch [exec cat $voicedir/$voiceout/$greeting.wav | wavtopvf \
                | pvfspeed -s $pvfsamples | pvftormd $MODEMTYPE $MODEMCOMP \
                > $voicedir/$voiceout/$greeting ]
}
######################## END proc convert_g #######################

proc delete_it {} {
global fnlist
  foreach i [lsort -integer -decreasing [.v.voice.list curselection]] {
    set MESSAGE [lindex $fnlist $i]
    exec rm -f $MESSAGE $MESSAGE.played
    set fnlist [lreplace $fnlist $i $i]
    .v.voice.list delete $i
  }
}
######################## END proc delete_it #######################

proc select_fax {} {
global tkvoicedir faxdir faxin faxdpi printcmd printsel fnlistfax
global userhome FAX PAGE PAGET tkVoice

foreach i [.f.fax.list curselection] {
    set tmp [lindex $fnlistfax $i]
# fax prefix char count
    set fpc [expr [string length $tmp]-4]
    set FAX [string range $tmp 0 $fpc]
    set a [eval exec ls [glob -nocomplain $FAX.??] | wc ]
    set b [string trim $a ]
    set c [string range $b 0 1]
     if {$c < 10} {
      set PAGET "0"
      append PAGET $c
      } else {
      set PAGET $c
      }
    set PAGE 01

 }
}
######################## END proc select_fax  #######################
proc delete_fax {} {
global fnlistfax
  foreach i [lsort -integer -decreasing [.f.fax.list curselection]] {
    set tmp [lindex $fnlistfax $i]
    set fpc [expr [string length $tmp]-4]
    set FAX [string range $tmp 0 $fpc]
    set DEL [eval exec ls [glob -nocomplain $FAX.??]]
  foreach x $DEL {
    exec rm -f $x
  }
    exec rm -f $FAX.01.viewed
    set fnlistfax [lreplace $fnlistfax $i $i]
    .f.fax.list delete $i
  }
}
######################## END proc delete_fax #######################


proc view_fax {} {
global tkvoicedir faxdir faxin faxdpi printcmd printsel fnlistfax
global userhome FAX PAGE PAGET tkVoice

select_fax

exec touch $FAX.$PAGE.viewed
exec chmod 666 $FAX.$PAGE.viewed

    foreach i [.f.fax.list curselection] {
    set z [.f.fax.list get $i]
    set l [string length $z]
        if {$l>19} {
        set z [string range $z 2 $l ]
        set y "\x3E\x20"
        append t $y $z
        .f.fax.list delete $i
        .f.fax.list insert $i $t
        }
    }
uplevel [list source [file join $tkvoicedir/TCL/tkviewfax.tcl]]
}
######################## END proc view_fax  #######################

proc print_fax {} {
global tkvoicedir faxdir faxin faxdpi printcmd printsel fnlistfax
global userhome FAX PAGE PAGET tkVoice

select_fax

uplevel [list source [file join $tkvoicedir/TCL/tkvprintfax.tcl]]
}
######################## END proc print_fax  #######################



proc get_files {} {
global voicedir voicein fnlist
  
 # clear the contents of listbox
 .v.voice.list delete 0 1000
  set fnlist {}
  if {[file exists $voicedir/$voicein/.timestamp]} {
    set lastplay [file mtime $voicedir/$voicein/.timestamp]
  } else {
    set lastplay -1
  }
 set vdlength [expr [string length $voicedir]-1]
 set test [eval exec ls -t [glob -nocomplain $voicedir/$voicein/*.rmd]]
    if {[string range $test 0 $vdlength] == $voicedir} {
 foreach n $test {
    set zerotest [exec ls -l $n | awk {{print $5}}]
    if {$zerotest == 0} {
    exec rm $n
    } else {
    set f [exec ls -l --full-time $n | awk {{print $6, $7, $8, $9, $10}}]
    set h [exec date -d $f "+* %a %b %e, %Y %l:%M%p  "]
    set g [exec ls $n | awk -F "-" {{print $4}} | awk -F "." {{print $1}}]
    if [string match O $g ] {
        set g "Not Available"
       } elseif [string match "" $g ] {
        set g "Not Available"
       } else {
	set acode [string range $g 0 2]
        set prefx [string range $g 3 5]
        set tailn [string range $g 6 9]
        set g "($acode)$prefx-$tailn"
       }
    set t ""
    append t $h $g
    lappend fnlist $n
    if { [file isfile $n.played] == 0} {
       append t " NEW"
    }
      .v.voice.list insert end $t
   }
  }
 }
}
######################## END proc get_files #######################
proc get_faxfiles {} {
global faxdir faxin fnlistfax
  
 # clear the contents of listbox
 .f.fax.list delete 0 1000
  set fnlistfax {}
  if {[file exists $faxdir/$faxin/.timestamp]} {
    set lastplay [file mtime $faxdir/$faxin/.timestamp]
  } else {
    set lastplay -1
  }
 set vdlength [expr [string length $faxdir]-1]
 set test [eval exec ls -t [glob -nocomplain $faxdir/$faxin/*.01]]
    if {[string range $test 0 $vdlength] == $faxdir} {
 foreach n $test {
    set f [exec ls -l --full-time $n | awk {{print $6, $7, $8, $9, $10}}]
    set h [exec date -d $f "+* %a %b %e, %Y %l:%M%p  "]
#
# Grab the fax station id: length of $faxdir $faxin plus 12 chars
# 1 for slash and 12 char for fax mgetty naming convention:
#
# The file name format is somewhat tricky (reason behind it is that I have to
# create something unique without using mktemp(), because that would make
# it impossible to find out which pages belong to which fax). It is:
# 
# f<res><seq><line>[-<remote id>].<pagenr>
# 
# <res> is n or f, depending on the resolution of the fax. 
# <seq> is a sequence number, 7 digits wide, related to the reception time. 
# <line> are the last two letters of the tty device, e.g. `S1'.
# If the sending side specified a fax station id, it comes next, after a 
# leading dash (all blanks are replaced by dashes).
# Finally, after a dot, you'll see the page number.
    set ids [expr [string length $faxdir]+[string length $faxin]+13]
# Stn ID end point
# knock the: .<pagenr> off the end (minus 4chars)
# end point is 3chars plus 1 due to counting starts at 0
    set ide [expr [string length $n]-4]
    set g [string range $n $ids $ide]
    if [string match O $g ] {
        set g "Not Available"
       } elseif [string match "" $g ] {
        set g "Not Available"
       }
    set t ""
    append t $h $g
    lappend fnlistfax $n
    if { [file isfile $n.viewed] == 0} {
       append t " NEW"
    }
      .f.fax.list insert end $t
  }
 }
}
######################## END proc get_faxfiles #######################

proc refresh {} {
# Need to do this check or tkvoice will not start up.
     if {[winfo exists .v.voice.list]} {

        # Refresh .your.listbox here
     get_files
     }
        # Reschedule ourselves 60 seconds in the future
     after 60000 refresh
}
# now start refresh proc (kind of puts itself in background)
refresh 

######################## END proc updatefiles #####################

proc timestamp {} {
global voicedir voicein

  set do_stamp 1
  for {set i 0} {$i<[.v.voice.list size]} {incr i} {
    if {[string length [.v.voice.list get $i]]<19} {set do_stamp 0}
  }
  if {$do_stamp} {
    exec touch $voicedir/$voicein/.timestamp
    exec rm -f $voicedir/.flag
  }
}
######################## END proc timestamp #######################

##############################################
# Under Greeting
##############################################
# Play Greeting
proc play_g {} {
global playwave tkvoicedir voicedir voiceout greeting playPID AUTOP userhome

exec rmdtopvf $voicedir/$voiceout/$greeting | pvftowav \
         > $userhome/tkvoice.tmp 2>/dev/null

if {$AUTOP == 1} {
    set playcmd "$tkvoicedir/bin/wavplay -M"
    set playPID [eval exec $playcmd $userhome/tkvoice.tmp > /dev/null 2>&1 &]
   } else {
    set playPID [eval exec $playwave $userhome/tkvoice.tmp > /dev/null 2>&1 &]
   }
tk_messageBox -icon info -type ok -title "tkVoice Out-Going Greeting" -message "Now listening to your:\n\nOUT-GOING GREETING"

}
######################## END proc play_g ##########################

#---------------------------------------------
# Record Greeting
proc record {} {
global tkVoice tkvoicedir voicedir voiceout greeting MODEMTYPE MODEMCOMP \
       recordwave rectime
  uplevel [list source [file join $tkvoicedir/TCL/tkvrecord.tcl]]
}
######################## END proc record ##########################


##############################################
# Under Options
##############################################
# Path setup
proc voicesetup {} {
global tkVoice tkvoicedir voicedir greeting
 uplevel [list source [file join $tkvoicedir/TCL/tkvsetupvoice.tcl]]
}
######################## END proc  ###########################
#---------------------------------------------
# Modem setup
proc modem {} {
global tkVoice tkvoicedir MODEMTYPE MODEMCOMP pvfsamples custpvfs
if { $pvfsamples == 7200 } {
     set custpvfs 0
   } elseif { $pvfsamples == 8000 } {
     set custpvfs 0
   } elseif { $pvfsamples == 9600 } {
     set custpvfs 0
   } else {
     set custpvfs 1
}
 uplevel [list source [file join $tkvoicedir/TCL/tkvmodem.tcl]]
}
######################## END proc modem ###########################
#---------------------------------------------
# Audio setup
proc audio {} {
global tkVoice tkvoicedir playwave recordwave AUTOP AUTOR
 uplevel [list source [file join $tkvoicedir/TCL/tkvaudio.tcl]]
}
######################## END proc audio ###########################
# FAX setup
proc faxsetup {} {
global tkVoice tkvoicedir drawfax faxdir faxin faxout faxdpi printcmd printsel
 uplevel [list source [file join $tkvoicedir/TCL/tkvsetupfax.tcl]]
}
######################## END proc  ###########################
# setup printer
proc printsetup {} {
global tkVoice tkvoicedir drawfax faxdir faxin faxout faxdpi printcmd printsel
 uplevel [list source [file join $tkvoicedir/TCL/tkvsetupprint.tcl]]
}
######################## END proc  ###########################
#---------------------------------------------
#---------------------------------------------

##############################################
# Under Help
proc faq {} {
global tkVoice tkvoicedir
  uplevel [list source [file join $tkvoicedir/TCL/tkvfaq.tcl]]
}

proc readme {} {
global tkVoice tkvoicedir
  uplevel [list source [file join $tkvoicedir/TCL/tkvreadme.tcl]]
}

proc aboutBox {} {
global TKVREV TKVDATE tkVoice tkvoicedir
  uplevel [list source [file join $tkvoicedir/TCL/tkvabout.tcl]]
}
######################## END proc aboutBox ########################

# positionWindow --
# Arguments:
# w -           The name of the window to position.
 
proc positionWindow w {
    wm geometry $w +300+300
}
##############################################
##### End of subs
##############################################
##### Start of Frames
##############################################

# Create the menu bar at the top of the window.
 
frame .menu -relief raised -borderwidth 2 
pack .menu -side top -fill x
 
# Under the File button
 
menubutton .menu.file -text File -menu .menu.file.m -underline 0
menu .menu.file.m
.menu.file.m add command -label "Delete Selected" -underline 0 \
        -command "delete_it"
.menu.file.m add command -label "Refresh List" -underline 0 \
        -command "get_files"
.menu.file.m add command -label "Stop Audio" -underline 0 \
        -command "stop_audio"
.menu.file.m add command -label "Play Selected" -underline 0 \
        -command "play_audio"
.menu.file.m add separator
.menu.file.m add command -label "Exit" -underline 1 \
        -command "timestamp; destroy ."

# Under the GREETING button
 
menubutton .menu.greeting -text Greeting -menu .menu.greeting.m -underline 0
menu .menu.greeting.m -tearoff 0
.menu.greeting.m add command -label "Listen to Greeting" -underline 0 \
        -command {play_g}
.menu.greeting.m add command -label "Record Greeting" -underline 0 \
        -command {record}

# Under the Option button
 
menubutton .menu.option -text Options -menu .menu.option.m -underline 0
menu .menu.option.m
.menu.option.m add cascade -label "VOICE" \
	-menu .menu.option.voice -underline 0
.menu.option.m add cascade -label "FAX" \
	-menu .menu.option.fax -underline 0

menu .menu.option.voice -tearoff 0
.menu.option.voice add command -label "Setup Voice" -underline 2 \
        -command {voicesetup}
.menu.option.voice add command -label "Setup Modem" -underline 2 \
        -command {modem}
.menu.option.voice add command -label "Setup Audio" -underline 2 \
        -command {audio}

menu .menu.option.fax -tearoff 0
.menu.option.fax add command -label "Setup FAX" -underline 2 \
        -command {faxsetup}
.menu.option.fax add command -label "Setup PRINTER" -underline 2 \
        -command {printsetup}

# Under the Help button
 
menubutton .menu.help -text Help -menu .menu.help.m -underline 0
menu .menu.help.m
.menu.help.m add command -label "FAQ" -underline 0 \
        -command {faq}
.menu.help.m add command -label "README" -underline 0 \
        -command {readme}
.menu.help.m add command -label "About tkVOICE" -underline 0 \
        -command {aboutBox}
 
pack .menu.file .menu.greeting .menu.option -side left
pack .menu.help -side right
 
# GIF frame on left of list
frame .gif -relief raised -borderwidth 2
pack .gif -side top -fill x

# tkvoice image
catch {image delete tkvoice}
image create photo tkvoice -file [file join $tkvoicedir/image/tkvoice.gif]
label .gif.tkvoice -image tkvoice -bd 1 -relief sunken

catch {image delete linux}
image create photo linux -file [file join $tkvoicedir/image/linux.gif]
label .gif.linux -image linux -bd 1 -relief sunken

catch {image delete phone}
image create photo phone -file [file join $tkvoicedir/image/phone.gif]
label .gif.phone -image phone -bd 1 -relief sunken

catch {image delete penguin}
image create photo penguin -file [file join $tkvoicedir/image/penguin.gif]
label .gif.penguin -image penguin -bd 1 -relief sunken

pack .gif.phone -side left 
pack .gif.tkvoice -side left -expand 1 -fill x
pack .gif.linux -side right 
pack .gif.penguin -side right

######### MAIN VOICE FRAME STARTS HERE ##############
frame .v 
frame .v.voice
label .v.voice.msg -font {times 18} -justify center -text "VOICE Messages"
listbox .v.voice.list -relief sunken -font {fixed 14} -width 46 -height 5 \
	        -yscrollcommand ".v.voice.scroll set" -background snow2
scrollbar .v.voice.scroll -command ".v.voice.list yview"

frame .v.button
image create photo exit -file [file join $tkvoicedir/image/exit.gif]
button .v.button.quit  -image exit -anchor center -command "timestamp; destroy ."
image create photo play -file [file join $tkvoicedir/image/play.gif]
button .v.button.playa -text "Play" -image play -anchor center -command play_audio
image create photo stop -file [file join $tkvoicedir/image/stop.gif]
button .v.button.stop -text "Stop" -image stop -anchor center -command stop_audio
image create photo reload -file [file join $tkvoicedir/image/reload.gif]
button .v.button.reload -text "Refresh" -image reload -anchor center -command "get_files"
image create photo del -file [file join $tkvoicedir/image/del.gif]
button .v.button.del   -image del -anchor center -command delete_it
######### MAIN VOICE FRAME ENDS HERE ##############

######### MAIN FAX FRAME STARTS HERE ##############
frame .f
frame .f.fax
label .f.fax.msg -font {times 18} -justify center -text "FAX Messages"
#                -background gray90 -relief sunken
listbox .f.fax.list -relief sunken -font {fixed 14} -width 46 -height 5 \
               -yscrollcommand ".f.fax.scroll set" -background snow2
scrollbar .f.fax.scroll -command ".f.fax.list yview"

frame .f.button
button .f.button.quit -text "Quit" -anchor center -command "timestamp; destroy ."
button .f.button.view   -text "View" -anchor center -command "view_fax"
button .f.button.print  -text "Print" -anchor center -command "print_fax"
button .f.button.reload -text "Refresh" -anchor center -command "get_faxfiles"
button .f.button.del    -text "Delete"  -anchor center -command "delete_fax"
######### MAIN FAX FRAME ENDS HERE ##############

if {$drawvoice == 1} {
  pack .v -padx 3 -pady 3
  pack .v.voice.msg -side top
  pack .v.voice -side top
  pack .v.voice.list -side left 
  pack .v.voice.scroll -side left -fill y -expand 1
  pack .v.button -side top -fill x
  pack .v.button.quit  -side right -expand 1 -fill x -padx 3 -pady 3
  pack .v.button.playa -side right -expand 1 -fill x -padx 3 -pady 3
  pack .v.button.stop -side right -expand 1 -fill x -padx 3 -pady 3
  pack .v.button.reload   -side right -expand 1 -fill x -padx 3 -pady 3
  pack .v.button.del   -side right -expand 1 -fill x -padx 3 -pady 3
  get_files
  bind .v.voice.list <Double-Button-1> play_audio
}

if {$drawfax == 1} {
  pack .f -padx 3 -pady 3
  pack .f.fax.msg -side top
  pack .f.fax -side top
  pack .f.fax.list -side left
  pack .f.fax.scroll -side left -fill y -expand 1
  pack .f.button -side bottom -fill x
  pack .f.button.quit  -side right -expand 1 -fill x -padx 3 -pady 3
  pack .f.button.view -side right -expand 1 -fill x -padx 3 -pady 3
  pack .f.button.print -side right -expand 1 -fill x -padx 3 -pady 3
  pack .f.button.reload   -side right -expand 1 -fill x -padx 3 -pady 3
  pack .f.button.del   -side right -expand 1 -fill x -padx 3 -pady 3
  get_faxfiles
  bind .f.fax.list <Double-Button-1> view_fax
}


wm protocol . WM_DELETE_WINDOW "timestamp; destroy ."
wm iconbitmap . @$tkvoicedir/image/icon

tkwait window .
