# Setting the Preferences (SP) # Gerald Banon, 1998, 1999 package provide dpi.inpe.br/banon/1998/08.02.08.56 2.1 # ---------------------------------------------------------------------- # SPDialog # Example 33-2 # the entry names and types are: # spLanguage .lis. # spMail .ent. # spBrowser .lis. # spPort .ent. proc SPDialog {} { global w global environmentArray global sp.prePostMenu global sp global spPreferenceButton global spCheck global languageTable global textLog global log global spPreference global typeTable global listNameTable global spLanguageLabel spMailLabel spBrowserLabel spPortLabel global spToupper global spDialogLanguage global spSettingArray global spArrayName global homePath global apacheRepository # global localURLibServer # global localURLibServerPort # global localURLibClientSocketId global loCoInRep ;# for installation purpose set buttonList {language mail browser port} if ![info exists environmentArray(spEMailAddressList)] { set environmentArray(spEMailAddressList) "" } set f .sp if ![info exists spArrayName] {set spArrayName environmentArray} set test "" set test $test[Dialog_Create $f "URLib Service" \ {-borderwidth 10} $spArrayName] if $test { set spLanguageLabel " Language " set spMailLabel " E-Mail Address " set spBrowserLabel " Browser " set spPortLabel " Port Number " set typeTable(spLanguage) .lis. set typeTable(spMail) .ent. set typeTable(spBrowser) .lis. set typeTable(spPort) .ent. set listNameTable(spLanguage) languageList set listNameTable(spMail) \ environmentArray(spEMailAddressList) set listNameTable(spBrowser) browserList set listNameTable(spPort) \ environmentArray(spPortList) set spToupper(language) Language set spToupper(mail) Mail set spToupper(browser) Browser set spToupper(port) Port if ![info exists spDialogLanguage] { SetInitialValue spPreferenceButton language set spPreference sp$spToupper($spPreferenceButton) } set currentLanguage $environmentArray(spLanguageEntry) # spDialogLanguage set spDialogLanguage $currentLanguage if {$spArrayName == "environmentArray"} { foreach button $buttonList { set entryName sp$spToupper($button) if [info exists \ environmentArray(${entryName}Entry)] { set spSettingArray(${entryName}Entry) \ $environmentArray(${entryName}Entry) } else { set spSettingArray(${entryName}Entry) {} } } } set W [winfo pixels $f 10c] wm minsize $f $W 200 ;# 200 could be anything else Header $f "Setting the Preferences" set font [lindex [$f.lb configure -font] end] # menubar frame $f.menubar set width 3 set height .66 pack propagate $f.menubar false foreach button $buttonList { frame $f.menubar.$button \ -width [format "%sc" $width] \ -height [format "%sc" $height] pack propagate $f.menubar.$button false set $button [button $f.menubar.$button.b \ -borderwidth 2 -cursor hand2 \ -command "ProcessPreferenceButtons $f $button"] set labelName sp$spToupper($button)Label eval ConfigText $$button $$labelName eval pack $$button -fill both -expand true } grid $f.menubar.language $f.menubar.mail grid $f.menubar.browser $f.menubar.port set bg [. cget -bg] set nc [NewColor . $bg] $f.menubar.$spPreferenceButton.b configure -bg $nc # menubar - end # scroll forward and backward frame $f.scroll -width 1.18c -height .5c set width .59c set height .5c set buttonNames {backward forward} set forwardLabel > set backwardLabel < pack propagate $f.scroll false foreach button $buttonNames { frame $f.scroll.$button -width $width -height $height pack propagate $f.scroll.$button false pack $f.scroll.$button -side left set $button [button $f.scroll.$button.b \ -cursor hand2 \ -font {-family courier -size 11 -weight normal} \ -command "ProcessScrollButtons $f \ $button {$buttonList}"] eval $$button config -text $${button}Label eval pack $$button -fill both -expand true } # scroll forward and backward - end frame $f.sp -height .6c ;# extra space # Preference frame $f.pre -borderwidth 4 -relief groove frame $f.pre.sp -height .2c ;# extra space label $f.lbpre -font {$font 10 roman} ConfigText $f.lbpre \ [subst $${spPreference}Label] set bg [lindex [$f configure -bg] end] set t [text $f.pre.text -wrap word -fg black \ -relief flat -bg $bg -width 50] ;# 50 = text size $spToupper($spPreferenceButton)Text $t set a [expr [expr 3.7 - 4.0] / [expr 94 - 76]] set b [expr 4.0 - 76 * $a] set center [expr $a * [winfo pixels $t 2c] + $b]c $t configure -tabs "$center center" $t configure -height 3 $t configure -state disabled set aPreference [Selector $f.pre spPreference sp 1 \ $listNameTable($spPreference) 0] # button4 ConfigText $aPreference.button4.4 Remove $aPreference.button4.4 configure \ -command "RemoveEntry $aPreference spPreference \ sp(result1)" ConfigText $f.pre.lb4 " Remove the Current Entry " pack propagate $aPreference.button4 false # button4 - end pack $f.pre.sp -side top ;# extra space pack $t -side top place $f.lbpre -in $f.pre -anchor center \ -relx 0.5 -y -2 # Preference - end frame $f.sp3 -height .25c ;# extra space set spCheck $environmentArray(spCheck) checkbutton $f.check -variable spCheck ConfigText $f.check \ {Always show the Preferences when starting} set b [Footer $f sp(ok)] pack $f.lb -side top -pady .25c pack $f.sp1 -side top ;# extra space pack $f.menubar -side top pack $f.scroll -side top pack $f.sp -side top ;# extra space pack $f.pre -side top -fill x -padx .2c -pady .05c pack $f.check -side top -pady .2c pack $aPreference -padx 1c -pady .45c pack $b -side top -pady .25c # bind $f.entry {set sp(ok) 1 ; break} # bind $f.entry {set sp(ok) 0 ; break} # help bind $f <1> "ProcessButton1 $f" ;# ??? # help - end set focus $aPreference.entry } else { set aPreference $f.pre.entry set focus [focus -lastfor $f] ProcessPreferenceButtons $f \ $environmentArray(spPreferenceButton) } # geometry set pixels [winfo pixels $f 1i] ;# $pixels == 96 or 120 # 28 is the scroll bar width at large font (120) set W [expr [winfo width .window] - int(($pixels. / 120) * 29) - 1] set H [expr $pixels * 3 + 76] set X [winfo pixels $f 0.08c] set Y [winfo pixels $f 1.96c] wm geometry $f ${W}x$H+$X+$Y # window has changed size # bind on $f.lb is better than on $f # the event occurs only once at each change bind $f.lb \ "$aPreference.entry xview moveto 1.0; \ set sp(ok) sp" # window has changed size - end set sp(ok) 0 Dialog_Wait $f sp(ok) $focus $aPreference spPreference 0 Dialog_Dismiss $f # to let dismiss the .sp window set x 0; after 1 {set x 1}; vwait x # to let dismiss the .sp window - end set sp.prePostMenu 0 if $sp(ok) { # OK set environmentArray(spPreferenceButton) \ $spPreferenceButton # save result in the spSettingArray if {$spPreferenceButton == "mail"} { # put to lower case # mkdir / windows 95 work properly just for lower case set sp(result1) [string tolower $sp(result1)] } set spSettingArray(${spPreference}Entry) $sp(result1) # save result in the spSettingArray - end # test the current entry if [TestEntry $f $spPreferenceButton] {return 1} # test the current entry - end # test other entries foreach button $buttonList { if [TestEntry $f $button] {return 1} } # test other entries - end # if ![info exists environmentArray(spEMailAddressList)] { # set environmentArray(spEMailAddressList) "" # } # mail if {[lsearch -exact $environmentArray(spEMailAddressList) \ $spSettingArray(spMailEntry)] == -1} { lappend environmentArray(spEMailAddressList) \ $spSettingArray(spMailEntry) } set environmentArray(spMailSelectMenu) [UpdateList \ $typeTable(spMail) sp \ environmentArray(spMailSelectMenu) \ $spSettingArray(spMailEntry) 8 \ environmentArray(spEMailAddressList)] # port if {[lsearch -exact $environmentArray(spPortList) \ $spSettingArray(spPortEntry)] == -1} { lappend environmentArray(spPortList) \ $spSettingArray(spPortEntry) } set environmentArray(spPortSelectMenu) [UpdateList \ $typeTable(spPort) sp \ environmentArray(spPortSelectMenu) \ $spSettingArray(spPortEntry) 8 \ environmentArray(spPortList)] # oldPortNumber set oldPortNumber $environmentArray(spPortEntry) foreach button $buttonList { set entryName sp$spToupper($button) set environmentArray(${entryName}Entry) \ $spSettingArray(${entryName}Entry) } # portNumber set portNumber $environmentArray(spPortEntry) set environmentArray(spCheck) $spCheck # source the current language SourceLanguage environmentArray # source the current language - end # start servers (unless loCoInRep doesn't exist (true at installation)) if {[info exists loCoInRep] && \ $oldPortNumber != "$portNumber"} { if [StartServers 0] {return 1} } # start servers - end # compute the log $log delete 1.0 end foreach cmd $textLog {eval [join $cmd \n]} # compute the log - end LogInsert [list [list $log insert end \n]] ;# blk line LogInsert [list [list Insert $log end \ {$var1 selected as your language} \ {} $spSettingArray(spLanguageEntry)] \ [list TagAdd $log italic8 \ {$var1} -forward \ $spSettingArray(spLanguageEntry)] \ [list $log insert insert \n]] LogInsert [list [list Insert $log end \ {<$var1> selected as your e-mail address} \ {} $spSettingArray(spMailEntry)] \ [list TagAdd $log fixed9 \ {<$var1>} -forward $spSettingArray(spMailEntry)] \ [list $log insert insert \n]] LogInsert [list [list Insert $log end \ {$var1 selected as your browser} \ {} $spSettingArray(spBrowserEntry)] \ [list TagAdd $log italic8 \ {$var1} -forward \ $spSettingArray(spBrowserEntry)] \ [list $log insert insert \n]] LogInsert [list [list Insert $log end \ {<$var1> selected as your port number} \ {} $spSettingArray(spPortEntry)] \ [list TagAdd $log fixed9 \ {<$var1>} -forward $spSettingArray(spPortEntry)] \ [list $log insert insert \n]] # display message (unless loCoInRep doesn't exist (true at installation)) # hostName set hostName $environmentArray(hostName) if {[info exists loCoInRep] && \ $oldPortNumber != "$portNumber"} { # domainName # set domainName $environmentArray(domainName) # serverName # set serverName $hostName.$domainName # serverAddress # set serverAddress $serverName:$portNumber set serverAddress [GetServerAddress] # regsub -all {\.|:} $serverAddress {} tagName set tagName $serverAddress LogInsert [list [list $log insert end \n]] LogInsert [list [list Insert $log end \ {internet address of the local collection: <$var1>} \ $tagName $serverAddress] \ [list TagAdd $log fixed9 {<$var1>} \ -forward $serverAddress] \ [list TagAdd $log blue {$var1} \ -forward $serverAddress] \ [list $log insert insert \n]] $log tag bind $tagName <1> "Link {} $serverAddress" $log tag bind $tagName "$log config -cursor hand2" $log tag bind $tagName "$log config -cursor double_arrow" } # update main window titlte and labels wm title $w "$hostName:$portNumber - ${Text::URLib Service}" ConfigText $w.sp.dd " Depositing a Document " ConfigText $w.sp.sp " Setting the Preferences " # update main window titlte and labels - end if ![info exists environmentArray(localCollectionIndexRepository)] { # display warning message LogInsert [list [list $log insert end \n]] LogInsert [list [list Insert $log end \ {installing the initial collection ...}] \ [list $log insert insert \n]] # display warning message - end } $log yview moveto 1.0 # SAVE StoreArray environmentArray \ ../auxdoc/.environmentArray.tcl destroy .sphelp # $aPreference.button1.1 configure -state normal ConfigText .window.menubar.dd.1 DD ConfigText .window.menubar.sp.1 SP ConfigText .window.menubar.quit.1 Quit set spArrayName environmentArray if ![info exists \ environmentArray(localCollectionIndexRepository)] { # installation time # create a repository for the Local Collection Index # set environmentArray(localCollectionIndexRepository) # create a repository for the corresponding metadata # StartService } return 0 } else { # cancel - nothing done; reset the entries # if is usefull when the window is withdrawn by a click on x button if ![winfo exists $f] {return 0} ProcessPreferenceButtons $f \ $environmentArray(spPreferenceButton) # the above command have the effect of # SetInitialValue spPreferenceButton language # process language SourceLanguage environmentArray # compute the log $log delete 1.0 end foreach cmd $textLog {eval [join $cmd \n]} # compute the log - end $log yview moveto 1.0 # process language - end foreach button $buttonList { set entryName sp$spToupper($button) if [info exists \ environmentArray(${entryName}Entry)] { set spSettingArray(${entryName}Entry) \ $environmentArray(${entryName}Entry) } } set spCheck $environmentArray(spCheck) destroy .sphelp return 0 } } # SPDialog - end # ---------------------------------------------------------------------- # ProcessPreferenceButtons proc ProcessPreferenceButtons {f activeButton} { global spLanguageLabel spMailLabel spBrowserLabel spPortLabel global spToupper global spPreferenceButton ;# values are language, mail, ... global spPreference ;# values are spLanguage, spMail, ... global listNameTable global typeTable global spSettingArray global sp # save result in the spSettingArray if {$spPreferenceButton == "mail"} { # put to lower case # mkdir / windows 95 work properly just for lower case set sp(result1) [string tolower $sp(result1)] } set spSettingArray(${spPreference}Entry) $sp(result1) # save result in the spSettingArray - end set bg [. cget -bg] $f.menubar.$spPreferenceButton.b configure -bg $bg set spPreferenceButton $activeButton set spPreference sp$spToupper($spPreferenceButton) ;# spMail set type $typeTable($spPreference) if [regexp {\.ent\.} $type] { pack $f.pre.entry.button4 -side right } else { pack forget $f.pre.entry.button4 } set nc [NewColor . $bg] $f.menubar.$spPreferenceButton.b configure -bg $nc ConfigText $f.lbpre [subst $${spPreference}Label] ;# spMailLabel $spToupper($spPreferenceButton)Text $f.pre.text ;# MailText # set entry SetEntry $f.pre.entry ${spPreference}Entry \ sp result1 spSettingArray ;# spMailEntry CompleteEntry $f.pre.entry.entry spPreference sp(result1) check } # ProcessPreferenceButtons - end # ---------------------------------------------------------------------- # ProcessScrollButtons proc ProcessScrollButtons {f activeButton buttonList} { global spPreferenceButton ;# values are language, mail, ... if {$activeButton == "forward"} { set newList $buttonList lappend newList [lindex $buttonList 0] set i [lsearch -exact $buttonList $spPreferenceButton] incr i } else { set newList [list [lindex $buttonList end]] set newList [concat $newList $buttonList] set i [lsearch -exact $buttonList $spPreferenceButton] } ProcessPreferenceButtons $f [lindex $newList $i] } # ProcessScrollButtons - end # ---------------------------------------------------------------------- # LanguageText proc LanguageText {t} { $t configure -state normal $t delete 1.0 end TextStyles $t $t insert insert "\n\t" Insert $t insert \ {Please choose one of the existing languages.} $t configure -state disabled } # LanguageText - end # ---------------------------------------------------------------------- # MailText proc MailText {t} { $t configure -state normal $t delete 1.0 end TextStyles $t $t insert insert "\t" Insert $t insert \ {Please enter your e-mail address.} $t insert insert "\n\t" Insert $t insert \ {It has to be of the form:} $t insert insert "\n\t" Insert $t insert \ {.} TagAdd $t fixed9 {} $t configure -state disabled } # MailText - end # ---------------------------------------------------------------------- # BrowserText proc BrowserText {t} { $t configure -state normal $t delete 1.0 end TextStyles $t $t insert insert "\n\t" Insert $t insert \ {Please choose one browser.} $t configure -state disabled } # BrowserText - end # ---------------------------------------------------------------------- # PortText proc PortText {t} { $t configure -state normal $t delete 1.0 end $t insert insert "\n\t" Insert $t insert \ {Please enter your port number.} $t insert insert "\n\t" Insert $t insert \ {It should be an integer between <1905> and <6553>.} TagAdd $t fixed9 {<1905>} TagAdd $t fixed9 {<6553>} $t configure -state disabled } # PortText - end # ---------------------------------------------------------------------- # TestEntry proc TestEntry {f button} { global spSettingArray global spLanguageLabel spMailLabel spBrowserLabel spPortLabel global spArrayName global log global textLog global environmentArray upvar #0 Text::enter enter upvar #0 Text::check check upvar #0 {Text:: Language } language upvar #0 {Text:: Browser } browser # test language entry if {$button == "language"} { if [regexp "^\[ \t]*$" $spSettingArray(spLanguageEntry)] { Dialog OK disabled -1 SP {the entry is empty} \ $language ProcessPreferenceButtons $f language set spArrayName spSettingArray return 1 } # process language SourceLanguage spSettingArray # compute the log $log delete 1.0 end foreach cmd $textLog {eval [join $cmd \n]} # compute the log - end # process language - end return 0 } # test mail entry if {$button == "mail"} { if ![string match *?@?* \ $spSettingArray(spMailEntry)] { if [regexp "^\[ \t]*$" $spSettingArray(spMailEntry)] { set word $enter } else { set word $check } Dialog OK disabled -1 SP {address syntax error} $word ProcessPreferenceButtons $f mail set spArrayName spSettingArray return 1 } return 0 } # test browser entry if {$button == "browser"} { if [regexp "^\[ \t]*$" $spSettingArray(spBrowserEntry)] { Dialog OK disabled -1 SP {the entry is empty} \ $browser ProcessPreferenceButtons $f browser set spArrayName spSettingArray return 1 } # >> if [regexp "Netscape" $spSettingArray(spBrowserEntry)] { # > # netscape if {![info exists environmentArray(netscape)] || \ [info exists environmentArray(netscape)] && \ ![file exists $environmentArray(netscape)]} { if [file exists \ {C:/Program Files/Netscape/Communicator/Program/netscape.exe}] { set environmentArray(netscape) \ {C:/Program Files/Netscape/Communicator/Program/netscape.exe} } else { if [file exists \ /home/galileo/solaris/netscape4.02/netscape] { set environmentArray(netscape) \ /home/galileo/solaris/netscape4.02/netscape } else { # > set warning [Warning SP searching netscape.exe] update idletasks ;# allows the warning to appear set filePath "" if {$tcl_platform(platform) == "windows"} { FindFile filePath C:/ netscape.exe } if {$tcl_platform(platform) == "unix"} { FindFile filePath / netscape } destroy $warning ;# because end of FindFile if {$filePath == ""} { Dialog OK disabled -1 SP {browser not found} \ Netscape ProcessPreferenceButtons $f browser set spArrayName spSettingArray return 1 } else { set environmentArray(netscape) $filePath } # < } } } # netscape - end # < } if [regexp "Internet Explorer" $spSettingArray(spBrowserEntry)] { # > # internet explorer if {![info exists environmentArray(internetExplorer)] || \ [info exists environmentArray(internetExplorer)] && \ ![file exists $environmentArray(internetExplorer)]} { if [file exists \ {C:/Program Files/Internet Explorer/Iexplore.exe}] { set environmentArray(internetExplorer) \ {C:/Program Files/Internet Explorer/Iexplore.exe} } else { set warning [Warning SP searching Iexplore.exe] update idletasks ;# allows the warning to appear set filePath "" FindFile filePath C:/ Iexplore.exe destroy $warning if {$filePath == ""} { Dialog OK disabled -1 SP {browser not found} \ {Internet Explorer} ProcessPreferenceButtons $f browser set spArrayName spSettingArray return 1 } else { set environmentArray(internetExplorer) $filePath } } } # internet explorer - end # < } StoreArray environmentArray ../auxdoc/.environmentArray.tcl # << return 0 } # test port entry if {$button == "port"} { if {$spSettingArray(spPortEntry) < 1905 || $spSettingArray(spPortEntry) > 6553} { if [regexp "^\[ \t]*$" $spSettingArray(spPortEntry)] { set word $enter } else { set word $check } Dialog OK disabled -1 SP {port syntax error} $word ProcessPreferenceButtons $f port set spArrayName spSettingArray return 1 } return 0 } } # TestEntry - end # ----------------------------------------------------------------------