[Tkabber-dev] r212 - trunk/plugins/bldjid

tkabber-svn at jabber.ru tkabber-svn at jabber.ru
Thu Apr 9 08:58:58 MSD 2009


Author: bigote
Date: 2009-04-09 08:58:56 +0400 (Thu, 09 Apr 2009)
New Revision: 212

Modified:
   trunk/plugins/bldjid/ChangeLog
   trunk/plugins/bldjid/README
   trunk/plugins/bldjid/TODO
   trunk/plugins/bldjid/bldjid.tcl
Log:
Added an option that allows you to redirect /visit* and /bldhelp commands output
to a special monitor window placed below the current chat input window.
See README or ChangeLog for more information about it.

A bug fixed in /visitors command.


Modified: trunk/plugins/bldjid/ChangeLog
===================================================================
--- trunk/plugins/bldjid/ChangeLog	2009-04-08 00:21:59 UTC (rev 211)
+++ trunk/plugins/bldjid/ChangeLog	2009-04-09 04:58:56 UTC (rev 212)
@@ -1,3 +1,23 @@
+2009-04-09  Serge Yudin  <xmpp:bigote at jabber.ru> <mailto:bigote at gmail.com>
+
+--- Version 0.5.11 of the plugin.
+--- Files modified:
+    bldjid.tcl, README, TODO, ChangeLog.
+
+--- Changes:
+	Added an option that allows you to redirect /visit* commands output
+	to a special monitor window placed below the current chat input window.
+	You can customize its timeout (30 seconds by default) or even to make
+	the window permanent by setting 0). The window can be closed at any moment
+	manually by typing /closemon command. You can scroll this window using
+	Alt-Shift-PgUp and Alt-Shift-PgDown hotkeys. This window is a bit annoying
+	so redirect to it is disabled by default. See README for more information
+	about it.
+
+	A bug fixed that gave an error when trying to use /visitors command
+	while ::plugins::bldjid::options(enabled) was disabled.
+	Added checking of this option to be enabled for /visit* commands.
+
 2009-04-07  Serge Yudin  <xmpp:bigote at jabber.ru> <mailto:bigote at gmail.com>
 
 --- Version 0.5.10 of the plugin.
@@ -5,7 +25,7 @@
     bldjid.tcl, ChangeLog.
 
 --- Changes:
-	Code optimization (regexp used in proc bldjid::visitors_compls,
+	Code refactoring (regexp used in proc bldjid::visitors_compls,
 	Thanks to Alexey Smirnov <mailto:alexey.smirnov at gmx.com>).
 
 2009-04-07  Serge Yudin  <xmpp:bigote at jabber.ru> <mailto:bigote at gmail.com>

Modified: trunk/plugins/bldjid/README
===================================================================
--- trunk/plugins/bldjid/README	2009-04-08 00:21:59 UTC (rev 211)
+++ trunk/plugins/bldjid/README	2009-04-09 04:58:56 UTC (rev 212)
@@ -29,8 +29,8 @@
 Some reason for banning (optional).
 
 ---	If you're in a good mood (it's your birthday, for instance),
-you might want to unban all people banned in a certain room.
-To do so, just write there the following command:
+	you might want to unban all people banned in a certain room.
+	To do so, just write there the following command:
 /amnesty
 and after a confirmation all outcasts from that room will be unbanned.
 
@@ -52,7 +52,7 @@
 room
 
 --- An enumerated list styled as 'info' will be shown in the current chat window.
-In order to choose a line from it use commands explained above:
+	In order to choose a line from it use commands explained above:
 /banjid ?n?
 reason
 
@@ -63,6 +63,14 @@
 
 where ?n? is an integer between 0 and the last item number.
 
+--- There is an option that allows you to redirect /visit* and /bldhelp
+	commands output to a special monitor window. To close it manually type:
+/closemon
+
+--- To clear the currently opened monitor window (not logs, neither the last search!)
+	use the command:
+/clearmon
+
 --- Autocompletion works for all these commands: write a couple
 	of the first letters of a command and hit TAB one of more times.
 -	Autocompletion also works in the same way for matching JIDs and nicks
