Author: bklaas
Date: Wed Feb 20 13:21:23 2008
New Revision: 1988

URL: http://svn.slimdevices.com?rev=1988&root=Jive&view=rev
Log:
Bug: 7188
Description: 
do not load SetupWallpaper applet from within SlimBrowser
use playerCurrent notification in SetupWallpaper to set wallpaper
stop using underscored _methodNames for public methods to SetupWallpaper
refactor SetupWallpaper to not violate encapsulation

Modified:
    trunk/jive/src/pkg/jive/share/applets/SelectPlayer/SelectPlayerApplet.lua
    
trunk/jive/src/pkg/jive/share/applets/SetupWallpaper/SetupWallpaperApplet.lua
    trunk/jive/src/pkg/jive/share/applets/SetupWallpaper/SetupWallpaperMeta.lua
    trunk/jive/src/pkg/jive/share/applets/SlimBrowser/SlimBrowserApplet.lua

Modified: 
trunk/jive/src/pkg/jive/share/applets/SelectPlayer/SelectPlayerApplet.lua
URL: 
http://svn.slimdevices.com/trunk/jive/src/pkg/jive/share/applets/SelectPlayer/SelectPlayerApplet.lua?rev=1988&root=Jive&r1=1987&r2=1988&view=diff
==============================================================================
--- trunk/jive/src/pkg/jive/share/applets/SelectPlayer/SelectPlayerApplet.lua 
(original)
+++ trunk/jive/src/pkg/jive/share/applets/SelectPlayer/SelectPlayerApplet.lua 
Wed Feb 20 13:21:23 2008
@@ -146,8 +146,7 @@
 
        -- if numberOfPlayers < 2 and selectPlayerMenuItem exists, get rid of it
        elseif _numberOfPlayers < 2 and self.selectPlayerMenuItem then
-               -- FIXME, this probably won't work quite right with new main 
menu code
-               jiveMain:removeItem(self.selectPlayerMenuItem)
+               jiveMain:removeItemById('selectPlayer')
                self.selectPlayerMenuItem = nil
        end
 end
@@ -266,7 +265,7 @@
 
 function _showWallpaper(self, playerId)
        log:info("previewing background wallpaper for ", playerId)
-       SetupWallpaper:_setBackground(nil, playerId)
+       SetupWallpaper:showBackground(nil, playerId)
 end
 
 
@@ -451,7 +450,11 @@
 function free(self)
 
        -- load the correct wallpaper on exit
-       self:_showWallpaper(self.selectedPlayer.id)
+       if self.selectedPlayer and self.selectedPlayer:getId() then
+               self:_showWallpaper(self.selectedPlayer:getId())
+       else
+               self:_showWallpaper('wallpaper')
+       end
        
        AppletManager:freeApplet("SetupWallpaper")
        -- Never free this applet

Modified: 
trunk/jive/src/pkg/jive/share/applets/SetupWallpaper/SetupWallpaperApplet.lua
URL: 
http://svn.slimdevices.com/trunk/jive/src/pkg/jive/share/applets/SetupWallpaper/SetupWallpaperApplet.lua?rev=1988&root=Jive&r1=1987&r2=1988&view=diff
==============================================================================
--- 
trunk/jive/src/pkg/jive/share/applets/SetupWallpaper/SetupWallpaperApplet.lua 
(original)
+++ 
trunk/jive/src/pkg/jive/share/applets/SetupWallpaper/SetupWallpaperApplet.lua 
Wed Feb 20 13:21:23 2008
@@ -89,24 +89,44 @@
 
 local REFRESH_TIME = 300 -- only fetch remote wallpapers while browsing if the 
file is older than this (seconds)
 
+function init(self)
+       jnt:subscribe(self)
+end
+
+-- notify_playerCurrent
+-- this is called when the current player changes (possibly from no player)
+function notify_playerCurrent(self, player)
+        log:info("SetupWallpaper:notify_playerCurrent(", player, ")")
+       if player == self.player then
+               return
+       end
+
+       self.player = player
+       if player and player:getId() then
+               self:setBackground(nil, player:getId())
+       else
+               self:setBackground(nil, 'wallpaper')
+       end
+end
 
 function settingsShow(self)
        local window = Window("window", self:string('WALLPAPER'), 
'settingstitle')
 
-       self.currentPlayer = _getCurrentPlayer()
        self.currentPlayerId = 'wallpaper'
 
-       local _currentPlayer = self.currentPlayer
-       local _playerId      = self.currentPlayerid
        local _playerName    = false
 
