[Tkabber-dev] r1702 - in trunk/tkabber-plugins: . checkers chess renju reversi

tkabber-svn at jabber.ru tkabber-svn at jabber.ru
Sat Mar 7 23:30:17 MSK 2009


Author: sergei
Date: 2009-03-07 23:30:16 +0300 (Sat, 07 Mar 2009)
New Revision: 1702

Modified:
   trunk/tkabber-plugins/ChangeLog
   trunk/tkabber-plugins/checkers/checkers.tcl
   trunk/tkabber-plugins/chess/chess.tcl
   trunk/tkabber-plugins/renju/renju.tcl
   trunk/tkabber-plugins/reversi/reversi.tcl
Log:
	* checkers/checkers.tcl, chess/chess.tcl, renju/renju.tcl,
	  reversi/reversi.tcl: Made Checkers, Chess, Renju and Reversi plugins
	  unloadable.


Modified: trunk/tkabber-plugins/ChangeLog
===================================================================
--- trunk/tkabber-plugins/ChangeLog	2009-03-05 18:40:54 UTC (rev 1701)
+++ trunk/tkabber-plugins/ChangeLog	2009-03-07 20:30:16 UTC (rev 1702)
@@ -1,3 +1,9 @@
+2009-03-07  Sergei Golovan <sgolovan at nes.ru>
+
+	* checkers/checkers.tcl, chess/chess.tcl, renju/renju.tcl,
+	  reversi/reversi.tcl: Made Checkers, Chess, Renju and Reversi plugins
+	  unloadable.
+
 2009-03-02  Sergei Golovan <sgolovan at nes.ru>
 
 	* aniemoticons/aniemoticons.tcl: Reload emoticons theme after enabling

Modified: trunk/tkabber-plugins/checkers/checkers.tcl
===================================================================
--- trunk/tkabber-plugins/checkers/checkers.tcl	2009-03-05 18:40:54 UTC (rev 1701)
+++ trunk/tkabber-plugins/checkers/checkers.tcl	2009-03-07 20:30:16 UTC (rev 1702)
@@ -3,15 +3,25 @@
 package require msgcat
 
 namespace eval checkers {
-    variable scriptdir [file dirname [info script]]
+    ::msgcat::mcload [file join [file dirname [info script]] msgs]
 
-    ::msgcat::mcload [file join $scriptdir msgs]
+    if {![::plugins::is_registered checkers]} {
+	::plugins::register checkers \
+			    -namespace [namespace current] \
+			    -source [info script] \
+			    -description [::msgcat::mc "Whether the Checkers plugin is loaded."] \
+			    -loadcommand [namespace code load] \
+			    -unloadcommand [namespace code unload]
+	return
+    }
 
     variable square_size 48
     variable line_width 1
 
     variable themes
-    set dirs [glob -nocomplain -directory [file join $scriptdir pixmaps] *]
+    set dirs \
+	[glob -nocomplain -directory [file join [file dirname [info script]] \
+						pixmaps] *]
     foreach dir $dirs {
 	pixmaps::load_theme_name [namespace current]::themes $dir
     }
@@ -33,9 +43,11 @@
     array set short_game_names $game_names_list
     set short_game_names(straight) [::msgcat::mc "Straight checkers"]
 
-    custom::defgroup Plugins [::msgcat::mc "Plugins options."] -group Tkabber
+    custom::defgroup Plugins [::msgcat::mc "Plugins options."] \
+	-group Tkabber
 
-    custom::defgroup Checkers [::msgcat::mc "Checkers plugin options."] -group Plugins
+    custom::defgroup Checkers [::msgcat::mc "Checkers plugin options."] \
+	-group Plugins
     custom::defvar options(theme) Checkers \
 	[::msgcat::mc "Checkers figures theme."] -group Checkers \
 	-type options -values $values \
@@ -45,7 +57,9 @@
 	-type options \
 	-values $game_names_list
     custom::defvar options(flip_black_view) 1 \
-	[::msgcat::mc "Flip board view when playing black (Russian, Spanish, Italian) or white (Straight, Pool, Brazilian) by default."] \
+	[::msgcat::mc "Flip board view when playing black (Russian, Spanish,\
+		       Italian) or white (Straight, Pool, Brazilian) by\
+		       default."] \
 	-type boolean -group Checkers
     custom::defvar options(show_last_move) 0 \
 	[::msgcat::mc "Show last move by default."] \
@@ -61,10 +75,80 @@
 	[::msgcat::mc "Allow illegal moves (useful for debugging)."] \
 	-type boolean -group Checkers
     custom::defvar options(accept_illegal) 0 \
-	[::msgcat::mc "Accept opponent illegal moves (useful for debugging)."] \
+	[::msgcat::mc "Accept opponent illegal moves (useful for\
+		       debugging)."] \
 	-type boolean -group Checkers
 }
 
