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

tkabber-svn at jabber.ru tkabber-svn at jabber.ru
Mon Sep 17 04:51:56 MSD 2007


Author: kostix
Date: 2007-09-17 04:51:56 +0400 (Mon, 17 Sep 2007)
New Revision: 40

Added:
   trunk/plugins/np_send/AUTHORS
   trunk/plugins/np_send/INSTALL
   trunk/plugins/np_send/README
   trunk/plugins/np_send/TODO
   trunk/plugins/np_send/contrib/
   trunk/plugins/np_send/contrib/README
   trunk/plugins/np_send/contrib/tkamarok/
   trunk/plugins/np_send/contrib/tkamarok/COPYING
   trunk/plugins/np_send/contrib/tkamarok/README
   trunk/plugins/np_send/contrib/tkamarok/mktarball
   trunk/plugins/np_send/contrib/tkamarok/tkamarok.spec
   trunk/plugins/np_send/contrib/tkamarok/tkamarok.tcl
   trunk/plugins/np_send/license.terms
   trunk/plugins/np_send/np_send.tcl
Log:
Initial import of "np_send" plugin + TkAmarok script.
np_send is not checked to work yet.


Added: trunk/plugins/np_send/AUTHORS
===================================================================
--- trunk/plugins/np_send/AUTHORS	                        (rev 0)
+++ trunk/plugins/np_send/AUTHORS	2007-09-17 00:51:56 UTC (rev 40)
@@ -0,0 +1 @@
+Konstantin Khomoutov <flatworm at users.sourceforge.com>


Property changes on: trunk/plugins/np_send/AUTHORS
___________________________________________________________________
Name: svn:eol-style
   + native

Added: trunk/plugins/np_send/INSTALL
===================================================================
--- trunk/plugins/np_send/INSTALL	                        (rev 0)
+++ trunk/plugins/np_send/INSTALL	2007-09-17 00:51:56 UTC (rev 40)
@@ -0,0 +1,19 @@
+In order to use this plugin you must have:
+* A working Foobar2000 installation.
+* "foobar_np_simple" Foobar2000 plugin installed and tuned
+  as explained in the README file.
+
+Note that since Foobar2000 is only available for Windows systems
+there's no sense to use this plugin on other platforms.
+
+As usually, copy this directory under the ~/.tkabber/plugins directory
+so that you get a hierarchy like this:
+  ~/.tkabber/plugins
+  ~/.tkabber/plugins/np_send/
+  ~/.tkabber/plugins/np_send/np_send.tcl
+
+Restart Tkabber, to get the plugin loaded.
+Visit the "Customize->Plugins->User Tune->Now Playing (Tk send)"
+block of settings and adjust them to match your setup.
+
+Consult the README file for the details about using this plugin.


Property changes on: trunk/plugins/np_send/INSTALL
___________________________________________________________________
Name: svn:eol-style
   + native

Added: trunk/plugins/np_send/README
===================================================================
--- trunk/plugins/np_send/README	                        (rev 0)
+++ trunk/plugins/np_send/README	2007-09-17 00:51:56 UTC (rev 40)
@@ -0,0 +1,24 @@
+"Now Playing via Tk [send]" plugin for Tkabber.
+$Id$
+
+I. The idea.
+
+...
+
+
+II. Supported media players.
+
+Currently these media players are supported:
+
+* Amarok [1] via "TkAmarok" script.
+
+
+III. Installation of TkAmarok script.
+
+
+V. References:
+
+1. http://amarok.kde.org
+
+
+vim:et:ts=4:sw=4:tw=64


Property changes on: trunk/plugins/np_send/README
___________________________________________________________________
Name: svn:keywords
   + Id
Name: svn:eol-style
   + native

Added: trunk/plugins/np_send/TODO
===================================================================
--- trunk/plugins/np_send/TODO	                        (rev 0)
+++ trunk/plugins/np_send/TODO	2007-09-17 00:51:56 UTC (rev 40)
@@ -0,0 +1,2 @@
+$Id$
+


Property changes on: trunk/plugins/np_send/TODO
___________________________________________________________________
Name: svn:keywords
   + Id
