#!/usr/bin/wish -f
# ###############################################################
# tXpppc Version 0.2
# ###############################################################
# This is a simple Frontend for the pppcosts- Program written by 
# Tillmann Steinbrecher tst@bigfoot.com
# The TCL/TK- Program is written by Carsten Schwede
# teddy@frankfurt.netsurf.de
# Look for an actual version of the pppcosts package at
# http://people.darmstadt.netsurf.de/tst/pppcosts.htm
# ###############################################################

# ######################################################################
# For use of the buttons for connecting and disconnecting fill here your 
# favourite scripts for this.

set pppstart ppp-go
set pppstop ppp-stop

# There is no need to edit any lines below
# ######################################################################



set pppcost Offline
set dummy Dummy
set info Info
set info2 Info2

frame .oben
frame .unten
button .anzeige_info -textvariable info -relief groove -cursor {X_cursor blue white} -command about 
button .anzeige_info2 -textvariable info2 -relief groove -cursor {X_cursor green white}
button .anzeige_cost -textvariable pppcost -relief groove -cursor {X_cursor red white}
button .start -text Connect -command {set file2 [open |$pppstart]}
button .stop -text Disconnect -command disconnect
button .exit -text Exit -command {destroy .}
button .help -text ? -command readme 

pack .oben -fill x
pack .unten 
pack .anzeige_info .anzeige_info2 .anzeige_cost -in .oben -fill x
pack .start .stop .help .exit -in .unten -side left 

wm iconbitmap . @/usr/local/pppcosts/teddyc.xbm
# wm iconbitmap . @teddyc.xbm
wm title . tXpppc

set prog [open {|pppcosts -n} r]

gets $prog dummy
gets $prog info
gets $prog info2

proc disconnect {} {
	global pppstop
	global info2
	if { [catch {exec $pppstop}]} {set info2 "Not connected."}
	}

proc auslesen {} {
	global pppcost
	global prog
	gets $prog pppcost
	after 900 auslesen
	}
	
proc total {} {
	global info2
	set datei [open ~/.pppcosts]
	gets $datei totalsec
	gets $datei totalunits
	set sekunden [expr int(fmod($totalsec,60))]
	set minuten [expr int(fmod(($totalsec/60),60))]
	set stunden [expr int([expr $totalsec/3600])]
	set zeit [format "%02d:%02d:%02d" $stunden $minuten $sekunden]
	set text "Total online:"
	set info2 "Total online: $zeit \( $totalunits units \)"
	close $datei
	after 5000 total
	}

proc readme {} {
	toplevel .z
	wm title .z Info
	frame .z.oben
	frame .z.unten
	button .z.done -text "OK" -command {destroy .z}
	text .z.readme -yscroll ".z.scroll set" -relief sunken
	.z.readme insert end [exec cat /usr/local/pppcosts/README]
	scrollbar .z.scroll -command {.z.readme yview}
	pack .z.oben .z.unten -fill x
	pack .z.readme -in .z.oben -side left
	pack .z.scroll -in .z.oben -side right -fill y
	pack .z.done -in .z.unten -fill x
	bind .z <Return> {destroy .z}
	wm iconbitmap .z questhead
	wm maxsize .z 593 352
	wm minsize .z 593 352
	grab .z
	}	

proc about {} {
	toplevel .z
	wm title .z About
	wm iconbitmap .z questhead
	label .z.oben -relief raised -background lightgreen
	label .z.unten -relief raised -background lightgreen
	frame .z.oben.links -background lightgreen
	frame .z.oben.rechts -background lightgreen
	label .z.text -text "pppcosts by Tillmann Steinbrecher" -background lightgreen
	label .z.text2 -text "tXpppc by Carsten Schwede" -background lightgreen
	label .z.pix -bitmap @/usr/local/pppcosts/teddyc.xbm -foreground blue -background lightgreen
	button .z.ok -text "Okie Dokie!" -command {destroy .z}
	pack .z.oben .z.unten -fill x
	pack .z.oben.links .z.oben.rechts -side left -in .z.oben
	pack .z.pix -in .z.oben.links -padx 20 -pady 20
	pack .z.text .z.text2 -fill x -fill y -padx 10 -in .z.oben.rechts
	pack .z.ok -in .z.unten -pady 10
	bind .z <Return> {destroy .z}
	grab .z
	}


auslesen
total