+proc checkers::load {} {
+    hook::add postload_hook [namespace current]::load_stored_theme 70
+
+    hook::add finload_hook [namespace current]::calc_moves 100
+
+    hook::add roster_create_groupchat_user_menu_hook \
+              [namespace current]::add_groupchat_user_menu_item 49
+    hook::add chat_create_user_menu_hook \
+              [namespace current]::add_groupchat_user_menu_item 49
+    hook::add roster_jid_popup_menu_hook \
+              [namespace current]::add_groupchat_user_menu_item 49
+
+    hook::add games_board_create_hook [namespace current]::iq_create
+    hook::add games_board_turn_hook [namespace current]::iq_turn
+
+    ::xmpp::iq::register set create games:board \
+			 [namespace parent]::iq_games_board_create
+    ::xmpp::iq::register set turn games:board \
+			 [namespace parent]::iq_games_board_turn
+
+    load_stored_theme
+    calc_moves
+}
+
+proc checkers::unload {} {
+    hook::remove postload_hook [namespace current]::load_stored_theme 70
+
+    hook::remove finload_hook [namespace current]::calc_moves 100
+
+    hook::remove roster_create_groupchat_user_menu_hook \
+              [namespace current]::add_groupchat_user_menu_item 49
+    hook::remove chat_create_user_menu_hook \
+              [namespace current]::add_groupchat_user_menu_item 49
+    hook::remove roster_jid_popup_menu_hook \
+              [namespace current]::add_groupchat_user_menu_item 49
+
+    hook::remove games_board_create_hook [namespace current]::iq_create
+    hook::remove games_board_turn_hook [namespace current]::iq_turn
+
+    if {[hook::is_empty games_board_create_hook]} {
+        ::xmpp::iq::unregister set create games:board
+        rename [namespace parent]::iq_games_board_create ""
+    }
+
+    if {[hook::is_empty games_board_turn_hook]} {
+        ::xmpp::iq::unregister set turn games:board
+        rename [namespace parent]::iq_games_board_turn ""
+    }
+
+    foreach var [info vars [namespace current]::*] {
+        upvar #0 $var flags
+        if {[info exists flags(window)]} {
+            destroy_win $flags(window)
+        }
+    }
+
+    foreach var [info vars [namespace current]::*] {
+        if {$var ne "[namespace current]::options"} {
+            unset $var
+        }
+    }
+
+    foreach img [image names] {
+        if {[string first checkers/ $img] == 0} {
+            image delete $img
+        }
+    }
+}
+
 proc checkers::load_stored_theme {args} {
     variable options
     variable themes
@@ -73,8 +157,6 @@
     pixmaps::load_dir $themes($options(theme))
 }
 
