####################################################
#
# First, set up some default configuration settings
#
####################################################

####################################################
# You may need to modify the variables below to make 
# TkReq v8.0 work at your site.  In particular, check
# CONF(reqdir)
# CONF(sendmail)
# CONF(tail)
# CONF(tkreqrc)
# CONF(cc)
# CONF(printCommand)
#####################################################
global tcl_platform CONF
if { [string compare $tcl_platform(os) "Windows NT"] == 0 } {
    set rootdir s:/
    set CONF(perlprefix) "perl "
    set CONF(tail) "[file join $rootdir std bin tail]"
} else {
    set rootdir /s
    set CONF(perlprefix) ""
    switch -exact [exec /usr/afsws/bin/sys] {
	"i386_linux3" { set CONF(tail) "/usr/bin/tail" }
	default       { set CONF(tail) "[file join $rootdir std bin tail]" }
    }
}

# Set up req directories
set CONF(reqdir)        "[file join $rootdir req-1.2.7]"
set CONF(dbdir)         "[file join $CONF(reqdir) reqdb]"
set CONF(faqdir)        "[file join $CONF(dbdir) faq]"
set CONF(bindir)        "[file join $CONF(reqdir) bin]"
# Set paths of some required programs
# If they are perl scripts, add the platform dependant perl prefix
set CONF(q)             "$CONF(perlprefix)[file join $CONF(bindir) q]"
set CONF(req)           "$CONF(perlprefix)[file join $CONF(bindir) req]"
set CONF(reqglimpse)    "[file join $CONF(bindir) reqglimpse]"
set CONF(sendmail)      "/usr/lib/sendmail"
set CONF(SMTP-server)   "CHANGE ME"
# Set paths of some other important files
set CONF(reqlog)        "[file join $CONF(dbdir) etc req-log]"
set CONF(tkreqrc)       "[file join $CONF(reqdir) lib tkreqrc]"
# Set some req/q operation parameters
set CONF(cc)            "CHANGE ME"
set CONF(reply-to)      ""
set CONF(sig-file)      ""
set CONF(q-owner)       "anyone"
set CONF(q-prio)        "default"
set CONF(q-status)      "any"
set CONF(q-queue)       "open"
set CONF(q-show)        "last:50"
set CONF(q-active)      0
set CONF(q-reverse)     0
# Set some tkreq operation parameters
# For these variables, 1 == yes; 0 == no
# sortBy          sort key for reqlist; default is by number, reversed
set CONF(sortBy)        "number"
# enablePopups    if popup menus are to be enabled; default is 1
set CONF(enablePopups)  1
# enableReqTail   if reqtail window is to be enabled; default is 1 on
# everything but Windows NT, where fileevents are kind of broken, so it 
# is 0 there.
if { [string compare $tcl_platform(os) "Windows NT"] == 0 } {
    set CONF(enableReqTail) 0
} else {
    set CONF(enableReqTail) 1
}

set CONF(showReqtail) 1
set CONF(showReqlist) 1
set CONF(showStatusBar) 1
set CONF(showButtonBar) 1
set CONF(showReqtext) 1
# prettyPrint     strip X-Request* headers when printing; default is 1
set CONF(prettyPrint)   1
# printCommand    command to use to print a file
set CONF(printCommand)  "/s/std/bin/lpr -P2a"
# autoRescan      auto rescan when scan options are changed; default is 1
set CONF(autoRescan)    1
# seekLastMail    position req display to top of last mail; default is 1
set CONF(seekLastMail)  1

# staffmembers    list of staffmembers, used for tab completion
set CONF(staffmembers)  "beaumont beebs bloy charlesm dionne dparter \
	dturner etler fruit grapes handsake huck jerel jiml jmelski john \
	kuchler kylef nmueller pdsalmon roger sjackson thomas ziel"


####################################################
#
# Now, begin the custom syntax highlighting defines
#
####################################################

set tagColors(names) #008000
set tagActions(names) youDaMan
set tagRegexp(names) "(beebs|dparter|jiml|thomas|john|huck|pdsalmon|sjackson|etler|kuchler|tesch|charlesm|jmelski|timc|jerel|kylef|dturner|fruit|roger|dionne|bloy|nmueller|grapes|ziel)"

proc youDaMan { name args } {
    set myname [exec whoami]
    if { [string compare $myname $name] == 0 } {
	tk_dialog .youdaman "You Da Man" "You are the man." info 0 "OK"
    } else {
	tk_dialog .notdaman "Not the Man" "$name is not the man." info 0 "OK"
    }
}

####################################################
#
# Begin URL highlighting/loading defines
#
###################################################

set tagColors(url) blue
set tagActions(url) loadURL
set tagRegexp(url) "\[A-Za-z\]+:(//)?\[^ \t\]+"
global netscape
set netscape "/s/std/bin/netscape"

proc loadURL { url x y } {
    global netscape
    if { [catch {exec $netscape -remote 'openURL($url)' >& /dev/null} err] } {
	if { [catch {exec $netscape $url &} err] } {
	    setStatus $err
	}
    }
}

####################################################
#
# End URL highlighting/loading defines
#
###################################################

####################################################
#
# Begin req number highlighting/loading defines
#
###################################################

set tagColors(reqno) darkblue
set tagActions(reqno) loadReq
set tagRegexp(reqno) {\[?CSL #[0-9]+\]?|merged into [0-9]+}

proc loadReq { match x y } {
    [SN reqTail] tag remove sel 1.0 end
    [SN reqList] selection clear 0 end
    if { ![regexp {\[?CSL #([0-9]+)\]?} $match full number] } {
	regexp {merged into ([0-9]+)} $match full number
    }
    showReq $number
}

####################################################
#
# End req number highlighting/loading defines
#
###################################################

####################################################
#
#  Begin FAX popup defines
#
####################################################

set tagColors(fax) #008080
set tagActions(fax) popupFax
set tagRegexp(fax) "FAX!:\[^ \t\]+"

proc popupFax { name x y } {
    global faxName
    regsub {FAX!:} $name {} faxName
    tk_popup .menuFax $x $y
}

proc openFax { } {
    global faxName
    catch {exec /s/std/bin/gv $faxName &}
}

proc removeFax { } {
    global faxName
    catch {file delete $faxName}
}

proc printFax { } {
    global printCallback
    set printCallback printFaxCallback
    ShowWindow.print
    focus .print.frmPrint.entPrint
    grab .print
}

proc printFaxCallback { } {
    global faxName printCommand
    if { [catch {eval exec $printCommand $faxName} result] } {
	puts $result
    }
}

proc saveFax { } {
    global faxName
    set filename [lindex [file split $faxName] end]
    set dirname [file dirname $faxName]
    set saveName [tk_getSaveFile -title "Save FAX As..." \
	    -initialfile $filename -initialdir $dirname]
    if { $saveName != "" } {
	catch {file copy $faxName $saveName}
    }
}

proc moveFax { } {
    global faxName
    set filename [lindex [file split $faxName] end]
    set dirname [file dirname $faxName]
    set saveName [tk_getSaveFile -title "Move FAX To..." \
	    -initialfile $filename -initialdir $dirname]
    if { $saveName != "" } {
	catch {file rename $faxName $saveName}
    }
}

menu .menuFax -tearoff 0
.menuFax add command -label "Open" -command openFax
.menuFax add command -label "Remove" -command removeFax
.menuFax add command -label "Print" -command printFax
.menuFax add command -label "Save as..." -command saveFax
.menuFax add command -label "Move..." -command moveFax

####################################################
#
#  End FAX popup defines
#
####################################################
