[Tkabber-dev] r1836 - in trunk/tkabber: . plugins/general

tkabber-svn at jabber.ru tkabber-svn at jabber.ru
Wed Sep 2 13:16:30 MSD 2009


Author: sergei
Date: 2009-09-02 13:16:30 +0400 (Wed, 02 Sep 2009)
New Revision: 1836

Modified:
   trunk/tkabber/ChangeLog
   trunk/tkabber/plugins/general/rawxml.tcl
Log:
	* plugins/general/rawxml.tcl: Added multiple connections support: allow
	  to choose outgoing connection and to display only messages for an
	  active connection. Removed quick access to prettyprinting XML config
	  variable and changed its default value to true. (thanks to Jan
	  Zachorowski)


Modified: trunk/tkabber/ChangeLog
===================================================================
--- trunk/tkabber/ChangeLog	2009-08-17 17:30:40 UTC (rev 1835)
+++ trunk/tkabber/ChangeLog	2009-09-02 09:16:30 UTC (rev 1836)
@@ -1,3 +1,11 @@
+2009-09-02  Sergei Golovan  <sgolovan at nes.ru>
+
+	* plugins/general/rawxml.tcl: Added multiple connections support: allow
+	  to choose outgoing connection and to display only messages for an
+	  active connection. Removed quick access to prettyprinting XML config
+	  variable and changed its default value to true. (thanks to Jan
+	  Zachorowski)
+
 2009-08-17  Sergei Golovan  <sgolovan at nes.ru>
 
 	* msgs/de.msg: Updated German translation (thanks to Roger Sondermann).

Modified: trunk/tkabber/plugins/general/rawxml.tcl
===================================================================
--- trunk/tkabber/plugins/general/rawxml.tcl	2009-08-17 17:30:40 UTC (rev 1835)
+++ trunk/tkabber/plugins/general/rawxml.tcl	2009-09-02 09:16:30 UTC (rev 1836)
@@ -17,20 +17,22 @@
     custom::defgroup Plugins [::msgcat::mc "Plugins options."] -group Tkabber
     custom::defgroup RawXML \
 	[::msgcat::mc "Options for Raw XML Input module,\
-which allows you to monitor\
-incoming/outgoing traffic from connection to server and send\
-custom XML stanzas."] -group Plugins -tag "Raw XML Input"
+		       which allows you to monitor\
+		       incoming/outgoing traffic from connection to server and send\
+		       custom XML stanzas."] \
+	-group Plugins -tag "Raw XML Input"
 	 
-    #set options(pretty_print) 0
-    custom::defvar options(pretty_print) 0 \
+    custom::defvar options(pretty_print) 1 \
 	[::msgcat::mc "Pretty print incoming and outgoing XML stanzas."] \
 	-group RawXML -type boolean
-    #set options(indent) 2
     custom::defvar options(indent) 2 \
 	[::msgcat::mc "Indentation for pretty-printed XML subtags."] \
 	-group RawXML -type integer
 
     variable tabs
+    variable rawxml_xlib_jid
+    variable rawxml_xlib
+    variable view_single_xlib
 }
 
 
@@ -58,20 +60,22 @@
 	}
     }
 
+    set prefix "[clock format [clock seconds] -format %T] $prefix"
+
     set dump $w.dump
     $dump configure -state normal
 
     set scroll [expr {[lindex [$dump yview] 1] == 1}]
 
     set id "($xlib)"
-    catch {set id "($xlib,[connection_jid $xlib])"}
+    catch {set id "($xlib, [connection_jid $xlib])"}
 
     $dump insert end \
-	"$prefix$id:\n" {} \
-	"$msg" $tag
+	"<!-- $prefix $id -->\n" [list xlib$xlib] \
+	"$msg" [list $tag xlib$xlib]
 
     if {![$dump compare "end -1 chars linestart" == "end -1 chars"]} {
-	$dump insert end "\n"
+	$dump insert end "\n" [list xlib$xlib]
     }
 
     if {$scroll} {
@@ -99,20 +103,22 @@
 	}
     }
 
+    set prefix "[clock format [clock seconds] -format %T] $prefix"
+
     set dump $w.dump
     $dump configure -state normal
 
     set scroll [expr {[lindex [$dump yview] 1] == 1}]
 
     set id "($xlib)"
-    catch {set id "($xlib,[connection_jid $xlib])"}
+    catch {set id "($xlib, [connection_jid $xlib])"}
 
-    $dump insert end "$prefix$id:\n"
+    $dump insert end "<!-- $prefix $id -->\n" [list xlib$xlib]
 
