[Tkabber-dev] r293 - in trunk/plugins: . prettymucmenu prettymucmenu/msgs

tkabber-svn at jabber.ru tkabber-svn at jabber.ru
Wed Feb 17 19:16:39 MSK 2010


Author: ancestor
Date: 2010-02-17 19:16:39 +0300 (Wed, 17 Feb 2010)
New Revision: 293

Added:
   trunk/plugins/prettymucmenu/
   trunk/plugins/prettymucmenu/INSTALL
   trunk/plugins/prettymucmenu/license.terms
   trunk/plugins/prettymucmenu/msgs/
   trunk/plugins/prettymucmenu/msgs/ru.msg
   trunk/plugins/prettymucmenu/prettymucmenu.tcl
Log:
1) New plugin prettymucmenu.tcl: provides an improved version of Tkabber MUC moderation menu.

Added: trunk/plugins/prettymucmenu/INSTALL
===================================================================
--- trunk/plugins/prettymucmenu/INSTALL	                        (rev 0)
+++ trunk/plugins/prettymucmenu/INSTALL	2010-02-17 16:16:39 UTC (rev 293)
@@ -0,0 +1,15 @@
+To install this plugin just place its directory (prettymucmenu) 
+into Tkabber's plugin directory. Most likely it is either 
+~/.tkabber/plugins
+or
+X:\Documents and Settings\YourUser\Application Data\Tkabber\plugins
+where X: is the drive your system is installed on.
+
+So, you'll have something like this:
+~/.tkabber/plugins/prettymucmenu/prettymucmenu.tcl
+or
+X:\Documents and Settings\YourUser\Application Data\Tkabber\plugins\prettymucmenu\prettymucmenu.tcl
+
+After that you have to restart Tkabber and go to 
+Customize -> Plugins Management and enable the plugin 
+in order to get its functionality.

Added: trunk/plugins/prettymucmenu/license.terms
===================================================================
--- trunk/plugins/prettymucmenu/license.terms	                        (rev 0)
+++ trunk/plugins/prettymucmenu/license.terms	2010-02-17 16:16:39 UTC (rev 293)
@@ -0,0 +1,20 @@
+Initial Copyright And Idea (c) 2009 Jet <xmpp:megaxbit at xmpp.ru>
+Modifications (c) 2010 ancestor <xmpp:ancestor at jabber.org>
+
+Permission is hereby granted, free of charge, to any person obtaining a
+copy of this software and associated documentation files (the "Software"),
+to deal in the Software without restriction, including without limitation
+the rights to use, copy, modify, merge, publish, distribute, sublicense,
+and/or sell copies of the Software, and to permit persons to whom the
+Software is furnished to do so, subject to the following conditions:
+
+The above copyright notice and this permission notice shall be included
+in all copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
+OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
+THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
+DEALINGS IN THE SOFTWARE.

Added: trunk/plugins/prettymucmenu/msgs/ru.msg
===================================================================
--- trunk/plugins/prettymucmenu/msgs/ru.msg	                        (rev 0)
+++ trunk/plugins/prettymucmenu/msgs/ru.msg	2010-02-17 16:16:39 UTC (rev 293)
@@ -0,0 +1,13 @@
+::msgcat::mcset ru "New MUC moderation menu." "Новое, удобное меню модерирования конференций."
+::msgcat::mcset ru "Whois" "Кто это?"
+::msgcat::mcset ru "Kick" "Выгнать из комнаты"
+::msgcat::mcset ru "Ban" "Запретить входить в комнату"
+::msgcat::mcset ru "Owner" "Владелец"
+::msgcat::mcset ru "Admin" "Администратор"
+::msgcat::mcset ru "Member" "Член"
+::msgcat::mcset ru "None" "Нет"
+::msgcat::mcset ru "Moderator" "Модератор"
+::msgcat::mcset ru "Participant" "Участник"
+::msgcat::mcset ru "Visitor" "Гость"
+::msgcat::mcset ru "Change affiliation" "Изменить ранг"
+::msgcat::mcset ru "Change role" "Изменить роль"

