X-Git-Url: http://www.wagner.pp.ru/gitweb/?p=oss%2Ffubar.git;a=blobdiff_plain;f=plugins%2Fphone_vcf;fp=plugins%2Fphone_vcf;h=f60262445da648834c62311b39e1668e5364f261;hp=cd0f27abef457a996fb11c4340a9d2d80cbdabaa;hb=45c0c5264259ed31018e3771d64142b723d7aa35;hpb=c3bcb0bdb509bb9b79646b31c4664b4e3d225755 diff --git a/plugins/phone_vcf b/plugins/phone_vcf index cd0f27a..f602624 100644 --- a/plugins/phone_vcf +++ b/plugins/phone_vcf @@ -1,6 +1,11 @@ #!/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" } @@ -32,12 +37,14 @@ namespace eval phonebook { 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 @@ -68,9 +75,18 @@ namespace eval phonebook { 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] } @@ -94,9 +110,9 @@ namespace eval phonebook { bind $w.list [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 @@ -129,8 +145,9 @@ namespace eval phonebook { } 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)" @@ -144,12 +161,18 @@ namespace eval phonebook { } 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 "" } }