Author: bklaas
Date: Wed Jan 23 19:36:45 2008
New Revision: 1593

URL: http://svn.slimdevices.com?rev=1593&root=Jive&view=rev
Log:
Bug: 5433, 5814, 5961, 6378, 6752
Description: 
Send notification on playlist change (keyed by change in playlist_timestamp)
Add notification handler for playlist change in SlimBrowser
Clean up notification handler for track change in SlimBrowser
add method to retrieve playlist timestamp from player object

Modified:
    
branches/7.0/jive/src/pkg/jive/share/applets/SlimBrowser/SlimBrowserApplet.lua
    branches/7.0/jive/src/pkg/jive/share/jive/slim/Player.lua

Modified: 
branches/7.0/jive/src/pkg/jive/share/applets/SlimBrowser/SlimBrowserApplet.lua
URL: 
http://svn.slimdevices.com/branches/7.0/jive/src/pkg/jive/share/applets/SlimBrowser/SlimBrowserApplet.lua?rev=1593&root=Jive&r1=1592&r2=1593&view=diff
==============================================================================
--- 
branches/7.0/jive/src/pkg/jive/share/applets/SlimBrowser/SlimBrowserApplet.lua 
(original)
+++ 
branches/7.0/jive/src/pkg/jive/share/applets/SlimBrowser/SlimBrowserApplet.lua 
Wed Jan 23 19:36:45 2008
@@ -1667,8 +1667,7 @@
        end
 end
 
-
-function notify_playerTrackChange(self, player, nowplaying)
+function notify_playerPlaylistChange(self, player)
        if _player ~= player then
                return
        end
@@ -1676,24 +1675,30 @@
        local playerStatus = player:getPlayerStatus()
        local step = _statusStep
 
-       -- move selection if playing track is selected
-       local moveSelection = (step.menu:getSelectedIndex() == 
step.db:playlistIndex())
-
-       if step.db:updateStatus(playerStatus) then
-               -- move selection if playlist has changed
-               moveSelection = true
-       end
-
-       if moveSelection then
-               step.menu:setSelectedIndex(step.db:playlistIndex())
-       else
-               step.menu:reLayout()
-       end
+       step.db:updateStatus(playerStatus)
+       step.menu:reLayout()
 
        -- does the playlist need loading?
        _requestStatus()
-end
-
+
+end
+
+function notify_playerTrackChange(self, player, nowplaying)
+
+       log:warn('SlimBrowser.notify_playerTrackChange')
+       if _player ~= player then
+               return
+       end
+       local playerStatus = player:getPlayerStatus()
+       local step = _statusStep
+
+       step.db:updateStatus(playerStatus)
+       step.menu:setSelectedIndex(step.db:playlistIndex())
+       step.menu:reLayout()
+
+        -- does the playlist need loading?
+        _requestStatus()
+end
 
 -- notify_playerNewName
 -- this is called when the player name changes

Modified: branches/7.0/jive/src/pkg/jive/share/jive/slim/Player.lua
URL: 
http://svn.slimdevices.com/branches/7.0/jive/src/pkg/jive/share/jive/slim/Player.lua?rev=1593&root=Jive&r1=1592&r2=1593&view=diff
==============================================================================
--- branches/7.0/jive/src/pkg/jive/share/jive/slim/Player.lua (original)
+++ branches/7.0/jive/src/pkg/jive/share/jive/slim/Player.lua Wed Jan 23 
19:36:45 2008
@@ -20,6 +20,7 @@
  playerDelete (performed by SlimServer)
  playerTrackChange
  playerModeChange
+ playerPlaylistChange
 
 =head1 FUNCTIONS
 
@@ -29,7 +30,7 @@
 local debug = require("jive.utils.debug")
 
 -- stuff we need
-local _assert, setmetatable, tonumber, tostring, pairs = _assert, 
setmetatable, tonumber, tostring, pairs
+local _assert, setmetatable, tonumber, tostring, pairs, ipairs = _assert, 
setmetatable, tonumber, tostring, pairs, ipairs
 
 local os             = require("os")
 local math           = require("math")
@@ -82,9 +83,11 @@
                        log:warn("########### ", err)
                        
                elseif chunk then
-                       --log:info(chunk)
-                       
                        local proc = "_process_" .. cmd[1]
+                       if cmd[1] == 'status' then
+                               log:debug('stored playlist timestamp: ', 
self.playlist_timestamp)
+                               log:debug('   new playlist timestamp: ', 
chunk.data.playlist_timestamp)
+                       end
                        if self[proc] then
                                self[proc](self, chunk)
                        end
@@ -159,10 +162,20 @@
        return nil
 end
 
+-- _setPlayerPlaylistChange()
+-- sends notifications when anything gets sent about the playlist changing
+local function _setPlayerPlaylistChange(self, timestamp)
+       log:debug("Player:_setPlayerPlaylistChange")
+       if self.playlist_timestamp != timestamp then
+               self.playlist_timestamp = timestamp
+               self.jnt:notify('playerPlaylistChange', self)
+       end
+end
+
 -- _setPlayerTrackChange()
 -- sends notifications when a change occurs to the currently playing track
-local function _setPlayerTrackChange(self, nowPlaying, data)
-       log:debug("_setPlayerTrackChange")
+local function _setPlayerTrackChange(self, nowPlaying)
+       log:debug("Player:_setPlayerTrackChange")
 
        if self.nowPlaying != nowPlaying then
                self.nowPlaying = nowPlaying
@@ -304,6 +317,20 @@
                return trackElapsed, self.trackDuration
        end
        
+end
+
+--[[
+
+=head2 jive.slim.Player:getPlaylistTimestamp()
+
+returns the playlist timestamp for a given player object
+the timestamp is an indicator of the last time the playlist changed
+it serves as a good check to see whether playlist items should be refreshed
+
+=cut
+--]]
+function getPlaylistTimestamp(self)
+       return self.playlist_timestamp
 end
 
 
@@ -625,11 +652,11 @@
 
        local nowPlaying = _whatsPlaying(event.data)
 
-       _setPlayerTrackChange(self, nowPlaying, event.data)
+       _setPlayerTrackChange(self, nowPlaying)
+       _setPlayerPlaylistChange(self, event.data.playlist_timestamp)
 
        self:updateIconbar()
 end
-
 
 function artworkThumbUri (iconId, size)
        return '/music/' .. iconId .. '/cover_' .. size .. 'x' .. size .. 
'_f_000000.jpg'

_______________________________________________
Jive-checkins mailing list
[email protected]
http://lists.slimdevices.com/cgi-bin/mailman/listinfo/jive-checkins

Reply via email to