@@ -95,12 +103,34 @@
 	user entrances.
 
 --- ::plugins::bldjid::options(matching_rules)
--	"Exact" matching obliges you provide exact parameters
+-	"Exact" matching obliges you to provide exact parameters
 	for /visit* commands to search.
 -	So the default setting is "Loose" matching that allows you
 	to put only a group name or even its part instead of full room's JID.
 	The same applies for nicks.
 
+--- ::plugins::bldjid::options(custom_separator)
+	Custom field separator for /visit* commands. Default value is "||".
+
+--- ::plugins::bldjid::options(redirect_output)
+	Disabled by default.
+	This option allows you to display /visit* and /bldhelp commands output
+	in a special monitor window placed below the current chat input window.
+	It can be closed manually by typing /closemon command at any moment
+	but it has a timeout after which it will be closed automatically.
+	Closing this monitor window doesn't mean you lose your search result.
+	You can still use ban and unban commands with a list number
+	if you remember it or using it with JID autocompletion.
+	Even more, your search history is kept in each monitor window
+	until you clear it by /clearmon command.
+	You can scroll monitor window up and down by pressing
+	Alt-Shift-PgUp and Alt-Shift-PgDown correspondingly.
+
+--- ::plugins::bldjid::options(wmon_timeout)
+	The lifetime of a currently opened monitor window. Default value is 30 seconds.
+	Zero means it won't be closed automatically. At any moment you can close it
+	by typing /closemon.
+
 --- ::plugins::bldjid::options(send_chat_messages)
 	Besides of logging user entrances, chat system messages are published.
 	Unlike usual messages that are sent by ::muc::options(gen_enter_exit_msgs)
@@ -108,9 +138,6 @@
 	if Minimum verbosity level is chosen. If not, if would be almost the same
 	as ::muc::options(gen_enter_exit_msgs) messages (without exit messages).
 
---- ::plugins::bldjid::options(custom_separator)
-	Custom field separator for /visit* commands. Default value is "||".
-
 --- ::plugins::bldjid::options(log_length)
 	Sets log length limit for each room. Default value is 0 that means no limit.
 	If you want to enable log limiting enter some value (1000 should be enough

Modified: trunk/plugins/bldjid/TODO
===================================================================
--- trunk/plugins/bldjid/TODO	2009-04-08 00:21:59 UTC (rev 211)
+++ trunk/plugins/bldjid/TODO	2009-04-09 04:58:56 UTC (rev 212)
@@ -1,6 +1,3 @@
-=== Add an option to choose whether to list users directly in a chat window
-	or to open a special monitor window to show output.
-
 ===	Add "Bldjid" menu item with all commands to room MUC menu.
 	Note that a list of rooms must be done for these commands to work.
 

Modified: trunk/plugins/bldjid/bldjid.tcl
===================================================================
--- trunk/plugins/bldjid/bldjid.tcl	2009-04-08 00:21:59 UTC (rev 211)
+++ trunk/plugins/bldjid/bldjid.tcl	2009-04-09 04:58:56 UTC (rev 212)
@@ -1,4 +1,4 @@
-# "Bldjid" plugin for Tkabber. 2009-04-07 v. 0.5.10
+# "Bldjid" plugin for Tkabber. 2009-04-09 v. 0.5.11
 # Written by Serge Yudin xmpp:bigote at jabber.ru
 # See README file for usage.
 
@@ -31,7 +31,8 @@
 		custom::defgroup Bldjid [::msgcat::mc "Bldjid options."] -group Plugins
 
 		custom::defvar options(enabled) 1 \
-			[::msgcat::mc "Enable JIDs logging."] \
+			[::msgcat::mc "Enable JIDs logging.\
+			Disabling it doesn't prevent /bldjid-like commands to work."] \
 			-type boolean -group Bldjid
 
 		custom::defvar options(filter_admin_rooms) 1 \
@@ -48,16 +49,27 @@
 			[::msgcat::mc "Matching rules for /visit* commands."] \
 			-type radio -group Bldjid -layout vertical -values $matching_rules
 
+		custom::defvar options(custom_separator) "||" \
+			[::msgcat::mc "Field separator for /visit* commands."] \
+			-type string -group Bldjid
+
+		custom::defvar options(redirect_output) 0 \
+			[::msgcat::mc "Redirect output of /visit* and /bldhelp commands\
+			to a special monitor window."] \
+			-type boolean -group Bldjid
+
+		custom::defvar options(wmon_timeout) 30 \
+			[::msgcat::mc "Timeout (in seconds) for monitor window described above,\
+			after which it will be closed automatically.\
+			Zero means no timeout.\
+			\nYou can still close the window at any moment by typing /closemon"] \
+			-type integer -group Bldjid
+
 		custom::defvar options(send_chat_messages) 0 \
 			[::msgcat::mc "Generate and send to chats smart system messages\
 			about user entrances (will only work with Minimum verbosity level)."] \
 			-type boolean -group Bldjid
 
-		custom::defvar options(custom_separator) "||" \
-			[::msgcat::mc "Field separator for /visit* commands."] \
-			-type string -group Bldjid
-
-
 		custom::defvar options(log_length) 0 \
 			[::msgcat::mc "Max length of your JID list for each room. \
 			 Zero means unlimited. See README for details."] \
@@ -107,24 +119,16 @@
 					}
 				}
 			}
