[Tkabber-dev] r1191 - in trunk/tkabber: . plugins/pep

tkabber-svn at jabber.ru tkabber-svn at jabber.ru
Sat Aug 18 00:26:06 MSD 2007


Author: sergei
Date: 2007-08-18 00:26:05 +0400 (Sat, 18 Aug 2007)
New Revision: 1191

Modified:
   trunk/tkabber/ChangeLog
   trunk/tkabber/pep.tcl
   trunk/tkabber/plugins/pep/user_mood.tcl
   trunk/tkabber/pubsub.tcl
Log:
	* pubsub.tcl: Added notification support when deleting published item.

	* pep.tcl: Added item ID support when publishing PEP item. Also, added
	  a node deleting procedure.

	* plugins/pep/user_mood.tcl: Added support of deleting published user
	  mood. Also, added publishing user mood for all connected resources
	  simultaneously.


Modified: trunk/tkabber/ChangeLog
===================================================================
--- trunk/tkabber/ChangeLog	2007-08-17 17:04:00 UTC (rev 1190)
+++ trunk/tkabber/ChangeLog	2007-08-17 20:26:05 UTC (rev 1191)
@@ -1,3 +1,14 @@
+2007-08-17  Sergei Golovan  <sgolovan at nes.ru>
+
+	* pubsub.tcl: Added notification support when deleting published item.
+
+	* pep.tcl: Added item ID support when publishing PEP item. Also, added
+	  a node deleting procedure.
+
+	* plugins/pep/user_mood.tcl: Added support of deleting published user
+	  mood. Also, added publishing user mood for all connected resources
+	  simultaneously.
+
 2007-08-16  Sergei Golovan  <sgolovan at nes.ru>
 
 	* datagathering.tcl: Register jabber:x:data to show in disco#info

Modified: trunk/tkabber/pep.tcl
===================================================================
--- trunk/tkabber/pep.tcl	2007-08-17 17:04:00 UTC (rev 1190)
+++ trunk/tkabber/pep.tcl	2007-08-17 20:26:05 UTC (rev 1191)
@@ -43,10 +43,11 @@
 # Publish item to PEP node "node" (8)
 # payload is a list of xml tags
 # node must not be empty
+# itemid may be empty
 # -connection is mandatory
 #
 