Name: svn:eol-style
   + native

Added: trunk/plugins/np_send/contrib/README
===================================================================
--- trunk/plugins/np_send/contrib/README	                        (rev 0)
+++ trunk/plugins/np_send/contrib/README	2007-09-17 00:51:56 UTC (rev 40)
@@ -0,0 +1,8 @@
+$Id$
+
+tkamarok -- TkAmarok script for Amarok media player.
+  To make a ready to use plugin out of it run "mktarball" script
+  in that directory which will create file named "tkamarok.amarokscript.tar"
+  under /tmp which can be installed using Amarok's script manager.
+  Note that "mktarball" relies on the presense of the "mktemp" utility.
+


Property changes on: trunk/plugins/np_send/contrib/README
___________________________________________________________________
Name: svn:keywords
   + Id
Name: svn:eol-style
   + native

Added: trunk/plugins/np_send/contrib/tkamarok/COPYING
===================================================================
--- trunk/plugins/np_send/contrib/tkamarok/COPYING	                        (rev 0)
+++ trunk/plugins/np_send/contrib/tkamarok/COPYING	2007-09-17 00:51:56 UTC (rev 40)
@@ -0,0 +1,19 @@
+Copyright (c) 2007 Konstantin Khomoutov <flatworm at users.sourceforge.net>
+
+Permission is hereby granted, free of charge, to any person obtaining a
+copy of this software and associated documentation files (the "Software"),
+to deal in the Software without restriction, including without limitation
+the rights to use, copy, modify, merge, publish, distribute, sublicense,
+and/or sell copies of the Software, and to permit persons to whom the
+Software is furnished to do so, subject to the following conditions:
+
+The above copyright notice and this permission notice shall be included
+in all copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
+OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
+THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
+DEALINGS IN THE SOFTWARE.


Property changes on: trunk/plugins/np_send/contrib/tkamarok/COPYING
___________________________________________________________________
Name: svn:eol-style
   + native

Added: trunk/plugins/np_send/contrib/tkamarok/README
===================================================================
--- trunk/plugins/np_send/contrib/tkamarok/README	                        (rev 0)
+++ trunk/plugins/np_send/contrib/tkamarok/README	2007-09-17 00:51:56 UTC (rev 40)
@@ -0,0 +1,10 @@
+<b>TkAmarok glues Amarok and Tkabber</b>
+<br>
+
+Blah-blah-blah...
+
+<b>Tkabber setup</b>
+<br>
+
+Foobar...
+


Property changes on: trunk/plugins/np_send/contrib/tkamarok/README
___________________________________________________________________
Name: svn:eol-style
   + native

Added: trunk/plugins/np_send/contrib/tkamarok/mktarball
===================================================================
--- trunk/plugins/np_send/contrib/tkamarok/mktarball	                        (rev 0)
+++ trunk/plugins/np_send/contrib/tkamarok/mktarball	2007-09-17 00:51:56 UTC (rev 40)
@@ -0,0 +1,13 @@
+#! /bin/sh
+# $Id$
+# Generates ready to use TkAmarok script tarball under /tmp
+
+dist=/tmp/tkamarok.amarokscript.tar
+
+dir=`mktemp -t -d tkamarok.XXXXXXXX` || exit 1
+svn export --force . $dir || exit 2
+test -x $dist && rm -f $dist
+chmod +x $dir/tkamarok.tcl
+tar cf $dist --exclude=mktarball -C $dir .
+rm -rf $dir
+


Property changes on: trunk/plugins/np_send/contrib/tkamarok/mktarball
___________________________________________________________________
Name: svn:executable
   + *
Name: svn:keywords
   + Id

Added: trunk/plugins/np_send/contrib/tkamarok/tkamarok.spec
===================================================================
--- trunk/plugins/np_send/contrib/tkamarok/tkamarok.spec	                        (rev 0)
+++ trunk/plugins/np_send/contrib/tkamarok/tkamarok.spec	2007-09-17 00:51:56 UTC (rev 40)
@@ -0,0 +1,2 @@
+name = TkAmarok
+type = generic


