Author: richard
Date: Thu Jan 22 06:35:04 2009
New Revision: 3911

URL: http://svn.slimdevices.com?rev=3911&root=Jive&view=rev
Log:
 r3...@harrypotter (orig r3910):  tom | 2009-01-22 14:28:18 +0000
 Bug: N/A
 Description:
 Action framework:
 - Input to action mapping maps put in own file
 - Basic "remote" style actions created
 - Screenshot applet uses action

Added:
    
7.4/branches/pango/squeezeplay/src/squeezeplay/share/jive/InputToActionMap.lua
Modified:
    7.4/branches/pango/   (props changed)
    
7.4/branches/pango/squeezeplay/src/squeezeplay/share/applets/Screenshot/ScreenshotApplet.lua
    
7.4/branches/pango/squeezeplay/src/squeezeplay/share/applets/SlimBrowser/SlimBrowserApplet.lua
    7.4/branches/pango/squeezeplay/src/squeezeplay/share/jive/JiveMain.lua
    7.4/branches/pango/squeezeplay/src/squeezeplay/share/jive/slim/Player.lua
    7.4/branches/pango/squeezeplay/src/squeezeplay/share/jive/ui/Framework.lua
    7.4/branches/pango/squeezeplay/src/squeezeplay/share/jive/ui/Widget.lua
    7.4/branches/pango/squeezeplay/src/squeezeplay/share/jive/ui/Window.lua

Propchange: 7.4/branches/pango/
------------------------------------------------------------------------------
--- svk:merge (original)
+++ svk:merge Thu Jan 22 06:35:04 2009
@@ -4,7 +4,7 @@
 bbe22326-0783-4b3a-ac2b-7ab96b24c8d9:/7.2/trunk:2921
 bbe22326-0783-4b3a-ac2b-7ab96b24c8d9:/7.3/private-branches/jive-refresh:3653
 bbe22326-0783-4b3a-ac2b-7ab96b24c8d9:/7.3/trunk:3856
-bbe22326-0783-4b3a-ac2b-7ab96b24c8d9:/7.4/trunk:3906
+bbe22326-0783-4b3a-ac2b-7ab96b24c8d9:/7.4/trunk:3910
 bbe22326-0783-4b3a-ac2b-7ab96b24c8d9:/branches/7.0:2013
 bbe22326-0783-4b3a-ac2b-7ab96b24c8d9:/branches/SN:1083
 bbe22326-0783-4b3a-ac2b-7ab96b24c8d9:/branches/scrolling:1378

Modified: 
7.4/branches/pango/squeezeplay/src/squeezeplay/share/applets/Screenshot/ScreenshotApplet.lua
URL: 
http://svn.slimdevices.com/7.4/branches/pango/squeezeplay/src/squeezeplay/share/applets/Screenshot/ScreenshotApplet.lua?rev=3911&root=Jive&r1=3910&r2=3911&view=diff
==============================================================================
--- 
7.4/branches/pango/squeezeplay/src/squeezeplay/share/applets/Screenshot/ScreenshotApplet.lua
 (original)
+++ 
7.4/branches/pango/squeezeplay/src/squeezeplay/share/applets/Screenshot/ScreenshotApplet.lua
 Thu Jan 22 06:35:04 2009
@@ -37,12 +37,12 @@
 oo.class(_M, Applet)
 
 
-local function _keyHold(self, event)
-       if event:getKeycode() == (KEY_REW | KEY_PAUSE) then
-               Framework:playSound("CLICK")
+local function _takeScreenshotAction(self)
+       Framework:playSound("CLICK")
 
-               -- write to /media/*/log/squeezeplayXXXX.bmp or userpath
-               local path = System.getUserDir()
+       -- write to /media/*/log/squeezeplayXXXX.bmp or userpath
+       local path = System.getUserDir()
+       if lfs.attributes("/media", "mode") ~= nil then
                for dir in lfs.dir("/media") do
                        local tmp = "/media/" .. dir .. "/log"
                        if lfs.attributes(tmp, "mode") == "directory" then