-hook::add postload_hook [namespace current]::checkers::load_stored_theme 70
-
 proc checkers::get_nick {xlib jid type} {
     if {[catch {chat::get_nick $xlib $jid $type} nick]} {
 	return [chat::get_nick $jid $type]
@@ -385,7 +467,6 @@
 
 proc checkers::turn_recv {gid xmlList} {
     variable options
-    variable prom_rev
     variable $gid
     upvar 0 $gid flags
 
@@ -529,8 +610,6 @@
     }
 }
 
-hook::add finload_hook [namespace current]::checkers::calc_moves 100
-
 proc checkers::center {c r} {
     variable square_size
     variable line_width
@@ -1199,7 +1278,6 @@
     $hw configure -state disabled
 }
 
-
 proc checkers::find_legal_moves {gid color} {
     variable moves
     variable jumps
@@ -1714,13 +1792,6 @@
 	-command [list [namespace current]::invite_dialog $xlib $jid]
 }
 
-hook::add roster_create_groupchat_user_menu_hook \
-    [namespace current]::checkers::add_groupchat_user_menu_item 49
-hook::add chat_create_user_menu_hook \
-    [namespace current]::checkers::add_groupchat_user_menu_item 49
-hook::add roster_jid_popup_menu_hook \
-    [namespace current]::checkers::add_groupchat_user_menu_item 49
-
 proc checkers::iq_create {varname xlib from iqid xml} {
     upvar 2 $varname var
 
@@ -1760,8 +1831,6 @@
     return
 }
 
-hook::add games_board_create_hook [namespace current]::checkers::iq_create
-
 proc checkers::iq_turn {varname xlib from xml} {
     upvar 2 $varname var
 
@@ -1791,9 +1860,7 @@
     return
 }
 
-hook::add games_board_turn_hook [namespace current]::checkers::iq_turn
 
-
 # Common games:board part
 proc iq_games_board_create {xlib from xml args} {
     set res [list error cancel feature-not-implemented]
@@ -1802,15 +1869,9 @@
     return $res
 }
 
-::xmpp::iq::register set create games:board \
-		     [namespace current]::iq_games_board_create
-
 proc iq_games_board_turn {xlib from xml args} {
     set res [list error cancel feature-not-implemented]
     hook::run games_board_turn_hook res $xlib $from $xml
     return $res
 }
 
-::xmpp::iq::register set turn games:board \
-		     [namespace current]::iq_games_board_turn
-

Modified: trunk/tkabber-plugins/chess/chess.tcl
===================================================================
--- trunk/tkabber-plugins/chess/chess.tcl	2009-03-05 18:40:54 UTC (rev 1701)
+++ trunk/tkabber-plugins/chess/chess.tcl	2009-03-07 20:30:16 UTC (rev 1702)
@@ -3,9 +3,17 @@
 package require msgcat
 
 namespace eval chess {
-    set scriptdir [file dirname [info script]]
+    ::msgcat::mcload [file join [file dirname [info script]] msgs]
 
-    ::msgcat::mcload [file join $scriptdir msgs]
+    if {![::plugins::is_registered chess]} {
+	::plugins::register chess \
+			    -namespace [namespace current] \
+			    -source [info script] \
+			    -description [::msgcat::mc "Whether the Chess plugin is loaded."] \
+			    -loadcommand [namespace code load] \
+			    -unloadcommand [namespace code unload]
+	return
+    }
 
     variable square_size 48
     variable line_width 1
@@ -26,7 +34,9 @@
     array set prom_rev [list queen q rook r bishop b knight n]
 
     variable themes
-    set dirs [glob -nocomplain -directory [file join $scriptdir pixmaps] *]
+    set dirs \
+	[glob -nocomplain -directory [file join [file dirname [info script]] \
+						pixmaps] *]
     foreach dir $dirs {
 	pixmaps::load_theme_name [namespace current]::themes $dir
     }
@@ -35,9 +45,11 @@
 	lappend values $theme $theme
     }
 
-    custom::defgroup Plugins [::msgcat::mc "Plugins options."] -group Tkabber
+    custom::defgroup Plugins [::msgcat::mc "Plugins options."] \
+	-group Tkabber
 
-    custom::defgroup Chess [::msgcat::mc "Chess plugin options."] -group Plugins
+    custom::defgroup Chess [::msgcat::mc "Chess plugin options."] \
+	-group Plugins
     custom::defvar options(theme) Classic \
 	[::msgcat::mc "Chess figures theme."] -group Chess \
 	-type options -values $values \
@@ -62,10 +74,80 @@
 	[::msgcat::mc "Allow illegal moves (useful for debugging)."] \
 	-type boolean -group Chess
     custom::defvar options(accept_illegal) 0 \
-	[::msgcat::mc "Accept opponent illegal moves (useful for debugging)."] \
+	[::msgcat::mc "Accept opponent illegal moves (useful for\
+		       debugging)."] \
 	-type boolean -group Chess
 }
 
