Bug fix.
[ir-tcl-moved-to-github.git] / client.tcl
index d82e8c6..a1ee047 100644 (file)
@@ -1,6 +1,27 @@
 #
 # $Log: client.tcl,v $
-# Revision 1.19  1995-04-18 16:11:50  adam
+# Revision 1.25  1995-05-31 13:09:57  adam
+# Client searches/presents may be interrupted.
+# New moving book-logo.
+#
+# Revision 1.24  1995/05/31  08:36:24  adam
+# Bug fix in client.tcl: didn't save options on clientrc.tcl.
+# New method: referenceId. More work on scan.
+#
+# Revision 1.23  1995/05/29  10:33:41  adam
+# README and rename of startup script.
+#
+# Revision 1.22  1995/05/26  11:44:09  adam
+# Bugs fixed. More work on MARC utilities and queries. Test
+# client is up-to-date again.
+#
+# Revision 1.21  1995/05/11  15:34:46  adam
+# Scan request changed a bit. This version works with RLG.
+#
+# Revision 1.20  1995/04/21  16:31:57  adam
+# New radiobutton: protocol (z39v2/SR).
+#
+# Revision 1.19  1995/04/18  16:11:50  adam
 # First version of graphical Scan. Some work on query-by-form.
 #
 # Revision 1.18  1995/04/10  10:50:22  adam
@@ -66,19 +87,22 @@ set hotTargets {}
 set hotInfo {}
 set busy 0
 
-set profile(Default) {{} {} {210} {} 16384 8192 tcpip {}}
+set profile(Default) {{} {} {210} {} 16384 8192 tcpip {} 1 {} {} z39v2}
 set hostid Default
 set settingsChanged 0
 set setNo 0
+set cancelFlag 0
+set searchEnable 0
 
 set queryTypes {Simple}
 set queryButtons { { {I 0} {I 1} {I 2} } }
-set queryInfo { { {Title ti} {Author au} {Subject sh} {Any any} } }
+set queryInfo { { {Title {1=4}} {Author {1=1}} \
+        {Subject {1=21}} {Any {1=1016}} } }
 
-wm minsize . 300 250
+wm minsize . 0 0
 
