###########################################################################
#                                                                         #
#               Copyright (C) 1995, Silicon Graphics, Inc.                #
#                                                                         #
#   These coded instructions, statements, and computer programs  contain  #
#   unpublished  proprietary  information of Silicon Graphics, Inc., and  #
#   are protected by Federal copyright law.  They  may  not be disclosed  #
#   to  third  parties  or copied or duplicated in any form, in whole or  #
#   in part, without the prior written consent of Silicon Graphics, Inc.  #
#                                                                         #
###########################################################################

#%COMMENT_BEGIN
# Filename:	advNfsPnl
# Version:	$Revision: 1.3 $
# Synopsis:	Encapsulates the panel that displays advanced NFS options.
# Functions:	advNfs:realize
#		advNfs:manage
#		advNfs:setDefaults
#		advNfs:setData
#		advNfs:getData
#		advNfs:_create
#		advNfs:_cacheCb
#%COMMENT_END

#########################################
#		Public			#
#########################################
#%COMMENT_BEGIN
# Function:	advNfs:realize
# Synopsis:	Creates an instance of the panel.  On the first call, any
#		class-wide data is initialized.  If an instance of this
#		panel already exists for the given handle, no action is taken
#		other than to return the top-level widget for the panel.
# Arguments:	- handle	An identifier that is used as a key for storing
#				(and later retrieving) the created widgets and
#				any instance specific data.
#		- parent	The parent for the created panel.
#%COMMENT_END
proc advNfsPnl:realize { handle parent } \
{
	global		_GW_advNfs _GD_advNfs

	if {! [info exists _GD_advNfs(initialized)]} {
		set _GD_advNfs(toggles)	\
			{XFS_FS_OPTS_RO XFS_FS_OPTS_RW XFS_FS_OPTS_NOAUTO
			 XFS_FS_OPTS_GRPID XFS_FS_OPTS_NOSUID
			 XFS_FS_OPTS_NODEV XFS_FS_OPTS_PRIV XFS_FS_OPTS_INTR
			 XFS_FS_OPTS_BG XFS_FS_OPTS_HARD cache}

		set _GD_advNfs(cache_texts)	\
			{XFS_FS_OPTS_ACREGMIN XFS_FS_OPTS_ACREGMAX
			 XFS_FS_OPTS_ACDIRMIN XFS_FS_OPTS_ACDIRMAX
			 cache_all}

		set _GD_advNfs(nfs_texts)	\
			{XFS_FS_OPTS_RSIZE XFS_FS_OPTS_WSIZE
			 XFS_FS_OPTS_RETRY XFS_FS_OPTS_TIMEO
			 XFS_FS_OPTS_RETRANS XFS_FS_OPTS_PORT}

		
		####	Default Values
		set _GD_advNfs(XFS_FS_OPTS_RO,default)		true
		set _GD_advNfs(XFS_FS_OPTS_RW,default)		true
		set _GD_advNfs(XFS_FS_OPTS_NOAUTO,default)	false
		set _GD_advNfs(XFS_FS_OPTS_GRPID,default)	false
		set _GD_advNfs(XFS_FS_OPTS_NOSUID,default)	false
		set _GD_advNfs(XFS_FS_OPTS_NODEV,default)	false
		set _GD_advNfs(XFS_FS_OPTS_PRIV,default)	false
		set _GD_advNfs(XFS_FS_OPTS_INTR,default)	false
		set _GD_advNfs(XFS_FS_OPTS_BG,default)		false
		set _GD_advNfs(XFS_FS_OPTS_HARD,default)	true
		set _GD_advNfs(cache,default)			false

		set _GD_advNfs(XFS_FS_OPTS_ACREGMIN,default) 3
		set _GD_advNfs(XFS_FS_OPTS_ACREGMAX,default) 60
		set _GD_advNfs(XFS_FS_OPTS_ACDIRMIN,default) 30
		set _GD_advNfs(XFS_FS_OPTS_ACDIRMAX,default) 60
		set _GD_advNfs(cache_all,default) ""

		set _GD_advNfs(XFS_FS_OPTS_RSIZE,default) 8096
		set _GD_advNfs(XFS_FS_OPTS_WSIZE,default) 8096
		set _GD_advNfs(XFS_FS_OPTS_RETRY,default) 10000
		set _GD_advNfs(XFS_FS_OPTS_TIMEO,default) 11
		set _GD_advNfs(XFS_FS_OPTS_RETRANS,default) 5
		set _GD_advNfs(XFS_FS_OPTS_PORT,default) 2049

		set _GD_advNfs(initialized) true
	}

	if {! [info exists _GW_advNfs($handle,panel)]} {
		set _GW_advNfs($handle,panel) [advNfsPnl:_create $handle $parent]
	}

	return $_GW_advNfs($handle,panel)
}

