#!/usr/X11R6/bin/tixwish -f



set defaults(local_config_file) ".tixlpqrc"

#=============================================================================#
#
# this defaults will be used, if the $defaults(local_config_file) in the $HOME 
# not found, otherwise they will be override from the values in this file !
#
# lib_path is used for lang-file and pixmaps
set defaults(lib_path) "/usr/X11R6/lib/tixlpq/"
#
# name of the lang_file :
set defaults(lang_file) "lang.msg"
#
# witch language should be used (1 => english, 2 => german, 3 => france):
set defaults(default_lang) 2
#
# value for auto-update (after start application) 1=> yes, 0=> no :
set defaults(autoupdate) 1
#
set defaults(update_time) 2
# value for balloonhelp (after start application) 1=> yes, 0=> no :
set defaults(balloon_on_off) 0
#
set defaults(colorize_foreign) 0
#=============================================================================#



set lib_path ""
set lang_file ""
set autoupdate ""
set update_time ""
set default_lang ""
set balloon_on_off ""
set colorize_foreign ""


set defaults(configlist) {"balloon_on_off" "lang_file" "autoupdate" "default_lang" "lib_path" "update_time" "colorize_foreign"}
set defaults(lang_from_config) 0
set version "0.3.2"
set hlist "t"
set lpqapp() ""
set sel_job "false"
set old_printer " "
set gnu 1
set lang_array(0,0) ""
set loc_autoupdate ""
set loc_update_time ""
set loc_balloon_on_of ""
set loc_default_lang ""
set loc_colorize_foreign ""

proc MainWindow {w} {
    set frame1 [MkMainPrinter $w]
    set frame2 [MkMainJobs $w]
    set frame3 [MkMainButtons $w]
    set frame4 [MkMainStatus $w]
    set frame5 [MkMainOptions $w]

    pack $frame3 -side top -fill both -padx 4 -pady 4               
    pack $frame4 -side bottom -fill both -padx 4 -pady 4            
    pack $frame2 -side right -expand yes -fill both -padx 4 -pady 4 
    pack $frame1 -side top -padx 4 -pady 4  -fill y  -expand yes   
    pack $frame5 -side top -padx 4 -pady 4  -fill x  -expand yes  

}

proc MkMainOptions {top} {
global autoupdate
global lang_array
global balloon_on_off
global update_time
global colorize_foreign

    set w [frame $top.f5 -relief groove -bd 1 ]
    label $top.f5.l1 -text $lang_array(text,options) 
    pack $top.f5.l1 -side top -fill both -padx 5 -pady 7

    checkbutton $top.f5.cb0 -bd 1 -text $lang_array(text,colorize_foreign) -variable colorize_foreign\
       -relief flat -selectcolor red
    
    checkbutton $top.f5.cb1 -bd 1 -text $lang_array(text,colorize_foreign) -variable colorize_foreign\
       -relief flat -selectcolor red

    checkbutton $top.f5.cb2 -bd 1 -text $lang_array(text,ballon_on_off) -variable balloon_on_off\
       -relief flat -selectcolor red -command "switch_balloon $top"
    
    checkbutton $top.f5.cb3 -bd 1 -text $lang_array(text,auto_update) -variable autoupdate\
       -relief flat -selectcolor red -command "auto_update $top" 

#    pack $top.f5.cb0 -side top -pady 2 -padx 2 -anchor w
    pack $top.f5.cb1 -side top -pady 2 -padx 2 -anchor w
    pack $top.f5.cb2 -side top -pady 2 -padx 2 -anchor w
    pack $top.f5.cb3 -side top -pady 2 -padx 2 -anchor w

    tixControl $top.f5.time -bd 1 -variable time -value $update_time -label $lang_array(text,time)\
       -labelside top -min 1 -max 100 -disabledforeground grey

    pack $top.f5.time -pady 10

   $top.balloon bind $top.f5.cb1 -balloonmsg $lang_array(balloon,colorize_foreign)
   $top.balloon bind $top.f5.cb2 -balloonmsg $lang_array(balloon,balloon_on_off)
   $top.balloon bind $top.f5.cb3 -balloonmsg $lang_array(balloon,auto_update)
   $top.balloon bind $top.f5.time -balloonmsg $lang_array(balloon,time)
    return $w
}

