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

tkabber-svn at jabber.ru tkabber-svn at jabber.ru
Wed Apr 15 06:06:59 MSD 2009


Author: bigote
Date: 2009-04-15 06:06:58 +0400 (Wed, 15 Apr 2009)
New Revision: 218

Modified:
   trunk/plugins/bldjid/ChangeLog
   trunk/plugins/bldjid/README
   trunk/plugins/bldjid/TODO
   trunk/plugins/bldjid/bldjid.tcl
Log:
-- Added a command /showmon to show a previously closed monitor window.
-- A hotkey <Control-m> is added to toggle between opened/closed states
of the monitor.
-- Some code refactoring.


Modified: trunk/plugins/bldjid/ChangeLog
===================================================================
--- trunk/plugins/bldjid/ChangeLog	2009-04-13 21:56:04 UTC (rev 217)
+++ trunk/plugins/bldjid/ChangeLog	2009-04-15 02:06:58 UTC (rev 218)
@@ -1,3 +1,23 @@
+2009-04-15  Serge Yudin  <xmpp:bigote at jabber.ru> <mailto:bigote at gmail.com>
+
+--- Version 0.5.15 of the plugin.
+--- Files modified:
+    bldjid.tcl, README, TODO, ChangeLog.
+
+--- Changes:
+	Added a command /showmon to show a previously closed monitor window.
+	A hotkey <Control-m> is added to toggle between opened/closed states
+	of the monitor.
+	Code refactoring (/bldhelp command is a separate procedure now).
+
+--- TODO:
+	Most likely, monitor timeout will be removed, since the hotkey allows
+	managing of the monitor's state in a rapid and comfortable way.
+	It's also probable that commands /showmon and /closemon will be
+	deprecated by the same reason.
+	The code that handles monitor state check needs to be refactored.
+	See TODO file for more plans.
+
 2009-04-13  Serge Yudin  <xmpp:bigote at jabber.ru> <mailto:bigote at gmail.com>
 
 --- Version 0.5.14 of the plugin.

Modified: trunk/plugins/bldjid/README
===================================================================
--- trunk/plugins/bldjid/README	2009-04-13 21:56:04 UTC (rev 217)
+++ trunk/plugins/bldjid/README	2009-04-15 02:06:58 UTC (rev 218)
@@ -67,6 +67,12 @@
 	commands output to a special monitor window. To close it manually type:
 /closemon
 
+--- It can be opened again by the following command:
+/showmon
+
+--- Please note that a hotkey <Control-m> is added to toggle between
+	open/close states of the monitor.
+
 --- To clear the currently opened monitor window (not logs, neither the last search!)
 	use the command:
 /clearmon

Modified: trunk/plugins/bldjid/TODO
===================================================================
--- trunk/plugins/bldjid/TODO	2009-04-13 21:56:04 UTC (rev 217)
+++ trunk/plugins/bldjid/TODO	2009-04-15 02:06:58 UTC (rev 218)
@@ -1,3 +1,25 @@
+=== Maybe monitor timeout isn't necessary now, when a hotkey
+	for its toggling is added. So it's very likely that it will be removed.
+--- The same about /showmon and /closemon commands.
+
+=== Since there's a nice proc named toggle_monitor that handles
+	checking of monitor window existence and its creating/deleting/showing
+	depending on the result, it would be nice, too, to refactor
+	the procedures that do these check by themselves.
+
+=== It seems that the plugin becomes too big ;) Most likely, it will be
+	splitted in three parts: bldjid.tcl, visits.tcl and monitor.tcl
+	Each one will be loaded if a corresponding Customize options enables it.
+--- Customize options part should be loaded dynamically, too. For example,
+	by default only bldjid.tcl is loaded, and its Customize menu contains
+	only options(enabled) item (unchecked by default). If we enable and set it,
+	visits.tcl part is loaded, with its part of the menu, which, in its turn,
+	contains options(redirect_output) unchecked. If we want to use redirect,
+	we enable it, too, and monitor.tcl is loaded.
+--- I'm not sure if it's possible to unload the loaded modules,
+	but at least the menu can be hidden dynamically when we uncheck and set
+	corresponding options.
+
 ===	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-13 21:56:04 UTC (rev 217)
+++ trunk/plugins/bldjid/bldjid.tcl	2009-04-15 02:06:58 UTC (rev 218)
@@ -1,4 +1,4 @@
-# "Bldjid" plugin for Tkabber. 2009-04-13 v. 0.5.14
+# "Bldjid" plugin for Tkabber. 2009-04-15 v. 0.5.15
 # Written by Serge Yudin xmpp:bigote at jabber.ru
 # See README file for usage.
 
@@ -8,6 +8,8 @@
 # An array where all user entrances are stored.
 	global jids_by_chats
 
+	event add <<ToggleMonitor>> <Control-m>
+
 		set winid 0
 		::msgcat::mcload [file join [file dirname [info script]] msgs]
 
@@ -15,6 +17,7 @@
 		[namespace current]::visitors_compls
 		hook::add chat_send_message_hook \
 		[namespace current]::handle_commands 17