Property changes on: trunk/plugins/np_send/contrib/tkamarok/tkamarok.spec
___________________________________________________________________
Name: svn:eol-style
   + native

Added: trunk/plugins/np_send/contrib/tkamarok/tkamarok.tcl
===================================================================
--- trunk/plugins/np_send/contrib/tkamarok/tkamarok.tcl	                        (rev 0)
+++ trunk/plugins/np_send/contrib/tkamarok/tkamarok.tcl	2007-09-17 00:51:56 UTC (rev 40)
@@ -0,0 +1,156 @@
+#! /usr/bin/env wish
+# Written by Konstantin Khomoutov <flatworm at users.sourceforge.net>
+
+wm withdraw .
+
+if {![catch {package require Tclx}]} {
+	signal trap SIGTERM shutdown
+}
+
+variable active true
+variable track
+variable tid ""
+variable laststate unknown
+
+proc laststate {op val} {
+	variable laststate
+
+	switch -- $op {
+		is  { expr {[string equal $laststate $val]} }
+		set { set laststate $val }
+		default {
+			return -code error "bad operation \"$op\":\
+				must be is or set"
+		}
+	}
+}
+
+proc process {} {
+	variable active
+
+	if {[eof stdin]} shutdown
+
+	if {!$active} continue
+
+	set line [string trim [gets stdin]]
+	switch -glob -- $line {
+		configure CmdConfigure
+	
+		engineStateChange:* {
+			CmdEngineStateChange [string trim [string range $line 19 end]]
+		}
+
+		trackChange CmdTrackChange
+	}
+}
+
+proc shutdown {} {
+	fileevent stdin readable {}
+	notify -state inactive
+	after 1000 set ::exit 0
+}
+
+proc dcop args {
+	eval {exec dcop amarok} $args
+}
+
+proc amarokShowMessage msg {
+	dcop playlist popupMessage $msg
+}
+
+proc CmdConfigure {} {
+	amarokShowMessage {TkAmarok plugin has no configuration options}
+}
+
+proc CmdEngineStateChange state {
+	variable tid
+
+	switch -- $state {
+		empty   {
+			set tid ""
+			HandleInactivity
+			laststate set empty
+		}
+		idle    -
+		paused  {
+			HandleInactivity
+			laststate set paused
+		}
+		playing {
+			if {[laststate is paused] && $tid != ""} ReportTrackChange
+			laststate set playing
+		}
+	}
+}
+
+proc CmdTrackChange {} {
+	set failed [catch {
+		variable tid
+
+		set trackid [dcop playlist currentTrackUniqueId]
+		if {![string equal $tid $trackid]} {
+			set tid $trackid
+
+			variable track
+			array unset track *
+
+			set track(artist) [dcop player artist]
+			set track(source) [dcop player album]
+			set track(title)  [dcop player title]
+			set track(track)  [dcop player track]
+			set track(length) [dcop player trackTotalTime]
+			set track(date)   [dcop player year]
+			set uri           [dcop player encodedURL]
+
+			if {[string match file://* $uri]} {
+				set track(uri) ""
+			} else {
+				set track(uri) $uri
+			}
+		} else {
+			amarokShowMessage "Same track..."
+		}
+
+		ReportTrackChange
+	} err]
+	if {$failed} {
+		variable active false
+		catch {amarokShowMessage $err}
+	}
+}
+
+proc HandleInactivity {} {
+	variable laststate
+
+	switch -- $laststate {
+		unknown -
+		playing {
+			notify -state inactive
+		}
+	}
+}
+
+proc ReportTrackChange {} {
+	variable track
+
+	set cmd [list notify -state active]
+	foreach {key val} [array get track] {
+		lappend cmd -$key $val
+	}
+
+	eval $cmd
+}
+
+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]
+	}
+}
+
+fconfigure stdin -encoding utf-8 -buffering line
+fileevent stdin readable process
+
+vwait exit
+exit $exit
+


Property changes on: trunk/plugins/np_send/contrib/tkamarok/tkamarok.tcl
___________________________________________________________________
Name: svn:executable
   + *
