Skip to content

Commit

Permalink
Refactor button-remapping code.
Browse files Browse the repository at this point in the history
Look for button remapping in playerStatus.buttons instead of
playerStatus.remoteMeta.buttons (the old location is maintained for
backwards compatibility).

Explicitly use a button remapping of type 'like' for the repeat button
and one of 'dislike' for the shuffle button (the old names, 'repeat' &
'shuffle' are used as a fallback for backwards compatibility).

TTP: TSK-2353, Story-225
Change-Id: I222aa23e3cbac024c28a7159ce020f03e5b39dd4
  • Loading branch information
logitech-replication committed Jul 12, 2012
1 parent d5d4e05 commit 971aeec
Showing 1 changed file with 34 additions and 26 deletions.
60 changes: 34 additions & 26 deletions src/squeezeplay/share/applets/NowPlaying/NowPlayingApplet.lua
Original file line number Diff line number Diff line change
Expand Up @@ -735,6 +735,15 @@ function _updateAll(self)
self:_updateVolume()
end

function _getButtons(self, playerStatus)
if not playerStatus then playerStatus = self.player:getPlayerStatus() end

if playerStatus then
return playerStatus.buttons or
(playerStatus.remoteMeta and playerStatus.remoteMeta.buttons)
end
end

function _updateButtons(self, playerStatus)
log:debug('_updateButtons')
-- no sense updating the transport buttons unless
Expand All @@ -743,49 +752,54 @@ function _updateButtons(self, playerStatus)
return
end

local remoteMeta = playerStatus.remoteMeta
local buttons = self:_getButtons(playerStatus)

local buttons = remoteMeta and remoteMeta.buttons
-- if we have buttons data, the remoteMeta is remapping some buttons
-- if we have buttons data we are remapping some buttons
if buttons then
log:debug('remap buttons to whatever remoteMeta needs')
log:debug('remap buttons')
local button

-- disable rew or fw as needed
if buttons.rew and tonumber(buttons.rew) == 0 then
button = buttons.rew
if button and tonumber(button) == 0 then
self:_remapButton('rew', 'rewDisabled', nil)
else
self.controlsGroup:setWidget('rew', self.rewButton)
end

if buttons.fwd and tonumber(buttons.fwd) == 0 then
button = buttons.fwd
if button and tonumber(button) == 0 then
-- Bug 15336: in order for a skip limit showBriefly to be generated, we still need to
-- allow the jump_fwd action to be sent for the disabled button
-- this could have implications for services that expect a disabled button to not send the action
self:_remapButton('fwd', 'fwdDisabled', nil)
else
self.controlsGroup:setWidget('fwd', self.fwdButton)
end

if buttons.shuffle then

button = buttons.like or buttons.shuffle -- backwards compatible
if button then
local callback = function()
local id = self.player:getId()
local server = self.player:getSlimServer()
local command = buttons.shuffle.command or function() return EVENT_CONSUME end
local command = button.command or function() return EVENT_CONSUME end
server:userRequest(nil, id, command)
end
self:_remapButton('shuffleMode', buttons.shuffle.jiveStyle, callback)
self:_remapButton('shuffleMode', button.jiveStyle, callback)
end

if buttons['repeat'] then

button = buttons.dislike or buttons['repeat'] -- backwards compatible
if button then
local callback = function()
local id = self.player:getId()
local server = self.player:getSlimServer()
local command = buttons['repeat'].command or function() return EVENT_CONSUME end
local command = button.command or function() return EVENT_CONSUME end
server:userRequest(nil, id, command)
end
self:_remapButton('repeatMode', buttons['repeat'].jiveStyle, callback)
self:_remapButton('repeatMode', button.jiveStyle, callback)
end

-- if we don't have remoteMeta and button remapping, go back to defaults
-- if we don't have button remapping, go back to defaults
else
local playlistSize = self.player and self.player:getPlaylistSize()
-- bug 15085, gray out buttons under certain circumstances
Expand Down Expand Up @@ -1060,11 +1074,8 @@ function _updateShuffle(self, mode)
log:debug("_updateShuffle(): ", mode)
-- don't update this if SC/SN has remapped shuffle button
if self.player then
local playerStatus = self.player:getPlayerStatus()
if playerStatus and
playerStatus.remoteMeta and
playerStatus.remoteMeta.buttons and
playerStatus.remoteMeta.shuffle then
local buttons = self:_getButtons()
if buttons and buttons.shuffle then
return
end
end
Expand All @@ -1084,11 +1095,8 @@ function _updateRepeat(self, mode)
log:debug("_updateRepeat(): ", mode)
-- don't update this if SC/SN has remapped repeat button
if self.player then
local playerStatus = self.player:getPlayerStatus()
if playerStatus and
playerStatus.remoteMeta and
playerStatus.remoteMeta.buttons and
playerStatus.remoteMeta['repeat'] then
local buttons = self:_getButtons()
if buttons and buttons['repeat'] then
return
end
end
Expand Down Expand Up @@ -1322,7 +1330,7 @@ function replaceNPWindow(self)

self.window = _createUI(self)
if self.player and self.player:getPlayerStatus() then
self:_updateButtons(self.player:getPlayerStatus())
self:_updateButtons()
self:_updateRepeat(self.player:getPlayerStatus()['playlist repeat'])
self:_updateShuffle(self.player:getPlayerStatus()['playlist shuffle'])
end
Expand Down

0 comments on commit 971aeec

Please sign in to comment.