+		::hook::add open_chat_post_hook [namespace current]::setup_bindings
 
 # Set plugin options.
 		set verbosity [list \
@@ -77,6 +80,12 @@
 
 }
 
+proc bldjid::setup_bindings {chatid type} {
+	set w [::chat::input_win $chatid]
+    bind $w <<ToggleMonitor>> [list [namespace current]::toggle_monitor $chatid]
+    bind $w <<ToggleMonitor>> +break
+}
+
 ## Thanks to Alexey Smirnov <alexey.smirnov at gmx.com>
 ## and Rakhmanin Ruslan <rakhmaninr at gmail.com>
 ## Adapted to bldjid's necessities by Serge Yudin
@@ -153,7 +162,7 @@
 
 	if {!$wordstart} {
 		lappend comps {/bldjid } {/unbldjid } {/banjid } {/amnesty } \
-			{/visitors } {/visited } {/bldhelp } {/closemon } {/clearmon }
+			{/visitors } {/visited } {/bldhelp } {/closemon } {/clearmon } {/showmon }
 	}
 
 	if {$wordstart && [regexp {^/(bldjid|banjid|unban|unbldjid).*} $line]} {
@@ -197,6 +206,8 @@
 		set cmd /closemon
 	} elseif {[string match {/clearmon*} $body]} {
 		set cmd /clearmon
+	} elseif {[string match {/showmon*} $body]} {
+		set cmd /showmon
 	} else return
 
 	if {$type != "groupchat"} return
@@ -224,10 +235,13 @@
 			lassign [muc::parse_nick_reason $body 9] nick room
 		}
 	} elseif {[string equal [string range $body 0 7] "/bldhelp"]} {
+		[namespace current]::help $chatid
 	} 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
+	} elseif {[string equal [string range $body 0 7] "/showmon"]} {
+		[namespace current]::show_monitor $chatid
 	} else {
 		return stop
 	}
@@ -309,11 +323,7 @@
 			append header " Show all visits to the "
 			if {$room == ""} {
 				set room $group
-#				if {!$options(redirect_output)} {
 					append header "current room:"
-#				} else {
-#					append header "room $room:"
-#				}
 			} elseif {$options(matching_rules) == "exact"} {
 				append header "room $room:"
 			} else {
@@ -358,7 +368,7 @@
 				if {![winfo exists [chat::winid $chatid].mon]} {
 					[namespace current]::create_monitor_window $chatid
 				} else {
-					[namespace current]::open_monitor_window $chatid
+					[namespace current]::show_monitor $chatid
 				}
 				[namespace current]::add_message_to_monitor $chatid $header
 				[namespace current]::add_message_to_monitor $chatid "[join $msg]\n\n"
@@ -425,7 +435,7 @@
 				if {![winfo exists [chat::winid $chatid].mon]} {
 					[namespace current]::create_monitor_window $chatid
 				} else {
-					[namespace current]::open_monitor_window $chatid
+					[namespace current]::show_monitor $chatid
 				}
 				[namespace current]::add_message_to_monitor $chatid $header
 				[namespace current]::add_message_to_monitor $chatid "[join $msg]\n\n"
@@ -437,57 +447,6 @@
 			chat::add_message $chatid $group error "JIDs gathering is disabled." {}
 		}
 		}
-
-		/bldhelp {
-			variable options
-			set group [chat::get_jid $chatid]
-			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:\
-			\n/unbldjid JID\
-			\n\nBan a user in the current room by his/her JID:\
-			\n/banjid JID\
-			\nSome reason for banning (optional).\
-			\n\nUnban all people banned in the current room:\
-			\n/amnesty\
-			\n\nShow all visitors of the current room:\
-			\n/visitors\
-			\n\nShow all visitors of rooms that match *room*:\
-			\n/visitors room\
-			\n\nShow visits made by someone whose nick or JID matches *nick*:\
-			\n/visited nick\
-			\n\nShows visits made by *nick*, to the rooms that match *room*:\
-			\n/visited nick\
-			\nroom\
-			\n\nBan in all rooms where you have admin privileges:\
-			\n?n? means an item number from a list given by a /visit* command.\
-			\n/bldjid ?n?\
-			\nSome reason for banning (optional).\
-			\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."
-			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 {}
-			}
-		}
 	}
 	return stop
 }