+proc chess::load {} {
+    hook::add postload_hook [namespace current]::load_stored_theme 70
+
+    hook::add finload_hook [namespace current]::calc_moves 100
+
+    hook::add roster_create_groupchat_user_menu_hook \
+              [namespace current]::add_groupchat_user_menu_item 48
+    hook::add chat_create_user_menu_hook \
+              [namespace current]::add_groupchat_user_menu_item 48
+    hook::add roster_jid_popup_menu_hook \
+              [namespace current]::add_groupchat_user_menu_item 48
+
+    hook::add games_board_create_hook [namespace current]::iq_create
+    hook::add games_board_turn_hook [namespace current]::iq_turn
+
+    ::xmpp::iq::register set create games:board \
+			 [namespace parent]::iq_games_board_create
+    ::xmpp::iq::register set turn games:board \
+			 [namespace parent]::iq_games_board_turn
+
+    load_stored_theme
+    calc_moves
+}
+
+proc chess::unload {} {
+    hook::remove postload_hook [namespace current]::load_stored_theme 70
+
+    hook::remove finload_hook [namespace current]::calc_moves 100
+
+    hook::remove roster_create_groupchat_user_menu_hook \
+              [namespace current]::add_groupchat_user_menu_item 48
+    hook::remove chat_create_user_menu_hook \
+              [namespace current]::add_groupchat_user_menu_item 48
+    hook::remove roster_jid_popup_menu_hook \
+              [namespace current]::add_groupchat_user_menu_item 48
+
+    hook::remove games_board_create_hook [namespace current]::iq_create
+    hook::remove games_board_turn_hook [namespace current]::iq_turn
+
+    if {[hook::is_empty games_board_create_hook]} {
+        ::xmpp::iq::unregister set create games:board
+        rename [namespace parent]::iq_games_board_create ""
+    }
+
+    if {[hook::is_empty games_board_turn_hook]} {
+        ::xmpp::iq::unregister set turn games:board
+        rename [namespace parent]::iq_games_board_turn ""
+    }
+
+    foreach var [info vars [namespace current]::*] {
+        upvar #0 $var flags
+        if {[info exists flags(window)]} {
+            destroy_win $flags(window)
+        }
+    }
+
+    foreach var [info vars [namespace current]::*] {
+        if {$var ne "[namespace current]::options"} {
+            unset $var
+        }
+    }
+
+    foreach img [image names] {
+        if {[string first chess/ $img] == 0} {
+            image delete $img
+        }
+    }
+}
+
 proc chess::load_stored_theme {args} {
     variable options
     variable themes
@@ -73,8 +155,6 @@
     pixmaps::load_dir $themes($options(theme))
 }
 
-hook::add postload_hook [namespace current]::chess::load_stored_theme 70
-
 proc chess::get_nick {xlib jid type} {
     if {[catch {chat::get_nick $xlib $jid $type} nick]} {
 	return [chat::get_nick $jid $type]
@@ -225,7 +305,6 @@
 }
 
 proc chess::start_play {xlib jid id color} {
-
     set gid [make_gid $jid $id]
     variable $gid
     variable options
@@ -540,8 +619,6 @@
     }
 }
 
-hook::add finload_hook [namespace current]::chess::calc_moves 100
-
 proc chess::center {c r} {
     variable square_size
     variable line_width
@@ -1350,9 +1427,6 @@
     $hw configure -state disabled
 }
 
-
-
-
 proc chess::find_pseudo_legal_moves {gid color callback} {
     variable moves
     variable $gid
@@ -1522,7 +1596,6 @@
     }
 }
 