#%COMMENT_BEGIN
# Function:	advNfs:manage
# Synopsis:	Manages an instance of the panel.
# Arguments:	- handle	The identifier for the desired instance.
#%COMMENT_END
proc advNfs:manage { handle } \
{
	global	_GW_advNfs
	if {[info exists _GW_advNfs($handle,panel)]} {
		$_GW_advNfs($handle,panel) manageChild
	}
}

#%COMMENT_BEGIN
# Function:	advNfs:setDefaults
# Synopsis:	Sets all XmTextFields/XmToggleButton widgets to their defaults.
# Arguments:	- handle	The identifier for the desired instance.
#%COMMENT_END
proc advNfsPnl:setDefaults { handle } \
{
	global	_GW_advNfs _GD_advNfs

	foreach key $_GD_advNfs(toggles) {
	    $_GW_advNfs($handle,$key) setValues -set $_GD_advNfs($key,default)
	}

	foreach key $_GD_advNfs(cache_texts) {
	    $_GW_advNfs($handle,$key) setString $_GD_advNfs($key,default)
	}

	foreach key $_GD_advNfs(nfs_texts) {
	    $_GW_advNfs($handle,$key) setString $_GD_advNfs($key,default)
	}

	advNfsPnl:_cacheCb $handle $_GD_advNfs(cache,default)
}

#%COMMENT_BEGIN
# Function:	advNfs:setData
# Synopsis:	Given a list of keyword/value pairs, fill in the appropriate
#		field with the appropriate value.
# Arguments:	- handle	The identifier for the desired instance.
#		- lst		A list of keyword/value pairs.
# Note:		Currently not implemented.
#%COMMENT_END
proc advNfsPnl:setData { handle lst } \
{
}

#%COMMENT_BEGIN
# Function:	advNfs:getData
# Synopsis:	Reads the data from the panel and stores it in keyword/value
#		pair format.  If a field is currently set to its' default
#		value, then it is ignored.  If an XmTextField is empty, it
#		is assumed to be the default and is ignored.
# Arguments:	- handle	The identifier for the desired instance.
#		- data		A reference to an array variable in which
#				to store the data.
#		- check		An optional parameter that indicates whether
#				or not to check the data for completeness.
#				(default value: true)
#%COMMENT_END
proc advNfsPnl:getData { handle data {check true} } \
{
	global		_GW_advNfs _GD_advNfs
	upvar $data	dat

	if {! [info exists _GW_advNfs($handle,panel)]} {
		return 1
	}

	foreach key $_GD_advNfs(nfs_texts) {
		set val [string trim [$_GW_advNfs($handle,$key) getString]]
		if {! [cequal $val ""] &&
		    ! [cequal $val $_GD_advNfs($key,default)]} {
			lappend dat "$key:$val"
		}
	}
	foreach key $_GD_advNfs(toggles) {
		if {$key != "cache"} {
			$_GW_advNfs($handle,$key) getValues -set val
			if {! [cequal $val $_GD_advNfs($key,default)]} {
				lappend dat "$key:$val"
			}
		}
	}

	$_GW_advNfs($handle,cache) getValues -set val
	if {$val} {
	    set key cache_all
	    set c_all [string trim [$_GW_advNfs($handle,$key) getString]]

	    foreach key $_GD_advNfs(cache_texts) {
		if {! [cequal $key "cache_all"]} {
		    if {[clength $c_all]} {
			lappend dat "$key:$c_all"
		    } else {
			set val [string trim \
				[$_GW_advNfs($handle,$key) getString]]
			if {! [cequal $val ""] &&
			    ! [cequal $val $_GD_advNfs($key,default)]} {
				lappend dat "$key:$val"
			}
		   }
		}
	    }
	}

	return 1
}

