[Tkabber-dev] r1680 - in trunk/tkabber-plugins: . attline browser

tkabber-svn at jabber.ru tkabber-svn at jabber.ru
Mon Feb 23 16:52:58 MSK 2009


Author: sergei
Date: 2009-02-23 16:52:58 +0300 (Mon, 23 Feb 2009)
New Revision: 1680

Modified:
   trunk/tkabber-plugins/ChangeLog
   trunk/tkabber-plugins/attline/attline.tcl
   trunk/tkabber-plugins/browser/browser.tcl
Log:
	* browser/browser.tcl: Made Jabber Browser plugin unloadable.

	* attline/attline.tcl: Fixed typo.


Modified: trunk/tkabber-plugins/ChangeLog
===================================================================
--- trunk/tkabber-plugins/ChangeLog	2009-02-20 21:16:56 UTC (rev 1679)
+++ trunk/tkabber-plugins/ChangeLog	2009-02-23 13:52:58 UTC (rev 1680)
@@ -1,3 +1,9 @@
+2009-02-23  Sergei Golovan <sgolovan at nes.ru>
+
+	* browser/browser.tcl: Made Jabber Browser plugin unloadable.
+
+	* attline/attline.tcl: Fixed typo.
+
 2009-02-20  Sergei Golovan <sgolovan at nes.ru>
 
 	* aniemoticons/aniemoticons.tcl, attline/attline.tcl,

Modified: trunk/tkabber-plugins/attline/attline.tcl
===================================================================
--- trunk/tkabber-plugins/attline/attline.tcl	2009-02-20 21:16:56 UTC (rev 1679)
+++ trunk/tkabber-plugins/attline/attline.tcl	2009-02-23 13:52:58 UTC (rev 1680)
@@ -87,7 +87,7 @@
 	set iw [chat::input_win $chatid]
 	bind $iw <<ChatSeeAttentionLine>> {}
 	# TODO: Unbind configure event?
-	delete_attline $cw
+	delete_attention_line $cw
 	cleanup $chatid
     }
 

Modified: trunk/tkabber-plugins/browser/browser.tcl
===================================================================
--- trunk/tkabber-plugins/browser/browser.tcl	2009-02-20 21:16:56 UTC (rev 1679)
+++ trunk/tkabber-plugins/browser/browser.tcl	2009-02-23 13:52:58 UTC (rev 1680)
@@ -5,21 +5,139 @@
 package require msgcat
 
 namespace eval browser {
-
     ::msgcat::mcload [file join [file dirname [info script]] msgs]
 
+    if {![::plugins::is_registered browser]} {
+	::plugins::register browser \
+			    -namespace [namespace current] \
+			    -source [info script] \
+			    -description [::msgcat::mc "Whether the Jabber Browser plugin is loaded."] \
+			    -loadcommand [namespace code load] \
+			    -unloadcommand [namespace code unload]
+	return
+    }
+
     set brwid 0
     custom::defvar browse_list {} [::msgcat::mc "List of browsed JIDs."] \
 	    -group Hidden
+
+    image create photo ""
 }
 
