[Tkabber-dev] r1745 - in trunk/tkabber-plugins: . spy tclchat traffic

tkabber-svn at jabber.ru tkabber-svn at jabber.ru
Thu Mar 26 17:29:56 MSK 2009


Author: sergei
Date: 2009-03-26 17:29:56 +0300 (Thu, 26 Mar 2009)
New Revision: 1745

Modified:
   trunk/tkabber-plugins/ChangeLog
   trunk/tkabber-plugins/spy/spy.tcl
   trunk/tkabber-plugins/tclchat/tclchat.tcl
   trunk/tkabber-plugins/tclchat/tclchat_commands.tcl
   trunk/tkabber-plugins/tclchat/tclchat_messages.tcl
   trunk/tkabber-plugins/traffic/traffic.tcl
Log:
	* spy/spy.tcl, tclchat/tclchat.tcl, tclchat/tclchat_commands.tcl,
	  tclchat/tclchat_messages.tcl, traffic/traffic.tcl: Made Tclchat,
	  Presence Spy and Traffic Counter plugins unloadable.


Modified: trunk/tkabber-plugins/ChangeLog
===================================================================
--- trunk/tkabber-plugins/ChangeLog	2009-03-25 19:39:09 UTC (rev 1744)
+++ trunk/tkabber-plugins/ChangeLog	2009-03-26 14:29:56 UTC (rev 1745)
@@ -1,3 +1,9 @@
+2009-03-26  Sergei Golovan <sgolovan at nes.ru>
+
+	* spy/spy.tcl, tclchat/tclchat.tcl, tclchat/tclchat_commands.tcl,
+	  tclchat/tclchat_messages.tcl, traffic/traffic.tcl: Made Tclchat,
+	  Presence Spy and Traffic Counter plugins unloadable.
+
 2009-03-25  Sergei Golovan <sgolovan at nes.ru>
 
 	* gmail/gmail.tcl, iconsets/iconsets.tcl, mute/mute.tcl: Made Gmail,

Modified: trunk/tkabber-plugins/spy/spy.tcl
===================================================================
--- trunk/tkabber-plugins/spy/spy.tcl	2009-03-25 19:39:09 UTC (rev 1744)
+++ trunk/tkabber-plugins/spy/spy.tcl	2009-03-26 14:29:56 UTC (rev 1745)
@@ -5,23 +5,23 @@
 # and/or file.
 #
 
-option add *Spy.timestampforeground Black         widgetDefault
-option add *Spy.nickforeground      DarkBlue      widgetDefault
-option add *Spy.jidforeground       DarkBlue      widgetDefault
-option add *Spy.presenceforeground  DarkRed       widgetDefault
-option add *Spy.reasonforeground    DarkMagenta   widgetDefault
-
 package require msgcat
 
 namespace eval spy {
-    set the_file ""
-    set watches {}
+    ::msgcat::mcload [file join [file dirname [info script]] msgs]
 
+    if {![::plugins::is_registered spy]} {
+	::plugins::register spy \
+			    -namespace [namespace current] \
+			    -source [info script] \
+			    -description [::msgcat::mc "Whether the Spy Presence plugin is loaded."] \
+			    -loadcommand [namespace code load] \
+			    -unloadcommand [namespace code unload]
+	return
+    }
+
     variable options
 
-    variable scriptdir [file dirname [info script]]
-    ::msgcat::mcload [file join $scriptdir msgs]
-
     custom::defgroup Plugins [::msgcat::mc "Plugins options."] \
 	-group Tkabber
     custom::defgroup Spy [::msgcat::mc "Spy Presence plugin options."] \
@@ -36,6 +36,52 @@
 	-type string -group Spy
 }
 