@@ -597,7 +556,7 @@
 proc bldjid::whoami {xlib where} {
 	global grouproster
 	if {[muc::is_compatible $where]} {
-		set chatid [chat::chatid $xlib $where]
+		set chatid [::chat::chatid $xlib $where]
 		set jid $where/[get_our_groupchat_nick $chatid]
 		return [list $muc::users(role,$xlib,$jid) \
 				$muc::users(affiliation,$xlib,$jid)]
@@ -613,7 +572,7 @@
 	global grouproster
 	set grpjids ""
 	foreach tmpchatid [lsort [lfilter chat::is_groupchat [chat::opened $xlib]]] {
-		set tmpgrp [chat::get_jid $tmpchatid]
+		set tmpgrp [::chat::get_jid $tmpchatid]
 		if {$pattern != ""} {
 			switch -- $options(matching_rules) {
 				exact {
@@ -635,7 +594,7 @@
 		return stop
 	}
 	foreach tmpchatid $grplist {
-		set tmpgrp [chat::get_jid $tmpchatid]
+		set tmpgrp [::chat::get_jid $tmpchatid]
 		set jid $tmpgrp/[get_our_groupchat_nick $tmpchatid]
 		if {[lcontain $grouproster(users,$tmpchatid) $jid]} {
 			switch -- $which {
@@ -658,7 +617,7 @@
 
 proc bldjid::pickup {index chatid} {
 	variable user_list
-	set group [chat::get_jid $chatid]
+	set group [::chat::get_jid $chatid]
 	set maxindex [expr {[llength $user_list] - 1}]
 	if {$maxindex < 0} {
 # Nothing to show: list is empty. There's a check for it up there, however.
@@ -677,6 +636,60 @@
 	}
 }
 
+proc bldjid::help {chatid} {
+	variable options
+	set group [::chat::get_jid $chatid]
+	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:\
+	\n/unbldjid JID\
+	\n\nBan a user in the current room by his/her JID:\
+	\n/banjid JID\
+	\nSome reason for banning (optional).\
+	\n\nUnban all people banned in the current room:\
+	\n/amnesty\
+	\n\nShow all visitors of the current room:\
+	\n/visitors\
+	\n\nShow all visitors of rooms that match *room*:\
+	\n/visitors room\
+	\n\nShow visits made by someone whose nick or JID matches *nick*:\
+	\n/visited nick\
+	\n\nShows visits made by *nick*, to the rooms that match *room*:\
+	\n/visited nick\
+	\nroom\
+	\n\nBan in all rooms where you have admin privileges:\
+	\n?n? means an item number from a list given by a /visit* command.\
+	\n/bldjid ?n?\
+	\nSome reason for banning (optional).\
+	\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\nShow monitor window that was already opened and then closed:\
+	\n/showmon\
+	\nUse <Control-m> shortcut to toggle between show and close monitor.
+	\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."
+	if {$options(redirect_output)} {
+		if {![winfo exists [::chat::winid $chatid].mon]} {
+			[namespace current]::create_monitor_window $chatid
+		} else {
+			[namespace current]::show_monitor $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 {}
+	}
+}
+
 ### Thanks to Alexey Smirnov <alexey.smirnov at gmx.com>
 proc bldjid::extract_user {msg tsVar nickVar jidVar} {
 	upvar 1 $tsVar timestamp $nickVar nick $jidVar jid
@@ -738,7 +751,7 @@
 proc bldjid::create_monitor_window {chatid} {
     variable options
 
-	set ccw [chat::winid $chatid]
+	set ccw [::chat::winid $chatid]
 	set wmon $ccw.mon
 	frame $wmon
 	pack $wmon -side top -fill x
@@ -768,18 +781,23 @@
 	}
 }
 
-proc bldjid::open_monitor_window {chatid} {
+proc bldjid::show_monitor {chatid} {
 	variable options
-	set ccw [chat::winid $chatid]
-	pack $ccw.mon -side top -fill x
-	if {$options(wmon_timeout) > 0} {
-		after [expr {1000 * $options(wmon_timeout)}] \
-		[list [namespace current]::close_monitor $chatid]
+	set ccw [::chat::winid $chatid]
+	catch {pack info $ccw.mon} res
+	if {[string match "*bad window path name*" $res]} {
+		[namespace current]::create_monitor_window $chatid
+	} elseif {[string match "*isn\'t packed*" $res]} {
+		pack $ccw.mon -side top -fill x
+		if {$options(wmon_timeout) > 0} {
+			after [expr {1000 * $options(wmon_timeout)}] \
+			[list [namespace current]::close_monitor $chatid]
+		}
 	}
 }
 
 proc bldjid::add_message_to_monitor {chatid body} {
-	set ccw [chat::winid $chatid]
+	set ccw [::chat::winid $chatid]
 	set t $ccw.mon.text
 	if {![winfo exists $t]} return
 
@@ -792,18 +810,30 @@
 }
 
 proc bldjid::close_monitor {chatid} {
-	set ccw [chat::winid $chatid]
+	set ccw [::chat::winid $chatid]
 	if {[winfo exists $ccw.mon]} {
-		pack forget $ccw.mon
-		pack forget $ccw.vsb
+		pack forget $ccw.mon $ccw.vsb
 	}
 }
 
 proc bldjid::clear_monitor {chatid} {
-	set ccw [chat::winid $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
 }
+
+# I have doubts if it's OK to use catch results as a condition...
+proc bldjid::toggle_monitor {chatid} {
+	variable options
+	set ccw [::chat::winid $chatid]
+	if {![catch {pack info $ccw.mon} res]} {
+		pack forget $ccw.mon $ccw.vsb
+	} elseif {[string match "*bad window path name*" $res]} {
+		[namespace current]::create_monitor_window $chatid
+	} elseif {[string match "*isn\'t packed*" $res]} {
+		pack $ccw.mon -side top -fill x
+	}
+}



More information about the Tkabber-dev mailing list