+proc browser::load {} {
+    if {[winfo exists [set m .b2popmenu]]} {
+	destroy $m
+    }
+    menu $m -tearoff 0
+    $m add command -label [::msgcat::mc "Join group..."] -command {
+	join_group_dialog \
+	    $::plugins::browser::browser(xlib,$::plugins::browser::headwindow) \
+	    -server [::xmpp::jid::server $::plugins::browser::headjid] \
+	    -group [::xmpp::jid::node $::plugins::browser::headjid]
+    }
+    $m add command -label [::msgcat::mc "Add conference..."] -command {
+	plugins::conferences::add_conference_dialog \
+	    $::plugins::browser::browser(xlib,$::plugins::browser::headwindow) \
+	    -group [::xmpp::jid::node $::plugins::browser::headjid] \
+	    -server [::xmpp::jid::server $::plugins::browser::headjid]
+    }
+    $m add separator
+    $m add command -label [::msgcat::mc "Browse"] \
+	  -command {::plugins::browser::browser_action browse \
+			$::plugins::browser::headwindow $::plugins::browser::headnode}
+    $m add command -label [::msgcat::mc "Sort items by name"] \
+	  -command {::plugins::browser::browser_action sort \
+			$::plugins::browser::headwindow $::browser::headnode}
+    $m add command -label [::msgcat::mc "Sort items by JID"] \
+	  -command {::plugins::browser::browser_action sortjid \
+			$::plugins::browser::headwindow $::plugins::browser::headnode}
 
+    if {[winfo exists [set m .b3popmenu]]} {
+	destroy $m
+    }
+    menu $m -tearoff 0
+    $m add command -label [::msgcat::mc "Browse"] \
+	  -command {::plugins::browser::browser_action browse \
+			$::plugins::browser::headwindow $::plugins::browser::headnode}
+    $m add command -label [::msgcat::mc "Sort items by name"] \
+	  -command {::plugins::browser::browser_action sort \
+			$::plugins::browser::headwindow $::plugins::browser::headnode}
+    $m add command -label [::msgcat::mc "Sort items by JID"] \
+	  -command {::plugins::browser::browser_action sortjid \
+			$::plugins::browser::headwindow $::plugins::browser::headnode}
+
+    if {[winfo exists [set m .b4popmenu]]} {
+	destroy $m
+    }
+    menu $m -tearoff 0
+    $m add command -label [::msgcat::mc "Browse"] \
+	  -command {::plugins::browser::browser_action browse \
+			$::plugins::browser::headwindow $::plugins::browser::headnode}
+
+    hook::add finload_hook [namespace current]::setup_menu
+
+    # Register disco#info and disco#items in browser only.
+    register_ns_handler http://jabber.org/protocol/disco#info \
+	    disco::browser::open_win \
+	    -desc [list * [::msgcat::mc "Discover service"]]
+    register_ns_handler http://jabber.org/protocol/disco#items \
+	    disco::browser::open_win \
+	    -desc [list * [::msgcat::mc "Discover service"]]
+
+    if {![catch {set m [.mainframe getmenu services]}] && $m != "" && \
+	    ![catch {set idx [$m index [::msgcat::mc "Service Discovery"]]}] && \
+	    $idx != "none"} {
+	$m insert $idx command -label [::msgcat::mc "Jabber Browser"] \
+			       -command [list [namespace current]::open]
+    }
+}
+
+proc browser::unload {} {
+    variable brwid
+    variable browser
+    variable config
+    variable headwindow
+    variable headnode
+    variable headjid
+
+    if {![catch {set m [.mainframe getmenu services]}] && $m != "" && \
+	    ![catch {set idx [$m index [::msgcat::mc "Jabber Browser"]]}] && \
+	    $idx != "none"} {
+	$m delete $idx
+    }
+
+    foreach bw [winfo children .] {
+	if {[info exists browser(xlib,$bw)]} {
+	    destroy_win $bw
+	}
+    }
+
+    if {[winfo exists [set m .b2popmenu]]} {
+	destroy $m
+    }
+    if {[winfo exists [set m .b3popmenu]]} {
+	destroy $m
+    }
+    if {[winfo exists [set m .b4popmenu]]} {
+	destroy $m
+    }
+
+    hook::remove finload_hook [namespace current]::setup_menu
+
+    catch {unset brwid}
+    catch {unset browser}
+    catch {unset config}
+    catch {unset headwindow}
+    catch {unset headnode}
+    catch {unset headjid}
+}
+
 proc browser::open {{xlib ""}} {
     variable brwid
     variable browser
     variable config
     variable browse_list
-    global brwserver$brwid
+    variable brwserver$brwid
 
     if {[llength [connections]] == 0} return
 
@@ -41,7 +159,7 @@
     set config(fill) 	[option get $bw fill         JDisco]
     set config(nscolor) [option get $bw featurecolor JDisco]
 
-    bind $bw <Destroy> [list [namespace current]::destroy_state $bw]
+    bind $bw <Destroy> [list [namespace current]::destroy_state $bw $brwid]
 
     frame $bw.navigate
     button $bw.navigate.back -text <- \
@@ -49,7 +167,7 @@
     button $bw.navigate.forward -text -> \
 	-command [list [namespace current]::history_move $bw -1]
     label $bw.navigate.lab -text [::msgcat::mc "JID:"]
-    ComboBox $bw.navigate.entry -textvariable brwserver$brwid \
+    ComboBox $bw.navigate.entry -textvariable [namespace current]::brwserver$brwid \
 	-dropenabled 1 -droptypes {JID {}} \
 	-dropcmd [list [namespace current]::entrydropcmd $bw] \
 	-command [list [namespace current]::go $bw] \
@@ -95,7 +213,7 @@
 
 proc browser::enter {bw} {
     variable browser
-    
+
     set jid [$bw.navigate.entry.e get]
 
     ::xmpp::sendIQ $browser(xlib,$bw) get \
@@ -107,7 +225,7 @@
 proc browser::go {bw} {
     variable browser
     variable browse_list
-    
+
     if {[winfo exists $bw]} {
 	set jid [$bw.navigate.entry.e get]
 
@@ -175,7 +293,7 @@
     }
 
     set jid  [::xmpp::xml::getAttr $attrs jid]
-    
+
     if {[cequal $jid ""]} {
 	set jid $from
     }
@@ -192,7 +310,7 @@
     set nchildren 0
 
     foreach subel $subels {
-	lappend children [process $bw $jid $subels [expr {$level+1}]]
+	lappend children [process $bw $jid $subel [expr {$level+1}]]
 	incr nchildren
     }
 
@@ -217,8 +335,6 @@
     return $node
 }
 
-image create photo ""
-
 proc browser::item_icon {category type} {
     switch -- $category {
 	service -
@@ -241,7 +357,6 @@
 }
 
 proc browser::add_line {tw parent node icon desc data args} {
-
     if {[$tw exists $node]} {
 	if {[$tw parent $node] != $parent && [$tw exists $parent] && \
 		$parent != $node} {
@@ -298,6 +413,7 @@
 
 proc browser::item_balloon_text {bw jid category type name version} {
     variable browser
+
     set text "$jid: "
     set delim ""
     if {![cequal $category {}] || ![cequal $type {}]} {
@@ -333,6 +449,13 @@
 	} elseif {[info exists tmp(*)]} {
 	    set desc "$tmp(*) ($ns)"
 	}
+    } elseif {[info exists ::disco::browser::browser(feature_handler_desc,$ns)]} {
+	array set tmp $::disco::browser::browser(feature_handler_desc,$ns)
+	if {[info exists tmp($category)]} {
+	    set desc "$tmp($category) ($ns)"
+	} elseif {[info exists tmp(*)]} {
+	    set desc "$tmp(*) ($ns)"
+	}
     }
     set icon ""
 
@@ -356,7 +479,7 @@
 
     set newjid [lindex $browser(hist,$bw) $newpos]
     set browser(histpos,$bw) $newpos
-    
+
     $bw.navigate.entry.e delete 0 end
     $bw.navigate.entry.e insert 0 $newjid
     enter $bw
@@ -380,7 +503,6 @@
 
     ::xmpp::xml::split $item tag xmlns attrs cdata subels
 
-    
     switch -- $tag {
 	ns {
 	    return
@@ -394,7 +516,7 @@
     }
 
     set jid  [::xmpp::xml::getAttr $attrs jid]
-    
+
     if {[string equal $jid ""]} {
 	set jid $from
     }
@@ -443,59 +565,19 @@
 		    eval $browser(ns_handler,$ns) [list $browser(xlib,$bw) $jid \
 			-category $category -type $subtype]
 		}
+	    } elseif {[info exists ::disco::browser::browser(feature_handler,$ns)]} {
+		if {$::disco::browser::browser(feature_handler_node,$ns)} {
+		    eval $::disco::browser::browser(feature_handler,$ns) [list $browser(xlib,$bw) $jid "" \
+			-category $category -type $subtype]
+		} else {
+		    eval $::disco::browser::browser(feature_handler,$ns) [list $browser(xlib,$bw) $jid \
+			-category $category -type $subtype]
+		}
 	    }
 	}
     }
 }
 
-if {[winfo exists [set m .b2popmenu]]} {
-    destroy $m
-}
-menu $m -tearoff 0
-$m add command -label [::msgcat::mc "Join group..."] -command {
-    join_group_dialog $::plugins::browser::browser(xlib,$::plugins::browser::headwindow) \
-	    -server [::xmpp::jid::server $::plugins::browser::headjid] \
-	    -group [::xmpp::jid::node $::plugins::browser::headjid]
-}
-$m add command -label [::msgcat::mc "Add conference..."] -command {
-    plugins::conferences::add_conference_dialog \
-	$::plugins::browser::browser(xlib,$::plugins::browser::headwindow) \
-	-group [::xmpp::jid::node $::plugins::browser::headjid] \
-	-server [::xmpp::jid::server $::plugins::browser::headjid]
-}
-$m add separator
-$m add command -label [::msgcat::mc "Browse"] \
-      -command {::plugins::browser::browser_action browse \
-		    $::plugins::browser::headwindow $::plugins::browser::headnode}
-$m add command -label [::msgcat::mc "Sort items by name"] \
-      -command {::plugins::browser::browser_action sort \
-		    $::plugins::browser::headwindow $::browser::headnode}
-$m add command -label [::msgcat::mc "Sort items by JID"] \
-      -command {::plugins::browser::browser_action sortjid \
-		    $::plugins::browser::headwindow $::plugins::browser::headnode}
-
-if {[winfo exists [set m .b3popmenu]]} {
-    destroy $m
-}
-menu $m -tearoff 0
-$m add command -label [::msgcat::mc "Browse"] \
-      -command {::plugins::browser::browser_action browse \
-		    $::plugins::browser::headwindow $::plugins::browser::headnode}
-$m add command -label [::msgcat::mc "Sort items by name"] \
-      -command {::plugins::browser::browser_action sort \
-		    $::plugins::browser::headwindow $::plugins::browser::headnode}
-$m add command -label [::msgcat::mc "Sort items by JID"] \
-      -command {::plugins::browser::browser_action sortjid \
-		    $::plugins::browser::headwindow $::plugins::browser::headnode}
-
-if {[winfo exists [set m .b4popmenu]]} {
-    destroy $m
-}
-menu $m -tearoff 0
-$m add command -label [::msgcat::mc "Browse"] \
-      -command {::plugins::browser::browser_action browse \
-		    $::plugins::browser::headwindow $::plugins::browser::headnode}
-
 proc browser::textpopup {bw node} {
     variable browser
     variable headwindow $bw
@@ -636,7 +718,7 @@
 	if {[set img [$t itemcget $node -image]] != ""} {
 	    pack [label $top.l -image $img -padx 0 -pady 0]
 	}
-	
+
 	return [list JID {copy} $data2]
     } else {
 	return {}
@@ -668,31 +750,20 @@
     }
 }
 
-hook::add browser_register_feature_handler_hook \
-	  [namespace current]::browser::register_ns_handler
-
 # Destroy all (global) state assotiated with the given browser window.
 # Intended to be bound to a <Destroy> event handler for browser windows.
-proc browser::destroy_state {bw} {
+proc browser::destroy_state {bw brwid} {
     variable browser
+    variable brwserver$brwid
 
     array unset browser *,$bw
     array unset browser *,$bw,*
+
+    unset brwserver$brwid
 }
 
-# Register disco#info and disco#items in browser only.
-hook::add postload_hook \
-    [list [namespace current]::browser::register_ns_handler \
-	  $::NS(disco_info) disco::browser::open_win \
-	  -desc [list * [::msgcat::mc "Discover service"]]]
-hook::add postload_hook \
-    [list [namespace current]::browser::register_ns_handler \
-	  $::NS(disco_items) disco::browser::open_win \
-	  -desc [list * [::msgcat::mc "Discover service"]]]
-
 # Menu setup
 proc browser::setup_menu {} {
-
     catch {
 	set m [.mainframe getmenu services]
 
@@ -703,5 +774,3 @@
     }
 }
 
-hook::add finload_hook [namespace current]::browser::setup_menu
-



More information about the Tkabber-dev mailing list