[Tkabber-dev] r1610 - in trunk/tkabber-plugins: . traffic

tkabber-svn at jabber.ru tkabber-svn at jabber.ru
Sun Nov 9 22:30:31 MSK 2008


Author: sergei
Date: 2008-11-09 22:30:31 +0300 (Sun, 09 Nov 2008)
New Revision: 1610

Modified:
   trunk/tkabber-plugins/ChangeLog
   trunk/tkabber-plugins/traffic/traffic.tcl
Log:
	* traffic/traffic.tcl: Adapted traffic plugin to new log callback from
	  XMPP library.


Modified: trunk/tkabber-plugins/ChangeLog
===================================================================
--- trunk/tkabber-plugins/ChangeLog	2008-11-09 19:05:26 UTC (rev 1609)
+++ trunk/tkabber-plugins/ChangeLog	2008-11-09 19:30:31 UTC (rev 1610)
@@ -1,3 +1,8 @@
+2008-11-09  Sergei Golovan <sgolovan at nes.ru>
+
+	* traffic/traffic.tcl: Adapted traffic plugin to new log callback from
+	  XMPP library.
+
 2008-11-03  Sergei Golovan <sgolovan at nes.ru>
 
 	* jidlink/jidlink.tcl: Rewritten to use xmpp::negotiate package for

Modified: trunk/tkabber-plugins/traffic/traffic.tcl
===================================================================
--- trunk/tkabber-plugins/traffic/traffic.tcl	2008-11-09 19:05:26 UTC (rev 1609)
+++ trunk/tkabber-plugins/traffic/traffic.tcl	2008-11-09 19:30:31 UTC (rev 1610)
@@ -23,8 +23,8 @@
     set columns [list presence,in presence,out iq,in iq,out message,in message,out total,in total,out]
     set sort_order total,in
 
-    set current_xlib 0
-    set wished_xlib "0 None"
+    set current_xlib {}
+    set wished_xlib [list {} None]
 
     set timer 5
     set timer_state 0
@@ -51,19 +51,41 @@
 # ############################
 # Handlers
 
-proc traffic::handle_inout {xlib xmldata size prefix attr} {
+proc traffic::handle_inout {xlib dir type xmldata} {
     variable stat
     variable jids
     variable columns
     variable names
 
-    ::xmpp::xml::split $xmldata tag xmlns attrs cdata subels
+    switch -- $dir {
+	output {
+	    set prefix out
+	    set attr to
+	}
+	default {
+	    set prefix in
+	    set attr from
+	}
+    }
 
-    set jid [::xmpp::xml::getAttr $attrs $attr]
-    if {[cequal $jid ""]} {
-	set jid "SERVER"
-    } else {
-	catch { set jid [::xmpp::jid::stripResource $jid] }
+    switch -- $type {
+	xml {
+	    set size [string bytelength [::xmpp::xml::toText $xmldata]]
+
+	    ::xmpp::xml::split $xmldata tag xmlns attrs cdata subels
+
+	    set jid [::xmpp::xml::getAttr $attrs $attr]
+	    if {[cequal $jid ""]} {
+		set jid SERVER
+	    } else {
+		catch { set jid [::xmpp::jid::stripResource $jid] }
+	    }
+	}
+	default {
+	    set tag ""
+	    set size [string bytelength $xmldata]
+	    set jid SERVER
+	}
     }
 
     if {![info exists jids($xlib,$jid)]} {
@@ -85,18 +107,13 @@
     incr stat($xlib,$jid,total,$prefix) $size
 }
 
-proc ::LOG_INPUT_SIZE {xlib xmldata size} \
-    "[namespace current]::traffic::handle_inout \$xlib \$xmldata \$size in from"
+hook::add log_hook [namespace current]::traffic::handle_inout
 
-proc ::LOG_OUTPUT_SIZE {xlib xmldata size} \
-    "[namespace current]::traffic::handle_inout \$xlib \$xmldata \$size out to"
-
-
 # ############################
 # GUI
 
 proc traffic::get_connections {} {
-    set res [list "0 None"]
+    set res [list [list {} None]]
     foreach con [connections] {
 	lappend res [list $con [connection_jid $con]]
     }
@@ -135,7 +152,7 @@
     ComboBox $tools.connection -textvariable [namespace current]::wished_xlib \
 	-values $connections -height [expr [llength $connections] + 1] -editable 0 \
 	-modifycmd [list [namespace current]::refresh]
-    pack $tools.connection -side right -anchor w
+    pack $tools.connection -side right -anchor w -expand yes -fill x
     unset connections
 
     button $tools.show_xml -text [::msgcat::mc "Show XML"] \
@@ -207,7 +224,7 @@
 	set current_xlib [lindex $wished_xlib 0]
     }
 
-    if {!$current_xlib} return
+    if {$current_xlib == {}} return
 
     # init sum counters
     array set sum {}
@@ -324,12 +341,13 @@
     set connections [get_connections]
 
     if {[cequal $type off] && [lsearch $connections $wished_xlib] < 0} {
-	set wished_xlib "0 None"
+	set wished_xlib [list {} None]
     }
 
-    $w.tools.connection configure -values $connections  -height [expr [llength $connections] + 1]
+    $w.tools.connection configure -values $connections \
+				  -height [expr [llength $connections] + 1]
 
-    if {[cequal $type on] && [cequal $wished_xlib "0 None"]} {
+    if {[cequal $type on] && [cequal $wished_xlib [list {} None]]} {
 	set wished_xlib [list $xlib [connection_jid $xlib]]
     }
 
@@ -422,7 +440,7 @@
     variable jids
     variable stat
 
-    if {!$current_xlib} return
+    if {$current_xlib != {}} return
 
     if {[MessageDlg .request_reset_traffic \
 	     -aspect 50000 \



More information about the Tkabber-dev mailing list