-proc pep::publish_item {node args} {
+proc pep::publish_item {node itemid args} {
 
     debugmsg pep [info level 0]
 
@@ -67,11 +68,47 @@
 
     set service [jlib::connection_bare_jid $connid]
 
-    eval [list pubsub::publish_item $service $node ""] $args
+    eval [list pubsub::publish_item $service $node $itemid] $args
 }
 
 ##########################################################################
 #
+# Delete item from PEP node "node"
+# node must not be empty
+# itemid must not be empty
+# -connection is mandatory
+#
+
+proc pep::delete_item {node itemid args} {
+
+    debugmsg pep [info level 0]
+
+    set command ""
+    foreach {key val} $args {
+	switch -- $key {
+	    -connection { set connid $val}
+	}
+    }
+
+    if {![info exists connid]} {
+	return -code error "pep::delete_item: -connection is mandatory"
+    }
+
+    if {$node == ""} {
+	return -code error "pep::delete_item: node must not be empty"
+    }
+
+    if {$itemid == ""} {
+	return -code error "pep::delete_item: Item ID must not be empty"
+    }
+
+    set service [jlib::connection_bare_jid $connid]
+
+    eval [list pubsub::delete_item $service $node $itemid] $args
+}
+
+##########################################################################
+#
 # Subscribe to PEP node "node" at bare JID "to" (5.2)
 # node must not be empty
 #

Modified: trunk/tkabber/plugins/pep/user_mood.tcl
===================================================================
--- trunk/tkabber/plugins/pep/user_mood.tcl	2007-08-17 17:04:00 UTC (rev 1190)
+++ trunk/tkabber/plugins/pep/user_mood.tcl	2007-08-17 20:26:05 UTC (rev 1191)
@@ -239,30 +239,38 @@
 
     set newmood ""
     set newtext ""
+    set retract false
     set parsed  false
 
     foreach item $items {
 	jlib::wrapper:splitxml $item tag vars isempty chdata children
 
-	foreach imood $children {
-	    jlib::wrapper:splitxml $imood tag1 vars1 isempty1 chdata1 children1
+	switch -- $tag {
+	    retract {
+		set retract true
+	    }
+	    default {
+		foreach imood $children {
+		    jlib::wrapper:splitxml $imood tag1 vars1 isempty1 chdata1 children1
 
-	    if {![string equal $tag1 mood]} continue
-	    set xmlns [jlib::wrapper:getattr $vars1 xmlns]
-	    if {![string equal $xmlns $node]} continue
+		    if {![string equal $tag1 mood]} continue
+		    set xmlns [jlib::wrapper:getattr $vars1 xmlns]
+		    if {![string equal $xmlns $node]} continue
 
-	    set parsed true
+		    set parsed true
 
-	    foreach i $children1 {
-		jlib::wrapper:splitxml $i tag2 vars2 isempty2 chdata2 children2
+		    foreach i $children1 {
+			jlib::wrapper:splitxml $i tag2 vars2 isempty2 chdata2 children2
 
-		switch -- $tag2 {
-		    text {
-			set newtext $chdata2
+			switch -- $tag2 {
+			    text {
+				set newtext $chdata2
+			    }
+			    default {
+				set newmood $tag2
+			    }
+			}
 		    }
-		    default {
-			set newmood $tag2
-		    }
 		}
 	    }
 	}
@@ -273,6 +281,11 @@
 	set mood(text,$jid) $newtext
 
 	hook::run user_mood_notification_hook $connid $jid $newmood $newtext
+    } elseif {$retract} {
+	catch {unset mood(mood,$jid)}
+	catch {unset mood(text,$jid)}
+
+	hook::run user_mood_notification_hook $connid $jid "" ""
     }
 }
 
@@ -284,9 +297,13 @@
 	set contact $jid
     }
 
-    set msg [::msgcat::mc "%s's mood changed to %s" $contact $m2d($mood)]
-    if {$text != ""} {
-	append msg ": $text"
+    if {$mood == ""} {
+	set msg [::msgcat::mc "%s's mood is unset" $contact]
+    } else {
+	set msg [::msgcat::mc "%s's mood changed to %s" $contact $m2d($mood)]
+	if {$text != ""} {
+	    append msg ": $text"
+	}
     }
 
     set_status $msg
@@ -309,23 +326,46 @@
 	lappend content [jlib::wrapper:createtag text -chdata $text]
     }
 
-    set cmd [list pep::publish_item $node \
-	-connection $connid \
-	-payload [list [jlib::wrapper:createtag mood \
-				-vars [list xmlns $node] \
-				-subtags $content]]]
+    set cmd [list pep::publish_item $node mood \
+		  -connection $connid \
+		  -payload [list [jlib::wrapper:createtag mood \
+				      -vars [list xmlns $node] \
+				      -subtags $content]]]
 
-    if {$cmd != ""} {
+    if {$callback != ""} {
 	lappend cmd -command $callback
     }
 
     eval $cmd
 }
 
+proc mood::unpublish {connid args} {
+    variable node
+
+    set callback ""
+    foreach {opt val} $args {
+	switch -- $opt {
+	    -command { set callback $val }
+	}
+    }
+
+    set cmd [list pep::delete_item $node mood \
+		  -notify true \
+		  -connection $connid]
+
+    if {$callback != ""} {
+	lappend cmd -command $callback
+    }
+
+    eval $cmd
+}
+
 proc mood::on_init {} {
     set m [pep::get_main_menu_pep_submenu]
     $m add command -label [::msgcat::mc "Publish user mood"] \
 	    -command [namespace current]::show_publish_dialog
+    $m add command -label [::msgcat::mc "Unublish user mood"] \
+	    -command [namespace current]::show_unpublish_dialog
 }   
 
 proc mood::show_publish_dialog {} {
@@ -334,6 +374,11 @@
     variable moodreason
     variable myjid
 
+    set w .user_mood
+    if {[winfo exists $w]} {
+	destroy $w
+    }
+
     set connids [jlib::connections]
     if {[llength $connids] == 0} {
 	tk_messageBox -icon error -title [::msgcat::mc "Error"] \
@@ -342,21 +387,15 @@
 	return
     }
 
-    set w .user_mood
-    if {[winfo exists $w]} {
-	focus -force $w
-	return
-    }
-
     Dialog $w -title [::msgcat::mc "User mood"] \
 	    -modal none -separator 1 -anchor e -default 0 -cancel 1 -parent .
-    $w add -text [::msgcat::mc "OK"] \
+    $w add -text [::msgcat::mc "Publish"] \
 	   -command [list [namespace current]::do_publish $w]
     $w add -text [::msgcat::mc "Cancel"] -command [list destroy $w]
 
     set f [$w getframe]
 
-    set connjids {}
+    set connjids [list [::msgcat::mc "All"]]
     foreach connid $connids {
 	lappend connjids [jlib::connection_jid $connid]
     }
@@ -387,7 +426,7 @@
     $w draw
 }
 
-proc mood::do_publish w {
+proc mood::do_publish {w} {
     variable d2m
     variable moodvalue
     variable moodreason
@@ -400,7 +439,8 @@
     }
 
     foreach connid [jlib::connections] {
-	if {[string equal $myjid [jlib::connection_jid $connid]]} {
+	if {[string equal $myjid [jlib::connection_jid $connid]] || \
+		[string equal $myjid [::msgcat::mc "All"]]} {
 	    publish $connid $d2m($moodvalue) \
 		    -reason $moodreason \
 		    -command [namespace current]::publish_result
@@ -427,6 +467,86 @@
 	-message [::msgcat::mc "User mood publishing failed: %s" $error]
 }
 
+proc mood::show_unpublish_dialog {} {
+    variable myjid
+
+    set w .user_mood
+    if {[winfo exists $w]} {
+	destroy $w
+    }
+
+    set connids [jlib::connections]
+    if {[llength $connids] == 0} {
+	tk_messageBox -icon error -title [::msgcat::mc "Error"] \
+		-message [::msgcat::mc "Unpublishing is only possible\
+					while being online"]
+	return
+    }
+
+    Dialog $w -title [::msgcat::mc "User mood"] \
+	    -modal none -separator 1 -anchor e -default 0 -cancel 1 -parent .
+    $w add -text [::msgcat::mc "Unpublish"] \
+	   -command [list [namespace current]::do_unpublish $w]
+    $w add -text [::msgcat::mc "Cancel"] -command [list destroy $w]
+
+    set f [$w getframe]
+
+    set connjids [list [::msgcat::mc "All"]]
+    foreach connid $connids {
+	lappend connjids [jlib::connection_jid $connid]
+    }
+    set myjid [lindex $connjids 0]
+
+    label $f.ccap -text [::msgcat::mc "Use connection:"]
+    ComboBox $f.conn -editable false \
+	    -values $connjids \
+	    -textvariable [namespace current]::myjid
+
+    if {[llength $connjids] > 1} {
+	grid $f.ccap   -row 0 -column 0 -sticky e
+	grid $f.conn   -row 0 -column 1 -sticky ew
+    }
+
+    grid columnconfigure $f 1 -weight 1
+
+    if {[llength $connids] == 1} {
+	do_unpublish $w
+    } else {
+	$w draw
+    }
+}
+
+proc mood::do_unpublish {w} {
+    variable myjid
+
+    foreach connid [jlib::connections] {
+	if {[string equal $myjid [jlib::connection_jid $connid]] || \
+		[string equal $myjid [::msgcat::mc "All"]]} {
+	    unpublish $connid \
+		    -command [namespace current]::unpublish_result
+	    break
+	}
+    }
+
+    unset myjid
+    destroy $w
+}
+
+# $res is one of: OK, ERR, DISCONNECT
+proc mood::unpublish_result {res child} {
+    switch -- $res {
+	ERR {
+	    set error [error_to_string $child]
+	}
+	default {
+	    return
+	}
+    }
+
+    tk_messageBox -icon error -title [::msgcat::mc "Error"] \
+	-message [::msgcat::mc "User mood unpublishing failed: %s" $error]
+}
+
 proc mood::provide_userinfo {notebook connid jid editable} {
     variable mood
     variable m2d

Modified: trunk/tkabber/pubsub.tcl
===================================================================
--- trunk/tkabber/pubsub.tcl	2007-08-17 17:04:00 UTC (rev 1190)
+++ trunk/tkabber/pubsub.tcl	2007-08-17 20:26:05 UTC (rev 1191)
@@ -711,14 +711,17 @@
 #
 # Delete item "itemid" from pubsub node "node" at service "service" (7.2)
 # node and itemid must not be empty
+# -notify is a boolean (true, false, 1, 0)
 
 proc pubsub::delete_item {service node itemid args} {
 
     debugmsg pubsub [info level 0]
 
     set command ""
+    set notify 0
     foreach {key val} $args {
 	switch -- $key {
+	    -notify { set notify $val }
 	    -connection { set connid $val}
 	    -command { set command $val }
 	}
@@ -736,12 +739,17 @@
 	return -code error "pubsub::delete_item: Item ID is empty"
     }
 
+    set vars [list node $node]
+    if {[string is true -strict $notify]} {
+	lappend vars notify true
+    }
+
     jlib::send_iq set \
 	[jlib::wrapper:createtag pubsub \
 	     -vars [list xmlns $::NS(pubsub)] \
 	     -subtags \
 		 [list [jlib::wrapper:createtag retract \
-			    -vars [list node $node] \
+			    -vars $vars \
 			    -subtags \
 				[list [jlib::wrapper:createtag item \
 					   -vars [list id $itemid]]]]]] \



More information about the Tkabber-dev mailing list