-# I turn off filtering here but leave the code just for any case
-			if {0 && $options(filter_admin_rooms)} {
-				set iam [lindex [whoami $xlib $group] 1]
-				if {($iam == "admin" || $iam == "owner")} {
-						lappend jids_by_chats($group) [list $ts $nick $real_jid]
-				}
-			} else {
-				if {$options(log_length) != "" \
-				&& [[namespace current]::is_any_integer $options(log_length)] \
-				&& $options(log_length) > 0 \
-				&& [info exists jids_by_chats($group)]\
-				&& [llength $jids_by_chats($group)] >= $options(log_length)} {
-					set jids_by_chats($group) [lreplace $jids_by_chats($group) 0 \
-					[expr {[llength $jids_by_chats($group)] \
-					- $options(log_length)}]]
-				}
+			if {$options(log_length) != "" \
+			&& [[namespace current]::is_any_integer $options(log_length)] \
+			&& $options(log_length) > 0 \
+			&& [info exists jids_by_chats($group)]\
+			&& [llength $jids_by_chats($group)] >= $options(log_length)} {
+				set jids_by_chats($group) [lreplace $jids_by_chats($group) 0 \
+				[expr {[llength $jids_by_chats($group)] \
+				- $options(log_length)}]]
+			}
 				lappend jids_by_chats($group) [list $ts $nick $real_jid]
-			}
 			if {$options(send_chat_messages) && $options(verbosity_level) == "min"} {
 				set occupant "$nick ($real_jid)"
 				set msg [::msgcat::mc "%s has entered" $occupant]
@@ -149,7 +153,7 @@
 
 	if {!$wordstart} {
 		lappend comps {/bldjid } {/unbldjid } {/banjid } {/amnesty } \
-					  {/visitors } {/visited } {/bldhelp }
+			{/visitors } {/visited } {/bldhelp } {/closemon } {/clearmon }
 	}
 
 	if {$wordstart && [regexp {^/(bldjid|banjid|unban|unbldjid).*} $line]} {
@@ -171,6 +175,7 @@
 	set filter_turned_on "You turned off showing results in the rooms\
 		where you don't have admin privileges."
 	set no_jid "I can't see any JID of this user."
+
 	variable user_list
 # Detect the command.
 	if {[string match {/bldjid*} $body]} {
@@ -187,6 +192,10 @@
 		set cmd /visited
 	} elseif {[string match {/bldhelp*} $body]} {
 		set cmd /bldhelp
+	} elseif {[string match {/closemon*} $body]} {
+		set cmd /closemon
+	} elseif {[string match {/clearmon*} $body]} {
+		set cmd /clearmon
 	} else return
 
 	if {$type != "groupchat"} return
@@ -214,6 +223,10 @@
 			lassign [muc::parse_nick_reason $body 9] nick room
 		}
 	} elseif {[string equal [string range $body 0 7] "/bldhelp"]} {
+	} elseif {[string equal [string range $body 0 8] "/closemon"]} {
+		[namespace current]::close_monitor $chatid
+	} elseif {[string equal [string range $body 0 8] "/clearmon"]} {
+		[namespace current]::clear_monitor $chatid
 	} else {
 		return stop
 	}