-       if _currentPlayer then
-               _playerId      = _currentPlayer:getId()
-               _playerName    = _currentPlayer:getName()
-       end
-
-       if _playerName then
-               window:addWidget(Textarea("help", 
self:string("WALLPAPER_HELP_PLAYER", _playerName)))
+       if not self.player then
+               self.player = _getCurrentPlayer()
+       end
+
+       if self.player then
+               self.currentPlayerId = self.player:getId()
+               self.playerName    = self.player:getName()
+       end
+
+       if self.playerName then
+               window:addWidget(Textarea("help", 
self:string("WALLPAPER_HELP_PLAYER", self.playerName)))
        else
                window:addWidget(Textarea("help", 
self:string("WALLPAPER_HELP_NO_PLAYER")))
        end
@@ -114,9 +134,10 @@
        self.menu = SimpleMenu("menu")
        window:addWidget(self.menu)
 
-       local wallpaper = self:getSettings()[_playerId]
+       local wallpaper = self:getSettings()[self.currentPlayerId]
 
        self.server = self:_getCurrentServer()
+
        self.group  = RadioGroup()
 
        self.menu:setComparator(SimpleMenu.itemComparatorWeightAlpha)
@@ -130,12 +151,12 @@
                                icon = RadioButton("radio", 
                                                                   self.group, 
                                                                   function()
-                                                                          
self:_setBackground(file, _playerId)
+                                                                          
self:setBackground(file, self.currentPlayerId)
                                                                   end,
                                                                   wallpaper == 
file
                                                           ),
                                focusGained = function(event)
-                                                                 
self:_showBackground(file, _playerId)
+                                                                 
self:showBackground(file, self.currentPlayerId)
                                                          end
                        })
 
@@ -166,7 +187,7 @@
        -- Store the applet settings when the window is closed
        window:addListener(EVENT_WINDOW_POP,
                function()
-                       self:_showBackground(nil, _playerId)
+                       self:showBackground(nil, self.currentPlayerId)
                        self:storeSettings()
                end
        )
@@ -175,7 +196,6 @@
        return window
 end
 
-
 function _getCurrentPlayer(self)
        local manager = AppletManager:getAppletInstance("SlimDiscovery")
 
@@ -185,20 +205,19 @@
        return false
 end
 
-
 function _getCurrentServer(self)
-       local manager = AppletManager:getAppletInstance("SlimDiscovery")
+
        local server
-       if manager then
-               if manager:getCurrentPlayer() then
-                       server = manager:getCurrentPlayer():getSlimServer()
-               else
-                       for _, s in manager:allServers() do
-                               server = s
-                               break
-                       end
-               end
-       end
+       if self.player then
+               server = self.player:getSlimServer()
+       else
+               local manager = AppletManager:getAppletInstance("SlimDiscovery")
+               for _, s in manager:allServers() do
+                       server = s
+                       break
+               end
+       end
+
        return server
 end
 
@@ -220,7 +239,7 @@
                                                                                
   local path = Framework:findFile(PREFIX) .. entry.file
                                                                                
   local attr = lfs.attributes(path)
                                                                                
   if attr then
-                                                                               
           self:_setBackground(entry.file, self.currentPlayerId)
+                                                                               
           self:setBackground(entry.file, self.currentPlayerId)
                                                                                
   end
                                                                           end
                                                                   ),
@@ -229,7 +248,7 @@
                                                                          local 
attr = lfs.attributes(path)
                                                                          if 
attr and os.time() - attr.modification < REFRESH_TIME then
                                                                                
  log:info("using local copy of: ", entry.file)
-                                                                               
  self:_showBackground(entry.file, self.currentPlayerId)
+                                                                               
  self:showBackground(entry.file, self.currentPlayerId)
                                                                          else
                                                                                
  log:info("fetching: ", entry.file)
                                                                                
  local url
@@ -238,7 +257,7 @@
                                                                                
  else
                                                                                
          url = entry.url
                                                                                
  end
-                                                                               
  self:_fetchFile(url, path, function() self:_showBackground(entry.file, 
self.currentPlayerId) end)
+                                                                               
  self:_fetchFile(url, path, function() self:showBackground(entry.file, 
self.currentPlayerId) end)
                                                                          end
                                                                  end
                                }
@@ -266,7 +285,7 @@
                        window:addWidget(Textarea("textarea", text))
                        self:tieAndShowWindow(window)
                end,
-               focusGained = function(event) self:_showBackground(nil, 
self.currentPlayerId) end
+               focusGained = function(event) self:showBackground(nil, 
self.currentPlayerId) end
        }
 end
 