proc MkMainPrinter {top} {
    global old_printer lang_array
    
    set w [frame $top.f1 -relief groove -bd 1]
    label $top.f1.l1 -text $lang_array(text,printers)
    pack $top.f1.l1 -side top -fill both -padx 5 -pady 4

    tixSelect $top.f1.printer -allowzero false -radio true\
	-orientation vertical -bd 1
    pack $top.f1.printer -side left -padx 7 -pady 7
    $top.f1.printer add lp -bd 1 -text $lang_array(button,lp)
    $top.f1.printer add ascii -bd 1 -text $lang_array(button,ascii)
    $top.f1.printer add raw -bd 1 -text $lang_array(button,raw)
    $top.f1.printer add all -bd 1 -text $lang_array(button,all)

    $top.f1.printer config -variable sel_printer
    global sel_printer

    set sel_printer lp
    set old_printer lp

    return $w
}

proc MkMainJobs {top} {
    global hlist jobline lang_array
    
    set w [frame $top.f2 -relief groove -bd 1]
    label $top.f2.l1 -text $lang_array(text,joblist)
    pack $top.f2.l1 -side top -fill both -padx 5 -pady 4

    tixScrolledHList $top.f2.joblist -bd 1 -options {
	hlist.columns 6
	hlist.header true
    }
    pack $top.f2.joblist -expand yes -fill both -padx 10 -pady 10 -side left
 
    set hlist [$top.f2.joblist subwidget hlist]
    $hlist header create 0 -itemtype text -borderwidth 1 -text $lang_array(text,rank) 
    $hlist header create 1 -itemtype text -borderwidth 1 -text $lang_array(text,owner)
    $hlist header create 2 -itemtype text -borderwidth 1 -text $lang_array(text,job)
    $hlist header create 3 -itemtype text -borderwidth 1 -text $lang_array(text,files)
    $hlist header create 4 -itemtype text -borderwidth 1 -text $lang_array(text,size)
    $hlist header create 5 -itemtype text -borderwidth 1 -text $lang_array(text,printer)
    $hlist configure -browsecmd set_line -selectmode single 
    return $w
}

proc MkMainButtons {top} {
    global env lang_array
    
    set w [frame $top.f3 -relief groove -bd 1]
    tixButtonBox $top.f3.mainbuttonbar -orientation horizontal -bd 0
    $top.f3.mainbuttonbar add update -text $lang_array(button,update) -bd 1 -width 10\
	-command {update_list $sel_printer 0}
    $top.f3.mainbuttonbar add remove -text $lang_array(button,remove) -bd 1 -width 10\
	-command {remove}
    $top.f3.mainbuttonbar add remove_all -text $lang_array(button,remove_all) -bd 1 -width 10\
	-command {remove_all}
    $top.f3.mainbuttonbar add top -text $lang_array(button,make_top) -bd 1 -width 10\
	-command {make_top}
    $top.f3.mainbuttonbar add stop -text $lang_array(button,stop) -bd 1 -width 10\
	-command {start_stop stop}
    $top.f3.mainbuttonbar add start -text $lang_array(button,start) -bd 1 -width 10 -command {start_stop start}
    $top.f3.mainbuttonbar add "exit" -text $lang_array(button,close) -bd 1 -width 10\
	-command exit

    pack $top.f3.mainbuttonbar -fill both
    $top.balloon bind $top.f3.mainbuttonbar.update -balloonmsg $lang_array(balloon,update)
    $top.balloon bind $top.f3.mainbuttonbar.remove -balloonmsg $lang_array(balloon,remove)
    $top.balloon bind $top.f3.mainbuttonbar.remove_all -balloonmsg $lang_array(balloon,remove_all)
    $top.balloon bind $top.f3.mainbuttonbar.top -balloonmsg $lang_array(balloon,move)
    $top.balloon bind $top.f3.mainbuttonbar.stop -balloonmsg $lang_array(balloon,stop)
    $top.balloon bind $top.f3.mainbuttonbar.start -balloonmsg $lang_array(balloon,start)
    $top.balloon bind $top.f3.mainbuttonbar.exit -balloonmsg $lang_array(balloon,close)

    if [string compare $env(USER) "root"] {   
	$top.f3.mainbuttonbar.top configure -fg grey50 -activeforeground  grey50
	$top.f3.mainbuttonbar.stop configure -fg grey50 -activeforeground  grey50
	$top.f3.mainbuttonbar.start configure -fg grey50 -activeforeground  grey50
    }
    return $w
}