@@ -281,6 +294,7 @@
 		/visitors {
 			variable options
 			set group [chat::get_jid $chatid]
+		if {$options(enabled)} {
 			global jids_by_chats
 			set user_list {}
 			set header "Group filtering is "
@@ -294,7 +308,11 @@
 			append header " Show all visits to the "
 			if {$room == ""} {
 				set room $group
-				append header "current room:"
+				if {!$options(redirect_output)} {
+					append header "current room:"
+				} else {
+					append header "room $room:"
+				}
 			} elseif {$options(matching_rules) == "exact"} {
 				append header "room $room:"
 			} else {
@@ -313,31 +331,49 @@
 						return stop
 					}
 				}
-				set user_list $jids_by_chats($room)
+				if {[info exists jids_by_chats($room)]} {
+					set user_list $jids_by_chats($room)
+				}
 			} else {
 				set groupjids [[namespace current]::valid_groups $xlib $which $room]
 				foreach grp $groupjids {
-					foreach item $jids_by_chats($grp) {
-						if {![string match "*current room:" $header]} {
-							lappend item $grp
+					if {[info exists jids_by_chats($grp)]} {
+						foreach item $jids_by_chats($grp) {
+							if {![string match "*current room:" $header]} {
+								lappend item $grp
+							}
+							lappend user_list $item
 						}
-						lappend user_list $item
 					}
 				}
 			}
 			set msg ""
 			set n 0
-			chat::add_message $chatid $group error $header {}
 			foreach user $user_list {
 				lappend msg [[namespace current]::format_msg $user $n]
 				incr n
 			}
-			chat::add_message $chatid $group info "[join $msg]" {}
+			if {$options(enabled) && $options(redirect_output)} {
+				if {![winfo exists [chat::winid $chatid].mon]} {
+					[namespace current]::create_monitor_window $chatid
+				} else {
+					[namespace current]::open_monitor_window $chatid
+				}
+				[namespace current]::add_message_to_monitor $chatid $header
+				[namespace current]::add_message_to_monitor $chatid "[join $msg]\n\n"
+			} elseif {$options(enabled)} {
+				chat::add_message $chatid $group error $header {}
+				chat::add_message $chatid $group info "[join $msg]" {}
+			}
+		} else {
+			chat::add_message $chatid $group error "JIDs gathering is disabled." {}
 		}
+		}
 
 		/visited {
 			variable options
 			set group [chat::get_jid $chatid]
+		if {$options(enabled)} {
 			global jids_by_chats
 			set user_list {}
 			set header "Group filtering is "
@@ -380,20 +416,32 @@
 			}
 			set msg ""
 			set n 0
-			chat::add_message $chatid $group error $header {}
 			foreach user $user_list {
 				lappend msg [[namespace current]::format_msg $user $n]
 				incr n
 			}
-			chat::add_message $chatid $group info "[join $msg]" {}
+			if {$options(redirect_output)} {
+				if {![winfo exists [chat::winid $chatid].mon]} {
+					[namespace current]::create_monitor_window $chatid
+				} else {
+					[namespace current]::open_monitor_window $chatid
+				}
+				[namespace current]::add_message_to_monitor $chatid $header
+				[namespace current]::add_message_to_monitor $chatid "[join $msg]\n\n"
+			} else {
+				chat::add_message $chatid $group error $header {}
+				chat::add_message $chatid $group info "[join $msg]" {}
+			}
+		} else {
+			chat::add_message $chatid $group error "JIDs gathering is disabled." {}
 		}
