3 # Revision 1.15 1995-03-28 12:45:22 adam
4 # New ir method failback: called on disconnect/protocol error.
5 # New ir set/get method: protocol: SR / Z3950.
6 # Simple popup and disconnect when failback is invoked.
8 # Revision 1.14 1995/03/22 16:07:55 adam
11 # Revision 1.13 1995/03/21 17:27:26 adam
12 # Short-hand keys in setup.
14 # Revision 1.12 1995/03/21 13:41:03 adam
15 # Comstack cs_create not used too often. Non-blocking connect.
17 # Revision 1.11 1995/03/21 10:39:06 adam
18 # Diagnostic error message displayed with tkerror.
20 # Revision 1.10 1995/03/20 15:24:06 adam
21 # Diagnostic records saved on searchResponse.
23 # Revision 1.9 1995/03/17 18:26:16 adam
24 # Non-blocking i/o used now. Database names popup as cascade items.
26 # Revision 1.8 1995/03/17 15:45:00 adam
27 # Improved target/database setup.
29 # Revision 1.7 1995/03/16 17:54:03 adam
30 # Minor changes really.
32 # Revision 1.6 1995/03/15 19:10:20 adam
33 # Database setup in protocol-setup (rather target setup).
35 # Revision 1.5 1995/03/15 13:59:23 adam
38 # Revision 1.4 1995/03/14 17:32:29 adam
39 # Presentation of full Marc record in popup window.
41 # Revision 1.3 1995/03/12 19:31:52 adam
42 # Pattern matching implemented when retrieving MARC records. More
43 # diagnostic functions.
45 # Revision 1.2 1995/03/10 18:00:15 adam
46 # Actual presentation in line-by-line format. RPN query support.
48 # Revision 1.1 1995/03/09 16:15:07 adam
49 # First presentRequest attempts. Hot-target list.
56 set profile(Default) {{} {} {210} {} 16384 8192 tcpip {}}
63 if {[file readable "~/.tk-c"]} {
67 proc top-down-window {w} {
68 frame $w.top -relief raised -border 1
69 frame $w.bot -relief raised -border 1
71 pack $w.top $w.bot -side top -fill both -expand yes
74 proc top-down-ok-cancel {w ok-action g} {
75 frame $w.bot.left -relief sunken -border 1
76 pack $w.bot.left -side left -expand yes -padx 5 -pady 5
77 button $w.bot.left.ok -width 6 -text {Ok} \
79 pack $w.bot.left.ok -expand yes -padx 3 -pady 3
80 button $w.bot.cancel -width 6 -text {Cancel} \
82 pack $w.bot.cancel -side left -expand yes
91 proc show-target {target} {
92 .bot.target configure -text "$target"
95 proc show-busy {v1 v2} {
98 .bot.status configure -fg $v1
99 after 200 [list show-busy $v2 $v1]
103 proc show-status {status b} {
106 .bot.status configure -text "$status"
107 .bot.status configure -fg black
113 # . config -cursor {watch black white}
115 # . config -cursor {top_left_arrow black white}
121 proc show-message {msg} {
122 .bot.message configure -text "$msg"
125 proc insertWithTags {w text args} {
126 set start [$w index insert]
127 $w insert insert $text
128 foreach tag [$w tag names $start] {
129 $w tag remove $tag $start insert
132 $w tag add $i $start insert
136 proc show-full-marc {no} {
141 if {[winfo exists $w]} {
142 $w.top.record delete 0.0 end
148 wm minsize $w 200 200
150 frame $w.top -relief raised -border 1
151 frame $w.bot -relief raised -border 1
153 pack $w.top -side top -fill both -expand yes
154 pack $w.bot -fill both
156 text $w.top.record -width 60 -height 12 -wrap word \
157 -yscrollcommand [list $w.top.s set]
158 scrollbar $w.top.s -command [list $w.top.record yview]
164 set r [z39.$setNo recordMarc $no line * * *]
166 $w.top.record tag configure marc-tag -foreground blue
167 $w.top.record tag configure marc-data -foreground black
168 $w.top.record tag configure marc-id -foreground red
171 set tag [lindex $line 0]
172 set indicator [lindex $line 1]
173 set fields [lindex $line 2]
175 if {$indicator != ""} {
176 insertWithTags $w.top.record "$tag $indicator" marc-tag
178 insertWithTags $w.top.record "$tag " marc-tag
180 foreach field $fields {
181 set id [lindex $field 0]
182 set data [lindex $field 1]
184 insertWithTags $w.top.record " $id " marc-id
186 set start [$w.top.record index insert]
187 insertWithTags $w.top.record $data {}
189 $w.top.record insert end "\n"
192 bind $w <Return> {destroy .full-marc}
194 pack $w.top.s -side right -fill y
195 pack $w.top.record -expand yes -fill both
197 frame $w.bot.left -relief sunken -border 1
198 pack $w.bot.left -side left -expand yes -padx 5 -pady 5
199 button $w.bot.left.close -width 6 -text {Close} \
200 -command {destroy .full-marc}
201 pack $w.bot.left.close -expand yes -padx 3 -pady 3
202 button $w.bot.edit -width 6 -text {Edit} \
203 -command {destroy .full-marc}
204 pack $w.bot.edit -side left -expand yes
208 proc update-target-hotlist {target} {
211 set len [llength $hotTargets]
213 .top.target.m delete 5 [expr 5+[llength $hotTargets]]
215 set indx [lsearch $hotTargets $target]
217 set hotTargets [lreplace $hotTargets $indx $indx]
219 set hotTargets [linsert $hotTargets 0 $target]
223 proc set-target-hotlist {} {
227 foreach target $hotTargets {
228 .top.target.m add command -label "$i $target" -command \
229 "menu-open-target $target {}"
237 proc menu-open-target {target base} {
238 open-target $target $base
239 update-target-hotlist $target
242 proc define-target-action {} {
245 set target [.target-define.top.target.entry get]
249 update-target-hotlist $target
250 foreach n [array names profile] {
256 set profile($target) $profile(Default)
257 protocol-setup $target
258 destroy .target-define
261 proc fail-response {target} {
263 tkerror "Target connection closed or protocol error"
266 proc connect-response {target} {
267 puts "connect-response"
272 proc open-target {target base} {
277 z39 comstack [lindex $profile($target) 6]
278 # z39 idAuthentication [lindex $profile($target) 3]
279 z39 maximumRecordSize [lindex $profile($target) 4]
280 z39 preferredMessageSize [lindex $profile($target) 5]
281 puts -nonewline "maximumRecordSize="
282 puts [z39 maximumRecordSize]
283 puts -nonewline "preferredMessageSize="
284 puts [z39 preferredMessageSize]
286 z39 databaseNames [lindex [lindex $profile($target) 7] 0]
288 z39 databaseNames $base
290 z39 failback [list fail-response $target]
291 z39 callback [list connect-response $target]
292 z39 connect [lindex $profile($target) 1]:[lindex $profile($target) 2]
293 show-status {Connecting} 1
295 .top.target.m disable 0
296 .top.target.m enable 1
299 proc close-target {} {
305 show-status {Not connected} 0
307 .top.target.m disable 1
308 .top.target.m enable 0
311 proc load-set-action {} {
317 set fname [.load-set.top.filename.entry get]
322 show-status {Loading} 1
323 z39.$setNo loadFile $fname
325 set no [z39.$setNo numberOfRecordsReturned]
326 add-title-lines $setNo $no 1
328 show-status {Ready} 0
341 frame $w.top.filename
343 pack $w.top.filename -side top -anchor e -pady 2
345 entry-fields $w.top {filename} \
347 {load-set-action} {destroy .load-set}
349 top-down-ok-cancel $w {load-set-action} 1
353 proc init-request {} {
356 z39 callback {init-response}
358 show-status {Initializing} 1
362 proc init-response {} {
363 show-status {Ready} 0
364 bind .mid.searchentry <Return> search-request
365 focus .mid.searchentry
368 proc search-request {} {
378 if {[lindex $profile($target) 10]} {
379 z39.$setNo setName $setNo
381 if {[lindex $profile($target) 8]} {
384 if {[lindex $profile($target) 9]} {
387 z39 callback {search-response}
388 z39.$setNo search [.mid.searchentry get]
389 show-status {Search} 1
392 proc search-response {} {
398 show-status {Ready} 0
399 show-message "[z39.$setNo resultCount] hits"
400 set setMax [z39.$setNo resultCount]
403 set status [z39.$setNo responseStatus]
404 if {[lindex $status 0] == "NSD"} {
405 set code [lindex $status 1]
406 set msg [lindex $status 2]
407 set addinfo [lindex $status 3]
408 tkerror "NSD$code: $msg: $addinfo"
415 z39 callback {present-response}
417 z39.$setNo present 1 $setMax
418 show-status {Retrieve} 1
421 proc init-title-lines {} {
422 .data.list delete 0 end
425 proc add-title-lines {setno no offset} {
426 for {set i 0} {$i < $no} {incr i} {
427 set o [expr $i + $offset]
428 set title [lindex [z39.$setno recordMarc $o field 245 * a] 0]
429 set year [lindex [z39.$setno recordMarc $o field 260 * c] 0]
430 set nostr [format "%3d" $o]
431 .data.list insert end "$nostr $title - $year"
435 proc present-response {} {
440 puts "In present-response"
441 set no [z39.$setNo numberOfRecordsReturned]
442 puts "Returned $no records, setOffset $setOffset"
443 add-title-lines $setNo $no $setOffset
444 set setOffset [expr $setOffset + $no]
445 set status [z39.$setNo responseStatus]
446 if {[lindex $status 0] == "NSD"} {
447 show-status {Ready} 0
448 set code [lindex $status 1]
449 set msg [lindex $status 2]
450 set addinfo [lindex $status 3]
451 tkerror "NSD$code: $msg: $addinfo"
454 if {$no > 0 && $setOffset <= $setMax} {
455 z39.$setNo present $setOffset [expr $setMax - $setOffset + 1]
457 show-status {Finished} 0
461 proc left-cursor {w} {
462 set i [$w index insert]
469 proc right-cursor {w} {
470 set i [$w index insert]
475 proc bind-fields {list returnAction escapeAction} {
476 set max [expr [llength $list]-1]
477 for {set i 0} {$i < $max} {incr i} {
478 bind [lindex $list $i] <Return> $returnAction
479 bind [lindex $list $i] <Escape> $escapeAction
480 bind [lindex $list $i] <Tab> [list focus [lindex $list [expr $i+1]]]
481 bind [lindex $list $i] <Left> [list left-cursor [lindex $list $i]]
482 bind [lindex $list $i] <Right> [list right-cursor [lindex $list $i]]
484 bind [lindex $list $i] <Return> $returnAction
485 bind [lindex $list $i] <Escape> $escapeAction
486 bind [lindex $list $i] <Tab> [list focus [lindex $list 0]]
487 bind [lindex $list $i] <Left> [list left-cursor [lindex $list $i]]
488 bind [lindex $list $i] <Right> [list right-cursor [lindex $list $i]]
489 focus [lindex $list 0]
492 proc entry-fields {parent list tlist returnAction escapeAction} {
495 foreach field $list {
496 set label ${parent}.${field}.label
497 set entry ${parent}.${field}.entry
498 label $label -text [lindex $tlist $i] -anchor e
499 entry $entry -width 32 -relief sunken
500 pack $label -side left
501 pack $entry -side right
505 bind-fields $alist $returnAction $escapeAction
508 proc define-target-dialog {} {
520 -side top -anchor e -pady 2
522 entry-fields $w.top {target} \
524 {define-target-action} {destroy .target-define}
526 top-down-ok-cancel $w {define-target-action} 1
529 proc protocol-setup-action {target} {
532 global settingsChanged
535 global ResultSetCheck
537 set w .setup-${target}.top
539 #set w .protocol-setup.top
542 set settingsChanged 1
543 set len [$w.databases.list size]
544 for {set i 0} {$i < $len} {incr i} {
545 lappend b [$w.databases.list get $i]
547 set profile($target) [list [$w.description.entry get] \
548 [$w.host.entry get] \
549 [$w.port.entry get] \
550 [$w.idAuthentication.entry get] \
551 [$w.maximumRecordSize.entry get] \
552 [$w.preferredMessageSize.entry get] \
560 puts $profile($target)
561 destroy .setup-${target}
565 proc place-force {window parent} {
566 set g [wm geometry $parent]
568 set p1 [string first + $g]
569 set p2 [string last + $g]
571 set x [expr 40+[string range $g [expr $p1 +1] [expr $p2 -1]]]
572 set y [expr 60+[string range $g [expr $p2 +1] end]]
573 wm geometry $window +${x}+${y}
577 proc add-database-action {target} {
578 set w .setup-${target}
580 ${w}.top.databases.list insert end \
581 [.database-select.top.database.entry get]
582 destroy .database-select
585 proc add-database {target} {
586 set w .database-select
591 place-force $w .setup-${target}
595 frame $w.top.database
597 pack $w.top.database -side top -anchor e -pady 2
599 entry-fields $w.top {database} \
600 {{Database to add:}} \
601 [list add-database-action $target] {destroy .database-select}
603 top-down-ok-cancel $w [list add-database-action $target] 1
607 proc delete-database {target} {
608 set w .setup-${target}
610 foreach i [lsort -decreasing \
611 [$w.top.databases.list curselection]] {
612 $w.top.databases.list delete $i
616 proc protocol-setup {target} {
623 global ResultSetCheck
627 wm title $w "Setup $target"
636 puts $profile($target)
640 frame $w.top.description
641 frame $w.top.idAuthentication
642 frame $w.top.maximumRecordSize
643 frame $w.top.preferredMessageSize
644 frame $w.top.cs-type -relief ridge -border 2
645 frame $w.top.query -relief ridge -border 2
646 frame $w.top.databases -relief ridge -border 2
648 # Maximum/preferred/idAuth ...
649 pack $w.top.description $w.top.host $w.top.port \
650 $w.top.idAuthentication $w.top.maximumRecordSize \
651 $w.top.preferredMessageSize -side top -anchor e -pady 2
653 entry-fields $w.top {description host port idAuthentication \
654 maximumRecordSize preferredMessageSize} \
655 {{Description:} {Host:} {Port:} {Id Authentification:} \
656 {Maximum Record Size:} {Preferred Message Size:}} \
657 [list protocol-setup-action $target] [list destroy $w]
659 foreach sub {description host port idAuthentication \
660 maximumRecordSize preferredMessageSize} {
662 bind $w.top.$sub.entry <Control-a> "add-database $target"
663 bind $w.top.$sub.entry <Control-d> "delete-database $target"
665 $w.top.description.entry insert 0 [lindex $profile($target) 0]
666 $w.top.host.entry insert 0 [lindex $profile($target) 1]
667 $w.top.port.entry insert 0 [lindex $profile($target) 2]
668 $w.top.idAuthentication.entry insert 0 [lindex $profile($target) 3]
669 $w.top.maximumRecordSize.entry insert 0 [lindex $profile($target) 4]
670 $w.top.preferredMessageSize.entry insert 0 [lindex $profile($target) 5]
671 set csRadioType [lindex $profile($target) 6]
672 set RPNCheck [lindex $profile($target) 8]
673 set CCLCheck [lindex $profile($target) 9]
674 set ResultSetCheck [lindex $profile($target) 10]
677 pack $w.top.databases -side left -pady 6 -padx 6 -expand yes -fill x
679 label $w.top.databases.label -text "Databases"
680 button $w.top.databases.add -text "Add" \
681 -command "add-database $target"
682 button $w.top.databases.delete -text "Delete" \
683 -command "delete-database $target"
684 listbox $w.top.databases.list -geometry 20x6 \
685 -yscrollcommand "$w.top.databases.scroll set"
686 scrollbar $w.top.databases.scroll -orient vertical -border 1
687 pack $w.top.databases.label -side top -fill x \
689 pack $w.top.databases.add $w.top.databases.delete -side top -fill x \
691 pack $w.top.databases.list -side left -fill both -expand yes \
693 pack $w.top.databases.scroll -side right -fill y \
695 $w.top.databases.scroll config -command "$w.top.databases.list yview"
697 foreach b [lindex $profile($target) 7] {
698 $w.top.databases.list insert end $b
702 pack $w.top.cs-type -pady 6 -padx 6 -side top
704 label $w.top.cs-type.label -text "Transport"
705 radiobutton $w.top.cs-type.tcpip -text "TCP/IP" \
706 -command {puts tcp/ip} -variable csRadioType -value tcpip
707 radiobutton $w.top.cs-type.mosi -text "MOSI" \
708 -command {puts mosi} -variable csRadioType -value mosi
710 pack $w.top.cs-type.label $w.top.cs-type.tcpip $w.top.cs-type.mosi \
711 -padx 4 -side top -fill x
714 pack $w.top.query -pady 6 -padx 6 -side top
716 label $w.top.query.label -text "Query support" -anchor e
717 checkbutton $w.top.query.c1 -text "RPN query" -variable RPNCheck
718 checkbutton $w.top.query.c2 -text "CCL query" -variable CCLCheck
719 checkbutton $w.top.query.c3 -text "Result sets" -variable ResultSetCheck
721 pack $w.top.query.label -side top
722 pack $w.top.query.c1 $w.top.query.c2 $w.top.query.c3 \
723 -padx 4 -side top -fill x
726 top-down-ok-cancel $w [list protocol-setup-action $target] 0
729 proc database-select-action {} {
730 set w .database-select.top
732 foreach indx [$w.databases.list curselection] {
733 lappend b [$w.databases.list get $indx]
738 destroy .database-select
741 proc database-select {} {
742 set w .database-select
752 frame $w.top.databases -relief ridge -border 2
754 pack $w.top.databases -side left -pady 6 -padx 6 -expand yes -fill x
756 label $w.top.databases.label -text "List"
757 listbox $w.top.databases.list -geometry 20x6 \
758 -yscrollcommand "$w.top.databases.scroll set"
759 scrollbar $w.top.databases.scroll -orient vertical -border 1
760 pack $w.top.databases.label -side top -fill x \
762 pack $w.top.databases.list -side left -fill both -expand yes \
764 pack $w.top.databases.scroll -side right -fill y \
766 $w.top.databases.scroll config -command "$w.top.databases.list yview"
768 foreach b [lindex $profile($hostid) 7] {
769 $w.top.databases.list insert end $b
771 top-down-ok-cancel $w {database-select-action} 1
774 proc cascade-target-list {} {
777 foreach sub [winfo children .top.target.m.clist] {
781 .top.target.m.clist delete 0 last
782 foreach n [array names profile] {
783 if {$n != "Default"} {
784 set nl [string tolower $n]
785 if {[llength [lindex $profile($n) 7]] > 1} {
786 .top.target.m.clist add cascade -label $n \
787 -menu .top.target.m.clist.$nl
788 menu .top.target.m.clist.$nl
789 foreach b [lindex $profile($n) 7] {
790 .top.target.m.clist.$nl add command -label $b \
791 -command "menu-open-target $n $b"
794 .top.target.m.clist add command -label $n \
795 -command "menu-open-target $n {}"
799 .top.target.m.slist delete 0 last
800 foreach n [array names profile] {
801 if {$n != "Default"} {
802 .top.target.m.slist add command -label $n \
803 -command "protocol-setup $n"
808 proc save-settings {} {
811 global settingsChanged
813 set f [open "~/.tk-c" w]
814 puts $f "# Setup file"
815 puts $f "set hotTargets \{ $hotTargets \}"
817 foreach n [array names profile] {
818 puts -nonewline $f "set profile($n) \{"
819 puts -nonewline $f $profile($n)
823 set settingsChanged 0
835 message $w.top.message -text $ask
837 pack $w.top.message -side left -pady 6 -padx 20 -expand yes -fill x
840 top-down-ok-cancel $w {alert-action} 1
844 proc alert-action {} {
850 proc exit-action {} {
851 global settingsChanged
853 if {$settingsChanged} {
854 set a [alert "you havent saved your settings. Do you wish to save?"]
862 frame .top -border 1 -relief raised
863 frame .mid -border 1 -relief raised
864 frame .data -border 1 -relief raised
865 frame .bot -border 1 -relief raised
866 pack .top .mid -side top -fill x
867 pack .data -side top -fill both -expand yes
870 menubutton .top.file -text "File" -underline 0 -menu .top.file.m
872 .top.file.m add command -label "Save settings" -command {save-settings}
873 .top.file.m add command -label "Load Set" -command {load-set}
874 .top.file.m add separator
875 .top.file.m add command -label "Exit" -command {exit-action}
877 menubutton .top.target -text "Target" -underline 0 -menu .top.target.m
879 .top.target.m add cascade -label "Connect" -menu .top.target.m.clist
880 .top.target.m add command -label "Disconnect" -command {close-target}
881 #.top.target.m add command -label "Initialize" -command {init-request}
882 .top.target.m add cascade -label "Setup" -menu .top.target.m.slist
883 .top.target.m add command -label "Setup new" -command {define-target-dialog}
884 .top.target.m add separator
887 .top.target.m disable 1
889 menu .top.target.m.clist
890 menu .top.target.m.slist
893 menubutton .top.database -text "Database" -underline 0 -menu .top.database.m
895 .top.database.m add command -label "Select ..." -command {database-select}
896 .top.database.m add command -label "Add ..." -command {puts "Add"}
898 menubutton .top.help -text "Help" -menu .top.help.m
901 .top.help.m add command -label "Help on help" -command {puts "Help on help"}
902 .top.help.m add command -label "About" -command {puts "About"}
904 pack .top.file .top.target .top.database -side left
905 pack .top.help -side right
907 label .mid.searchlabel -text {Search:}
908 entry .mid.searchentry -width 32 -relief sunken
909 pack .mid.searchlabel -side left
910 pack .mid.searchentry -side left -fill x -expand yes
912 focus .mid.searchentry
913 bind .mid.searchentry <Left> {left-cursor .mid.searchentry}
914 bind .mid.searchentry <Right> {right-cursor .mid.searchentry}
916 listbox .data.list -yscrollcommand {.data.scroll set}
917 scrollbar .data.scroll -orient vertical -border 1
918 pack .data.list -side left -fill both -expand yes
919 pack .data.scroll -side right -fill y
920 .data.scroll config -command {.data.list yview}
922 message .bot.target -text "None" -aspect 1000 -relief sunken -border 1
923 label .bot.status -text "Not connected" -width 12 -relief \
924 sunken -anchor w -border 1
925 label .bot.set -textvariable setNo -width 5 -relief \
926 sunken -anchor w -border 1
927 label .bot.message -text "" -width 14 -relief \
928 sunken -anchor w -border 1
929 pack .bot.target .bot.status .bot.set .bot.message -anchor nw \
930 -side left -padx 2 -pady 2
932 bind .data.list <Double-Button-1> {set indx [.data.list nearest %y]
933 show-full-marc $indx}