+proc spy::load {} {
+    variable the_file
+    variable watches
+    
+    set the_file ""
+    set watches {}
+
+    hook::add postload_hook [namespace current]::init_spy 100
+    hook::add client_presence_hook [namespace current]::client_presence_handler 100
+    hook::add quit_hook [namespace current]::deinit_spy 100
+    hook::add finload_hook [namespace current]::setup_menu
+    hook::add save_session_hook [namespace current]::save_session
+
+    init_spy
+    setup_menu
+}
+
+proc spy::unload {} {
+    variable the_file
+    variable watches
+    
+    desetup_menu
+
+    if {[winfo exists .spy]} {
+	destroy_win .spy
+    }
+    deinit_spy
+
+    hook::remove postload_hook [namespace current]::init_spy 100
+    hook::remove client_presence_hook [namespace current]::client_presence_handler 100
+    hook::remove quit_hook [namespace current]::deinit_spy 100
+    hook::remove finload_hook [namespace current]::setup_menu
+    hook::remove save_session_hook [namespace current]::save_session
+
+    set the_file ""
+    set watches {}
+
+    namespace delete [namespace current]::search
+}
+
+option add *Spy.timestampforeground Black         widgetDefault
+option add *Spy.nickforeground      DarkBlue      widgetDefault
+option add *Spy.jidforeground       DarkBlue      widgetDefault
+option add *Spy.presenceforeground  DarkRed       widgetDefault
+option add *Spy.reasonforeground    DarkMagenta   widgetDefault
+
 proc spy::open_window {} {
     variable watches
 
@@ -218,7 +264,6 @@
     chat::open_to_user $xlib $jid
 }
 
-
 proc spy::display {xlib jid nick type reason} {
     variable options
     variable watches
@@ -348,10 +393,14 @@
     }
 }
 
-hook::add postload_hook [namespace current]::spy::init_spy 100
-hook::add client_presence_hook [namespace current]::spy::client_presence_handler 100
-hook::add quit_hook [namespace current]::spy::deinit_spy 100
-hook::add finload_hook [namespace current]::spy::setup_menu
+proc spy::desetup_menu {} {
+    catch { 
+	set m [.mainframe getmenu plugins]
+	set idx [$m index [::msgcat::mc "Spy presence"]]
+    
+        $m delete $idx
+    }
+}
 
 namespace eval spy::search {}
 
@@ -412,5 +461,3 @@
     }
 }
 
-hook::add save_session_hook [namespace current]::spy::save_session
-

Modified: trunk/tkabber-plugins/tclchat/tclchat.tcl
===================================================================
--- trunk/tkabber-plugins/tclchat/tclchat.tcl	2009-03-25 19:39:09 UTC (rev 1744)
+++ trunk/tkabber-plugins/tclchat/tclchat.tcl	2009-03-26 14:29:56 UTC (rev 1745)
@@ -11,17 +11,25 @@
 namespace eval tclchat {
     ::msgcat::mcload [file join [file dirname [info script]] msgs]
 
-    custom::defgroup Plugins [::msgcat::mc "Plugins options."] -group Tkabber
+    if {![::plugins::is_registered tclchat]} {
+	::plugins::register tclchat \
+			    -namespace [namespace current] \
+			    -source [info script] \
+			    -description [::msgcat::mc "Whether the Tclchat plugin is loaded."] \
+			    -loadcommand [namespace code load] \
+			    -unloadcommand [namespace code unload]
+	return
+    }
 
-    custom::defgroup Tclchat [::msgcat::mc "Tclchat plugin options."] -group Plugins
+    custom::defgroup Plugins [::msgcat::mc "Plugins options."] \
+	-group Tkabber
 
+    custom::defgroup Tclchat [::msgcat::mc "Tclchat plugin options."] \
+	-group Plugins
+
     custom::defvar options(use_tkchat_colors) 1 \
         [::msgcat::mc "Use TkChat embedded colors."] \
         -group Chat -group Tclchat -type boolean
-
-    hook::add finload_hook [namespace current]::on_init 30
-    hook::add open_chat_post_hook [namespace current]::on_open_chat
-    hook::add chat_send_message_xlist_hook [namespace current]::add_color
 }
 
 # Load in the additional files that are part of the tclchat plugin.