+		}
 
 		/bldhelp {
+			variable options
 			set group [chat::get_jid $chatid]
-			chat::add_message $chatid $group error \
-			"Short usage examples for Bldjid plugin" {}
-			chat::add_message $chatid $group info \
-			"\nBan in all rooms where you have admin privileges:\
+			set header "Short usage examples for Bldjid plugin"
+			set msg "\nBan in all rooms where you have admin privileges:\
 			\n/bldjid JID\
 			\nSome reason for banning (optional).\
 			\n\nUnban a banned person in these rooms:\
@@ -419,10 +467,30 @@
 			\n\nBan in the current room by a number from a list given by a /visit* command.\
 			\n/banjid ?n?\
 			\nSome reason for banning (optional).\
+			\n\nClose the currently opened monitor window:\
+			\n/closemon\
+			\n\nClear the currently opened monitor window:\
+			\n/clearmon\
 			\n\nSee README file for more information.\
 			\nVisit Tkabber -> Customize -> Plugins -> Bldjid\
-			\nto tune the plugin for your needs." {}
+			\nto tune the plugin for your needs."
+			if {$options(redirect_output)} {
+				if {![winfo exists [chat::winid $chatid].mon]} {
+					[namespace current]::create_monitor_window $chatid
+				} else {
+					[namespace current]::open_monitor_window $chatid
+				}
+				[namespace current]::add_message_to_monitor $chatid $header
+				[namespace current]::add_message_to_monitor $chatid "$msg\n\n"
+			} else {
+				chat::add_message $chatid $group error $header {}
+				chat::add_message $chatid $group info $msg {}
+			}
 		}
+
+		/closemon {
+#			[namespace current]::close_monitor $chatid
+		}
 	}
 	return stop
 }
@@ -661,3 +729,72 @@
 proc bldjid::is_any_integer a {
 	regexp \\d+ [string trim $a]
 }
+
+# These two next procs are taken from snoopstatus.tcl and modified a bit.
+proc bldjid::create_monitor_window {chatid} {
+    variable options
+
+	set ccw [chat::winid $chatid]
+	set wmon $ccw.mon
+	frame $wmon
+	pack $wmon -side top -fill x
+	text $wmon.text -state disabled -wrap word \
+		-yscrollcommand [list $ccw.vsb set]
+	scrollbar $ccw.vsb -command [list $wmon.text yview]
+
+	grid $wmon.text $ccw.vsb -sticky ns
+	grid $wmon.text -sticky news
+	grid rowconfigure $wmon 0 -weight 1
+	grid columnconfigure $wmon 0 -weight 1
+
+	regsub -all %W [bind Text <Prior>] $wmon.text prior_binding
+	regsub -all %W [bind Text <Next>] $wmon.text next_binding
+	bind $ccw.input <Shift-Meta-Prior> $prior_binding
+	bind $ccw.input <Shift-Meta-Next> $next_binding
+	bind $ccw.input <Shift-Alt-Prior> $prior_binding
+	bind $ccw.input <Shift-Alt-Next> $next_binding
+	bind $ccw.input <Shift-Meta-Prior> +break
+	bind $ccw.input <Shift-Meta-Next> +break
+	bind $ccw.input <Shift-Alt-Prior> +break
+	bind $ccw.input <Shift-Alt-Next> +break
+
+	if {$options(wmon_timeout) > 0} {
+		after [expr {1000 * $options(wmon_timeout)}] \
+		[list [namespace current]::close_monitor $chatid]
+	}
+}
+
+proc bldjid::open_monitor_window chatid {
+	set ccw [chat::winid $chatid]
+	pack $ccw.mon -side top -fill x
+}
+
+proc bldjid::add_message_to_monitor {chatid body} {
+	set ccw [chat::winid $chatid]
+	set t $ccw.mon.text
+	if {![winfo exists $t]} return
+
+	append msg $body
+
+	$t configure -state normal
+	$t insert end $msg
+	$t configure -state disabled
+	$t see end
+}
+
+proc bldjid::close_monitor chatid {
+	set ccw [chat::winid $chatid]
+	if {[winfo exists $ccw.mon]} {
+		pack forget $ccw.mon
+		pack forget $ccw.vsb
+	}
+}
+
+proc bldjid::clear_monitor chatid {
+	set ccw [chat::winid $chatid]
+	set t $ccw.mon.text
+	if {![winfo exists $t]} return
+	$t configure -state normal
+	$t delete 0.0 end
+	$t configure -state disabled
+}



More information about the Tkabber-dev mailing list