[Tkabber-dev] r46 - trunk/plugins/np_file

tkabber-svn at jabber.ru tkabber-svn at jabber.ru
Thu Sep 20 21:50:28 MSD 2007


Author: kostix
Date: 2007-09-20 21:50:28 +0400 (Thu, 20 Sep 2007)
New Revision: 46

Modified:
   trunk/plugins/np_file/np_file.tcl
Log:
Prepared for merging np_send and np_registry in:
halfway implemented the concept of "methods" (file, registry, send).
The plugin is in non-working state now.


Modified: trunk/plugins/np_file/np_file.tcl
===================================================================
--- trunk/plugins/np_file/np_file.tcl	2007-09-19 17:33:51 UTC (rev 45)
+++ trunk/plugins/np_file/np_file.tcl	2007-09-20 17:50:28 UTC (rev 46)
@@ -10,6 +10,7 @@
 namespace eval np_file {
 	variable options
 	variable lasttime 0
+	variable lastmethod none
 	variable connections [list]
 	variable monitoring off
 	variable nwarns
@@ -85,6 +86,40 @@
 	expr {$options(media_player) != ""}
 }
 
+proc np_file::monitoring {op args} {
+	variable monitoring
+
+	switch -- $op {
+		get {
+			set monitoring
+		}
+		is {
+			expr {$monitoring && [lindex $args 0]}
+		}
+		set {
+			variable options
+			variable repollid
+
+			set activate [lindex $args 0]
+
+			if {$activate && !$monitoring} {
+				set monitoring on
+				[mycmd poll] ;# must be fully qualified
+			} elseif {$monitoring && !$activate} {
+				set monitoring off
+				if {[info exists repollid]} {
+					after cancel $repollid
+				}
+			}
+			set monitoring
+		}
+		default {
+			return -code error "Bad operation \"$op\":\
+				must be get, is or set"
+		}
+	}
+}
+
 # Calling of this procedure does only have sense when done from
 # a np_file_enumerate_media_players hook.
 proc np_file::add_media_player args {
@@ -95,6 +130,7 @@
 		switch -- $opt {
 			-tag    { set tag $val }
 			-name   { set name $val }
+			-method { set method $val }
 			-parser { set parser $val }
 			default {
 				return -code error "Bad option \"$opt\":\
@@ -103,7 +139,7 @@
 		}
 	}
 
-	foreach v {tag name parser} {
+	foreach v {tag name method parser} {
 		if {![info exists $v]} {
 			return -code error "Required option missing: -$v"
 		}
@@ -113,7 +149,16 @@
 		return -code error "Empty tag is reserved and cannot be used"
 	}
 
-	set options(name,$tag) $name
+	switch -- $method {
+		file - registry - send - {}
+		default {
+			return -code error "Bad method \"$method\":\
+				must be one of file, registry or send"
+		}
+	}
+
+	set options(name,$tag)   $name
+	set options(method,$tag) $method
 	set options(parser,$tag) $parser
 
 	lappend players $tag $name
@@ -123,17 +168,18 @@
 	variable options
 	variable players
 
-	foreach {tag name parser} [list \
-		foobar     "Foobar2000"   [mycmd foobar_yield] \
-		QL         "Quod Libet"   [mycmd quodlibet_yield]  \
+	foreach {tag name method parser} [list \
+		none       [::msgcat::mc "None"]  none     {} \
+		foobar     "Foobar2000"           file     [mycmd foobar_yield] \
+		QL         "Quod Libet"           file     [mycmd quodlibet_yield] \
+		wmp        "Windows Media Player" registry [mycmd wmp_yield]  \
 	] {
-		add_media_player -tag $tag -name $name -parser $parser
+		add_media_player -tag $tag -name $name -method $method -parser $parser
 	}
 
 	hook::run np_file_enumerate_media_players
 
-	custom::configvar [namespace current]::options(media_player) \
-		-values [concat [list "" [::msgcat::mc "None"]] $players]
+	custom::configvar [namespace current]::options(media_player) -values $players
 
 	unset players
 }
@@ -143,7 +189,7 @@
 
 	set connections [lsort -unique [lappend connections $connid]]
 
-	monitoring [expr {[enabled] && [llength $connections] > 0}]
+	monitoring set [expr {[enabled] && [llength $connections] > 0}]
 }
 
 proc np_file::on_connection_gone connid {
@@ -154,25 +200,23 @@
 		set connections [lreplace $connections $ix $ix]
 	}
 
-	monitoring [expr {[enabled] && [llength $connections] > 0}]
+	monitoring set [expr {[enabled] && [llength $connections] > 0}]
 }
 
-proc np_file::monitoring activate {
-	variable options
-	variable monitoring
-	variable repollid
+#### Method: none
 
-	if {$activate && !$monitoring} {
-		set monitoring on
-		[mycmd poll] ;# must be fully qualified
-	} elseif {$monitoring && !$activate} {
-		set monitoring off
-		if {[info exists repollid]} {
-			after cancel $repollid
-		}
-	}
+proc np_file::method_start_none {} {}
+
+proc np_file::method_stop_none {} {}
+
+#### Method: file
+
+proc np_file::method_start_file {} {
 }
 
+proc np_file::method_stop_file {} {
+}
+
 proc np_file::poll {} {
 	variable options
 	variable repollid
@@ -212,8 +256,23 @@
 
 proc np_file::on_media_player_changed args {
 	variable connections
+	variable lastmethod
+	variable players
 
-	monitoring [expr {[enabled] && [llength $connections] > 0}]
+	# TODO remove this:
+	# method should become enabled when method isn't "none"
+	monitoring set [expr {[enabled] && [llength $connections] > 0}]
+
+	upvar 0 options(player) tag
+	upvar 0 players($tag,method) method
+
+	if {![string equal $lastmethod $method]} {
+		method_stop_$lastmethod
+	}
+	if {[monitoring is on]} {
+		method_start_$method
+	}
+	set lastmethod $method
 }
 
 proc np_file::on_update_thresh_changed args {
@@ -382,5 +441,23 @@
 	}
 }
 
+#### Method: send
+
+proc np_file::method_start_send {} {
+}
+
+proc np_file::method_stop_send {} {
+}
+
+#### Method: registry
+
+proc np_file::method_start_registry {} {
+}
+
+proc np_file::method_stop_registry {} {
+}
+
+#### Final startup
+
 np_file::enumerate_media_players
 



More information about the Tkabber-dev mailing list