[Tkabber-dev] r50 - trunk/plugins/now_playing

tkabber-svn at jabber.ru tkabber-svn at jabber.ru
Fri Sep 21 22:09:14 MSD 2007


Author: kostix
Date: 2007-09-21 22:09:14 +0400 (Fri, 21 Sep 2007)
New Revision: 50

Modified:
   trunk/plugins/now_playing/now_playing.tcl
Log:
Several fixes to now_playing plugin:
* Starts up w/o errors;
* Disconnections are now properly tracked.


Modified: trunk/plugins/now_playing/now_playing.tcl
===================================================================
--- trunk/plugins/now_playing/now_playing.tcl	2007-09-21 06:16:04 UTC (rev 49)
+++ trunk/plugins/now_playing/now_playing.tcl	2007-09-21 18:09:14 UTC (rev 50)
@@ -29,7 +29,7 @@
 			served by various media players."] \
 		-group "User Tune"
 
-	custom::defvar options(media_player) "" \
+	custom::defvar options(media_player) none \
 		[::msgcat::mc "Media player that manages the now playing file.\
 			Please note that some media players and/or their \"now playing\"\
 			plugins require additional configuration to work with this plugin.\
@@ -55,7 +55,9 @@
 		-group "Now Playing"
 
 	custom::defvar options(file) [file join $::configdir now_playing] \
-		[::msgcat::mc "Pathname of the now playing file."] \
+		[::msgcat::mc "Pathname of the now playing file.\
+			(This setting is only relevant to those media players that\
+			serve the information about their user tune using a text file."] \
 		-type file \
 		-group "Now Playing"
 
@@ -86,7 +88,13 @@
 	expr {![string equal $options(media_player) none]}
 }
 
-proc now_playing::monitoring {op args} {
+proc now_playing::method {} {
+	variable options
+
+	set options(method,$options(media_player))
+}
+
+proc now_playing::monitoring {op {val ""}} {
 	variable monitoring
 
 	switch -- $op {
@@ -94,22 +102,18 @@
 			set monitoring
 		}
 		is {
-			expr {$monitoring && [lindex $args 0]}
+			expr {$monitoring && $val]}
 		}
 		set {
 			variable options
 			variable repollid
 
-			set activate [lindex $args 0]
-
-			if {$activate && !$monitoring} {
+			if {$val && !$monitoring} {
 				set monitoring on
-				[mycmd poll] ;# must be fully qualified
-			} elseif {$monitoring && !$activate} {
+				method_start_[method]
+			} elseif {$monitoring && !$val} {
 				set monitoring off
-				if {[info exists repollid]} {
-					after cancel $repollid
-				}
+				method_stop_[method]
 			}
 			set monitoring
 		}
@@ -121,7 +125,7 @@
 }
 
 # Calling of this procedure does only have sense when done from
-# a np_file_enumerate_media_players hook.
+# a now_playing_enumerate_media_players hook.
 proc now_playing::add_media_player args {
 	variable options
 	variable players
@@ -145,12 +149,8 @@
 		}
 	}
 
-	if {$tag == ""} {
-		return -code error "Empty tag is reserved and cannot be used"
-	}
-
 	switch -- $method {
-		file - registry - send - {}
+		none - file - registry - send {}
 		default {
 			return -code error "Bad method \"$method\":\
 				must be one of file, registry or send"
@@ -178,7 +178,7 @@
 		add_media_player -tag $tag -name $name -method $method -parser $parser
 	}
 
-	hook::run np_file_enumerate_media_players
+	hook::run now_playing_enumerate_media_players
 
 	custom::configvar [namespace current]::options(media_player) -values $players
 
@@ -188,7 +188,7 @@
 proc now_playing::on_new_connection connid {
 	variable connections
 
-	set connections [lsort -unique [lappend connections $connid]]
+	lappend connections $connid
 
 	monitoring set [expr {[enabled] && [llength $connections] > 0}]
 }
@@ -196,31 +196,28 @@
 proc now_playing::on_connection_gone connid {
 	variable connections
 
-	set ix [lsearch -sorted $connections $connid]
-	if {$ix >= 0} {
-		set connections [lreplace $connections $ix $ix]
+	# Empty $connid means all the connections are gone at once.
+	if {$connid == ""} {
+		set connections [list]
+	} else {
+		set ix [lsearch -exact $connections $connid]
+		if {$ix >= 0} {
+			set connections [lreplace $connections $ix $ix]
+		}
 	}
 
 	monitoring set [expr {[enabled] && [llength $connections] > 0}]
 }
 
 proc now_playing::on_media_player_changed args {
+	variable lastmethod
 	variable connections
-	variable lastmethod
-	variable players
 
-	monitoring set [expr {[enabled] && [llength $connections] > 0}]
-
-	upvar 0 options(media_player) player
-	upvar 0 players($tag,method) method
-
-	if {![string equal $lastmethod $method]} {
+	if {![string equal $lastmethod [method]]} {
 		method_stop_$lastmethod
 	}
-	if {[monitoring is on]} {
-		method_start_$method
-	}
-	set lastmethod $method
+
+	monitoring set [expr {[enabled] && [llength $connections] > 0}]
 }
 
 proc now_playing::on_update_thresh_changed args {
@@ -268,7 +265,6 @@
 }
 
 proc now_playing::polling_start with {
-	variable repollid
 }
 
 proc now_playing::polling_cancel {} {
@@ -286,15 +282,21 @@
 #### Method: file
 
 proc now_playing::method_start_file {} {
+	debugmsg tune [info level 0]
+	[mycmd file_poll]
 }
 
 proc now_playing::method_stop_file {} {
+	debugmsg tune [info level 0]
+	polling_cancel
 }
 
 proc now_playing::file_poll {} {
 	variable options
 	variable repollid
 
+	debugmsg tune [info level 0]
+
 	file_yield
 
 	if {$options(check_timeout) > 0} {
@@ -503,5 +505,5 @@
 
 #### Final startup
 
-np_file::enumerate_media_players
+now_playing::enumerate_media_players
 



More information about the Tkabber-dev mailing list