Added: trunk/plugins/prettymucmenu/prettymucmenu.tcl
===================================================================
--- trunk/plugins/prettymucmenu/prettymucmenu.tcl	                        (rev 0)
+++ trunk/plugins/prettymucmenu/prettymucmenu.tcl	2010-02-17 16:16:39 UTC (rev 293)
@@ -0,0 +1,197 @@
+# Initial idea and Copyright (c) New MUC moderation menu plugin (Jet <megaxbit at xmpp.ru>)
+# Modifications, bugfixes etc. (c) Pretty MUC menu plugin 17-02-2010 (ancestor <ancestor at jabber.org>)
+# This plugin provides an improved version of Tkabber MUC moderation menu.
+
+namespace eval prettymucmenu {
+	::msgcat::mcload [file join [file dirname [info script]] msgs]
+
+    if {![::plugins::is_registered prettymucmenu]} {
+	::plugins::register prettymucmenu \
+			    -namespace [namespace current] \
+			    -source [info script] \
+			    -description [::msgcat::mc "New MUC moderation menu."] \
+			    -loadcommand [namespace code load] \
+			    -unloadcommand [namespace code unload]
+	return
+    }
+	set mcloc(Owner)		[::msgcat::mc "Owner"]
+	set mcloc(Admin)		[::msgcat::mc "Admin"]
+	set mcloc(Member)		[::msgcat::mc "Member"]
+	set mcloc(None)			[::msgcat::mc "None"]
+	set mcloc(Moderator)		[::msgcat::mc "Moderator"]
+	set mcloc(Participant)		[::msgcat::mc "Participant"]
+	set mcloc(Visitor)		[::msgcat::mc "Visitor"]
+	set mcloc(Change_affiliation)	[::msgcat::mc "Change affiliation"]
+	set mcloc(Change_role)		[::msgcat::mc "Change role"]
+}
+
+######################################################################################
+
+proc prettymucmenu::set_reason {type val down xlib jid reason reschatid} {
+	::muc::change_item_attr $xlib $jid $type $val down $reason $reschatid
+}
+
+proc prettymucmenu::pre_proc {xlib jid reschatid oldval newval reason type} {
+	switch -- $type {
+		role			{set rval [::xmpp::muc::CompareRoles $oldval $newval]}
+		affiliation		{set rval [::xmpp::muc::CompareAffiliations $oldval $newval]}
+		default return
+	}
+
+	if {$rval > 0} {
+		set pos down
+	} elseif {$rval < 0} {
+		set pos up
+	} else return
+
+	::muc::change_item_attr $xlib $jid $type $newval $pos $reason $reschatid
+}
+
+######################################################################################
+
+proc prettymucmenu::add_groupchat_user_menu_items_new {type m xlib jid} {
+	variable users
+    set group [::xmpp::jid::stripResource $jid]
+
+    if {![::muc::is_compatible $group]} return
+
+    set chatid [chat::chatid $xlib $group]
+
+    if {![chat::is_groupchat $chatid]} {
+	return
+    }
+
+    switch -- $type {
+	chat { set reschatid [chat::chatid $xlib $jid] }
+	roster { set reschatid $chatid }
+    }
+	
+	$m add command -label [::msgcat::mc "Whois"] \
+	-command [list muc::whois $xlib $jid $reschatid]
+	$m add separator
+
+	foreach r {none visitor participant moderator} {set mstate(role,$r) normal}
+	foreach a {outcast none member admin owner} {set mstate(aff,$a) normal}
+
+	set aff [::muc::get_affiliation $xlib $jid]
+	set role [::muc::get_role $xlib $jid]
+	
+	set my_jid [::chat::our_jid $chatid]	
+	set my_aff [::muc::get_affiliation $xlib $my_jid]
+	set my_role [::muc::get_role $xlib $my_jid]
+	
+	if {$jid == $my_jid} {
+		foreach s [array names mstate] {set mstate($s) disabled}
+	}
+
+	if {$aff == "owner" || $aff == "admin"} {
+		foreach s [array names mstate role,*] {set mstate($s) disabled}
+	}
+
+	if {$my_role == "moderator"} {
+		switch -- $my_aff {
+			none {
+				foreach s [array names mstate] {set mstate($s) disabled}
+				if {$aff == "none" && $role != "moderator"} {
+						set mstate(role,none) normal
+						set mstate(role,visitor) normal
+						set mstate(role,participant) normal
+				}
+				if {$role != "moderator"} {set mstate(role,none) normal}
+			}
+			member {
+				foreach s [array names mstate] {set mstate($s) disabled}
+				if {($aff == "none" || $aff == "member") && $role != "moderator"} {
+						set mstate(role,none) normal
+						set mstate(role,visitor) normal
+						set mstate(role,participant) normal
+				}
+				if {$role != "moderator"} {set mstate(role,none) normal}
+			}
+			admin {
+				if {$aff == "admin" || $aff == "owner"} {
+					foreach s [array names mstate] {set mstate($s) disabled}
+				}
+				set mstate(aff,admin) disabled
+				set mstate(aff,owner) disabled
+			}
+			owner {}			
+			default {
+				foreach s [array names mstate] {set mstate($s) disabled}
+			}
+		}
+	} else {
+		foreach s [array names mstate] {set mstate($s) disabled}
+	}
+
+	set mstate(role,$role) normal
+	set mstate(aff,$aff) normal	
+	
+	$m add command -label [::msgcat::mc "Kick"] -state $mstate(role,none) \
+	-command [list muc::change_item_attr $xlib $jid role none down "" $reschatid]
+
+    $m add command -label [::msgcat::mc "Ban"] -state $mstate(aff,outcast) \
+	-command [list muc::change_item_attr $xlib $jid affiliation outcast down "" $reschatid]
+#-------------------------------------------------------------------------------------
+	set ::affvar $aff	
+	set am [menu $m.amuc -tearoff 0]
+	$am add radiobutton -label $::plugins::prettymucmenu::mcloc(Owner) -state $mstate(aff,owner) \
+		-value owner -variable affvar \
+		-command [list ::plugins::prettymucmenu::pre_proc \
+		$xlib $jid $reschatid $aff owner "" affiliation]		
+	$am add radiobutton -label $::plugins::prettymucmenu::mcloc(Admin) -state $mstate(aff,admin) \
+		-value admin -variable affvar \
+		-command [list ::plugins::prettymucmenu::pre_proc \
+		$xlib $jid $reschatid $aff admin "" affiliation]
+	$am add radiobutton -label $::plugins::prettymucmenu::mcloc(Member) -state $mstate(aff,member) \
+		-value member -variable affvar \
+		-command [list ::plugins::prettymucmenu::pre_proc \
+		$xlib $jid $reschatid $aff member "" affiliation]
+	$am add radiobutton -label $::plugins::prettymucmenu::mcloc(None) -state $mstate(aff,none) \
+		-value none -variable affvar \
+		-command [list ::plugins::prettymucmenu::pre_proc \
+		$xlib $jid $reschatid $aff none "" affiliation]
+	$m add cascade -label $::plugins::prettymucmenu::mcloc(Change_affiliation) -menu $am 
+
+	set ::rolevar $role	
+	set rm [menu $m.rmuc -tearoff 0]
+	$rm add radiobutton -label $::plugins::prettymucmenu::mcloc(Moderator) -state $mstate(role,moderator) \
+		-value moderator -variable rolevar \
+		-command [list ::plugins::prettymucmenu::pre_proc \
+		$xlib $jid $reschatid $role moderator "" role]	
+	$rm add radiobutton -label $::plugins::prettymucmenu::mcloc(Participant) -state $mstate(role,participant) \
+		-value participant -variable rolevar \
+		-command [list ::plugins::prettymucmenu::pre_proc \
+		$xlib $jid $reschatid $role participant "" role]		
+	$rm add radiobutton -label $::plugins::prettymucmenu::mcloc(Visitor) -state $mstate(role,visitor) \
+		-value visitor -variable rolevar \
+		-command [list ::plugins::prettymucmenu::pre_proc \
+		$xlib $jid $reschatid $role visitor "" role]
+	$m add cascade -label $::plugins::prettymucmenu::mcloc(Change_role) -menu $rm
+}
+
+######################################################################################
+
+proc prettymucmenu::load {} {
+	hook::remove chat_create_user_menu_hook \
+	  [list ::ifacetk::muc::add_groupchat_user_menu_items chat] 43
+	hook::remove roster_create_groupchat_user_menu_hook \
+	  [list ::ifacetk::muc::add_groupchat_user_menu_items roster] 39
+	
+	hook::add chat_create_user_menu_hook \
+	  [list [namespace current]::add_groupchat_user_menu_items_new chat] 43
+	hook::add roster_create_groupchat_user_menu_hook \
+	  [list [namespace current]::add_groupchat_user_menu_items_new roster] 39
+}
+
+proc prettymucmenu::unload {} {
+	hook::remove chat_create_user_menu_hook \
+	  [list [namespace current]::add_groupchat_user_menu_items_new chat] 43
+	hook::remove roster_create_groupchat_user_menu_hook \
+	  [list [namespace current]::add_groupchat_user_menu_items_new roster] 39
+	
+	hook::add chat_create_user_menu_hook \
+	  [list ::ifacetk::muc::add_groupchat_user_menu_items chat] 43
+	hook::add roster_create_groupchat_user_menu_hook \
+	  [list ::ifacetk::muc::add_groupchat_user_menu_items roster] 39
+}
\ No newline at end of file



More information about the Tkabber-dev mailing list