-
 proc chess::find_legal_moves {gid color} {
     variable $gid
     upvar 0 $gid flags
@@ -1718,7 +1791,6 @@
     expr {[lmatch -regexp $flags(legal_moves) ^[list $cf $rf $ct $rt]] != {}}
 }
 
-
 proc chess::highlight_legal_moves {gid cf rf} {
     variable $gid
     upvar 0 $gid flags
@@ -1783,13 +1855,6 @@
 	-command [list [namespace current]::invite_dialog $xlib $jid]
 }
 
-hook::add roster_create_groupchat_user_menu_hook \
-    [namespace current]::chess::add_groupchat_user_menu_item 48
-hook::add chat_create_user_menu_hook \
-    [namespace current]::chess::add_groupchat_user_menu_item 48
-hook::add roster_jid_popup_menu_hook \
-    [namespace current]::chess::add_groupchat_user_menu_item 48
-
 proc chess::iq_create {varname xlib from iqid xml} {
     upvar 2 $varname var
 
@@ -1816,8 +1881,6 @@
     return
 }
 
-hook::add games_board_create_hook [namespace current]::chess::iq_create
-
 proc chess::iq_turn {varname xlib from xml} {
     upvar 2 $varname var
 
@@ -1834,9 +1897,7 @@
     return
 }
 
-hook::add games_board_turn_hook [namespace current]::chess::iq_turn
 
-
 # Common games:board part
 proc iq_games_board_create {xlib from xml args} {
     set res [list error cancel feature-not-implemented]
@@ -1845,15 +1906,9 @@
     return $res
 }
 
-::xmpp::iq::register set create games:board \
-		     [namespace current]::iq_games_board_create
-
 proc iq_games_board_turn {xlib from xml args} {
     set res [list error cancel feature-not-implemented]
     hook::run games_board_turn_hook res $xlib $from $xml
     return $res
 }
 
-::xmpp::iq::register set turn games:board \
-		     [namespace current]::iq_games_board_turn
-

Modified: trunk/tkabber-plugins/renju/renju.tcl
===================================================================
--- trunk/tkabber-plugins/renju/renju.tcl	2009-03-05 18:40:54 UTC (rev 1701)
+++ trunk/tkabber-plugins/renju/renju.tcl	2009-03-07 20:30:16 UTC (rev 1702)
@@ -3,15 +3,25 @@
 package require msgcat
 
 namespace eval renju {
-    variable scriptdir [file dirname [info script]]
+    ::msgcat::mcload [file join [file dirname [info script]] msgs]
 
-    ::msgcat::mcload [file join $scriptdir msgs]
+    if {![::plugins::is_registered renju]} {
+	::plugins::register renju \
+			    -namespace [namespace current] \
+			    -source [info script] \
+			    -description [::msgcat::mc "Whether the Gomoku/Renju plugin is loaded."] \
+			    -loadcommand [namespace code load] \
+			    -unloadcommand [namespace code unload]
+	return
+    }
 
     variable square_size 31
     variable line_width 1
 
     variable themes
-    set dirs [glob -nocomplain -directory [file join $scriptdir pixmaps] *]
+    set dirs \
+	[glob -nocomplain -directory [file join [file dirname [info script]] \
+						pixmaps] *]
     foreach dir $dirs {
 	pixmaps::load_theme_name [namespace current]::themes $dir
     }
@@ -59,6 +69,75 @@
 	-type boolean -group Gomoku/Renju
 }
 