-    pretty_print $dump $xml "" $tag
+    pretty_print $dump $xml "" $tag $xlib
 
     if {![$dump compare "end -1 chars linestart" == "end -1 chars"]} {
-	$dump insert end "\n"
+	$dump insert end "\n" [list xlib$xlib]
     }
 
     if {$scroll} {
@@ -122,10 +128,11 @@
     $dump configure -state disabled
 }
 
-proc rawxml::pretty_print {t xmldata prefix tag {pxmlns jabber:client}
+proc rawxml::pretty_print {t xmldata prefix tag {xlib {}} {pxmlns jabber:client}
 	    {prefixes {xml xml http://etherx.jabber.org/streams stream}}} {
     variable options
     variable tabs
+    variable rawxml_xlib
 
     ::xmpp::xml::split $xmldata stag xmlns attrs cdata subels
 
@@ -163,7 +170,7 @@
 	}
     }
 
-    $t insert end "$prefix<" {} $stag ${tag}tag
+    $t insert end "$prefix<" [list xlib$xlib] $stag [list ${tag}tag xlib$xlib]
     if {[llength $attrs1] != 0} {
 	set arr_index "$prefix<$stag "
 	if {![info exists tabs($arr_index)]} {
@@ -172,41 +179,49 @@
 	$t tag configure $arr_index -tabs [list $tabs($arr_index)]
 
 	set attrs2 [lassign $attrs1 attr value]
+	if {$tag == "template" && $attr == "id" && $value == "" && $rawxml_xlib!=""} {
+	    set value [::xmpp::packetID $rawxml_xlib]
+	}
 	$t insert end \
-	    " $attr" ${tag}attr \
-	    "=" {} \
-	    "'[::xmpp::xml::Escape $value]'" ${tag}value
+	    " $attr" [list ${tag}attr xlib$xlib] \
+	    "=" [list xlib$xlib] \
+	    "'[::xmpp::xml::Escape $value]'" [list ${tag}value xlib$xlib]
 	foreach {attr value} $attrs2 {
+	    if {$tag == "template" && $attr == "id" && $value == "" && $rawxml_xlib!=""} {
+		set value [::xmpp::packetID $rawxml_xlib]
+	    }
 	    $t insert end \
-		"\n\t$attr" [list ${tag}attr $arr_index]\
-		"=" {} \
-		"'[::xmpp::xml::Escape $value]'" ${tag}value
+		"\n\t$attr" [list ${tag}attr $arr_index xlib$xlib]\
+		"=" [list xlib$xlib] \
+		"'[::xmpp::xml::Escape $value]'" [list ${tag}value xlib$xlib]
 	}
     }
     if {$cdata == "" && [llength $subels] == 0} {
-	$t insert end "/>\n"
+	$t insert end "/>\n" [list xlib$xlib]
 	return
     } else {
-	$t insert end ">"
+	$t insert end ">" [list xlib$xlib]
     }
 
     if {[llength $subels] == 0} {
-	$t insert end [::xmpp::xml::Escape $cdata] ${tag}cdata
-	$t insert end "</" {} $stag ${tag}tag ">\n"
+	$t insert end [::xmpp::xml::Escape $cdata] [list ${tag}cdata xlib$xlib]
+	$t insert end "</" [list xlib$xlib] $stag [list ${tag}tag xlib$xlib] ">\n" [list xlib$xlib]
     } else {
-	$t insert end "\n"
+	$t insert end "\n" [list xlib$xlib]
         foreach subdata $subels {
 	    pretty_print $t $subdata \
-		$prefix[string repeat " " $options(indent)] $tag \
+		$prefix[string repeat " " $options(indent)] $tag $xlib \
 		$pxmlns [array get p]
 	}
-	$t insert end "$prefix</" {} $stag ${tag}tag ">\n"
+	$t insert end "$prefix</" [list xlib$xlib] $stag [list ${tag}tag xlib$xlib] ">\n" [list xlib$xlib]
     }
 }
 
 hook::add log_hook [namespace current]::rawxml::handle_inout
 
 proc rawxml::open_window {} {
+    variable rawxml_xlib
+    variable rawxml_xlib_jid
     set w .rawxml
     if {[winfo exists $w]} {
 	return
@@ -222,9 +237,9 @@
     set tools [frame $w.tools]
     pack $tools -side top -anchor w -fill x
 
-    checkbutton $tools.pp -text [::msgcat::mc "Pretty print XML"] \
-	-variable [namespace current]::options(pretty_print)
-    pack $tools.pp -side left -anchor w
+    #checkbutton $tools.pp -text [::msgcat::mc "Pretty print XML"] \
+    #	-variable [namespace current]::options(pretty_print)
+    #pack $tools.pp -side left -anchor w
 
     menubutton $tools.templates -text [::msgcat::mc "Templates"] \
     	-relief $::tk_relief \
@@ -240,6 +255,29 @@
         "
     pack $tools.clear -side left -anchor w
 
+    set connection_jids {}
+    foreach c [connections] {
+	lappend connection_jids [connection_jid $c]
+    }
+    set rawxml_xlib [lindex [connections] 0]
+    set rawxml_xlib_jid [lindex $connection_jids 0]
+    label $tools.lconnection -text [::msgcat::mc "Connection:"]
+    ComboBox $tools.connection -textvariable [namespace current]::rawxml_xlib_jid \
+			       -values $connection_jids \
+			       -editable false \
+			       -modifycmd [namespace current]::select_xlib
+
+    checkbutton $tools.singlexlib -variable [namespace current]::view_single_xlib \
+				  -command [namespace current]::select_xlib \
+				  -text "Hide other connections"
+    
+    if {[llength $connection_jids] > 1} {
+	pack $tools.lconnection -side left -anchor w
+	pack $tools.connection -side left -anchor w
+
+	pack $tools.singlexlib -side left -anchor w
+    }
+
     PanedWin $w.pw -side right -pad 0 -width 4
     pack $w.pw -fill both -expand yes
 
@@ -307,6 +345,74 @@
     hook::run open_rawxml_post_hook $w
 }
 
+proc rawxml::select_xlib {} {
+    variable rawxml_xlib_jid
+    variable rawxml_xlib
+    variable view_single_xlib
+    set w .rawxml.dump
+
+    set rawxml_xlib {}
+    foreach c [connections] {
+	if {[connection_jid $c] == $rawxml_xlib_jid} {
+	    set rawxml_xlib $c
+	    break
+	}
+    }
+    
+    foreach tag [lsearch -all -glob -inline [.rawxml.dump tag names] xlib*] {
+	set elide [expr {"xlib$rawxml_xlib" != $tag && $view_single_xlib \
+		   && $rawxml_xlib != ""}]
+	$w tag configure $tag -elide $elide
+    }
+}
+
+proc rawxml::update_xlib_choice {action xlib} {
+    variable rawxml_xlib_jid
+    variable rawxml_xlib
+    variable view_single_xlib
+    
+    set tools .rawxml.tools
+    set combobox $tools.connection
+    if {![winfo exists $combobox]} return
+
+    set connection_jids [lindex [$combobox configure -values] 4]
+    set connection_jid [connection_jid $xlib]
+    switch $action {
+	add {
+	    lappend connection_jids $connection_jid
+	    if {[llength $connection_jids] == 1} {
+		set rawxml_xlib_jid $connection_jid
+		set rawxml_xlib $xlib
+	    }
+	}
+	remove {
+	    set idx [lsearch -exact $connection_jids $connection_jid]
+	    set connection_jids [lreplace $connection_jids $idx $idx]
+	    if {$rawxml_xlib == $xlib} {
+		set rawxml_xlib [lindex [connections] 0]
+		if {$rawxml_xlib != ""} {
+		    set rawxml_xlib_jid [connection_jid $rawxml_xlib]
+		} else {
+		    set rawxml_xlib_jid ""
+		}
+		select_xlib
+	    }
+	}
+    }
+    $combobox configure -values $connection_jids
+
+    if {[llength $connection_jids] > 1} {
+        pack $tools.lconnection -side left -anchor w
+        pack $combobox -side left -anchor w
+	pack $tools.singlexlib -side left -anchor w
+    } else {
+	pack forget $tools.lconnection $combobox $tools.singlexlib
+    }
+}
+
+hook::add connected_hook [list [namespace current]::rawxml::update_xlib_choice add]
+hook::add disconnected_hook [list [namespace current]::rawxml::update_xlib_choice remove]
+
 proc rawxml::history_move {shift} {
     variable history
 
@@ -330,6 +436,7 @@
 
 proc rawxml::send_xml {} {
     variable history
+    variable rawxml_xlib
 
     set input .rawxml.input
     set xml [$input get 0.0 "end - 1c"]
@@ -340,8 +447,7 @@
     if {[llength [connections]] == 0} {
 	return -code error [::msgcat::mc "Not connected"]
     } else {
-	set xlib [lindex [connections] 0]
-	::xmpp::outText $xlib $xml
+	::xmpp::outText $rawxml_xlib $xml
     }
     $input delete 1.0 end
 }



More information about the Tkabber-dev mailing list