@@ -50,28 +50,27 @@
                                break
                        end
                end
-
-               local file = path .. string.format("/squeezeplay%04d.bmp", 
self.number)
-               self.number = self.number + 1
-               
-               log:warn("Taking screenshot " .. file)
-
-               -- take screenshot
-               local sw, sh = Framework:getScreenSize()
-
-               local window = Framework.windowStack[1]
-               local bg = Framework.getBackground()
-
-               local srf = Surface:newRGB(sw, sh)
-               bg:blit(srf, 0, 0, sw, sh)
-               window:draw(srf, JIVE_LAYER_ALL)
-
-               srf:saveBMP(file)
-
-               return EVENT_CONSUME
        end
 
-       return EVENT_UNUSED
+
+       local file = path .. string.format("/squeezeplay%04d.bmp", self.number)
+       self.number = self.number + 1
+       
+       log:warn("Taking screenshot " .. file)
+
+       -- take screenshot
+       local sw, sh = Framework:getScreenSize()
+
+       local window = Framework.windowStack[1]
+       local bg = Framework.getBackground()
+
+       local srf = Surface:newRGB(sw, sh)
+       bg:blit(srf, 0, 0, sw, sh)
+       window:draw(srf, JIVE_LAYER_ALL)
+
+       srf:saveBMP(file)
+
+       return EVENT_CONSUME
 end
 
 
@@ -81,11 +80,7 @@
        local obj = oo.rawnew(self, Applet(...))
        obj.number = 1
        
-       Framework:addListener(EVENT_KEY_HOLD,
-               function(...)
-                       return _keyHold(obj, ...)
-               end
-       )
+       Framework:addActionListener("take_screenshot", obj, 
_takeScreenshotAction)
        
        return obj
 end

Modified: 
7.4/branches/pango/squeezeplay/src/squeezeplay/share/applets/SlimBrowser/SlimBrowserApplet.lua
URL: 
http://svn.slimdevices.com/7.4/branches/pango/squeezeplay/src/squeezeplay/share/applets/SlimBrowser/SlimBrowserApplet.lua?rev=3911&root=Jive&r1=3910&r2=3911&view=diff
==============================================================================
--- 
7.4/branches/pango/squeezeplay/src/squeezeplay/share/applets/SlimBrowser/SlimBrowserApplet.lua
 (original)
+++ 
7.4/branches/pango/squeezeplay/src/squeezeplay/share/applets/SlimBrowser/SlimBrowserApplet.lua
 Thu Jan 22 06:35:04 2009
@@ -1395,6 +1395,110 @@
 }
 
 
