#!/usr/bin/wish
# Fubar plug-in to handle phonebook
-package require Img
+if [catch {package require Img} msg] {
+ puts stderr "Failed to load IMG package: $msg"
+ set noImg 1
+} else {
+ set noImg 0
+}
if {![file exists ~/.phonebook.vcf]} {
error "Phonebook file $env(HOME)/.phonebook.vcf not found"
}
set list [split $field ";"]
if {[llength $list>1]} {
set field [lindex $list 0]
+ if {$field != "N" && $field != "FN" } {
foreach opt [lrange $list 1 end] {
if {[string match CHARSET=* $opt]||
[string match ENCODING=* $opt]||
$opt eq "PREF"} continue
lappend field $opt
}
+ }
}
if {$field eq "END"} {
assemble_record cur_record
proc assemble_record {var} {
upvar $var record
variable phones
- set index $record(N)
+ if {[info exists record(FN)]} {
+ set index $record(FN)
+ } elseif {[info exists record(N)]} {
+ set index $record(N)
+ } elseif {[info exists record(NICKNAME)]} {
+ set index $record(NICKNAME)
+ }
if [info exists record(ORG)] { append index ",$record(ORG)"}
if [info exists record(TITLE)] { append index ",$record(TITLE)"}
+ if {![info exists index]} {
+ after idle "error \"record [array get record] has no name\""
+ }
set phones($index) [array get record]
}
bind $w.list <Key> [list ::phonebook::keyEvent $w.search.pattern %k %s %A %K]
scrollbar $w.y -orient vert -command "$w.list yview"
frame $w.record
- foreach {name title} {name "éÍÑ" org "ïÒÇÁÎÉÚÁÃÉÑ" title "ú×ÁÎÉÅ"
- telcell "ôÅÌ. íÏÂ" telwork "ôÅÌ.òÁÂ." telhome "ôÅÌ.äÏÍ." telother
- "ðÒÏÞÅÅ" fax "æÁËÓ" email "E-Mail"} {
+ foreach {name title} {name "Name" org "Organization" title "Title"
+ telcell "Tel. Cell" telwork "Tel. Work" telhome "Tel. Home" telother
+ "Other" fax "Fax" email "E-Mail"} {
label $w.record.l$name -text $title -anchor e
label $w.record.$name -anchor w
grid $w.record.l$name $w.record.$name -sticky news
} else {
array set record {}
if {[info exists current]} {unset current}
- }
- $w.record.name configure -text $record(N);
+ }
+
+ $w.record.name configure -text $index
set_if_exists $w.record.org record(ORG)
set_if_exists $w.record.title record(TITLE)
set_if_exists $w.record.telcell "record(TEL CELL)"
} else {
$w.record.mail configure -state disabled
}
+ set hasImage 0
if {[llength [set img_index [lindex [array names record PHOTO*] 0]]]} {
if {![regexp {TYPE=([^[:space:]]+)} $img_index msg fmt]} {
set fmt JPEG
}
+ if {!$::noImg || $fmt eq "GIF" || $fmt eq "PPM"} {
$w.record.image configure -image [image create photo -format $fmt -data $record($img_index)]
- } else {
+ set hasImage 1
+ }
+
+ }
+ if {!$hasImage} {
$w.record.image configure -image ""
}
}