+proc renju::load {} {
+    hook::add postload_hook [namespace current]::load_stored_theme 70
+
+    hook::add finload_hook [namespace current]::calc_moves 100
+
+    hook::add roster_create_groupchat_user_menu_hook \
+              [namespace current]::add_groupchat_user_menu_item 52
+    hook::add chat_create_user_menu_hook \
+              [namespace current]::add_groupchat_user_menu_item 52
+    hook::add roster_jid_popup_menu_hook \
+              [namespace current]::add_groupchat_user_menu_item 52
+
+    hook::add games_board_create_hook [namespace current]::iq_create
+    hook::add games_board_turn_hook [namespace current]::iq_turn
+
+    ::xmpp::iq::register set create games:board \
+			 [namespace parent]::iq_games_board_create
+    ::xmpp::iq::register set turn games:board \
+			 [namespace parent]::iq_games_board_turn
+
+    load_stored_theme
+    calc_moves
+}
+
+proc renju::unload {} {
+    hook::remove postload_hook [namespace current]::load_stored_theme 70
+
+    hook::remove finload_hook [namespace current]::calc_moves 100
+
+    hook::remove roster_create_groupchat_user_menu_hook \
+              [namespace current]::add_groupchat_user_menu_item 52
+    hook::remove chat_create_user_menu_hook \
+              [namespace current]::add_groupchat_user_menu_item 52
+    hook::remove roster_jid_popup_menu_hook \
+              [namespace current]::add_groupchat_user_menu_item 52
+
+    hook::remove games_board_create_hook [namespace current]::iq_create
+    hook::remove games_board_turn_hook [namespace current]::iq_turn
+
+    if {[hook::is_empty games_board_create_hook]} {
+        ::xmpp::iq::unregister set create games:board
+        rename [namespace parent]::iq_games_board_create ""
+    }
+
+    if {[hook::is_empty games_board_turn_hook]} {
+        ::xmpp::iq::unregister set turn games:board
+        rename [namespace parent]::iq_games_board_turn ""
+    }
+
+    foreach var [info vars [namespace current]::*] {
+        upvar #0 $var flags
+        if {[info exists flags(window)]} {
+            destroy_win $flags(window)
+        }
+    }
+
+    foreach var [info vars [namespace current]::*] {
+        if {$var ne "[namespace current]::options"} {
+            unset $var
+        }
+    }
+
+    foreach img [image names] {
+        if {[string first renju/ $img] == 0} {
+            image delete $img
+        }
+    }
+}
+
 proc renju::load_stored_theme {args} {
     variable options
     variable themes
@@ -66,8 +145,6 @@
     pixmaps::load_dir $themes($options(theme))
 }
 
-hook::add postload_hook [namespace current]::renju::load_stored_theme 70
-
 proc renju::get_nick {xlib jid type} {
     if {[catch {chat::get_nick $xlib $jid $type} nick]} {
 	return [chat::get_nick $jid $type]
@@ -152,7 +229,6 @@
     start_play $game $xlib $jid $id $color
 }
 
-
 proc renju::invited_dialog {game xlib jid iqid id color} {
     variable game_names
 
@@ -406,7 +482,6 @@
     }
 }
 
-
 ###############################################################################
 
 proc renju::calc_moves {} {
@@ -446,8 +521,6 @@
     }
 }
 
-hook::add finload_hook [namespace current]::renju::calc_moves 100
-
 proc renju::center {c r} {
     variable square_size
     variable line_width
@@ -1459,13 +1532,6 @@
 	-command [list [namespace current]::invite_dialog $xlib $jid]
 }
 
-hook::add roster_create_groupchat_user_menu_hook \
-    [namespace current]::renju::add_groupchat_user_menu_item 51
-hook::add chat_create_user_menu_hook \
-    [namespace current]::renju::add_groupchat_user_menu_item 51
-hook::add roster_jid_popup_menu_hook \
-    [namespace current]::renju::add_groupchat_user_menu_item 51
-
 proc renju::iq_create {varname xlib from iqid xml} {
     upvar 2 $varname var
 
@@ -1501,8 +1567,6 @@
 		 $color]
 }
 
-hook::add games_board_create_hook [namespace current]::renju::iq_create
-
 proc renju::iq_turn {varname xlib from xml} {
     upvar 2 $varname var
 
@@ -1526,9 +1590,7 @@
     }
 }
 
-hook::add games_board_turn_hook [namespace current]::renju::iq_turn
 
-
 # Common games:board part
 proc iq_games_board_create {xlib from xml args} {
     set res [list error cancel feature-not-implemented]
@@ -1537,15 +1599,9 @@
     return $res
 }
 