+function _goMenuTableItem(key)
+       if jiveMain:getMenuTable()[key] then
+               Framework:playSound("JUMP")
+               jiveMain:getMenuTable()[key].callback()
+       end
+
+end
+
+function _goNowPlayingAction()
+       appletManager:callService("goNowPlaying", "browse")
+end
+
+function _goSearchAction()
+       _goMenuTableItem("myMusicSearch")
+end
+
+function _goMusicLibraryAction()
+       _goMenuTableItem("myMusic")
+end
+
+
+function _goPlaylistAction()
+       _goPlaylist()
+end
+
+
+function _goFavoritesAction()
+       _goMenuTableItem("favorites")
+end
+
+
+function _goPlaylistsAction()
+       _goMenuTableItem("myMusicPlaylists")
+end
+
+
+function _goRhapsodyAction()
+       _goMenuTableItem("opmlrhapsodydirect")
+end
+
+
+function _goRepeatToggleAction()
+       _player:repeatToggle()
+end
+
+function _goShuffleToggleAction()
+       _player:shuffleToggle()
+end
+
+
+function _goCurrentTrackDetailsAction()
+       --todo -get menu object, iterate through to current, select it - doh, 
harder than I thought for something that's not yet a requirement
+end
+
+-- _globalActions
+-- provides a function for default button behaviour, called outside of the 
context of the browser
+--TRANSITIONING from old _globalAction style to new system wide action event 
model, will rename this when old one is eliminated
+--not sure yet how to deal with things like rew and vol which need 
up/down/press considerations
+local _globalActionsNEW = {
+
+       ["go_now_playing"] = _goNowPlayingAction,
+       ["go_playlist"] = _goPlaylistAction,
+       ["go_search"] = _goSearchAction,
+       ["go_favorites"] = _goFavoritesAction,
+       ["go_playlists"] = _goPlaylistsAction,
+       ["go_music_library"] = _goMusicLibraryAction,
+       ["go_rhapsody"] = _goRhapsodyAction,
+       ["go_current_track_details"] = _goCurrentTrackDetailsAction,
+       ["repeat_toggle"] = _goRepeatToggleAction,
+       ["shuffle_toggle"] = _goShuffleToggleAction,
+       ["go_home"] = function()
+               local windowStack = Framework.windowStack
+                          
+               -- are we in home?
+               if #windowStack > 1 then
+                       _goNow('home')
+               else
+                       _goNow('nowPlaying', Window.transitionPushLeft)
+               end
+                               
+               return EVENT_CONSUME
+       end,
+
+       ["play"] = function()
+               Framework:playSound("PLAYBACK")
+               _player:play()
+               return EVENT_CONSUME
+       end,
+
+       ["pause"] = function()
+               Framework:playSound("PLAYBACK")
+               _player:togglePause()
+               return EVENT_CONSUME
+       end,
+
+       ["stop"] = function()
+               Framework:playSound("PLAYBACK")
+               _player:stop()
+               return EVENT_CONSUME
+       end,
+
+}
+
+
 -- _defaultActions
 -- provides a function for each actionName for which Jive provides a default 
behaviour
 -- the function prototype is the same than _actionHandler (i.e. the whole 
shebang to cover all cases)
@@ -2092,13 +2196,32 @@
        _playerKeyHandler = false
 end
 
-function _goSearch()
-       --bring up music library search
-       if jiveMain:getMenuTable().myMusicSearch then
-               Framework:playSound("JUMP")
-               jiveMain:getMenuTable().myMusicSearch.callback()
-       end
-end
+local function _installActionListeners(self)
+       if _actionListenerHandles  then
+               return
+       end
+       
+       _actionListenerHandles = {}
+       
+       for action, func in pairs( _globalActionsNEW ) do
+               local handle = Framework:addActionListener(action, self, func)
+               table.insert(_actionListenerHandles, handle)
+       end
+       
+end
+
+local function _removeActionListeners(self)
+       if not _actionListenerHandles then
+               return
+       end
+
+       for i, handle in ipairs( _actionListenerHandles ) do
+               Framework:removeListener(handle)
+       end
+
+       _actionListenerHandles = false
+end
+
 
 
--==============================================================================
 -- SlimBrowserApplet public methods
@@ -2498,9 +2621,9 @@
        _connectingToPlayer(self)
 
        jiveMain:setTitle(_player:getName())
+       _installActionListeners(self)
        _installPlayerKeyHandler(self)
        
-       Framework:addActionListener("go_search", self, "SlimBrowser", _goSearch)
 end
 
 function notify_playerNeedsUpgrade(self, player, needsUpgrade, isUpgrading)
@@ -2679,7 +2802,8 @@
        end
 
        _removePlayerKeyHandler(self)
-
+       _removeActionListeners(self)
+       
        -- remove player menus
        jiveMain:setTitle(nil)
        for id, v in pairs(_playerMenus) do