proc MkMainStatus {top} {
    global lpqapp gnu lang_array lib_path
    
    set w [frame $top.f4 -relief raised -bd 1]
    set lpqapp(statusbar)\
	[label $w.status \
             -relief sunken -bd 1 -highlightthickness 2]
    set lpqapp(b1) [button $w.b1 -command config_tixlpq]
    set lpqapp(b2) [button $w.b2 -command help]


    set img0 [tix getimage $lib_path/config]
    set help_img [image create compound -window $w.b1]
    $help_img add image -image $img0
    $w.b1 config -image $help_img -highlightthickness 4 -border 0
    
    $top.balloon bind $w.b1 -balloonmsg $lang_array(balloon,config)

    
    set img1 [tix getimage $lib_path/help]
    set help_img [image create compound -window $w.b2]
    $help_img add image -image $img1
    $w.b2 config -image $help_img -highlightthickness 4 -border 0

    $top.balloon bind $w.b2 -balloonmsg $lang_array(balloon,info) 
 
    set lpqapp(label) [label $w.label -text $lang_array(text,status) -pady 4]
    tixForm $lpqapp(label)    -padx 10 -pady 3
    tixForm $lpqapp(b1) -right %97
    tixForm $lpqapp(b2) -right %100
    tixForm $lpqapp(statusbar) -padx 3 -pady 3 -left 65 -right %93

    return $w
}