@@ -314,7 +333,7 @@
 end
 
 
-function _showBackground(self, wallpaper, playerId)
+function showBackground(self, wallpaper, playerId)
        if not playerId then playerId = 'wallpaper' end
        if not wallpaper then
                wallpaper = self:getSettings()[playerId]
@@ -336,14 +355,18 @@
 end
 
 
-function _setBackground(self, wallpaper, playerId)
-       if not playerId then playerId = 'wallpaper' end
+function setBackground(self, wallpaper, playerId)
+
+       if not playerId then 
+               playerId = 'wallpaper' 
+       end
+       log:info('SetupWallpaper, setting wallpaper for ', playerId)
        -- set the new wallpaper, or use the existing setting
        if wallpaper then
                self:getSettings()[playerId] = wallpaper
        end
 
-       self:_showBackground(wallpaper, playerId)
+       self:showBackground(wallpaper, playerId)
 end
 
 

Modified: 
trunk/jive/src/pkg/jive/share/applets/SetupWallpaper/SetupWallpaperMeta.lua
URL: 
http://svn.slimdevices.com/trunk/jive/src/pkg/jive/share/applets/SetupWallpaper/SetupWallpaperMeta.lua?rev=1988&root=Jive&r1=1987&r2=1988&view=diff
==============================================================================
--- trunk/jive/src/pkg/jive/share/applets/SetupWallpaper/SetupWallpaperMeta.lua 
(original)
+++ trunk/jive/src/pkg/jive/share/applets/SetupWallpaper/SetupWallpaperMeta.lua 
Wed Feb 20 13:21:23 2008
@@ -43,7 +43,7 @@
 function registerApplet(meta)
        -- load default wallpaper
        local obj = appletManager:loadApplet("SetupWallpaper")
-       obj:_setBackground(nil) -- nil is default from settings
+       obj:setBackground(nil) -- nil is default from settings
        appletManager:freeApplet("SetupWallpaper")
 
        -- add a menu item for configuration

Modified: 
trunk/jive/src/pkg/jive/share/applets/SlimBrowser/SlimBrowserApplet.lua
URL: 
http://svn.slimdevices.com/trunk/jive/src/pkg/jive/share/applets/SlimBrowser/SlimBrowserApplet.lua?rev=1988&root=Jive&r1=1987&r2=1988&view=diff
==============================================================================
--- trunk/jive/src/pkg/jive/share/applets/SlimBrowser/SlimBrowserApplet.lua 
(original)
+++ trunk/jive/src/pkg/jive/share/applets/SlimBrowser/SlimBrowserApplet.lua Wed 
Feb 20 13:21:23 2008
@@ -2028,7 +2028,7 @@
 end
 
 function notify_playerPlaylistChange(self, player)
-       log:warn('SlimBrowser.notify_playerPlaylistChange')
+       log:debug('SlimBrowser.notify_playerPlaylistChange')
        if _player ~= player then
                return
        end
@@ -2050,7 +2050,7 @@
 end
 
 function notify_playerTrackChange(self, player, nowplaying)
-       log:warn('SlimBrowser.notify_playerTrackChange')
+       log:debug('SlimBrowser.notify_playerTrackChange')
 
        if _player ~= player then
                return
@@ -2106,7 +2106,7 @@
 -- notify_playerCurrent
 -- this is called when the current player changes (possibly from no player)
 function notify_playerCurrent(self, player)
-       log:info("SlimBrowserApplet:notify_playerCurrent(", player, ")")
+       log:debug("SlimBrowserApplet:notify_playerCurrent(", player, ")")
 
        -- has the player actually changed?
        if _player == player then
@@ -2116,16 +2116,6 @@
        -- free current player
        if _player then
                self:free()
-       end
-
-       -- FIXME this is badly placed. the per player wallpaper now seems to
-       -- be split into three different applets (SelectPlayer, SetupWallpaper
-       -- and here). This should be refactored, preferably into one place
-       if not _player and player then
-               log:info("First load...get the correct wallpaper on screen")
-               local SetupWallpaper = 
AppletManager:loadApplet("SetupWallpaper")
-               SetupWallpaper:_setBackground(nil, player:getId())
-               AppletManager:freeApplet("SetupWallpaper")
        end
 
        -- clear any errors, we may have changed servers
@@ -2209,6 +2199,7 @@
 end
 
 function notify_playerNeedsUpgrade(self, player, needsUpgrade)
+       log:debug("SlimBrowserApplet:notify_playerNeedsUpgrade(", player, ")")
 
        if _player ~= player then
                return

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

Reply via email to