-::xmpp::iq::register set create games:board \
-		     [namespace current]::iq_games_board_create
-
 proc iq_games_board_turn {xlib from xml args} {
     set res [list error cancel feature-not-implemented]
     hook::run games_board_turn_hook res $xlib $from $xml
     return $res
 }
 
-::xmpp::iq::register set turn games:board \
-		     [namespace current]::iq_games_board_turn
-

Modified: trunk/tkabber-plugins/reversi/reversi.tcl
===================================================================
--- trunk/tkabber-plugins/reversi/reversi.tcl	2009-03-05 18:40:54 UTC (rev 1701)
+++ trunk/tkabber-plugins/reversi/reversi.tcl	2009-03-07 20:30:16 UTC (rev 1702)
@@ -3,15 +3,25 @@
 package require msgcat
 
 namespace eval reversi {
-    variable scriptdir [file dirname [info script]]
+    ::msgcat::mcload [file join [file dirname [info script]] msgs]
 
-    ::msgcat::mcload [file join $scriptdir msgs]
+    if {![::plugins::is_registered reversi]} {
+	::plugins::register reversi \
+			    -namespace [namespace current] \
+			    -source [info script] \
+			    -description [::msgcat::mc "Whether the Reversi plugin is loaded."] \
+			    -loadcommand [namespace code load] \
+			    -unloadcommand [namespace code unload]
+	return
+    }
 
     variable square_size 48
     variable line_width 1
 
     variable themes
-    set dirs [glob -nocomplain -directory [file join $scriptdir pixmaps] *]
+    set dirs \
+	[glob -nocomplain -directory [file join [file dirname [info script]] \
+						pixmaps] *]
     foreach dir $dirs {
 	pixmaps::load_theme_name [namespace current]::themes $dir
     }
@@ -20,9 +30,11 @@
 	lappend values $theme $theme
     }
 
-    custom::defgroup Plugins [::msgcat::mc "Plugins options."] -group Tkabber
+    custom::defgroup Plugins [::msgcat::mc "Plugins options."] \
+	-group Tkabber
 
-    custom::defgroup Reversi [::msgcat::mc "Reversi plugin options."] -group Plugins
+    custom::defgroup Reversi [::msgcat::mc "Reversi plugin options."] \
+	-group Plugins
     custom::defvar options(theme) Checkers \
 	[::msgcat::mc "Reversi figures theme."] -group Reversi \
 	-type options -values $values \
@@ -44,10 +56,80 @@
 	[::msgcat::mc "Allow illegal moves (useful for debugging)."] \
 	-type boolean -group Reversi
     custom::defvar options(accept_illegal) 0 \
-	[::msgcat::mc "Accept opponent illegal moves (useful for debugging)."] \
+	[::msgcat::mc "Accept opponent illegal moves (useful for\
+		       debugging)."] \
 	-type boolean -group Reversi
 }
 
