##############################################################################
#
#	Tkmasqconf V 0.01 17-1-1999 
#
#	The Tkmasqdialer Configuration script by Michael H. Voase
#	Copyright 1999 Michael H. Voase under the GNU Public License Version 2
#	Permission is granted to use and modify this file free of charge
#	provided that this notice accompanies this software unmodified along
#	with a copy of the GNU public license .
# 
#	THIS SOFTWARE IS SUPPLIED 'AS IS' WITHOUT ANY FORM OF WARRANTY
#	EXPRESSED OR IMPLIED . BY USING THIS SOFTWARE YOU HEREBY RECOGNIZE
#	THE MICHAEL VOASE SHALL NOT BE HELD LIABLE FOR ANY DAMAGES USING OR
#	MISUSING THIS SOFTWARE . 
#
#
###############################################################################
#
#	Ok , now that the formalities are over , this script is 'sourced'
#	by tcl when its executed to ensure that it has full access to the 
#	internal procs from masqdialer . 
#
#
#

set ProgramName "Tkmasqconf V0.01" 

proc tkmasqconf { } {

    create_conf_data
    create_conf_win
}

proc create_conf_win { } {
    global tkmdconf confr1 confr2 conf_save_but help2_lab conf_quit_but
    global conf_user_lab conf_pass_lab conf_serv_lab conf_port_lab    
    global conf_user_ent conf_pass_ent conf_serv_ent conf_port_ent
    global dconnsound_ent connsound_ent dconnsound_lab connsound_lab

    toplevel .cf
    Set_wm tkmdconf
    Set_frame confr1
    Set_frame confr2
    Set_button conf_save_but
    Set_button conf_quit_but
    Set_label help2_lab
    Set_label conf_user_lab
    Set_label conf_pass_lab
    Set_label conf_serv_lab
    Set_label conf_port_lab
    Set_label dconnsound_lab
    Set_label connsound_lab
    Set_entry dconnsound_ent
    Set_entry connsound_ent
    Set_entry conf_user_ent
    Set_entry conf_pass_ent
    Set_entry conf_serv_ent
    Set_entry conf_port_ent
}
############################################################################
#
#	Action section . Wrappers for all the button functions used
#	by tkmasqconf .
#

proc conf_quit_action { } {
    destroy .cf
}

proc save_config {} {
  global configfilename Serv_addr position mute checkcontime \
         connsound dconnsound username password User_Config help2_lab
  if { $Serv_addr(addr) == "NULL" || $Serv_addr(addr) == "" } { 
      set help2_lab(text) "Please set server Address !"
      Set_text help2_lab
      return 
      }
    if { $Serv_addr(port) == "NULL" || $Serv_addr(port) == "" } {
	set Serv_addr(port) 222
	}
  set file [open $User_Config "w"]
  puts $file "\
##############################################################################
#
#	Tkmasqdailer Configuration V 1.10 
#	
#	This is a machine generated file.
#
#	Do not hand edit unless you know how
#	to program tcl . There  are tokens embeded in this code to
#	help tkmasqconf apply diffs to the file . All tkmasqcode
#	will be encapsulated in begin - end tags . So long as you put
#	your code outside these sections , it will be happily overwritten
#	until I get this code fully debugged so that it respects all
#	code outside these sections and preserves the contents
#	exactly as you wrote it ... dont worry , all sections wether
#	they be tagged or not will be processed for EXECUTION !
#
#
 
set Serv_addr(addr) $Serv_addr(addr)
set Serv_addr(port) $Serv_addr(port)
set position [wm geometry .]
set mute $mute
set connsound $connsound
set dconnsound $dconnsound
set username $username
set password $password
"
  close $file
  eval exec chmod 0600 $User_Config 
  return
}

###############################################################################
#
#	Paramters for the tkmasconf windows widgets and other
#	General bits and pieces .
#
#
#