Added: 
7.4/branches/pango/squeezeplay/src/squeezeplay/share/jive/InputToActionMap.lua
URL: 
http://svn.slimdevices.com/7.4/branches/pango/squeezeplay/src/squeezeplay/share/jive/InputToActionMap.lua?rev=3911&root=Jive&view=auto
==============================================================================
--- 
7.4/branches/pango/squeezeplay/src/squeezeplay/share/jive/InputToActionMap.lua 
(added)
+++ 
7.4/branches/pango/squeezeplay/src/squeezeplay/share/jive/InputToActionMap.lua 
Thu Jan 22 06:35:04 2009
@@ -1,0 +1,54 @@
+-- input to action mappings
+
+local Framework        = require("jive.ui.Framework")
+module(..., Framework.constants)
+
+
+charActionMappings = {}
+charActionMappings.press = {
+--BEGIN temp shortcuts to test action framework
+       ["["]  = "go_now_playing",
+       ["]"]  = "go_playlist",
+       ["{"]  = "go_current_track_details",
+       ["}"]  = "go_playlists",
+       [";"]  = "go_music_library",
+       [":"]  = "go_favorites",
+       ["'"]  = "go_rhapsody",
+       [","]  = "shuffle_toggle",
+       ["."]  = "repeat_toggle",
+       ["Q"]  = "power",
+
+--END temp shortcuts to test action framework
+
+       ["/"]   = "go_search",
+       ["h"]   = "go_home",
+       ["J"]   = "go_home",
+       ["x"]   = "play",
+       ["p"]   = "play",
+       ["P"]   = "create_mix",
+       [" "]   = "pause",
+       ["c"]   = "pause",
+       ["C"]   = "stop",
+       ["a"]   = "addEnd",
+       ["A"]   = "addNext",
+       ["\b"]  = "back", -- BACKSPACE
+       ["\27"] = "back", -- ESC
+       ["j"]   = "back",
+       ["l"]   = "go",
+       ["S"]   = "take_screenshot",
+       
+}
+
+
+keyActionMappings = {}
+keyActionMappings.press = {
+       [KEY_HOME] = "go_home"
+}
+
+
+keyActionMappings.hold = {
+       [KEY_BACK] = "disconnect_player",
+       [KEY_LEFT] = "go_home",
+       [KEY_REW | KEY_PAUSE] = "take_screenshot"  -- a stab at how to handle 
multi-press
+}
+

Modified: 7.4/branches/pango/squeezeplay/src/squeezeplay/share/jive/JiveMain.lua
URL: 
http://svn.slimdevices.com/7.4/branches/pango/squeezeplay/src/squeezeplay/share/jive/JiveMain.lua?rev=3911&root=Jive&r1=3910&r2=3911&view=diff
==============================================================================
--- 7.4/branches/pango/squeezeplay/src/squeezeplay/share/jive/JiveMain.lua 
(original)
+++ 7.4/branches/pango/squeezeplay/src/squeezeplay/share/jive/JiveMain.lua Thu 
Jan 22 06:35:04 2009
@@ -58,6 +58,8 @@
 local Task          = require("jive.ui.Task")
 local Timer         = require("jive.ui.Timer")
 local Event         = require("jive.ui.Event")
+
+local inputToActionMap = require("jive.InputToActionMap")
 
 local debug         = require("jive.utils.debug")
 local log           = require("jive.utils.log").logger("jive.main")
@@ -128,24 +130,6 @@
 }
 
 
-local charActionMappings = {}
-charActionMappings.press = {
-       ["/"] = "go_search"
-}
-
-
-local keyActionMappings = {}
-keyActionMappings.press = {
-       [KEY_HOME] = "go_home"
-}
-
-
-keyActionMappings.hold = {
-       [KEY_BACK] = "disconnect_player",
-       [KEY_LEFT] = "go_home",
-       [KEY_REW | KEY_PAUSE] = "take_screenshot"  -- a stab at how to handle 
multi-press
-}
-
 local _defaultSkin
 local _fullscreen
 