@@ -29,15 +37,43 @@
 source [file join [file dirname [info script]] tclchat_messages.tcl]
 source [file join [file dirname [info script]] tclchat_commands.tcl]
 
+proc tclchat::load {} {
+    load_commands
+    load_messages
+
+    hook::add finload_hook [namespace current]::on_init 30
+    hook::add open_chat_post_hook [namespace current]::on_open_chat
+    hook::add chat_send_message_xlist_hook [namespace current]::add_color
+
+    on_init
+}
+
+proc tclchat::unload {} {
+    catch {
+	set menu [.mainframe getmenu plugins]
+	set idx [$menu index [msgcat::mc "Tkchat colors"]]
+	$menu delete $idx
+    }
+
+    unload_commands
+    unload_messages
+
+    hook::remove finload_hook [namespace current]::on_init 30
+    hook::remove open_chat_post_hook [namespace current]::on_open_chat
+    hook::remove chat_send_message_xlist_hook [namespace current]::add_color
+}
+
 proc tclchat::on_init {} {
     global tcl_platform
     global loginconf
     variable Options
     variable urlid 0
 
-    set menu [.mainframe getmenu plugins]
-    $menu add checkbutton -label [msgcat::mc "Tkchat colors"] \
-        -underline 0 -variable [namespace current]::options(use_tkchat_colors)
+    catch {
+	set menu [.mainframe getmenu plugins]
+	$menu add checkbutton -label [msgcat::mc "Tkchat colors"] \
+	      -underline 0 -variable [namespace current]::options(use_tkchat_colors)
+    }
 
     array set Options {
         auth          {}
@@ -54,10 +90,6 @@
         -proxyfilter [namespace origin proxyfilter] \
         -useragent $loginconf(proxyuseragent)
 
-    if {[package provide tls] != {}} {
-        http::register https 443 ::tls::socket
-    }
-        
     if {$loginconf(proxy) == "https"} {
         if {[string length $loginconf(proxyusername)] > 0} {
             set Options(auth) [list Proxy-Authorization \
@@ -148,7 +180,7 @@
 
 proc tclchat::ParseHistLog {log {reverse 0}} {
     variable Options
-    
+
     set retList {}
     set MsgRE {^\s*(?:Mon|Tue|Wed|Thu|Fri|Sat|Sun).+?\[([^\]]+)\]\s+([^:]+):?\s*(.*)$}
     set ircRE {ircbridge: \*\*\* (.+) (.+)$}
@@ -159,7 +191,7 @@
     set url "$Options(url)/$log"
     debugmsg tclchat "fetch log \"$url\""
     set tok [::http::geturl $url -headers $Options(auth)]
-    
+
     debugmsg tclchat "status [::http::status $tok] [::http::code $tok]"
     switch -- [::http::status $tok] {
         ok {
@@ -188,7 +220,7 @@
 # so not bothering to backgound it
 proc tclchat::LoadHistory {chatid} {
     variable Options
-    
+
     set FinalList {}
     if {$Options(HistoryLines) == 0} {
 	# don't even bother
@@ -253,7 +285,7 @@
     }
 
     set W [chat::chat_win $chatid]
-    
+
     # Set a mark for the history insertion point.
     if {[lsearch -exact [$W mark names] HISTORY] == -1} {
         $W config -state normal
@@ -296,7 +328,7 @@
     } else {
         after idle [list [namespace origin LoadHistoryLines] $chatid]
     }
-    
+
     $w configure -state $state
 }
 
@@ -342,9 +374,9 @@
     set Options(HaveHistory) 1
     set time [clock scan ${when} -gmt 1]
     lappend Options(History) $time $nick $msg
-    if { [llength $args] > 0 } {
+    if {[llength $args] > 0} {
 	debugmsg tclchat "WARNING: Log incorrect log format."
-    }   
+    }
     #debugmsg tclchat "[clock format $time] $nick :: $msg $opts $args"
 }
 

Modified: trunk/tkabber-plugins/tclchat/tclchat_commands.tcl
===================================================================
--- trunk/tkabber-plugins/tclchat/tclchat_commands.tcl	2009-03-25 19:39:09 UTC (rev 1744)
+++ trunk/tkabber-plugins/tclchat/tclchat_commands.tcl	2009-03-26 14:29:56 UTC (rev 1745)
@@ -3,13 +3,22 @@
 #
 # $Id$
 
-namespace eval tclchat {
+namespace eval tclchat {}
+
+proc tclchat::load_commands {} {
     hook::add chat_send_message_hook \
-        [namespace current]::send_commands 50
+	      [namespace current]::send_commands 50
     hook::add generate_completions_hook \
-        [namespace current]::command_completion
+	      [namespace current]::command_completion
 }
 
+proc tclchat::unload_commands {} {
+    hook::remove chat_send_message_hook \
+		 [namespace current]::send_commands 50
+    hook::remove generate_completions_hook \
+		 [namespace current]::command_completion
+}
+
 proc tclchat::command_completion {chatid compsvar wordstart line} {
     upvar 0 $compsvar comps
     if {!$wordstart} {

Modified: trunk/tkabber-plugins/tclchat/tclchat_messages.tcl
===================================================================
--- trunk/tkabber-plugins/tclchat/tclchat_messages.tcl	2009-03-25 19:39:09 UTC (rev 1744)
+++ trunk/tkabber-plugins/tclchat/tclchat_messages.tcl	2009-03-26 14:29:56 UTC (rev 1745)
@@ -31,13 +31,22 @@
 		       are treated specially, replacing his nickname by\
 		       corresponding IRC user nickname."] \
         -group Tclchat -type string
-    
+}
+
+proc tclchat::load_messages {} {
     hook::add presence_xlist_hook  [namespace current]::request_users_list
     hook::add process_message_hook [namespace current]::fill_irc_users 30
     hook::add process_message_hook [namespace current]::process_ijchain_message 30
     hook::add draw_message_hook    [namespace current]::check_color 62
 }
 
+proc tclchat::unload_messages {} {
+    hook::remove presence_xlist_hook  [namespace current]::request_users_list
+    hook::remove process_message_hook [namespace current]::fill_irc_users 30
+    hook::remove process_message_hook [namespace current]::process_ijchain_message 30
+    hook::remove draw_message_hook    [namespace current]::check_color 62
+}
+
 # VERY DIRTY HACK. Tkabber doesn't have appropriate hook, so using inappropriate
 proc tclchat::request_users_list {vxlist xlib stat} {
     upvar 2 newargs args

Modified: trunk/tkabber-plugins/traffic/traffic.tcl
===================================================================
--- trunk/tkabber-plugins/traffic/traffic.tcl	2009-03-25 19:39:09 UTC (rev 1744)
+++ trunk/tkabber-plugins/traffic/traffic.tcl	2009-03-26 14:29:56 UTC (rev 1745)
@@ -3,10 +3,49 @@
 #
 # Bugs and feature request send to feez at jabber.ru
 
+package require msgcat
+
 namespace eval traffic {
-
     ::msgcat::mcload [file join [file dirname [info script]] msgs]
 
+    if {![::plugins::is_registered traffic]} {
+	::plugins::register traffic \
+			    -namespace [namespace current] \
+			    -source [info script] \
+			    -description [::msgcat::mc "Whether the Traffic Counter plugin is loaded."] \
+			    -loadcommand [namespace code load] \
+			    -unloadcommand [namespace code unload]
+	return
+    }
+
+    # Options
+    custom::defgroup Plugins [::msgcat::mc "Plugins options."] -group Tkabber
+
+    custom::defgroup Traffic [::msgcat::mc "Traffic Counter plugin options."] -group Plugins
+
+    custom::defvar options(show_nick) 1 \
+        [::msgcat::mc "Show nick instead of JID."] \
+        -type boolean -group Traffic \
+	-command [namespace code clear_and_refresh]
+
+    custom::defvar options(human_readable) 1 \
+        [::msgcat::mc "Use human-readable counters with K, M, G."] \
+        -type boolean -group Traffic
+}
+
+proc traffic::load {} {
+    variable stats
+    variable jids
+    variable names
+    variable columns
+    variable sort_order
+    variable current_xlib
+    variable wished_xlib
+    variable timer
+    variable timer_state
+    variable timer_id
+    variable timer_names
+
     array set stats {}
     array set jids {}
 
@@ -31,21 +70,51 @@
     set timer_id {}
     array set timer_names [list 0 [::msgcat::mc "On"] 1 [::msgcat::mc "Off"]]
 
+    hook::add log_hook [namespace current]::handle_inout
+    hook::add finload_hook [namespace current]::setup_menu
+    hook::add connected_hook [namespace code [list update_connections on]
+    hook::add disconnected_hook [namespace code [list update_connections off]
+    hook::add save_session_hook [namespace current]::save_session
 
-    # Options
-    custom::defgroup Plugins [::msgcat::mc "Plugins options."] -group Tkabber
+    setup_menu
+}
 
-    custom::defgroup Traffic [::msgcat::mc "Traffic plugin options."] -group Plugins
+proc traffic::unload {} {
+    variable stats
+    variable jids
+    variable names
+    variable columns
+    variable sort_order
+    variable current_xlib
+    variable wished_xlib
+    variable timer
+    variable timer_state
+    variable timer_id
+    variable timer_names
 
-    custom::defvar options(show_nick) 1 \
-        [::msgcat::mc "Show nick instead of JID."] \
-        -type boolean -group Traffic
+    setup_menu
 
-    custom::defvar options(human_readable) 1 \
-        [::msgcat::mc "Use human-readable counters with K, M, G."] \
-        -type boolean -group Traffic
+    if {[winfo exists .traffic_stats]} {
+	destroy_win .traffic_stats
+    }
 
-    trace variable options(show_nick) w [list [namespace current]::clear_and_refresh]
+    hook::remove log_hook [namespace current]::handle_inout
+    hook::remove finload_hook [namespace current]::setup_menu
+    hook::remove connected_hook [namespace code [list update_connections on]
+    hook::remove disconnected_hook [namespace code [list update_connections off]
+    hook::remove save_session_hook [namespace current]::save_session
+
+    catch {unset stats}
+    catch {unset jids}
+    catch {unset names}
+    catch {unset columns}
+    catch {unset sort_order}
+    catch {unset current_xlib}
+    catch {unset wished_xlib}
+    catch {unset timer}
+    catch {unset timer_state}
+    catch {unset timer_id}
+    catch {unset timer_names}
 }
 
 # ############################
@@ -107,8 +176,6 @@
     incr stat($xlib,$jid,total,$prefix) $size
 }
 
-hook::add log_hook [namespace current]::traffic::handle_inout
-
 # ############################
 # GUI
 
@@ -470,7 +537,6 @@
 # Register in the main menu
 
 proc traffic::setup_menu {} {
-
     catch {
 	set m [.mainframe getmenu plugins]
 	set ind [$m index end]
@@ -479,15 +545,15 @@
 	    -command [list [namespace current]::open_window]
     }
 }
-hook::add finload_hook [namespace current]::traffic::setup_menu
 
-# ##############################################
-# Hooks on connect and disconnect (update GUI)
+proc traffic::desetup_menu {} {
+    catch {
+	set m [.mainframe getmenu plugins]
+	set ind [$m index [::msgcat::mc "Traffic statistics"]]
 
-hook::add connected_hook \
-	  [list [namespace current]::traffic::update_connections on]
-hook::add disconnected_hook \
-	  [list [namespace current]::traffic::update_connections off]
+	$m delete $ind
+    }
+}
 
 ##############################################################################
 
@@ -520,5 +586,3 @@
     }
 }
 
-hook::add save_session_hook [namespace current]::traffic::save_session
-



More information about the Tkabber-dev mailing list