proc create_conf_data { } {
    global tkmdconf confr1 confr2 conf_save_but help2_lab 
    global conf_quit_but conf_user_ent conf_pass_ent conf_serv_ent conf_port_ent
    global conf_user_lab conf_pass_lab conf_serv_lab conf_port_lab
    global dconnsound_ent connsound_ent dconnsound_lab connsound_lab

##############################################################################
#
# Root window declaration tkmasqconf
#
array set tkmdconf { 
    root "cf" max_x 358 max_y 166
    min_x 1 min_y 1 resize_x 0 resize_y 0 Position "200x400"
    Geom "258x196" base .cf.f border 2 padx 0 pady 0 style "groove"
    column 0 row 0 columnspan 5 rowspan 10 ipadx 0 ipady 0 sticky {}
}
#############################################################################
#
# Define the base frames first - two in all
#
array set confr1 {
    base .cf.f.confr1 border 1 style ridge column 0 row 0 columnspan 5
    rowspan 9 ipadx 0 ipady 0 sticky {} padx 0 pady 0
}

array set confr2 { 
    base .cf.f.confr2 border 1 style ridge column 0 row 10 columnspan 5
    rowspan 1 ipadx 0 ipady 0 sticky {} padx 0 pady 0
}
#############################################################################
#
# now for the labels
#

array set conf_user_lab { 
    base .cf.f.confr1.some_lab style raised text "Username" border 1 column 0
    row 0 ipadx 0 ipady 0 padx 0 pady 0 sticky e width 16 fg "rgb:00/00/00"
    columnspan 1 rowspan 1 
}
array set help2_lab { 
    base .cf.f.confr2.help2_lab style sunken
    text "Tkmasqdialer configuration"
    border 1 column 0 row 0 ipadx 0 ipady 0 padx 0 pady 0 sticky {}
    width 34 fg "rgb:00/00/00" columnspan 5 rowspan 1
}

array set conf_pass_lab { 
    base .cf.f.confr1.conf_pass_lab style raised
    text "Password"
    border 1 column 0 row 1 ipadx 0 ipady 0 padx 0 pady 0 sticky {}
    width 16 fg "rgb:00/00/00" columnspan 1 rowspan 1
}
array set conf_port_lab { 
    base .cf.f.confr1.conf_port_lab style raised
    text "Server Port"
    border 1 column 0 row 3 ipadx 0 ipady 0 padx 0 pady 0
    sticky {} width 16 fg "rgb:00/00/00" columnspan 1 rowspan 1
}
array set conf_serv_lab { 
    base .cf.f.confr1.conf_serv_lab style raised
    text "Server Address"
    border 1 column 0 row 2 ipadx 0 ipady 0 padx 0 pady 0
    sticky {} width 16 fg "rgb:00/00/00" columnspan 1 rowspan 1
}
array set connsound_lab { 
    base .cf.f.confr1.connsound_lab style raised
    text "Connect Sound"
    border 1 column 0 row 4 ipadx 0 ipady 0 padx 0 pady 0
    sticky {} width 16 fg "rgb:00/00/00" columnspan 1 rowspan 1
}
array set dconnsound_lab { 
    base .cf.f.confr1.dconnsound_lab style raised
    text "Disconnect Sound"
    border 1 column 0 row 5 ipadx 0 ipady 0 padx 0 pady 0
    sticky {} width 16 fg "rgb:00/00/00" columnspan 1 rowspan 1
}

###############################################################################
#
# And now for the buttons
#
array set conf_save_but {
    base .cf.f.confr1.save_conf_but style raised 
    text "Save"
    border 0 column 0 row 9 ipadx 0 ipady 0 padx 0 pady 0 sticky {} width 10
    fg "rgb:00/00/00" columnspan 1 rowspan 1 undl 0 command "save_config"
    enter_opt ".cf.f.confr2.help2_lab configure -text {Save the base Config}" 
    leave_opt ".cf.f.confr2.help2_lab configure -text { }"
    state normal
}

array set conf_quit_but {
    base .cf.f.confr1.conf_quit_but style raised
    text "Quit" border 0 column 1 row 9 ipadx 0 ipady 0 padx 0 pady 0
    sticky e width 7 fg "rgb:00/00/00" columnspan 1 rowspan 1 undl 0
    command "{conf_quit_action}"
    enter_opt ".cf.f.confr2.help2_lab configure -text {Quit configure Utility}" 
    leave_opt ".cf.f.confr2.help2_lab configure -text { }"
    state normal
}
###############################################################################
#
# Now for the enteries ...
#
array set conf_user_ent {
    base .cf.f.confr1.conf_user_ent text "" show "" textvariable username 
    exportSelection 1 width 10 column 1 row 0 ipadx 0 ipady 0 padx 0 
    pady 0 sticky e columnspan 1 rowspan 1
    enter_opt ".cf.f.confr2.help2_lab configure -text {Enter your username}"
    leave_opt ".cf.f.confr2.help2_lab configure -text { }"
}

array set conf_pass_ent {
    base .cf.f.confr1.conf_paas_ent text "" show "*" textvariable password
    exportSelection 1 width 10 column 1 row 1 ipadx 0 ipady 0 padx 0
    pady 0 sticky e columnspan 1 rowspan 1
    enter_opt ".cf.f.confr2.help2_lab configure -text {Enter your password}"
    leave_opt ".cf.f.confr2.help2_lab configure -text { }"
}

array set conf_serv_ent {
    base .cf.f.confr1.conf_serv_ent text "" show "" textvariable Serv_addr(addr)
    exportSelection 1 width 10 column 1 row 2 ipadx 0 ipady 0 padx 0
    pady 0 sticky e columnspan 1 rowspan 1
    enter_opt ".cf.f.confr2.help2_lab configure -text {Enter the Server address}"
    leave_opt ".cf.f.confr2.help2_lab configure -text { }"
}

array set conf_port_ent {
    base .cf.f.confr1.conf_port_ent text "" show "" textvariable Serv_addr(port)
    exportSelection 1 width 10 column 1 row 3 ipadx 0 ipady 0 padx 0
    pady 0 sticky e columnspan 1 rowspan 1
    enter_opt ".cf.f.confr2.help2_lab configure -text {Enter the Server port}"
    leave_opt ".cf.f.confr2.help2_lab configure -text { }"
}
array set connsound_ent {
    base .cf.f.confr1.connsound_ent text "" show "" textvariable connsound
    exportSelection 1 width 10 column 1 row 4 ipadx 0 ipady 0 padx 0
    pady 0 sticky e columnspan 1 rowspan 1
    enter_opt ".cf.f.confr2.help2_lab configure -text {Path to the Connect Sound File}"
    leave_opt ".cf.f.confr2.help2_lab configure -text { }"
}
array set dconnsound_ent {
    base .cf.f.confr1.dconnsound_ent text "" show "" textvariable dconnsound
    exportSelection 1 width 10 column 1 row 5 ipadx 0 ipady 0 padx 0
    pady 0 sticky e columnspan 1 rowspan 1
    enter_opt ".cf.f.confr2.help2_lab configure -text {Path to the Disconnect Sound File}"
    leave_opt ".cf.f.confr2.help2_lab configure -text { }"
}

}

tkmasqconf