@@ -201,36 +185,49 @@
 
 -- transform user input events (key, etc) to a matching action name
 local function getAction(event)
-       --naive implementation for demonstration - will be more involved later
 
        local eventType = event:getType()
        local action = nil
        
        if eventType == EVENT_KEY_PRESS then
-               action = keyActionMappings.press[event:getKeycode()]
+               action = 
inputToActionMap.keyActionMappings.press[event:getKeycode()]
        elseif eventType == EVENT_KEY_HOLD then
-               action = keyActionMappings.hold[event:getKeycode()]
+               action = 
inputToActionMap.keyActionMappings.hold[event:getKeycode()]
        elseif eventType == EVENT_CHAR_PRESS then
-               action = 
charActionMappings.press[string.char(event:getUnicode())]
+               action = 
inputToActionMap.charActionMappings.press[string.char(event:getUnicode())]
        end
        
        return action
        
 end
 
-function registerDefaultActions()
-       for key, action in pairs(keyActionMappings.press) do 
+function _registerDefaultActions()
+       for key, action in pairs(inputToActionMap.keyActionMappings.press) do 
                Framework:registerAction(action)
        end
-       for key, action in pairs(keyActionMappings.hold) do 
+       for key, action in pairs(inputToActionMap.keyActionMappings.hold) do 
                Framework:registerAction(action)
        end
-       for key, action in pairs(charActionMappings.press) do 
+       for key, action in pairs(inputToActionMap.charActionMappings.press) do 
                Framework:registerAction(action)
        end
 
 end
 
+
+
+
+--local lastResortActionToKeyMap = {   
+--     ["back"]  = { keyCode = KEY_LEFT, event = EVENT_KEY_PRESS },
+--     ["disconnect_player "]  = { keyCode = KEY_BACK, event = EVENT_KEY_HOLD 
},
+--     ["go_home"]  = { keyCode = KEY_HOME, event = EVENT_KEY_PRESS },
+--     ["play"]  = { keyCode = KEY_PLAY, event = EVENT_KEY_HOLD },
+--     ["create_mix"]  = { keyCode = KEY_PLAY, event = EVENT_KEY_HOLD },
+--     ["pause"]  = { keyCode = KEY_PAUSE, event = EVENT_KEY_PRESS },
+--     ["stop"]  = { keyCode = KEY_PAUSE, event = EVENT_KEY_HOLD },
+--     ["addEnd"]  = { keyCode = KEY_ADD, event = EVENT_KEY_PRESS },
+--     ["addNext"]  = { keyCode = KEY_ADD, event = EVENT_KEY_HOLD },
+--}
 
 -- __init
 -- creates our JiveMain main object
@@ -255,6 +252,8 @@
        -- Singleton instances (locals)
        _globalStrings = locale:readGlobalStringsFile()
 
+       _registerDefaultActions()
+
        -- create the main menu
        jiveMain = oo.rawnew(self, HomeMenu(_globalStrings:str("HOME"), nil, 
"hometitle"))
 
@@ -271,7 +270,7 @@
        Framework:addListener(
                EVENT_CHAR_PRESS| EVENT_KEY_PRESS | EVENT_KEY_HOLD,
                function(event)
-                       _homeHandler(event)
+                       return _homeHandler(event)
                end,
                10)
 
@@ -283,32 +282,62 @@
                end,
                10)
 
-       registerDefaultActions()
 
        -- action mapping listener, should be last listener in chain to allow 
