namespace eval phonebook { set m .find.m #balloonhelp $m -index "Search for a host on the network" $m add command -label "Person..." -command [list create_or_raise\ .find_phone ::phonebook::find] proc find {w} { wm title $w "Find person" label $w.l -text "Enter name:" -anchor w entry $w.name -width 30 -font 6x13 bind $w.name [list search_phonebook $w] button $w.phone -text "Phonebook" -command [list search_phonebook $w] button $w.finger -text "Finger" -command "open_pipe $w.result\ \"finger \\\"\[$w.name get\]\\\"\"" button $w.add -text "Add to phonebook" -command "create_or_raise \ .add_phone ::phonebook::add" grid $w.l $w.name - - -sticky news grid $w.finger $w.phone $w.add - -sticky ns text $w.result -height 5 -yscrollcommand [list $w.y set] -state disabled\ -font 6x13 $w.result tag configure error -foreground red $w.result tag configure done -foreground green $w.result tag configure mail -foreground blue -underline y $w.result tag bind mail <1> "mail_person $w.result @%x,%y" scrollbar $w.y -orient vert -command [list $w.result yview] grid $w.result - - $w.y -sticky news grid columnconfigure $w 0 -weight 0 grid columnconfigure $w 1 -weight 1 grid columnconfigure $w 2 -weight 0 grid columnconfigure $w 3 -weight 0 foreach row {0 1} { grid rowconfigure $w $row -weight 0 } grid rowconfigure $w 2 -weight 1 } proc search_phonebook {w} { global CONFIGDIR set pattern [$w.name get] set f [open "$CONFIGDIR/phonebook"] clearresult $w.result while {[gets $f line]>=0} { if {[regexp "\[ \t\]*#" $line]} { continue } foreach {n1 n2 t num time mail} [split $line :] break if {[regexp $pattern $n1]||[regexp $pattern $n2]} { show_phone $w.result $n1 $t $num $time $mail } } close $f } proc show_phone {win name type num time mail} { $win configure -state normal $win insert end "$name\($type\)\t$num" if [string length $time] { $win insert end "\($time\)" } if [string length $mail] { $win insert end "\t" {} $mail mail } $win insert end \n $win see end $win configure -state disabled } proc mail_person {w index} { global CONFIGDIR set range [$w tag nextrange mail "$index linestart"] set address [eval $w get $range] exec $CONFIGDIR/mail $address & } proc add {w} { wm title $w "Add to phone book" label $w.l1 -text "Person name:" entry $w.name -width 30 -font 6x13 label $w.l2 -text "Person nickname:" entry $w.nick -width 30 -font 6x13 label $w.l3 -text "Type of phone:" tk_optionMenu $w.type phone_type дом. раб. пейджер факс модем контакт label $w.l4 -text "Phone number:" entry $w.phone -width 30 -font 6x13 label $w.l5 -text "Time interval:" entry $w.time -width 30 -font 6x13 label $w.l6 -text "E-Mail" entry $w.mail -width 30 -font 6x13 button $w.add -command "add_phone $w" -text "Add" button $w.cancel -command "destroy $w" -text Cancel grid $w.l1 $w.name -sticky w grid $w.l2 $w.nick -sticky w grid $w.l3 $w.type -sticky w grid $w.l4 $w.phone -sticky w grid $w.l5 $w.time -sticky w grid $w.l6 $w.mail -sticky w grid $w.add $w.cancel -sticky ns } proc add_phone {w} { global CONFIGDIR global phone_type set f [open "$CONFIGDIR/phonebook" a+] puts $f [join [list [$w.name get] [$w.nick get] $phone_type\ [$w.phone get] [$w.time get] [$w.mail get]] :] close $f wm withdraw $w } }