proc update_list {printer removed} {
    global hlist lpqapp sel_job old_printer lang_array env colorize_foreign
    
    set sel_line_nr [$hlist selection get]

    set style(lp) [tixDisplayStyle text  -refwindow $hlist\
       		       -font [tix option get bold_font]\
       		       -fg #206020]
    set style(ascii) [tixDisplayStyle text -refwindow $hlist\
			  -font [tix option get bold_font]\
			  -fg #801010]
    set style(raw) [tixDisplayStyle text -refwindow $hlist\
			-font [tix option get bold_font]\
			-fg #202060]
			
    set style(other) [tixDisplayStyle text -refwindow $hlist\
			-font [tix option get bold_font]\
			-fg grey]


    if ![string compare "all" $printer] {
	set printers {lp ascii raw} 
    } else {
	set printers $printer
    }
    $hlist delete all
    set counter 0
    foreach printer_entry $printers {	
	set lpq [exec lpq -P$printer_entry]
	set lpqlist [split $lpq \n]

	if {![string compare "no entries" $lpq] && ![string compare [llength $printers] "1"]} {
  	    	    $lpqapp(statusbar) configure -text [subst_var $lang_array(text,no_entry) "printer" $printer]
	} else {
	    $lpqapp(statusbar) configure -text "  "
	    foreach Element $lpqlist {
		if  [string compare [llength $printers] "3"] {
		    if {![string compare $Element "$printer_entry is ready and printing"] } {
			$lpqapp(statusbar) configure -text \
                        [subst_var $lang_array(text,ready) "printer_entry" $printer_entry]
		    }
		    if {![string compare $Element "Warning: $printer is down: printing disabled"] } {
			$lpqapp(statusbar) configure -text \
                        [subst_var $lang_array(text,down) "printer" $printer]
		    }	
		    if {![string compare $Element "waiting for $printer_entry to become ready (offline ?)" ] } {
			$lpqapp(statusbar) configure -text \
                        [subst_var $lang_array(text,offline) "printer_entry" $printer_entry]
                       }	
		}

		if [string match *bytes* $Element] {
		    if {![string compare [lindex $Element 3] "(standard"] && ![string compare [lindex $Element 4] "input)"]} {
			set Element [lreplace $Element 3 4 "(standard input)"]
		    }


		    if {[string  compare [lindex $Element 1] $env(USER)] && $colorize_foreign ==1} {
		    	set style_act $style(other)
		    } else {
		    	set style_act $style($printer_entry)
		    }

	   	        $hlist add $counter -itemtype text -text [lindex $Element 0]\
			        -style $style_act
		        foreach entry { 1 2 3 4} {
			   $hlist item create $counter $entry -itemtype text \
			          -text [lindex $Element $entry]\
			          -style $style_act
		        }		
		        $hlist item create $counter 5  -itemtype text\
			       -text $printer_entry -style $style_act
		        set counter [expr $counter+1]
		    
		

		
		} 
	    }
	}
    }

    if {[string compare "" $sel_line_nr] && ![string compare $old_printer $printer]\
	    && [string compare $removed  "1"] && ![catch {$hlist selection set $sel_line_nr}] } {
        $hlist selection set $sel_line_nr
        $hlist anchor set $sel_line_nr
    } else {
       set sel_job "false"
    }
    set old_printer $printer
}

		    
proc auto_update {top} {
global sel_printer time  autoupdate lang_array

    if {$autoupdate == 1} {
    	$top.f5.time configure -state normal
        $top.balloon bind $top.f5.time -balloonmsg $lang_array(balloon,time)
	after [expr $time*1000] auto_update $top
	update_list $sel_printer 0
    } else {
	$top.f5.time configure -state disabled
        $top.balloon unbind $top.f5.time
    }
}

proc switch_balloon {top} {
global balloon_on_off

	if {$balloon_on_off==0} {
	   $top.balloon  configure -state none
	} else {
	   $top.balloon configure -state balloon
	}
}



proc start_stop {status} {
    global sel_printer
    global env
    global lpqapp
    global lang_array

    if ![string compare $env(USER) "root"] {
	exec lpc $status $sel_printer
	if [string compare $status "start"] {
	    exec lpc restart $sel_printer
	}
    } else {
    tk_dialog .warn {Hint} $lang_array(dialog,root) {error} -1 {Ok}
    }
}


proc make_top { } {
    global sel_job lpqapp sel_printer env lang_array

  if ![string compare $env(USER) "root"] {   
  if [string compare $sel_job "false"] {
	set printer [lindex $sel_job 4]
	set job_nr [lindex $sel_job 1]
	set file_name [lindex $sel_job 2]
	set button [tk_dialog .warn {Delete} \
                   [subst_var $lang_array(dialog,top) "file_name" $file_name]\
		   {warning} -1 {Ok} $lang_array(button,cancel)]
        if {$button == 0} {
	    exec lpc top $printer $job_nr 
		update_list $sel_printer 1
	}
    } else {
	$lpqapp(statusbar) configure -text $lang_array(text,no_entry_select)
    }
    } else {
    tk_dialog .warn {Hint} $lang_array(dialog,root) {error} -1 {Ok}
    }
}	

proc set_line {wert} {
    global hlist sel_job lpqapp
    
    set sel_job ""
    $lpqapp(statusbar) configure -text ""
    foreach entry {1 2 3 4 5} { 
	lappend sel_job [$hlist item cget $wert $entry -text]
    }
}

proc remove_all { } {
    global sel_printer
    global lpqapp
    global env
    global lang_array

    update_list $sel_printer 1

    set button [tk_dialog .warn {Delete} \
               [subst_var $lang_array(dialog,remove_all) "sel_printer" $sel_printer] \
               {warning} -1 {Ok} $lang_array(button,cancel)]
    if {$button == 0} {

	if ![string compare $env(USER) "root"] { start_stop {stop}}

	.lpq configure -cursor {watch black white}
	$lpqapp(statusbar) configure -text $lang_array(text,wait)
	update
	if ![string compare "all" $sel_printer] {
	    set printers {lp ascii raw} 
	} else {
	    set printers $sel_printer
	}

	set counter 0
	foreach printer_entry $printers {
	    
	    set lpq [exec lpq -P$printer_entry]
	    set lpqlist [split $lpq \n]

	    if [string compare "no entries" $lpq] {
		foreach Element $lpqlist {
		    if [string match *bytes* $Element] {
			set job_nr [lindex $Element 2]
			set user_name [lindex $Element 1]
	                if {![string compare $env(USER) $user_name] || ![string compare $env(USER) "root"]} {
			    $lpqapp(statusbar) configure -text $lang_array(text,wait)
                            update
			    update idletask

			    exec lprm -P$printer_entry $job_nr
			    update_list $sel_printer 0
			    $lpqapp(statusbar) configure -text $lang_array(text,wait)
                            update
			}
			set counter [expr $counter+1]
		    }		    
		}
	    }
	}
	
	if ![string compare $env(USER) "root"] {start_stop {start}}
    }
    .lpq configure -cursor {top_left_arrow black white}
}

proc remove { } {
    global autoupdate sel_job sel_printer lpqapp env lang_array

    if [string compare $sel_job "false"] {
	set printer [lindex $sel_job 4]
	set job_nr [lindex $sel_job 1]
	set file_name [lindex $sel_job 2]
	set user_name [lindex $sel_job 0]
	if {![string compare $env(USER) $user_name] || ![string compare $env(USER) "root"]} {
	    set button [tk_dialog .warn {Delete} \
                       [subst_var $lang_array(dialog,remove_one) "file_name" $file_name] \
                       {warning} -1 {Ok} $lang_array(button,cancel)]
	    if {$button == 0} {
		.lpq configure -cursor {watch black white}
		update
		update idletask
		exec lprm -P$printer $job_nr 
		update_list $sel_printer 1
		.lpq configure -cursor {top_left_arrow black white}
	    }
	} else {
	   tk_dialog .warn {Hint} $lang_array(dialog,o_job) {error} -1 {Ok} 
	}
     } else {
	 $lpqapp(statusbar) configure -text $lang_array(text,no_entry_select)      
     }
}

proc load_lang { } {
    global lang_file lib_path env lang_array default_lang defaults
     if [file exist $lib_path/$lang_file] {
       set lang_file_ID [open $lib_path/$lang_file]
       puts "open lang-file"
       puts {set tmp, (try it, if $LANG not exist, it must not unset)}
       if [catch {set tmp $env(LANG)}]==1 {
          puts {$LANG not exist, load default_lang!}
          set index1 $default_lang       
        } else {
            if ![string compare $env(LANG) "ENGLISH"] {
                        puts $default_lang
               if {$defaults(lang_from_config)==0} {
                  set index1 1
                  puts "found LANG => ENGLISH, no local configfile"
               } else {
                  set index1 $default_lang
                  puts "found LANG => ENGLISH, but there exist local configfile"
                  }
               
            } elseif ![string compare $env(LANG) "GERMAN"] {
               if {$defaults(lang_from_config)==0} {
                  set index1 2
                  puts "found LANG => GERMAN no local configfile"
               } else {
                  set index1 $default_lang
                  puts "found LANG => GERMAN, but there exist local configfile"
                  }
               
            } elseif ![string compare $env(LANG) "FRANCE"] {
               if {$defaults(lang_from_config)==0} {
               
                  set index1 3
                  puts "found LANG => FRANCE no local configfile"
               } else {
                  set index1 $default_lang
                  puts "found LANG => FRANCE,but there exist  local configfile"
                  }
            } elseif ![string compare $env(LANG) "SPAIN"] {
               if {$defaults(lang_from_config)==0} {

                  set index1 4
                  puts "found LANG => SPAIN no local configfile"
               } else {
                  set index1 $default_lang
                  puts "found LANG => SPAIN, but there exist local configfile"
                  }
               
            } else {
              puts {$LANG not ENGLISH, GERMAN, FRANCE, SPAIN load defaults}
              puts $env(LANG)
              set index1 $default_lang
            }
            unset tmp
            puts "unset tmp"
        }   
          set TestString ""
          set i 0
          set first_char ""
          while {![eof $lang_file_ID]} {
             gets $lang_file_ID TestString
             set tmpstr [string trim $TestString]        
             set first_char [string index $tmpstr 0]
             if {![string compare $first_char "#"] || ![string compare $tmpstr ""] } {
                #puts "zeile enthaelt als erstes fuehrendes zeichen ein #, oder ist leer !" 
             } elseif {![string compare $first_char ":"]} {
                if ![string compare $tmpstr ":text"] {
                   set i [expr $i+1]
                   set index0 "text"
                }
                if ![string compare $tmpstr ":button"] {
                   set i [expr $i+1]
                   set index0 "button"
                }
                if ![string compare $tmpstr ":balloon"] {
                   set i [expr $i+1]
                   set index0 "balloon"
                }
                if ![string compare $tmpstr ":dialog"] {
                   set i [expr $i+1]
                   set index0 "dialog"
                } 
             } else {
               set lang_array($index0,[lindex [string trim $TestString] 0]) [lindex $TestString $index1]
             }
             
          }
          if {$i<4} {
            tk_dialog .warn {ERROR in tixlpq} "lang-file: $lib_path/$lang_file not o.k\ exit!" {error} -1 {Ok} 
            puts "langfile not o.k."
            exit
          }     
        close $lang_file_ID
        puts "close file lang-file"
    } else {
        tk_dialog .warn {ERROR in tixlpq} "lang-file: $lib_path/$lang_file not found!" {error} -1 {Ok} 
        puts "lang-file $lib_path/$lang_file not found, exit!"
        exit
    }
}


proc subst_var {strg var_name var} {
set tmp ""
regsub .$var_name $strg $var tmp
return $tmp
}


proc load_config { } {
global env defaults balloon_on_off lang_file default_lang autoupdate lib_path update_time colorize_foreign

    if [file exist $env(HOME)/$defaults(local_config_file)] {
       set config_file_ID [open $env(HOME)/$defaults(local_config_file)]
       puts "open local config-file"
       while {![eof $config_file_ID]} {
          gets $config_file_ID TestString
          set first_char [string index [string trim $TestString] 0]
          if {([llength $TestString]!=2) && ((![string match $first_char "#"]) && (![string length $first_char]==0))} {
             puts "config-file not ok, load for the rest the defaults"
          break
          }
          foreach Element $defaults(configlist) {
             if ![string compare $Element [lindex [string trim $TestString] 0]] {
             set defaults($Element) [lindex [string trim $TestString] 1]
             if ![string compare $Element "default_lang"] { set defaults(lang_from_config) 1}
             }
         }    
       }   
       close $config_file_ID
       puts "close local config-file"
    } else {
       puts "no local configfile, load defaults"
    }
    set balloon_on_off $defaults(balloon_on_off)
    set lang_file $defaults(lang_file)
    set default_lang $defaults(default_lang)
    set autoupdate $defaults(autoupdate)
    set lib_path $defaults(lib_path)
    set update_time $defaults(update_time)
    set colorize_foreign $defaults(colorize_foreign)
    

puts $update_time
}

proc help { } {
if ![winfo exists .help] {
	global lang_array version img_hlp lib_path
	set h .help
	toplevel $h -background white
	wm title $h "Help"
	label $h.l1 -background white
	set img [tix getimage $lib_path/logo]
	set logo_img [image create compound -window $h.l1]
	$logo_img add image -image $img
	$h.l1 config -image $logo_img -border 0 
	pack $h.l1 
	frame $h.f1 -relief groove -bd 2 
	pack $h.f1 -padx 10 -pady 10 -fill both
	label $h.f1.l2 -pady 20 -padx 10 -background white -text [subst_var $lang_array(dialog,copyright) "version" $version] -justify left
	pack $h.f1.l2
	button $h.b1  -text "Ok" -command "destroy $h"
	pack $h.b1   -pady 10
}
}

    
proc config_tixlpq { } {
global lang_array defaults env defaults

global autoupdate loc_autoupdate
global update_time loc_update_time
global default_lang loc_default_lang
global balloon_on_off loc_balloon_on_off
global colorize_foreign loc_colorize_foreign

set loc_autoupdate $autoupdate
set loc_update_time $update_time
set loc_default_lang $default_lang
set loc_balloon_on_off $balloon_on_off
set loc_colorize_foreign $colorize_foreign



set c .config
if ![winfo exists .config] {
	toplevel $c
	wm title $c "local configuration for tixlpq"
	tixBalloon $c.balloon
	frame $c.f0 -relief groove -bd 2 
	frame $c.f1 -relief groove -bd 2 
	frame $c.f2 -relief groove -bd 2 
	frame $c.f3 -relief groove -bd 2 
	pack $c.f0 $c.f1 $c.f2 $c.f3 -side top -fill both -padx 4 -pady 4 -anchor n

	label $c.f0.text -justify left -padx 5 -pady 5 -text $lang_array(text,config)
	pack $c.f0.text -side left


	label $c.f1.text -pady 5 -text $lang_array(text,deflang)

	radiobutton $c.f1.english -variable loc_default_lang -anchor w -value "1" -text $lang_array(text,english)
	radiobutton $c.f1.german -variable loc_default_lang -anchor w -value "2" -text $lang_array(text,german)
	
# uncommend follow two lines if france and spain translated !!! 
#	radiobutton $c.f1.france -variable loc_default_lang -anchor w -value "3" -text $lang_array(text,france)
#	radiobutton $c.f1.spain -variable loc_default_lang -anchor w  -value "4" -text $lang_array(text,spain)
	pack $c.f1.text $c.f1.english $c.f1.german -side top  -fill x

#add this to the previous line if france and spain translated !!! 
#$c.f1.france $c.f1.spain 

	$c.balloon bind $c.f1.english -balloonmsg $lang_array(balloon,lang)
	$c.balloon bind $c.f1.german -balloonmsg $lang_array(balloon,lang)

# uncommend follow two lines if france and spain translated !!! 
#	$c.balloon bind $c.f1.france -balloonmsg $lang_array(balloon,lang)
#	$c.balloon bind $c.f1.spain -balloonmsg $lang_array(balloon,lang)

	label $c.f2.text -pady 5 -text $lang_array(text,misc)

	checkbutton $c.f2.colorize_foreign -variable loc_colorize_foreign -anchor w -text $lang_array(text,colorize_foreign)
	checkbutton $c.f2.balloonhelp -variable loc_balloon_on_off -anchor w -text $lang_array(text,ballon_on_off)
	checkbutton $c.f2.autoupdate -variable loc_autoupdate -anchor w -text $lang_array(text,auto_update)

	tixControl $c.f2.time -variable loc_update_time -value loc_update_time -label $lang_array(text,time)\
 	      -labelside top -min 1 -max 100 -padx 5 -pady 5

	pack $c.f2.text $c.f2.colorize_foreign $c.f2.balloonhelp $c.f2.autoupdate -fill x
	pack  $c.f2.time -side left
	
	$c.balloon bind $c.f2.colorize_foreign -balloonmsg $lang_array(balloon,colorize_foreign)
	$c.balloon bind $c.f2.balloonhelp -balloonmsg $lang_array(balloon,balloon_on_off)
	$c.balloon bind $c.f2.autoupdate -balloonmsg $lang_array(balloon,auto_update)
	$c.balloon bind $c.f2.time -balloonmsg $lang_array(balloon,time_select)

    	tixButtonBox $c.f3.toolbuttonbar -orientation horizontal -bd 0
    
    	$c.f3.toolbuttonbar add save -text $lang_array(button,save) -bd 1 -width 10 -command store_config
    	$c.f3.toolbuttonbar add delete -text $lang_array(button,delete) -bd 1 -width 10 -command delete_configfile
    	$c.f3.toolbuttonbar add cancel -text $lang_array(button,close) -bd 1 -width 10 -command "destroy $c"
    
    	pack $c.f3.toolbuttonbar -fill both
    	$c.balloon bind $c.f3.toolbuttonbar.save -balloonmsg $lang_array(balloon,save)
    	$c.balloon bind $c.f3.toolbuttonbar.delete -balloonmsg $lang_array(balloon,delete)
    	$c.balloon bind $c.f3.toolbuttonbar.cancel -balloonmsg $lang_array(balloon,cancel)
  
}
}

#end config_tixlpq=============================================================================================


proc delete_configfile { } {
global defaults env lang_array
set error ""
set button [tk_dialog .warn {delete} $lang_array(dialog,delete_config) {warning} -1 {Ok} $lang_array(button,cancel)]
if {$button == 0} {
	catch {exec rm $env(HOME)/$defaults(local_config_file)} $error
}
}




proc store_config { } {
global loc_autoupdate loc_balloon_on_off loc_update_time loc_default_lang loc_colorize_foreign env defaults
global lang_file lib_path version lang_array


  puts $loc_update_time
      set config_file_ID [open $env(HOME)/$defaults(local_config_file) w]
       puts "open local config-file for config_write"
       puts $config_file_ID "# ================== This is the tixlpqrc for tixlpq$version ! =============== #"
       puts $config_file_ID {# it should store on ~/.tixlpqrc, if it not stored there, the defaults}
       puts $config_file_ID {# where load from application}
       puts $config_file_ID {# empty lines  are allow in this file, comments starts with "#"}
       puts $config_file_ID {# Values must be quoted !!!!}
       puts $config_file_ID {# NOTE: the values in this file have priority !}
       puts $config_file_ID {# ========================================================================= #}
       puts $config_file_ID ""
       puts $config_file_ID {# path to search lang_file and pixmaps}
       puts $config_file_ID "lib_path \"$lib_path\""
       puts $config_file_ID ""
       puts $config_file_ID {# put here the name of the langfile}
       puts $config_file_ID "lang_file \"$lang_file\""
       puts $config_file_ID ""
       puts $config_file_ID {# select the default language (1 => english, 2 => german, 3 => france 4 = >spain)}
       puts $config_file_ID "default_lang \"$loc_default_lang\""
       puts $config_file_ID ""
       puts $config_file_ID {# if auto-update should turn on after start, put "1" otherwise "0"}
       puts $config_file_ID "autoupdate \"$loc_autoupdate\""
       puts $config_file_ID ""
       puts $config_file_ID {# if balloon-help should turn on after start, put "1" otherwise "0"}
       puts $config_file_ID "balloon_on_off \"$loc_balloon_on_off\""
       puts $config_file_ID ""
       puts $config_file_ID {# this is the default value for update-time}
       puts $config_file_ID "update_time \"$loc_update_time\""
       puts $config_file_ID ""
       puts $config_file_ID {# this is the default value for colorize_foreign}
       puts $config_file_ID "colorize_foreign \"$loc_colorize_foreign\""

      close $config_file_ID
      puts "close file"

      tk_dialog .saved {} $lang_array(dialog,conf_saved) {} -1 {Ok}

}


#================================================================================#

wm withdraw .
load_config
load_lang
tix configure -fontset 12Point

#-borderwith 1
set w .lpq
toplevel $w
wm geometry $w 700x430+200+200
wm title $w "Print-Manager, for user: $env(USER)"
wm protocol $w WM_DELETE_WINDOW { }
tixBalloon $w.balloon
switch_balloon $w
MainWindow $w
update_list lp 0
auto_update $w
#$w configure -borderwidth 1


