[Tkabber-dev] r41 - in trunk/plugins/np_send: . contrib/tkamarok

tkabber-svn at jabber.ru tkabber-svn at jabber.ru
Mon Sep 17 20:26:06 MSD 2007


Author: kostix
Date: 2007-09-17 20:26:06 +0400 (Mon, 17 Sep 2007)
New Revision: 41

Modified:
   trunk/plugins/np_send/TODO
   trunk/plugins/np_send/contrib/tkamarok/README
   trunk/plugins/np_send/contrib/tkamarok/tkamarok.tcl
   trunk/plugins/np_send/np_send.tcl
Log:
TkAmarok pushed to the state of invoking actual Tkabber code (or its "np_send" plugin).

np_send.tcl: several updates. works now.

TODO updated.


Modified: trunk/plugins/np_send/TODO
===================================================================
--- trunk/plugins/np_send/TODO	2007-09-17 00:51:56 UTC (rev 40)
+++ trunk/plugins/np_send/TODO	2007-09-17 16:26:06 UTC (rev 41)
@@ -1,2 +1,6 @@
 $Id$
 
+* Think about implementing "request" command that would be distributed
+  to all interps whose appname matches certain pattern via [send]
+  so that they could report their current playing state, if any.
+

Modified: trunk/plugins/np_send/contrib/tkamarok/README
===================================================================
--- trunk/plugins/np_send/contrib/tkamarok/README	2007-09-17 00:51:56 UTC (rev 40)
+++ trunk/plugins/np_send/contrib/tkamarok/README	2007-09-17 16:26:06 UTC (rev 41)
@@ -1,10 +1,14 @@
 <b>TkAmarok glues Amarok and Tkabber</b>
-<br>
 
+<h1>Plugin dependencies</h1>
+
+<p>
 Blah-blah-blah...
+</p>
 
 <b>Tkabber setup</b>
-<br>
 
+<p>
 Foobar...
+</p>
 

Modified: trunk/plugins/np_send/contrib/tkamarok/tkamarok.tcl
===================================================================
--- trunk/plugins/np_send/contrib/tkamarok/tkamarok.tcl	2007-09-17 00:51:56 UTC (rev 40)
+++ trunk/plugins/np_send/contrib/tkamarok/tkamarok.tcl	2007-09-17 16:26:06 UTC (rev 41)
@@ -1,4 +1,8 @@
 #! /usr/bin/env wish
+# $Id$
+# TkAmarok scripts that monitors Amarok playing state and sends
+# relevant "now playing" info to all present instances of Tkabber.
+# Requires "np_send" plugin installed on Tkabber's part.
 # Written by Konstantin Khomoutov <flatworm at users.sourceforge.net>
 
 wm withdraw .
@@ -142,9 +146,8 @@
 }
 
 proc notify args {
-	#set cmd [linsert $args 0 ::plugins::np_send::state_changed]
-	foreach app [lsearch -all -inline [winfo interps] tknowplaying*] {
-		eval [list send -async $app ::now_playing $args]
+	foreach app [lsearch -all -inline [winfo interps] tkabber*] {
+		eval [list send -async $app ::plugins::np_send::now_playing $args]
 	}
 }
 

Modified: trunk/plugins/np_send/np_send.tcl
===================================================================
--- trunk/plugins/np_send/np_send.tcl	2007-09-17 00:51:56 UTC (rev 40)
+++ trunk/plugins/np_send/np_send.tcl	2007-09-17 16:26:06 UTC (rev 41)
@@ -12,10 +12,6 @@
 	variable connections [list]
 	variable monitoring off
 
-	proc mycmd args {
-		lset args 0 [uplevel 1 namespace current]::[lindex $args 0]
-	}
-
 	custom::defgroup "User Tune" \
 		[::msgcat::mc "Plugins for automatic gathering of\
 			information for User Tune personal eventing facility."] \
@@ -26,34 +22,64 @@
 			managed by various media players."] \
 		-group "User Tune"
 
+	custom::defvar options(enabled) 1 \
+		[::msgcat::mc "Enable this plugin."] \
+		-type boolean \
+		-command [namespace current]::on_state_changed \
+		-group NowPlayingTkSend
+
 	custom::defvar options(update_threshold) 30 \
 		[::msgcat::mc "Minimal amount of time (in seconds) that must tick\
-			between adjacent now-playing information updates
+			between adjacent now-playing information updates\
 			for the latter to be considered."] \
 		-type integer \
-		-command on_update_thresh_changed \
+		-command [namespace current]::on_update_thresh_changed \
 		-group NowPlayingTkSend
 
 	hook::add connected_hook \
-		[mycmd on_new_connection]
+		[namespace current]::on_new_connection
 	hook::add disconnected_hook \
-		[mycmd on_connection_gone]
+		[namespace current]::on_connection_gone
 }
 
 # TODO get rid of this:
-proc np_send::enabled {} {
-	return 1
+proc np_send::monitoring activate {
+	variable options
+	variable monitoring
+
+	if {$activate && !$monitoring} {
+		set monitoring on
+	} elseif {$monitoring && !$activate} {
+		set monitoring off
+	}
 }
 
+proc np_send::on_state_changed args {
+	variable options
+
+	monitoring $options(enabled)
+}
+
+proc np_send::on_update_thresh_changed args {
+	variable options
+
+	# Prevent update threshold from being lower than 10 seconds:
+	if {$options(update_threshold) < 10} {
+		set options(update_threshold) 10
+	}
+}
+
 proc np_send::on_new_connection connid {
+	variable options
 	variable connections
 
 	set connections [lsort -unique [lappend connections $connid]]
 
-	monitoring [expr {[enabled] && [llength $connections] > 0}]
+	monitoring [expr {$options(enabled) && [llength $connections] > 0}]
 }
 
 proc np_send::on_connection_gone connid {
+	variable options
 	variable connections
 
 	set ix [lsearch -sorted $connections $connid]
@@ -61,19 +87,10 @@
 		set connections [lreplace $connections $ix $ix]
 	}
 
-	monitoring [expr {[enabled] && [llength $connections] > 0}]
+	monitoring [expr {$options(enabled) && [llength $connections] > 0}]
 }
 
-proc np_send::extract_opt {vlist opt} {
-	upvar 1 $vlist L
-	set a [lsearch -exact $L $opt]
-	set b [expr {$a + 1}]
-	set item [lindex $L $a]
-	set L [lreplace $L $a $b]
-	set item
-}
-
-proc np_send::player args {
+proc np_send::now_playing args {
 	variable options
 	variable lasttime
 	variable monitoring
@@ -86,21 +103,34 @@
 	set lasttime $time
 
 	# TODO check options for sanity
-	set state [extract_opt args -state]
-	set opts [array get $args]
 
-	switch -- $opts(state) {
+	set state ""
+	set opts [list]
+	foreach {opt val} $args {
+		if {[string equal $opt -state]} {
+			set state $val
+		} else {
+			if {$val != ""} {
+				lappend opts $opt $val
+			}
+		}
+	}
+
+	switch -- $state {
 		inactive {
-			# TODO implement publishing of "stopped":
 			foreach connid $connections {
-				#::plugins::tune::unpublish $connid
+				::plugins::tune::unpublish $connid
 			}
 		}
 		active {
 			foreach connid $connections {
-				eval [list ::plugins::tune::publish $connid] $args
+				eval [list ::plugins::tune::publish $connid] $opts
 			}
 		}
+		default {
+			return -code error "Bad playing status: \"$state\":\
+				must be active or inactive"
+		}
 	}
 }
 



More information about the Tkabber-dev mailing list