Name: svn:keywords
   + Id
Name: svn:eol-style
   + native

Added: trunk/plugins/np_send/license.terms
===================================================================
--- trunk/plugins/np_send/license.terms	                        (rev 0)
+++ trunk/plugins/np_send/license.terms	2007-09-17 00:51:56 UTC (rev 40)
@@ -0,0 +1,19 @@
+Copyright (c) 2007 Konstantin Khomoutov <flatworm at users.sourceforge.net>
+
+Permission is hereby granted, free of charge, to any person obtaining a
+copy of this software and associated documentation files (the "Software"),
+to deal in the Software without restriction, including without limitation
+the rights to use, copy, modify, merge, publish, distribute, sublicense,
+and/or sell copies of the Software, and to permit persons to whom the
+Software is furnished to do so, subject to the following conditions:
+
+The above copyright notice and this permission notice shall be included
+in all copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
+OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
+THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
+DEALINGS IN THE SOFTWARE.


Property changes on: trunk/plugins/np_send/license.terms
___________________________________________________________________
Name: svn:eol-style
   + native

Added: trunk/plugins/np_send/np_send.tcl
===================================================================
--- trunk/plugins/np_send/np_send.tcl	                        (rev 0)
+++ trunk/plugins/np_send/np_send.tcl	2007-09-17 00:51:56 UTC (rev 40)
@@ -0,0 +1,106 @@
+# $Id$
+# "Now Playing via Tk [send]" -- User Tune plugin for Tkabber.
+# Listens to "now playing" info sent by other Tk applications
+# and publishes it to the user's "User Tune" PEP nodes.
+# Written by Konstantin Khomoutov <flatworm at users.sourceforge.net>
+# See license.terms for details about distribution.
+# See README for details about usage.
+
+namespace eval np_send {
+	variable options
+	variable lasttime 0
+	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."] \
+		-group Plugins
+
+	custom::defgroup NowPlayingTkSend \
+		[::msgcat::mc "Support for files with \"now playing\" information\
+			managed by various media players."] \
+		-group "User Tune"
+
+	custom::defvar options(update_threshold) 30 \
+		[::msgcat::mc "Minimal amount of time (in seconds) that must tick\
+			between adjacent now-playing information updates
+			for the latter to be considered."] \
+		-type integer \
+		-command on_update_thresh_changed \
+		-group NowPlayingTkSend
+
+	hook::add connected_hook \
+		[mycmd on_new_connection]
+	hook::add disconnected_hook \
+		[mycmd on_connection_gone]
+}
+
+# TODO get rid of this:
+proc np_send::enabled {} {
+	return 1
+}
+
+proc np_send::on_new_connection connid {
+	variable connections
+
+	set connections [lsort -unique [lappend connections $connid]]
+
+	monitoring [expr {[enabled] && [llength $connections] > 0}]
+}
+
+proc np_send::on_connection_gone connid {
+	variable connections
+
+	set ix [lsearch -sorted $connections $connid]
+	if {$ix >= 0} {
+		set connections [lreplace $connections $ix $ix]
+	}
+
+	monitoring [expr {[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 {
+	variable options
+	variable lasttime
+	variable monitoring
+	variable connections
+
+	if {!$monitoring} return
+
+	set time [clock seconds]
+	if {$time - $lasttime < $options(update_threshold)} return
+	set lasttime $time
+
+	# TODO check options for sanity
+	set state [extract_opt args -state]
+	set opts [array get $args]
+
+	switch -- $opts(state) {
+		inactive {
+			# TODO implement publishing of "stopped":
+			foreach connid $connections {
+				#::plugins::tune::unpublish $connid
+			}
+		}
+		active {
+			foreach connid $connections {
+				eval [list ::plugins::tune::publish $connid] $args
+			}
+		}
+	}
+}
+


Property changes on: trunk/plugins/np_send/np_send.tcl
___________________________________________________________________
Name: svn:keywords
   + Id
Name: svn:eol-style
   + native



More information about the Tkabber-dev mailing list