for direct access to keys/other input types if needed.
        --todo add other input types
        Framework:addListener(EVENT_KEY_ALL | EVENT_CHAR_PRESS ,
                function(event)
-                   local action = getAction(event)
-                   if not action then
-                       return EVENT_UNUSED
-                   end
-                   
-                   local actionEvent = Framework:newActionEvent(action)
-                   if not actionEvent then
-                       log:error("Odd, newActionEvent returned nil, but should 
always return a result when match was found for action: ", action)
-                       return EVENT_UNUSED
-                   end
-                   
-                   log:debug("Pushing action event (", action, ") - 
event:getAction: " , actionEvent:getAction())
-               Framework:pushEvent(actionEvent)
+                       local action = getAction(event)
+                       if not action then
+                               return EVENT_UNUSED
+                       end
+                       
+                       local actionEvent = Framework:newActionEvent(action)
+                       if not actionEvent then
+                               log:error("Odd, newActionEvent returned nil, 
but should always return a result when match was found for action: ", action)
+                               return EVENT_UNUSED
+                       end
+                       
+                       --getmetatable(actionEvent).sourceEvent = event 
+
+                       log:debug("Pushing action event (", action, "), 
triggered from source event:", event:tostring())
+                       Framework:pushEvent(actionEvent)
                        return EVENT_CONSUME
                end,
                9999)
+
+
+       
+       --"Last Resort" action listener - provides backwords compatibility for 
applets that only respond to KEY events
+       -- This listeners says, "in no one has use an ACTION, send a key event 
that matchs that action"
+       -- This is needed, for instance, for keyboard shortcut input, which now 
only creates action events
+---- DOESN"T WORK! new action listeners will pick up the action events before 
the old KEY style listeners will get a chance
+--     Framework:addListener(ACTION,
+--             function(actionEvent)
+--                     local sourceEvent = 
getmetatable(actionEvent).sourceEvent
+--                     
+--                     if (sourceEvent:getType() & EVENT_KEY_ALL) == 0 then
+--                             --Only do last resort key event if source event 
was not a key event (key event s would cause infinite loop)
+--                             local action = actionEvent:getAction()
+--                             if not lastResortActionToKeyMap[action] then
+--                                     return EVENT_UNUSED
+--                             end
+--             
+--                             local keyCode = 
lastResortActionToKeyMap[action].keyCode
+--                             local keyEvent = 
lastResortActionToKeyMap[action].event
+--                             log:debug("Pushing last resort key event for 
unused action (", action, ")")
+--                             Framework:pushEvent(Event:new(keyEvent, 
keyCode))
+--                                     
+--                             return EVENT_CONSUME
+--                     end
+--                     
+--                     return EVENT_UNUSED
+--             end,
+--             10000)
                
-       
+                               
        -- disconnect from player on press and hold left
-       Framework:addActionListener("disconnect_player", self, "JiveMain", 
_disconnectPlayer)
+       Framework:addActionListener("disconnect_player", self, 
_disconnectPlayer)
        
        -- show our window!
        jiveMain.window:show()

Modified: 
7.4/branches/pango/squeezeplay/src/squeezeplay/share/jive/slim/Player.lua
URL: 
http://svn.slimdevices.com/7.4/branches/pango/squeezeplay/src/squeezeplay/share/jive/slim/Player.lua?rev=3911&root=Jive&r1=3910&r2=3911&view=diff
==============================================================================
--- 7.4/branches/pango/squeezeplay/src/squeezeplay/share/jive/slim/Player.lua 
(original)
+++ 7.4/branches/pango/squeezeplay/src/squeezeplay/share/jive/slim/Player.lua 
Thu Jan 22 06:35:04 2009
@@ -1160,6 +1160,15 @@
        end
 end
 
+function repeatToggle(self)
+       self:button('repeat')
+end
+
+function shuffleToggle(self)
+       self:button('shuffle')
+end
+
+
 -- scan_rew
 -- what to do for the rew button when held
 -- use button so that the reverse scan mode is triggered.

Modified: 
7.4/branches/pango/squeezeplay/src/squeezeplay/share/jive/ui/Framework.lua
URL: 
http://svn.slimdevices.com/7.4/branches/pango/squeezeplay/src/squeezeplay/share/jive/ui/Framework.lua?rev=3911&root=Jive&r1=3910&r2=3911&view=diff
==============================================================================
--- 7.4/branches/pango/squeezeplay/src/squeezeplay/share/jive/ui/Framework.lua 
(original)
+++ 7.4/branches/pango/squeezeplay/src/squeezeplay/share/jive/ui/Framework.lua 
Thu Jan 22 06:35:04 2009
@@ -485,6 +485,29 @@
 
 
 --[[
+=head2 jive.ui.Framework:callerToString()
+
+Returns source:lineNumber information about the caller from the Lua call stack 
+
+=cut
+--]]
+function callerToString(self)
+       local info = debug.getinfo(3, "Sl")
+       if not info then 
+               return "No caller found" 
+       end
+       
+       if info.what == "C" then
+               return "C function"
+       end             
+
+       
+       -- else is a Lua function
+       return string.format("[%s]:%d", info.short_src, info.currentline)
+end
+
+
+--[[
 
 =head2 jive.ui.Framework:addListener(mask, listener, priority)
 
@@ -611,28 +634,36 @@
 end
 
 
---example: addActionListener("disconnect_player", self, "MyApplet" 
disconnectPlayerAction)
-function addActionListener(self, action, obj, sourceBreadCrumb, listener)
+--example: addActionListener("disconnect_player", self, disconnectPlayerAction)
+function addActionListener(self, action, obj, listener)
        _assert(type(listener) == "function")
 
+       local callerInfo = "N/A"
+       if log:isDebug() then
+               callerInfo = self:callerToString()
+       end
 
        if not self:_getActionEventIndexByName(action) then
                log:error("action name not registered:(" , action, "). 
Available actions: ", self:dumpActions() )
                return 
        end
-       log:debug("Creating action listener for action: (" , action, ") from 
source: ", sourceBreadCrumb)
-       
-       self:addListener(ACTION,
+       log:debug("Creating action listener for action: (" , action, ") from 
source: ", callerInfo)
+       
+       return self:addListener(ACTION,
                function(event)
                        local eventAction = event:getAction()
                        if eventAction != action then
                                return EVENT_UNUSED
                        end
-                       log:debug("Calling action listener for action: (" , 
action, ") from source: ", sourceBreadCrumb)
+                       log:debug("Calling action listener for action: (" , 
action, ") from source: ", callerInfo)
                
                        local listenerResult = listener(obj, event)
                        --default to consume unless the listener specifically 
wants to set a specific event return
-                       return listenerResult and listenerResult or 
EVENT_CONSUME
+                       local eventResult = listenerResult and listenerResult 
or EVENT_CONSUME
+                       if eventResult == EVENT_CONSUME then
+                               log:debug("Action (" , action, ") consumed by 
source: ", callerInfo)
+                       end
+                       return eventResult
                end
        )
        

Modified: 
7.4/branches/pango/squeezeplay/src/squeezeplay/share/jive/ui/Widget.lua
URL: 
http://svn.slimdevices.com/7.4/branches/pango/squeezeplay/src/squeezeplay/share/jive/ui/Widget.lua?rev=3911&root=Jive&r1=3910&r2=3911&view=diff
==============================================================================
--- 7.4/branches/pango/squeezeplay/src/squeezeplay/share/jive/ui/Widget.lua 
(original)
+++ 7.4/branches/pango/squeezeplay/src/squeezeplay/share/jive/ui/Widget.lua Thu 
Jan 22 06:35:04 2009
@@ -81,6 +81,7 @@
 local EVENT_HIDE    = jive.ui.EVENT_HIDE
 local EVENT_UPDATE  = jive.ui.EVENT_UPDATE
 local EVENT_CONSUME = jive.ui.EVENT_CONSUME
+local ACTION        = jive.ui.ACTION
 
 
 -- our class
@@ -409,27 +410,36 @@
 end
 
 
-function addActionListener(self, action, obj, sourceBreadCrumb, listener)
+function addActionListener(self, action, obj, listener)
        _assert(type(listener) == "function")
        
+       local callerInfo = "N/A"
+       if log:isDebug() then
+               callerInfo = Framework:callerToString()
+       end
        
        if not Framework:_getActionEventIndexByName(action) then
-               log:error("action name not registered:(" , action, "). 
Available actions: ", self:dumpActions() )
+               log:error("action name not registered:(" , action, "). 
Available actions: ", Framework:dumpActions() )
                return 
        end
-       log:debug("Creating widget action listener for action: (" , action, ") 
from source: ", sourceBreadCrumb)
+       log:debug("Creating widget action listener for action: (" , action, ") 
from source: ", callerInfo)
        
-       self:addListener(ACTION,
+       return self:addListener(ACTION,
                        function(event)
                                local eventAction = event:getAction()
                                if eventAction != action then
                                        return EVENT_UNUSED
                                end
-                               log:debug("Calling widget action listener for 
action: (" , action, ") from source: ", sourceBreadCrumb)
+                               log:debug("Calling widget action listener for 
action: (" , action, ") from source: ", callerInfo)
                                
                                local listenerResult = listener(obj, event)
                                --default to consume unless the listener 
specifically wants to set a specific event return
-                               return listenerResult and listenerResult or 
EVENT_CONSUME
+                               local eventResult = listenerResult and 
listenerResult or EVENT_CONSUME
+                               if eventResult == EVENT_CONSUME then
+                                       log:debug("Action (" , action, ") 
consumed by widget source: ", callerInfo)
+                               end
+                               return eventResult
+
                        end
        )
     

Modified: 
7.4/branches/pango/squeezeplay/src/squeezeplay/share/jive/ui/Window.lua
URL: 
http://svn.slimdevices.com/7.4/branches/pango/squeezeplay/src/squeezeplay/share/jive/ui/Window.lua?rev=3911&root=Jive&r1=3910&r2=3911&view=diff
==============================================================================
--- 7.4/branches/pango/squeezeplay/src/squeezeplay/share/jive/ui/Window.lua 
(original)
+++ 7.4/branches/pango/squeezeplay/src/squeezeplay/share/jive/ui/Window.lua Thu 
Jan 22 06:35:04 2009
@@ -103,6 +103,12 @@
 local Framework = require("jive.ui.Framework")
 
 
+function _bump(self)
+       self:playSound("BUMP")
+       self:getWindow():bumpRight()
+       return EVENT_CONSUME
+end
+
 --[[
 
 =head2 jive.ui.Window(style, title, titleStyle)
@@ -137,6 +143,9 @@
                                back = Button(
                                        Icon("back"), 
                                        function() 
+                                               --todo: might like to do the 
following, but would break back-compatibility
+                                               --Framework:dispatchEvent(obj, 
Framework:newActionEvent("back")) 
+                                               
                                                
obj:dispatchNewEvent(EVENT_KEY_PRESS, KEY_BACK) 
                                                return EVENT_CONSUME 
                                        end
@@ -146,6 +155,8 @@
                                        function() 
                                                -- check if player is connected
                                                if appletManager then
+                                                       --todo use this once we 
resolve bump handling
+                                                       
--Framework:dispatchEvent(obj, Framework:newActionEvent("go_now_playing"))
                                                        
obj:dispatchNewEvent(EVENT_KEY_PRESS, self:_goNowPlaying(obj))
                                                end
                                                return EVENT_CONSUME 
@@ -155,7 +166,9 @@
                )
        end
        
-       -- by default bump the window on GO or RIGHT, add this as a
+       obj:addActionListener("go", obj, _bump)
+       obj:addActionListener("back", obj, _bump)
+       -- by default bump the window on GO or BACK actions, add this as a
        -- listener to allow other handlers to act on these events
        -- first
        obj:addListener(EVENT_KEY_PRESS,

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

Reply via email to