#########################################
#		Private			#
#########################################
#%COMMENT_BEGIN
# Function:	advNfs:_create
# Synopsis:	Creates an instance of the panel.
# Arguments:	- handle	The identifier for the new instance.
#		- parent	The parent for the created panel.
#%COMMENT_END
proc advNfsPnl:_create { handle parent } \
{
	global		_GW_advNfs _GD_advNfs
	set name	advNfsPnl

	set container [xmForm $parent.$name]
	set form [xmForm $container.$handle \
			-topAttachment attach_form \
			-leftAttachment attach_form \
			-rightAttachment attach_form \
			-bottomAttachment attach_form]

	set p1 [xmRowColumn $form.p1 \
			-orientation vertical \
			-topAttachment attach_form \
			-leftAttachment attach_form \
			-rightAttachment attach_none \
			-bottomAttachment attach_none]

	set p2 [xmRowColumn $form.p2 \
			-orientation vertical \
			-topAttachment attach_widget \
			-leftAttachment attach_form \
			-rightAttachment attach_none \
			-bottomAttachment attach_none \
			-topWidget $p1 \
			-leftOffset 20]

	set p3 [xmRowColumn $form.p3 \
			-orientation vertical \
			-topAttachment attach_form \
			-leftAttachment attach_widget \
			-rightAttachment attach_none \
			-bottomAttachment attach_none \
			-leftWidget $p1 \
			-leftOffset 20]

	set i 0
	foreach item $_GD_advNfs(toggles) {
		set _GW_advNfs($handle,$item) [xmToggleButton $p1.$item managed]
		incr i
	}
	$_GW_advNfs($handle,cache) valueChangedCallback \
			"$name:_cacheCb $handle %set"

	set i 0
	foreach item $_GD_advNfs(cache_texts) {
		set rc [xmRowColumn $p2.rc managed \
				-orientation horizontal \
				-marginHeight 0 \
				-spacing 6]
		xmLabel $rc.$item-label managed
		set _GW_advNfs($handle,$item) [xmTextField $rc.$item managed \
				-columns 5 \
				-maxLength 5]
		$_GW_advNfs($handle,$item) modifyVerifyCallback \
			"tfu:onlyIntsCb %w %ptr %length %startPos %endPos %doit"
		incr i
	}

	set i 0
	foreach item $_GD_advNfs(nfs_texts) {
		set rc [xmRowColumn $p3.rc managed \
				-orientation horizontal \
				-marginHeight 0 \
				-spacing 6]
		xmLabel $rc.$item-label managed
		set _GW_advNfs($handle,$item) [xmTextField $rc.$item managed]

		$_GW_advNfs($handle,$item) modifyVerifyCallback \
			"tfu:onlyIntsCb %w %ptr %length %startPos %endPos %doit"
		incr i
	}

	$p1 manageChild
	$p2 manageChild
	$p3 manageChild
	$form manageChild

	set _GW_advNfs($handle,cache_container) $p2
	$name:_cacheCb $handle false

	return $container
}

#########################################
#		Callbacks		#
#########################################
#%COMMENT_BEGIN
# Function:	advNfs:_cacheCb
# Synopsis:	This sets the sensitivity of the cache timeout text input
#		fields.  The sensitivity is determined by the "cache"
#		toggle button.
# Arguments:	- handle	The identifier for the desired instance.
#		- set		A true/false value.  True makes the input
#				fields sensitive, fales makes them insensitive.
#%COMMENT_END
proc advNfsPnl:_cacheCb { handle set } \
{
	global	_GW_advNfs

	$_GW_advNfs($handle,cache_container) setSensitive $set
}