+proc reversi::load {} {
+    hook::add postload_hook [namespace current]::load_stored_theme 70
+
+    hook::add finload_hook [namespace current]::calc_moves 100
+
+    hook::add roster_create_groupchat_user_menu_hook \
+              [namespace current]::add_groupchat_user_menu_item 51
+    hook::add chat_create_user_menu_hook \
+              [namespace current]::add_groupchat_user_menu_item 51
+    hook::add roster_jid_popup_menu_hook \
+              [namespace current]::add_groupchat_user_menu_item 51
+
+    hook::add games_board_create_hook [namespace current]::iq_create
+    hook::add games_board_turn_hook [namespace current]::iq_turn
+
+    ::xmpp::iq::register set create games:board \
+			 [namespace parent]::iq_games_board_create
+    ::xmpp::iq::register set turn games:board \
+			 [namespace parent]::iq_games_board_turn
+
+    load_stored_theme
+    calc_moves
+}
+
+proc reversi::unload {} {
+    hook::remove postload_hook [namespace current]::load_stored_theme 70
+
+    hook::remove finload_hook [namespace current]::calc_moves 100
+
+    hook::remove roster_create_groupchat_user_menu_hook \
+              [namespace current]::add_groupchat_user_menu_item 51
+    hook::remove chat_create_user_menu_hook \
+              [namespace current]::add_groupchat_user_menu_item 51
+    hook::remove roster_jid_popup_menu_hook \
+              [namespace current]::add_groupchat_user_menu_item 51
+
+    hook::remove games_board_create_hook [namespace current]::iq_create
+    hook::remove games_board_turn_hook [namespace current]::iq_turn
+
+    if {[hook::is_empty games_board_create_hook]} {
+        ::xmpp::iq::unregister set create games:board
+        rename [namespace parent]::iq_games_board_create ""
+    }
+
+    if {[hook::is_empty games_board_turn_hook]} {
+        ::xmpp::iq::unregister set turn games:board
+        rename [namespace parent]::iq_games_board_turn ""
+    }
+
+    foreach var [info vars [namespace current]::*] {
+        upvar #0 $var flags
+        if {[info exists flags(window)]} {
+            destroy_win $flags(window)
+        }
+    }
+
+    foreach var [info vars [namespace current]::*] {
+        if {$var ne "[namespace current]::options"} {
+            unset $var
+        }
+    }
+
+    foreach img [image names] {
+        if {[string first reversi/ $img] == 0} {
+            image delete $img
+        }
+    }
+}
+
 proc reversi::load_stored_theme {args} {
     variable options
     variable themes
@@ -55,8 +137,6 @@
     pixmaps::load_dir $themes($options(theme))
 }
 
-hook::add postload_hook [namespace current]::reversi::load_stored_theme 70
-
 proc reversi::get_nick {xlib jid type} {
     if {[catch {chat::get_nick $xlib $jid $type} nick]} {
 	return [chat::get_nick $jid $type]
@@ -360,7 +440,6 @@
     }
 }
 
-
 ###############################################################################
 
 proc reversi::calc_moves {} {
@@ -400,8 +479,6 @@
     }
 }
 
-hook::add finload_hook [namespace current]::reversi::calc_moves 100
-
 proc reversi::center {c r} {
     variable square_size
     variable line_width
@@ -1095,7 +1172,6 @@
     expr {[lmatch -regexp $flags(legal_moves) ^[list $ct $rt]] != {}}
 }
 
-
 proc reversi::highlight_legal_moves {gid} {
     variable $gid
     upvar 0 $gid flags
@@ -1150,13 +1226,6 @@
 	-command [list [namespace current]::invite_dialog $xlib $jid]
 }
 
-hook::add roster_create_groupchat_user_menu_hook \
-    [namespace current]::reversi::add_groupchat_user_menu_item 51
-hook::add chat_create_user_menu_hook \
-    [namespace current]::reversi::add_groupchat_user_menu_item 51
-hook::add roster_jid_popup_menu_hook \
-    [namespace current]::reversi::add_groupchat_user_menu_item 51
-
 proc reversi::iq_create {varname xlib from iqid xml} {
     upvar 2 $varname var
 
@@ -1183,8 +1252,6 @@
     return
 }
 
-hook::add games_board_create_hook [namespace current]::reversi::iq_create
-
 proc reversi::iq_turn {varname xlib from xml} {
     upvar 2 $varname var
 
@@ -1201,9 +1268,7 @@
     return
 }
 
-hook::add games_board_turn_hook [namespace current]::reversi::iq_turn
 
-
 # Common games:board part
 proc iq_games_board_create {xlib from xml args} {
     set res [list error cancel feature-not-implemented]
@@ -1212,15 +1277,9 @@
     return $res
 }
 
-::xmpp::iq::register set create games:board \
-		     [namespace current]::iq_games_board_create
-
 proc iq_games_board_turn {xlib from xml args} {
     set res [list error cancel feature-not-implemented]
     hook::run games_board_turn_hook res $xlib $from $xml
     return $res
 }
 
-::xmpp::iq::register set turn games:board \
-		     [namespace current]::iq_games_board_turn
-



More information about the Tkabber-dev mailing list