]> www.wagner.pp.ru Git - oss/fubar.git/blob - plugins/phonebook
Reimport after CVS crash
[oss/fubar.git] / plugins / phonebook
1
2 namespace eval phonebook {
3         set m .find.m
4 #balloonhelp $m -index  "Search for a host on the network"      
5 $m add command -label "Person..." -command [list create_or_raise\
6         .find_phone ::phonebook::find]
7
8 proc find {w} {
9    wm title $w "Find person"
10    label $w.l -text "Enter name:" -anchor w
11    entry $w.name -width 30 -font 6x13
12    bind $w.name <Key-Return> [list search_phonebook $w]
13    button $w.phone -text "Phonebook" -command [list search_phonebook $w]
14    button $w.finger -text "Finger" -command "open_pipe $w.result\
15     \"finger \\\"\[$w.name get\]\\\"\""
16    button $w.add -text "Add to phonebook" -command "create_or_raise \
17         .add_phone ::phonebook::add"
18    grid $w.l $w.name - - -sticky news
19    grid $w.finger $w.phone $w.add - -sticky ns
20   
21   text $w.result -height 5 -yscrollcommand [list $w.y set] -state disabled\
22      -font 6x13
23      $w.result tag configure error -foreground red
24      $w.result tag configure done -foreground green 
25      $w.result tag configure mail -foreground blue -underline y
26      $w.result tag bind mail <1> "mail_person $w.result  @%x,%y"
27      scrollbar $w.y -orient vert -command [list $w.result yview]
28      grid $w.result - -  $w.y -sticky news
29      grid columnconfigure $w 0 -weight 0 
30      grid columnconfigure $w 1 -weight 1 
31      grid columnconfigure $w 2 -weight 0 
32      grid columnconfigure $w 3 -weight 0
33      foreach row {0 1} {
34          grid rowconfigure $w $row -weight 0
35      }
36      grid rowconfigure $w 2 -weight 1
37 }
38
39 proc search_phonebook {w} {
40   global CONFIGDIR
41   set pattern [$w.name get]
42   set f [open "$CONFIGDIR/phonebook"]
43   clearresult $w.result
44   while {[gets $f line]>=0} {
45      if {[regexp "\[ \t\]*#" $line]} {
46          continue
47      }  
48       foreach {n1 n2 t num time mail} [split $line :] break
49       if {[regexp $pattern $n1]||[regexp $pattern $n2]} {
50         show_phone $w.result $n1 $t $num $time $mail
51       }
52   }
53   close $f
54 }        
55
56 proc show_phone {win name type num time mail} {
57   $win configure -state normal
58   $win insert end "$name\($type\)\t$num"
59   if [string length $time] {
60      $win insert end "\($time\)"
61   }
62   if [string length $mail] {
63      $win insert end "\t" {} $mail mail
64   }
65   $win insert end \n
66   $win see end
67   $win configure -state disabled
68 }  
69
70 proc mail_person {w index} {
71   global CONFIGDIR
72   set range [$w tag nextrange mail "$index linestart"]
73   set address [eval $w get $range]
74   exec $CONFIGDIR/mail $address &
75 }  
76
77 proc add {w} {
78      wm title $w "Add to phone book"
79      label $w.l1 -text "Person name:"
80      entry $w.name -width 30 -font 6x13
81      label $w.l2 -text "Person nickname:"
82      entry $w.nick -width 30 -font 6x13
83      label $w.l3 -text "Type of phone:"
84      tk_optionMenu $w.type phone_type ÄÏÍ. ÒÁÂ. ÐÅÊÄÖÅÒ ÆÁËÓ ÍÏÄÅÍ ËÏÎÔÁËÔ 
85      label $w.l4 -text "Phone number:" 
86      entry $w.phone -width 30 -font 6x13
87      label $w.l5 -text "Time interval:"
88      entry $w.time -width 30 -font 6x13
89      label $w.l6 -text "E-Mail"
90      entry $w.mail -width 30 -font 6x13
91      button $w.add -command "add_phone $w" -text "Add"
92      button $w.cancel -command "destroy $w" -text Cancel
93      grid $w.l1 $w.name -sticky w
94      grid $w.l2 $w.nick -sticky w
95      grid $w.l3 $w.type -sticky w
96      grid $w.l4 $w.phone -sticky w
97      grid $w.l5 $w.time -sticky w
98      grid $w.l6 $w.mail -sticky w
99      grid $w.add $w.cancel -sticky ns
100 }
101
102 proc add_phone {w} {
103    global CONFIGDIR
104    global phone_type
105    set f [open "$CONFIGDIR/phonebook" a+]
106    puts $f [join [list [$w.name get] [$w.nick get] $phone_type\
107            [$w.phone get] [$w.time get] [$w.mail get]] :]
108    close $f
109    wm withdraw $w
110 }  
111 }