-if {[file readable "~/.tk-c"]} {
-    source "~/.tk-c"
+if {[file readable "clientrc.tcl"]} {
+    source "clientrc.tcl"
 }
 
 set queryButtonsFind [lindex $queryButtons 0]
@@ -88,7 +112,8 @@ proc top-down-window {w} {
     frame $w.top -relief raised -border 1
     frame $w.bot -relief raised -border 1
     
-    pack  $w.top $w.bot -side top -fill both -expand yes
+    pack  $w.top -side top -fill both -expand yes
+    pack  $w.bot -fill both
 }
 
 proc top-down-ok-cancel {w ok-action g} {
@@ -136,34 +161,64 @@ proc top-down-ok-cancelx {w buttonList g} {
     }
 }
 
+proc cancel-operation {} {
+    global cancelFlag
+
+    set cancelFlag 1
+    show-status Cancelled 0 {}
+}
+
 proc show-target {target} {
     .bot.target configure -text "$target"
 }
 
-proc show-busy {v1 v2} {
+proc show-logo {v1} {
     global busy
     if {$busy != 0} {
-        .bot.status configure -fg $v1
-        after 200 [list show-busy $v2 $v1]
+        incr v1 -1
+        if {$v1==0} {
+            set v1 9
+        }
+        .mid.logo configure -bitmap @book${v1}
+        after 140 [list show-logo $v1]
+        return
+    }
+    while {1} {
+        tkwait variable busy
+        if {$busy} {
+            show-logo 1
+            return
+        }
+        .mid.logo configure -bitmap @book1
     }
 }
         
-proc show-status {status b} {
+proc show-status {status b sb} {
     global busy
-    global statusbg
+    global searchEnable
+
     .bot.status configure -text "$status"
-    .bot.status configure -fg black
-    if {$b != 0} {
-        if {$busy == 0} {
-            set busy $b   
-            show-busy red blue
-        }
-        #        . config -cursor {watch black white}
+    if {$b == 1} {
+        if {$busy == 0} {set busy 1}
     } else {
-        #        . config -cursor {top_left_arrow black white}
-        puts "Normal"
+        set busy 0
+    }
+    if {$sb == {}} {
+        return
+    }
+    if {$sb} {
+        .top.search configure -state normal
+        .mid.search configure -state normal
+        .mid.scan configure -state normal
+        .mid.present configure -state normal
+        set searchEnable 1
+    } else {
+        .top.search configure -state disabled
+        .mid.search configure -state disabled
+        .mid.scan configure -state disabled
+        .mid.present configure -state disabled
+        set searchEnable 0
     }
-    set busy $b
 }
 
 proc show-message {msg} {
@@ -209,7 +264,7 @@ proc show-full-marc {no} {
     }
     incr no
     
-    set r [z39.$setNo recordMarc $no line * * *]
+    set r [z39.$setNo getMarc $no list * * *]
 
     $w.top.record tag configure marc-tag -foreground blue
     $w.top.record tag configure marc-data -foreground black
@@ -324,7 +379,7 @@ proc open-target {target base} {
 
     z39 disconnect
     z39 comstack [lindex $profile($target) 6]
-    # z39 idAuthentication [lindex $profile($target) 3]
+    z39 idAuthentication [lindex $profile($target) 3]
     z39 maximumRecordSize [lindex $profile($target) 4]
     z39 preferredMessageSize [lindex $profile($target) 5]
     puts -nonewline "maximumRecordSize="
@@ -339,7 +394,7 @@ proc open-target {target base} {
     z39 failback [list fail-response $target]
     z39 callback [list connect-response $target]
     z39 connect [lindex $profile($target) 1]:[lindex $profile($target) 2]
-    show-status {Connecting} 1
+    show-status {Connecting} 1 0
     set hostid $target
     .top.target.m disable 0
     .top.target.m enable 1
@@ -347,37 +402,37 @@ proc open-target {target base} {
 
 proc close-target {} {
     global hostid
+    global cancelFlag
 
+    set cancelFlag 0
     set hostid Default
     z39 disconnect
     show-target {None}
-    show-status {Not connected} 0
+    show-status {Not connected} 0 0
     show-message {}
     .top.target.m disable 1
     .top.target.m enable 0
-    .top.search configure -state disabled
-    .mid.search configure -state disabled
-    .mid.scan configure -state disabled
+    .mid.logo configure -bitmap @book1
 }
 
 proc load-set-action {} {
     global setNo
 
     incr setNo
-    ir-set z39.$setNo
+    ir-set z39.$setNo z39
 
     set fname [.load-set.top.filename.entry get]
     destroy .load-set
     if {$fname != ""} {
         init-title-lines
 
-        show-status {Loading} 1
+        show-status {Loading} 1 {}
         z39.$setNo loadFile $fname
 
         set no [z39.$setNo numberOfRecordsReturned]
         add-title-lines $setNo $no 1
     }
-    show-status {Ready} 0
+    show-status {Ready} 0 {}
 }
 
 proc load-set {} {
@@ -404,48 +459,69 @@ proc load-set {} {
 
 proc init-request {} {
     global setNo
-    
+    global cancelFlag
+
+    if {$cancelFlag} {
+        close-target
+        return
+    }
     z39 callback {init-response}
+    show-status {Initializing} 1 {}
     z39 init
-    show-status {Initializing} 1
 }
 
 proc init-response {} {
-    show-status {Ready} 0
-    .top.search configure -state normal
-    .mid.search configure -state normal
-    .mid.scan configure -state normal
+    global cancelFlag
+
+    if {$cancelFlag} {
+        close-target
+        return
+    }
+    show-status {Ready} 0 1
+    .mid.logo configure -bitmap @book1
+    if {![z39 initResult]} {
+        set u [z39 userInformationField]
+        close-target
+        tkerror "Connection rejected by target: $u"
+    }
 }
 
 proc search-request {} {
     global setNo
     global profile
     global hostid
+    global busy
+    global cancelFlag
+    global searchEnable
 
     set target $hostid
 
+    if {$searchEnable == 0} {
+        return
+    }
     set query [index-query]
     if {$query==""} {
         return
     }
     incr setNo
-    ir-set z39.$setNo
-
+    ir-set z39.$setNo z39
 
-    if {[lindex $profile($target) 10]} {
+    if {[lindex $profile($target) 10] == 1} {
         z39.$setNo setName $setNo
+        puts "setName=${setNo}"
     } else {
         z39.$setNo setName Default
+        puts "setName=Default"
     }
-    if {[lindex $profile($target) 8]} {
-        z39 query rpn
+    if {[lindex $profile($target) 8] == 1} {
+        z39.$setNo queryType rpn
     }
-    if {[lindex $profile($target) 9]} {
-        z39 query ccl
+    if {[lindex $profile($target) 9] == 1} {
+        z39.$setNo queryType ccl
     }
     z39 callback {search-response}
     z39.$setNo search $query
-    show-status {Search} 1
+    show-status {Search} 1 0
 }
 
 proc scan-request {} {
@@ -456,7 +532,7 @@ proc scan-request {} {
 
     set target $hostid
 
-    ir-scan z39.scan
+    ir-scan z39.scan z39
 
     z39 callback {scan-response}
     if {![winfo exists $w]} {
@@ -477,9 +553,10 @@ proc scan-request {} {
 
         top-down-ok-cancelx $w [list {Close} [list destroy $w]] 0 
     }
-    z39.scan scan 0
+    z39.scan numberOfTermsRequested 100
+    z39.scan scan "@attr 1=4 0"
     
-    show-status {Scan} 1
+    show-status {Scan} 1 0
 }
 
 proc scan-response {} {
@@ -492,16 +569,23 @@ proc scan-response {} {
 
         $w.top.list insert end "$nostr $term"
     }
-    show-status {Ready} 0
+    show-status {Ready} 0 1
 }
 
 proc search-response {} {
     global setNo
     global setOffset
     global setMax
+    global cancelFlag
+    global busy
 
+    puts "In search-response"
     init-title-lines
-    show-status {Ready} 0
+    show-status {Ready} 0 1
+    if {$cancelFlag} {
+        set cancelFlag 0
+        return
+    }
     show-message "[z39.$setNo resultCount] hits"
     set setMax [z39.$setNo resultCount]
     puts $setMax
@@ -515,13 +599,13 @@ proc search-response {} {
         }
         return
     }
-    if {$setMax > 4} {
-        set setMax 4
+    if {$setMax > 10} {
+        set setMax 10
     }
     z39 callback {present-response}
     set setOffset 1
     z39.$setNo present $setOffset $setMax
-    show-status {Retrieve} 1
+    show-status {Retrieve} 1 0
 }
 
 proc present-more {number} {
@@ -546,7 +630,7 @@ proc present-more {number} {
     }
     z39 callback {present-response}
     z39.$setNo present $setOffset [expr $setMax - $setOffset + 1]
-    show-status {Retrieve} 1
+    show-status {Retrieve} 1 0
 }
 
 proc init-title-lines {} {
@@ -556,8 +640,8 @@ proc init-title-lines {} {
 proc add-title-lines {setno no offset} {
     for {set i 0} {$i < $no} {incr i} {
         set o [expr $i + $offset]
-        set title [lindex [z39.$setno recordMarc $o field 245 * a] 0]
-        set year  [lindex [z39.$setno recordMarc $o field 260 * c] 0]
+        set title [lindex [z39.$setno getMarc $o field 245 * a] 0]
+        set year  [lindex [z39.$setno getMarc $o field 260 * c] 0]
         set nostr [format "%5d" $o]
         .data.list insert end "$nostr $title - $year"
     }
@@ -567,6 +651,7 @@ proc present-response {} {
     global setNo
     global setOffset
     global setMax
+    global cancelFlag
 
     puts "In present-response"
     set no [z39.$setNo numberOfRecordsReturned]
@@ -575,17 +660,22 @@ proc present-response {} {
     set setOffset [expr $setOffset + $no]
     set status [z39.$setNo responseStatus]
     if {[lindex $status 0] == "NSD"} {
-        show-status {Ready} 0
+        show-status {Ready} 0 1
         set code [lindex $status 1]
         set msg [lindex $status 2]
         set addinfo [lindex $status 3]
         tkerror "NSD$code: $msg: $addinfo"
         return
     }
+    if {$cancelFlag} {
+        show-status {Ready} 0 1
+        set cancelFlag 0
+        return
+    }
     if {$no > 0 && $setOffset <= $setMax} {
         z39.$setNo present $setOffset [expr $setMax - $setOffset + 1]
     } else {
-        show-status {Finished} 0
+        show-status {Finished} 0 1
     }
 }
 
@@ -654,6 +744,7 @@ proc define-target-dialog {} {
 proc protocol-setup-action {target} {
     global profile
     global csRadioType
+    global protocolRadioType
     global settingsChanged
     global RPNCheck
     global CCLCheck
@@ -679,7 +770,8 @@ proc protocol-setup-action {target} {
             $b \
             $RPNCheck \
             $CCLCheck \
-            $ResultSetCheck ]
+            $ResultSetCheck \
+            $protocolRadioType ]
 
     cascade-target-list
     puts $profile($target)
@@ -741,6 +833,7 @@ proc protocol-setup {target} {
 
     global profile
     global csRadioType
+    global protocolRadioType
     global RPNCheck
     global CCLCheck
     global ResultSetCheck
@@ -765,6 +858,7 @@ proc protocol-setup {target} {
     frame $w.top.maximumRecordSize
     frame $w.top.preferredMessageSize
     frame $w.top.cs-type -relief ridge -border 2
+    frame $w.top.protocol -relief ridge -border 2
     frame $w.top.query -relief ridge -border 2
     frame $w.top.databases -relief ridge -border 2
 
@@ -775,7 +869,7 @@ proc protocol-setup {target} {
     
     entry-fields $w.top {description host port idAuthentication \
             maximumRecordSize preferredMessageSize} \
-            {{Description:} {Host:} {Port:} {Id Authentification:} \
+            {{Description:} {Host:} {Port:} {Id Authentication:} \
             {Maximum Record Size:} {Preferred Message Size:}} \
             [list protocol-setup-action $target] [list destroy $w]
     
@@ -795,9 +889,13 @@ proc protocol-setup {target} {
     set RPNCheck [lindex $profile($target) 8]
     set CCLCheck [lindex $profile($target) 9]
     set ResultSetCheck [lindex $profile($target) 10]
+    set protocolRadioType [lindex $profile($target) 11]
+    if {$protocolRadioType == ""} {
+        set protocolRadioType z39v2
+    }
 
     # Databases ....
-    pack $w.top.databases -side left -pady 6 -padx 6 -expand yes -fill x
+    pack $w.top.databases -side left -pady 6 -padx 6 -expand yes -fill both
 
     label $w.top.databases.label -text "Databases"
     button $w.top.databases.add -text "Add" \
@@ -822,24 +920,36 @@ proc protocol-setup {target} {
     }
 
     # Transport ...
-    pack $w.top.cs-type -pady 6 -padx 6 -side top
+    pack $w.top.cs-type -pady 6 -padx 6 -side top -fill x
     
     label $w.top.cs-type.label -text "Transport" 
-    radiobutton $w.top.cs-type.tcpip -text "TCP/IP" \
+    radiobutton $w.top.cs-type.tcpip -text "TCP/IP" -anchor w \
             -command {puts tcp/ip} -variable csRadioType -value tcpip
-    radiobutton $w.top.cs-type.mosi -text "MOSI" \
+    radiobutton $w.top.cs-type.mosi -text "MOSI" -anchor w\
             -command {puts mosi} -variable csRadioType -value mosi
     
     pack $w.top.cs-type.label $w.top.cs-type.tcpip $w.top.cs-type.mosi \
             -padx 4 -side top -fill x
 
+    # Protocol ...
+    pack $w.top.protocol -pady 6 -padx 6 -side top -fill x
+    
+    label $w.top.protocol.label -text "Protocol" 
+    radiobutton $w.top.protocol.z39v2 -text "Z39.50" -anchor w \
+            -command {puts z39v2} -variable protocolRadioType -value z39v2
+    radiobutton $w.top.protocol.sr -text "SR" -anchor w \
+            -command {puts sr} -variable protocolRadioType -value sr
+    
+    pack $w.top.protocol.label $w.top.protocol.z39v2 $w.top.protocol.sr \
+            -padx 4 -side top -fill x
+
     # Query ...
-    pack $w.top.query -pady 6 -padx 6 -side top
+    pack $w.top.query -pady 6 -padx 6 -side top -fill x
 
-    label $w.top.query.label -text "Query support" -anchor e
-    checkbutton $w.top.query.c1 -text "RPN query" -variable RPNCheck
-    checkbutton $w.top.query.c2 -text "CCL query" -variable CCLCheck
-    checkbutton $w.top.query.c3 -text "Result sets" -variable ResultSetCheck
+    label $w.top.query.label -text "Query support"
+    checkbutton $w.top.query.c1 -text "RPN query" -anchor w -variable RPNCheck
+    checkbutton $w.top.query.c2 -text "CCL query" -anchor w -variable CCLCheck
+    checkbutton $w.top.query.c3 -text "Result sets" -anchor w -variable ResultSetCheck
 
     pack $w.top.query.label -side top 
     pack $w.top.query.c1 $w.top.query.c2 $w.top.query.c3 \
@@ -956,7 +1066,7 @@ proc save-settings {} {
     global queryButtons
     global queryInfo
 
-    set f [open "~/.tk-c" w]
+    set f [open "clientrc.tcl" w]
     puts $f "# Setup file"
     puts $f "set hotTargets \{ $hotTargets \}"
 
@@ -1014,7 +1124,7 @@ proc exit-action {} {
             save-settings
         }
     }
-    destroy .
+    exit 0
 }
 
 proc listbuttonaction {w name h user i} {
@@ -1293,13 +1403,16 @@ proc index-query {} {
         set term [string trim [.lines.$i.e get]]
         if {$term != ""} {
             set attr [lindex [lindex $queryInfoFind [lindex $b 1]] 1]
-            if {$qs != ""} {
-                set qs "${qs} and "
+
+            set term "\{${term}\}"
+            foreach a $attr {
+                set term "@attr $a ${term}"
             }
-            if {$attr != ""} {
-                set qs "${qs}${attr}="
+            if {$qs != ""} {
+                set qs "@and ${qs} ${term}"
+            } else {
+                set qs $term
             }
-            set qs "${qs}(${term})"
         }
         incr i
     }
@@ -1315,21 +1428,24 @@ proc index-lines {w realOp buttonInfo queryInfo handle} {
         }
         listbuttonx $w.$i.l [lindex $b 1] $queryInfo $handle $i
 
-        if {! [winfo exists $w.$i.e]} {
-            if {$realOp} {
-                entry $w.$i.e -width 32 -relief sunken
-            }
-            pack $w.$i.l -side left
-            if {$realOp} {
+        if {$realOp} {
+            if {! [winfo exists $w.$i.e]} {
+                entry $w.$i.e -width 32 -relief sunken -border 1
+                bind $w.$i.e <FocusIn> [list $w.$i configure \
+                        -background red]
+                bind $w.$i.e <FocusOut> [list $w.$i configure \
+                        -background white]
+                pack $w.$i.l -side left
                 pack $w.$i.e -side left -fill x -expand yes
+                pack $w.$i -side top -fill x -padx 2 -pady 2
+                bind $w.$i.e <Left> [list left-cursor $w.$i.e]
+                bind $w.$i.e <Right> [list right-cursor $w.$i.e]
+                bind $w.$i.e <Return> search-request
             }
+        } else {
+            pack $w.$i.l -side left
             pack $w.$i -side top -fill x -padx 2 -pady 2
         }
-        if {$realOp} {
-            bind $w.$i.e <Left> [list left-cursor $w.$i.e]
-            bind $w.$i.e <Right> [list right-cursor $w.$i.e]
-            bind $w.$i.e <Return> search-request
-        }
         incr i
     }
     set j $i
@@ -1344,17 +1460,12 @@ proc index-lines {w realOp buttonInfo queryInfo handle} {
     incr i -1
     while {$j < $i} {
         set k [expr $j+1]
-        bind $w.$j.e <Tab> "focus $w.$k.e \n
-        $w.$k configure -background red \n
-        $w.$j configure -background white"
+        bind $w.$j.e <Tab> "focus $w.$k.e"
         set j $k
     }
     if {$i >= 0} {
-        bind $w.$i.e <Tab> "focus $w.0.e \n
-        $w.0 configure -background red \n
-        $w.$i configure -background white"
+        bind $w.$i.e <Tab> "focus $w.0.e"
         focus $w.0.e
-        $w.0 configure -background red
     }
 }
 
@@ -1449,20 +1560,29 @@ cascade-query-list
 menubutton .top.help -text "Help" -menu .top.help.m
 menu .top.help.m
 
-.top.help.m add command -label "Help on help" -command {puts "Help on help"}
-.top.help.m add command -label "About" -command {puts "About"}
+.top.help.m add command -label "Help on help" \
+        -command {tkerror "Help on help not available. Sorry"}
+.top.help.m add command -label "About" \
+        -command {tkerror "About not available. Sorry"}
 
 pack .top.file .top.target .top.query .top.search -side left
 pack .top.help -side right
 
 index-lines .lines 1 $queryButtonsFind [lindex $queryInfo 0] activate-index
 
-button .mid.search -width 6 -text {Search} -command search-request \
+button .mid.search -width 7 -text {Search} -command search-request \
+        -state disabled
+button .mid.scan -width 7 -text {Scan} -command scan-request \
         -state disabled
-button .mid.scan -width 6 -text {Scan} -command scan-request \
+button .mid.present -width 7 -text {Present} -command [list present-more 10] \
         -state disabled
-button .mid.clear -width 6 -text {Clear} -command index-clear
-pack .mid.search .mid.scan .mid.clear -side left -padx 5 -pady 3
+
+button .mid.clear -width 7 -text {Clear} -command index-clear
+pack .mid.search .mid.scan .mid.present .mid.clear -side left \
+        -fill y -padx 5 -pady 3
+
+button .mid.logo  -bitmap @book1 -command cancel-operation
+pack .mid.logo -side right -pady 3
 
 listbox .data.list -yscrollcommand {.data.scroll set} -font fixed
 scrollbar .data.scroll -orient vertical -border 1
@@ -1484,3 +1604,6 @@ bind .data.list <Double-Button-1> {set indx [.data.list nearest %y]
 show-full-marc $indx}
 
 ir z39
+
+show-logo 1
+