[Tkabber-dev] r1777 - trunk/tkabber

tkabber-svn at jabber.ru tkabber-svn at jabber.ru
Sun Apr 5 22:20:41 MSD 2009


Author: sergei
Date: 2009-04-05 22:20:40 +0400 (Sun, 05 Apr 2009)
New Revision: 1777

Modified:
   trunk/tkabber/ChangeLog
   trunk/tkabber/pubsub.tcl
Log:
	* pubsub.tcl: Added simple user interface for subscription,
	  unsubscription and configuring subscription.


Modified: trunk/tkabber/ChangeLog
===================================================================
--- trunk/tkabber/ChangeLog	2009-04-05 15:58:14 UTC (rev 1776)
+++ trunk/tkabber/ChangeLog	2009-04-05 18:20:40 UTC (rev 1777)
@@ -12,6 +12,9 @@
 	* pubsub.tcl: Started to implement user interface to pubsub. So far
 	  added two menu items to Disco browser nodes.
 
+	* pubsub.tcl: Added simple user interface for subscription,
+	  unsubscription and configuring subscription.
+
 2009-04-02  Sergei Golovan  <sgolovan at nes.ru>
 
 	* plugins/general/comm.tcl, tkabber-remote.tcl: Made errors from a

Modified: trunk/tkabber/pubsub.tcl
===================================================================
--- trunk/tkabber/pubsub.tcl	2009-04-05 15:58:14 UTC (rev 1776)
+++ trunk/tkabber/pubsub.tcl	2009-04-05 18:20:40 UTC (rev 1777)
@@ -60,7 +60,6 @@
 }
 
 proc pubsub::SubscriptionOptionsResult {xlib service commands status res} {
-
     debugmsg pubsub [info level 0]
 
     if {![string equal $status ok]} {
@@ -82,7 +81,6 @@
 
 # TODO: $commands
 proc pubsub::SendSubscriptionOptions {xlib service node jid subid commands w restags} {
-
     debugmsg pubsub [info level 0]
 
     destroy $w.error.msg
@@ -93,6 +91,75 @@
 	    -command [list data::test_error_res $w]
 }
 
+proc pubsub::retrieveSubscriptions {xlib service node} {
+    debugmsg pubsub [info level 0]
+
+    if {$node == ""} {
+	set args {}
+    } else {
+	set args [list -node $node]
+    }
+
+    eval {::xmpp::pubsub::requestSubscriptions $xlib $service} $args \
+	 {-command [namespace code [list RetrieveSubscriptionsResult $xlib $service]]}
+}
+
+proc pubsub::RetrieveSubscriptionsResult {xlib service status items} {
+    debugmsg pubsub [info level 0]
+
+    if {![string equal $status ok]} {
+	if {[llength $commands] > 0} {
+	    eval [lindex $commands 0] [list $status $items]
+	}
+	return
+    }
+
+    set w .pubsub_subscriptions
+    if {[winfo exists $w]} {
+	destroy $w
+    }
+
+    Dialog $w -title [::msgcat::mc "Subscriptions to pubsub nodes at %s" $service] \
+	      -modal none -separator 1 -anchor e -default 0 -cancel 0 -parent .
+
+    $w add -text [::msgcat::mc "Close"] -command [list destroy $w]
+
+    set wf [$w getframe]
+
+    set sw [ScrolledWindow $wf.sw -scrollbar vertical]
+    set sf [ScrollableFrame $w.fields -constrainedwidth yes]
+    set f [$sf getframe]
+    $sw setwidget $sf
+
+    set row 1
+    foreach item $items {
+	set node         [::xmpp::xml::getAttr $item node]
+	set jid          [::xmpp::xml::getAttr $item jid]
+	set subscription [::xmpp::xml::getAttr $item subscription]
+	set subid        [::xmpp::xml::getAttr $item subid]
+
+	label $f.node$row -text $node
+	label $f.jid$row -text $jid
+	label $f.subscription -text $subscription
+	label $f.subid -text $subid
+
+	grid $f.node$row -row $row -column 0
+	grid $f.jid$row -row $row -column 1
+	grid $f.subscription$row -row $row -column 2
+	grid $f.subid$row -row $row -column 3
+
+	set command [list requestSubscriptionOptions $xlib $service $node \
+			  -jid $jid -command [namespace code test_error]]
+	if {[::xmpp::xml::isAttr $item subid]} {
+	    lappend command -subid $subid
+	}
+
+	button $f.edit$row -text [::msgcat::mc "Edit"] \
+			   -command [namespace code $command]
+	grid $f.edit$row -row $row -column 4
+    }
+}
+
 ##########################################################################
 #
 # Owner use cases (8)
@@ -592,7 +659,12 @@
 
 		    $m add command -label [::msgcat::mc "Request default configuration"] \
 			-command [namespace code [list requestDefaultConfig $xlib $jid \
-					-command [namespace code test_result]]]
+					-command [namespace code test_error]]]
+
+		    $m add command -label [::msgcat::mc "Retrieve subscriptions"] \
+			-command [namespace code [list requestSubscriptions $xlib $jid $node \
+					-command [namespace code test_error]]]
+
 		    if {$node == ""} {
 			set state disabled
 		    } else {
@@ -601,8 +673,16 @@
 
 		    $m add command -label [::msgcat::mc "Configure node"] \
 			-command [namespace code [list configureNode $xlib $jid $node \
-					-command [namespace code test_result]]] \
+					-command [namespace code test_error]]] \
 			-state $state
+
+		    $m add command -label [::msgcat::mc "Subscribe"] \
+			-command [list ::xmpp::pubsub::subscribe $xlib $jid $node \
+					-command [namespace code test_result]] \
+
+		    $m add command -label [::msgcat::mc "Unubscribe"] \
+			-command [list ::xmpp::pubsub::unsubscribe $xlib $jid $node \
+					-command [namespace code test_result]] \
 		    return
 		}
 	    }
@@ -612,7 +692,7 @@
 
 hook::add disco_node_menu_hook pubsub::disco_node_menu_setup 60
 
-proc pubsub::test_result {status xml} {
+proc pubsub::test_error {status xml} {
     if {[string equal $status ok]} {
 	return
     }
@@ -621,7 +701,23 @@
 	    -aspect 50000 \
 	    -icon error \
 	    -title [::msgcat::mc "Error"] \
-	    -message [::msgcat::mc "Pubsub error: %s" [error_to_string $xml]]
+	    -message [::msgcat::mc "Pubsub request failed: %s" [error_to_string $xml]]
 }
 
+proc pubsub::test_result {status xml} {
+    if {[string equal $status ok]} {
+	NonmodalMessageDlg [epath] \
+	    -aspect 50000 \
+	    -icon warning \
+	    -title [::msgcat::mc "Success"] \
+	    -message [::msgcat::mc "Pubsub request succeeded"]
+    } else {
+	NonmodalMessageDlg [epath] \
+	    -aspect 50000 \
+	    -icon error \
+	    -title [::msgcat::mc "Error"] \
+	    -message [::msgcat::mc "Pubsub request failed: %s" [error_to_string $xml]]
+    }
+}
+
 # vim:ts=8:sw=4:sts=4:noet



More information about the Tkabber-dev mailing list