Author: bklaas
Date: Mon Apr 19 13:39:28 2010
New Revision: 8717

URL: http://svn.slimdevices.com/jive?rev=8717&view=rev
Log:
Bug: 15827
Description: First live checkin of new Media Manager framework
handling of media management now handled by a separate applet than 
SqueezeCenterApplet
service methods are defined in MediaManagerApplet that allow other applets to:
        1. add an item to the menu for an attached device
        2. register handlers for service methods to be run when a device is 
mounted
        3. register handlers for service methods to be run when a device is 
ejected
Behavior of Fab4 when a device is added is different than 7.5.0 now-- a menu of 
choices is presented to the user when a device is mounted rather than 
automatically starting up SqueezeCenter
There is more work to be done with this before 7.5.1 release, but this has been 
tested as initially okay for 7.5.1 nightly builds

Modified:
    
7.5/trunk/squeezeplay/src/squeezeplay/share/applets/ImageViewer/ImageViewerApplet.lua
    
7.5/trunk/squeezeplay/src/squeezeplay/share/applets/ImageViewer/ImageViewerMeta.lua
    
7.5/trunk/squeezeplay/src/squeezeplay_fab4/share/applets/MediaManager/MediaManagerApplet.lua
    
7.5/trunk/squeezeplay/src/squeezeplay_fab4/share/applets/MediaManager/MediaManagerMeta.lua
    
7.5/trunk/squeezeplay/src/squeezeplay_fab4/share/applets/SqueezeCenter/SqueezeCenterApplet.lua
    
7.5/trunk/squeezeplay/src/squeezeplay_fab4/share/applets/SqueezeCenter/SqueezeCenterMeta.lua
    
7.5/trunk/squeezeplay/src/squeezeplay_fab4/share/applets/SqueezeCenter/strings.txt

Modified: 
7.5/trunk/squeezeplay/src/squeezeplay/share/applets/ImageViewer/ImageViewerApplet.lua
URL: 
http://svn.slimdevices.com/jive/7.5/trunk/squeezeplay/src/squeezeplay/share/applets/ImageViewer/ImageViewerApplet.lua?rev=8717&r1=8716&r2=8717&view=diff
==============================================================================
--- 
7.5/trunk/squeezeplay/src/squeezeplay/share/applets/ImageViewer/ImageViewerApplet.lua
 (original)
+++ 
7.5/trunk/squeezeplay/src/squeezeplay/share/applets/ImageViewer/ImageViewerApplet.lua
 Mon Apr 19 13:39:28 2010
@@ -451,7 +451,6 @@
                )
 end
 
-
 --service method
 function unregisterRemoteScreensaver(self, id)
        appletManager:callService("removeScreenSaver", "ImageViewer", 
"openRemoteScreensaver", _, id)
@@ -475,6 +474,13 @@
                self.window = nil
        end
 end
+
+-- callback called from media manager
+function mmImageViewerMenu(self, devName)
+       log:info('mmImageViewerMenu: ', devName)
+       self:startSlideshow(false, ImageSourceLocalStorage(self, { path = 
'/media/' .. devName }))
+end
+
 
 function free(self)
        log:info("destructor of image viewer")

Modified: 
7.5/trunk/squeezeplay/src/squeezeplay/share/applets/ImageViewer/ImageViewerMeta.lua
URL: 
http://svn.slimdevices.com/jive/7.5/trunk/squeezeplay/src/squeezeplay/share/applets/ImageViewer/ImageViewerMeta.lua?rev=8717&r1=8716&r2=8717&view=diff
==============================================================================
--- 
7.5/trunk/squeezeplay/src/squeezeplay/share/applets/ImageViewer/ImageViewerMeta.lua
 (original)
+++ 
7.5/trunk/squeezeplay/src/squeezeplay/share/applets/ImageViewer/ImageViewerMeta.lua
 Mon Apr 19 13:39:28 2010
@@ -40,12 +40,25 @@
        meta:registerService("registerRemoteScreensaver")
        meta:registerService("unregisterRemoteScreensaver")
        meta:registerService("openRemoteScreensaver")
+       meta:registerService("mmImageViewerMenu")
 end
 
 
 function configureApplet(self)
-       appletManager:callService("addScreenSaver", 
self:string("IMAGE_VIEWER"), "ImageViewer",
-               "startScreensaver", self:string("IMAGE_VIEWER_SETTINGS"), 
"openSettings", 90, "closeRemoteScreensaver")
+       appletManager:callService("addScreenSaver",
+               self:string("IMAGE_VIEWER"),
+               "ImageViewer",
+               "startScreensaver",
+               self:string("IMAGE_VIEWER_SETTINGS"),
+               "openSettings",
+               90,
+               "closeRemoteScreensaver"
+       )
+
+       appletManager:callService("mmRegisterMenuItem", {
+               serviceMethod = "mmImageViewerMenu",
+               menuText      = self:string('IMAGE_VIEWER_START_SLIDESHOW')
+       })
 end
 
 

Modified: 
7.5/trunk/squeezeplay/src/squeezeplay_fab4/share/applets/MediaManager/MediaManagerApplet.lua
URL: 
http://svn.slimdevices.com/jive/7.5/trunk/squeezeplay/src/squeezeplay_fab4/share/applets/MediaManager/MediaManagerApplet.lua?rev=8717&r1=8716&r2=8717&view=diff
==============================================================================
--- 
7.5/trunk/squeezeplay/src/squeezeplay_fab4/share/applets/MediaManager/MediaManagerApplet.lua
 (original)
+++ 
7.5/trunk/squeezeplay/src/squeezeplay_fab4/share/applets/MediaManager/MediaManagerApplet.lua
 Mon Apr 19 13:39:28 2010
@@ -29,11 +29,12 @@
 oo.class(_M, Applet)
 
 function init(self)
-       self.mountedDevices           = self:getSettings()['mountedDevices']
        self.MOUNTING_DRIVE_TIMEOUT   = 60
        self.UNMOUNTING_DRIVE_TIMEOUT = 10
        self.WIPE_TIMEOUT             = 60
        self.supportedFormats         = {"FAT16","FAT32","NTFS","ext2","ext3"}
+       self.mmOnEjectHandlers        = {}
+       self.mmOnMountHandlers        = {}
        self.mmMenuItems              = {}
 end
 
@@ -61,28 +62,22 @@
                        log:debug('STARTUP | Create main menu item for ', k)
                        self:addMountedDevice(k, false)
                end
-       else
-               -- remove mounted devices from settings since we don't have any
-               self:getSettings()['mountedDevices'] = self.mountedDevices
-               self:storeSettings()
        end
 
 end
 
 
 function addMountedDevice(self, devName)
-       log:warn('addMountedDevice: ', devName)
+       log:info('addMountedDevice: ', devName)
        self.mountedDevices[devName] = {
                devName    = devName,
                deviceName = "/dev/"   .. devName,
                mountPath  = "/media/" .. devName,
                devType    = self:mediaType(devName),
        }
-       self:getSettings()['mountedDevices'] = self.mountedDevices
-       self:storeSettings()
 
        -- add menu item for this device
-       log:warn('addDeviceMenuItem(): ', devName)
+       log:info('addDeviceMenuItem(): ', devName)
 
        local iconStyle
        if self.mountedDevices[devName].devType == 'SD' then
@@ -114,34 +109,48 @@
 -- create and display a window that shows the items in the menu for devName
 function showMediaManagerWindow(self, devName)
 
-       log:warn('showMediaManagerWindow(): ', devName)
+       log:info('showMediaManagerWindow(): ', devName)
        local token = self:mediaType(devName)
        local window = Window('text_list', self:string(token))
        local menu = SimpleMenu("menu")
 
        -- go through mmMenuItems and add items to the menu
        for k, v in pairs(self.mmMenuItems) do
-               log:warn('adding menu item for ', k)
-
-               local callback = function() 
appletManager:callService(v.serviceMethod, devName, v.serviceMethodParams) end
-               local text
-               if v.menuToken then
-                       if v.devNameAsTokenArg then
-                               text = self:string(v.menuToken, 
self:mediaType(devName))
+               log:info('adding menu item for ', k)
+
+               local addThisItem = true
+               if v.onlyIfTrue or v.onlyIfFalse then
+                       if v.onlyIfTrue then
+                               log:info('onlyIfTrue method needs to return 
true to add this menu item')
+                               addThisItem = 
appletManager:callService(v.onlyIfTrue, devName)
+                       elseif v.onlyIfFalse then
+                               log:info('onlyIfFalse method needs to return 
false to add this menu item')
+                               addThisItem = not 
appletManager:callService(v.onlyIfFalse, devName)
+                       end
+                       log:info('---> addThisItem is now ', addThisItem)
+               end
+
+               if addThisItem then
+                       local callback = function() 
appletManager:callService(v.serviceMethod, devName, v.serviceMethodParams) end
+                       local text
+                       if v.menuToken then
+                               if v.devNameAsTokenArg then
+                                       text = self:string(v.menuToken, 
self:mediaType(devName))
+                               else
+                                       text = self:string(v.menuToken)
+                               end
                        else
-                               text = self:string(v.menuToken)
+                               text = v.menuText
                        end
-               else
-                       text = v.menuText
-               end
-
-               menu:addItem({
-                       text     = text,
-                       style    = v.itemStyle or 'item',
-                       weight   = v.weight or 50,
-                       sound    = "WINDOWSHOW",                
-                       callback = callback,
-               })
+
+                       menu:addItem({
+                               text     = text,
+                               style    = v.itemStyle or 'item',
+                               weight   = v.weight or 50,
+                               sound    = "WINDOWSHOW",                
+                               callback = callback,
+                       })
+               end
        end
        window:addWidget(menu)
        self:tieAndShowWindow(window)
@@ -187,9 +196,11 @@
 
 
 function mmGetMountedDevices(self)
+       log:info('mmGetMountedDevices()')
        if self.mountedDevices then
                return self.mountedDevices
        end
+       log:warn('no mounted devices found, returning false')
        return false
 end
 
@@ -237,10 +248,41 @@
 
        -- if there's an options.key, use that. otherwise, use 
options.serviceMethod
        local key = options.key or options.serviceMethod
-       log:warn('key for this item is set to: ', key)
+       log:info('key for this item is set to: ', key)
         self.mmMenuItems[key] = options
 
        return true
+end
+
+
+-- mmRegisterOnEjectHandler
+-- service method for registering service methods to be called at the time of 
a device eject
+-- by design, these methods are run before the device is unmounted
+function mmRegisterOnEjectHandler(self, options)
+       if not options.serviceMethod then
+               log:error('mmRegisterOnEjectHandler() called without a service 
method')
+               return false
+       end
+
+       local key = options.key or options.serviceMethod
+       log:info('adding an onEject handler for ', key)
+       self.mmOnEjectHandlers[key] = options
+
+end
+
+
+--mmRegisterOnMountHandler
+-- service method for registering service methods to be called at the time of 
a device eject
+-- by design, these methods are run before the device is unmounted
+function mmRegisterOnMountHandler(self, options)
+       if not options.serviceMethod then
+               log:error('mmRegisterOnMountHandler() called without a service 
method')
+               return false
+       end
+
+       local key = options.key or options.serviceMethod
+       self.mmOnMountHandlers[key] = options
+
 end
 
 
@@ -307,6 +349,10 @@
        if self.mountedDevices and self.mountedDevices[devName] then
                
                log:warn('!!! Drive ', self.mountedDevices[devName].deviceName, 
' was unsafely ejected.')
+
+               -- perform registered on eject methods first
+               self:_runOnEjectHandlers(devName)
+
                local window = Window("text_list", 
self:string("DEVICE_REMOVAL_WARNING"))
                window:setAllowScreensaver(false)
                local menu = SimpleMenu("menu")
@@ -333,9 +379,6 @@
 
                --Bug 15793, remove eject item from menu after bad eject
                self:removeMountedDevice(devName)
-
-               self:getSettings()['mountedDevices'] = self.mountedDevices
-               self:storeSettings()
                
                self:tieAndShowWindow(window)
                return window
@@ -356,11 +399,21 @@
 end
 
 
+function _runOnEjectHandlers(self, devName)
+
+       log:info('running registered on eject handlers')
+       for k, v in pairs(self.mmOnEjectHandlers) do
+               log:info('calling handler for ', k)
+               appletManager:callService(v.serviceMethod, devName, 
v.serviceMethodParams)
+       end
+end
+
+
 -- _unmountingDrive
 -- full screen popup that appears until unmounting is complete or failed
 function _unmountDrive(self, devName, force)
        
-       log:warn('_unmountDrive() ', devName)
+       log:info('_unmountDrive() ', devName)
 
        local item = self:_getItemFromDevName(devName)
 
@@ -370,6 +423,9 @@
                log:warn("no mountPath to eject item")
                return EVENT_UNUSED
        end
+
+       -- run the service handlers first
+       self:_runOnEjectHandlers(devName)
 
        self:_unmountActions(devName, _, force)
 
@@ -688,7 +744,7 @@
        for file in lfs.dir("/media") do
                local dummy = string.match(file, devName)
                if dummy then
-                       log:warn("media dir found: ", dummy)
+                       log:info("media dir found: ", dummy)
                        return true
                end
        end
@@ -761,6 +817,10 @@
        return window
 end
 
+function free(self)
+       return false
+end
+
 --[[
 
 =head1 LICENSE

Modified: 
7.5/trunk/squeezeplay/src/squeezeplay_fab4/share/applets/MediaManager/MediaManagerMeta.lua
URL: 
http://svn.slimdevices.com/jive/7.5/trunk/squeezeplay/src/squeezeplay_fab4/share/applets/MediaManager/MediaManagerMeta.lua?rev=8717&r1=8716&r2=8717&view=diff
==============================================================================
--- 
7.5/trunk/squeezeplay/src/squeezeplay_fab4/share/applets/MediaManager/MediaManagerMeta.lua
 (original)
+++ 
7.5/trunk/squeezeplay/src/squeezeplay_fab4/share/applets/MediaManager/MediaManagerMeta.lua
 Mon Apr 19 13:39:28 2010
@@ -1,8 +1,7 @@
-
 local oo            = require("loop.simple")
 
+local System        = require("jive.System")
 local AppletMeta    = require("jive.AppletMeta")
-
 local appletManager = appletManager
 local jiveMain      = jiveMain
 
@@ -16,7 +15,7 @@
 end
 
 
-function defaultSettings(meta)
+function defaultSettings(self)
        return {
                mountedDevices = {},
        }
@@ -24,24 +23,25 @@
 
 
 function registerApplet(meta)
---[[ disabled in subversion until ready to go live
        meta:registerService("mmRegisterMenuItem")
+       meta:registerService("mmRegisterOnEjectHandler")
+       meta:registerService("mmRegisterOnMountHandler")
        meta:registerService("mmStartupCheck")
        meta:registerService("udevEventHandler")
        meta:registerService("mmConfirmEject")
        meta:registerService("mmGetMountedDevices")
---]]
 end
 
 function configureApplet(meta)
+       meta:registerService("mmRegisterMenuItem")
 
---[[ disabled in subversion until ready to go live
         -- add an eject item to the submenu
         appletManager:callService("mmRegisterMenuItem", 
                 {
                         serviceMethod     = "mmConfirmEject",
                         menuToken         = "EJECT_DRIVE",
                         devNameAsTokenArg = true,
+                       weight            = 10, -- default is 50, so this will 
put it at/near the top
                 }
         )
 
@@ -53,7 +53,6 @@
                        appletManager:callService("udevEventHandler", evt, msg)
                end
        )
---]]
 
 end
 

Modified: 
7.5/trunk/squeezeplay/src/squeezeplay_fab4/share/applets/SqueezeCenter/SqueezeCenterApplet.lua
URL: 
http://svn.slimdevices.com/jive/7.5/trunk/squeezeplay/src/squeezeplay_fab4/share/applets/SqueezeCenter/SqueezeCenterApplet.lua?rev=8717&r1=8716&r2=8717&view=diff
==============================================================================
--- 
7.5/trunk/squeezeplay/src/squeezeplay_fab4/share/applets/SqueezeCenter/SqueezeCenterApplet.lua
 (original)
+++ 
7.5/trunk/squeezeplay/src/squeezeplay_fab4/share/applets/SqueezeCenter/SqueezeCenterApplet.lua
 Mon Apr 19 13:39:28 2010
@@ -23,6 +23,7 @@
 local Task                   = require("jive.ui.Task")
 local Timer                  = require("jive.ui.Timer")
 local Window                 = require("jive.ui.Window")
+local SlimServer             = require("jive.slim.SlimServer")
 
 local appletManager          = appletManager
 local jiveMain               = jiveMain
@@ -32,12 +33,7 @@
 oo.class(_M, Applet)
 
 function init(self)
-       self.mountedDevices = self:getSettings()['mountedDevices']
-       self.ejectItems     = {}
-       self.MOUNTING_DRIVE_TIMEOUT = 60
-       self.UNMOUNTING_DRIVE_TIMEOUT = 10
        self.WIPE_TIMEOUT = 60
-       self.supportedFormats = {"FAT16","FAT32","NTFS","ext2","ext3"}
        self.prefsFile = "/etc/squeezecenter/prefs.json"
 
        self.settingsMenuItems = {
@@ -69,10 +65,6 @@
 -- do the right thing on jive startup
 function squeezecenterStartupCheck(self)
 
-       -- the startup check is re-initializing which drives are mounted, so 
whatever is pulled from settings in init() needs clearing here first
-       self.mountedDevices = {}
-
-
        local mountedDrives       = self:mountedDriveCheck()
        local usbDrives           = {}
        local sdDrives            = {}
@@ -102,8 +94,6 @@
                        -- mountpath represents a mounted drive
                        if mountedDrives[devName] then 
                                log:debug('STARTUP (3A)| prefs.json mountpath 
represents a mounted drive')
-                               -- store device in self.mountedDevices
-                               self:addMountedDevice(devName, true)
                        -- mountpath represents an umounted drive
                        else
                                log:debug('STARTUP (3B)| prefs.json mountpath 
is not a mounted drive')
@@ -117,7 +107,6 @@
                                end
                                -- write prefs.json
                                log:debug('STARTUP (5)| Write prefs.json file')
-                               self:addMountedDevice(scDrive, true)
                                self:_writeSCPrefsFile(scDrive)
 
                        end
@@ -135,26 +124,14 @@
                        end
                        -- write prefs.json
                        log:debug('STARTUP (5)| Write prefs.json file')
-                       self:addMountedDevice(scDrive, true)
                        self:_writeSCPrefsFile(scDrive)
                end
 
                log:debug('STARTUP (6)| Restart Server')
                self:restartServer(true)
 
-               -- populate non-SC mounted drives to self.mountedDevices
-               -- create menu items for each
-               for k, v in pairs(mountedDrives) do
-                       if not self.mountedDevices[k] then
-                               self:addMountedDevice(k, false)
-                       end
-                       log:debug('STARTUP (7)| Create eject item for ', k)
-                       self:_addEjectDeviceItem(k)
-               end
        else
-               -- remove mounted devices from settings since we don't have any
-               self:getSettings()['mountedDevices'] = self.mountedDevices
-               self:storeSettings()
+               -- nothing right now
        end
 
 end
@@ -167,20 +144,75 @@
 end
 
 
-function addMountedDevice(self, devName, isSCDrive)
-       log:warn('addMountedDevice: ', devName)
-       self.mountedDevices[devName] = {
-               devName    = devName,
-               deviceName = "/dev/"   .. devName,
-               mountPath  = "/media/" .. devName,
-               devType    = self:mediaType(devName),
-               SCDrive    = isSCDrive,
-       }
-       self:getSettings()['mountedDevices'] = self.mountedDevices
-       self:storeSettings()
-       --debug.dump(self.mountedDevices)
-       return true
-end
+function mmSqueezeCenterMenu(self, devName)
+
+       log:info('mmSqueezeCenterMenu: ', devName)
+       -- we decide which menu to present based on whether this drive is the 
SC drive and whether SBS is running
+
+       -- server is running
+       if self:serverRunning() then
+               -- and pointed to this devName
+               if self:_scDrive() == devName then
+                       log:info('SBS running and pointed to this device')
+                       -- deliver status menu
+                       self:settingsShow()
+               -- but not pointed to this devName
+               else
+                       log:info('SBS running but not pointed to this device: ')
+                       self:switchServerToDifferentMedia(devName)
+               end
+       else
+               -- present option to start it
+               log:info('SBS not running')
+               self:settingsShow()
+
+       end
+end
+
+
+function switchServerToDifferentMedia(self, devName)
+
+       self.devName = devName
+
+       -- Squeezebox Server is Squeezebox Server in all langs, so no need to 
translate title text
+       local window = Window("text_list", 'Squeezebox Server')
+       
+       window:setAllowScreensaver(false)
+       local menu = SimpleMenu("menu")
+
+       menu:setHeaderWidget( Textarea("help_text", 
self:string('SWITCH_MEDIA_HELP')))
+
+       menu:addItem({
+               text = self:string( 'SWITCH_MEDIA', self:mediaType(devName) ),
+               sound = "WINDOWSHOW",
+               callback = function()
+                       self:_writeSCPrefsFile(self.devName)
+                       
+--[[ we should be able to just change the audiodir pref - don't know why it 
doesn't work...
+                       local server = SlimServer:getCurrentServer()
+                       server:request(function(chunk, err)
+                               debug.dump(chunk.data)
+                               log:debug(err)
+                       end, nil, {'pref', 'audiodir', '/media/' .. devName})
+                       window:hide()
+--]]
+                       self:restartServer()
+               end,
+       })
+       menu:addItem({
+               text = self:string("CANCEL"),
+               sound = "WINDOWHIDE",
+               callback = function() 
+                       window:hide()
+               end
+       })
+
+       window:addWidget(menu)
+       
+       self:tieAndShowWindow(window)
+       return window
+end
+
 
 function settingsShow(self)
        -- Squeezebox Server is Squeezebox Server in all langs, so no need to 
translate title text
@@ -266,6 +298,7 @@
                                        local scanData = self:_scanStatus()
                                        if count > 5 and ( scanData or count == 
60) then
                                                popup:hide()
+                                               Framework:pushAction("go_home")
                                        end
                                end
                        )
@@ -392,118 +425,14 @@
        return false
 end
 
--- _mountingDrive
--- full screen popup that appears until mounting is complete or failed
----function _mountingDrive(self)
-function _mountingDrive(self, devName)
-       log:debug('**** popup during drive mount')
-       if self.popupMountWaiting then
-               return
-       end
-
-        local popup = Popup("waiting_popup")
-        local icon  = Icon("icon_connecting")
-
-       -- set self.devType var based on devName during the _mountingDrive 
method
-       self.devType = self:mediaType(devName)
-       self.mountingDriveTimeout = 0
-
-       icon:addTimer(1000,
-               function()
-                       _mountingDriveTimer(self, devName)
-               end)
-
-        popup:addWidget(icon)
-
-       local label = Label("text", self:string('ATTACHING') )
-       popup:addWidget(label)
-
-       local token = 'DEVICE'
-       if self.devType then
-               token = self.devType
-       end
-       local sublabel = Label("subtext", self:string(token) )
-       popup:addWidget(sublabel)
-
-        --make sure this popup remains on screen
-       popup:setAllowScreensaver(false)
-       popup:setAlwaysOnTop(true)
-       popup:setAutoHide(false)
-       popup:setTransparent(false)
-       popup:ignoreAllInputExcept()
-
-       self.popupMountWaiting = popup
-       self:tieAndShowWindow(popup)
-       return popup
-end
-
-
--- _deviceRemoval
--- kicked off when udev listener detects a device removal
--- checks if device is still in mount table, 
--- if so push on the DON'T DO THAT window, stop SC if drive was attached to SC
----function _mountingDrive(self)
-function _deviceRemoval(self, devName)
-
-       -- if devName is still in the self.mountedDevices table, consider this 
an unsafe eject
-       if self.mountedDevices and self.mountedDevices[devName] then
-               
-               --Bug 15793, remove eject item from menu after bad eject
-               self:_removeEjectDeviceItem(devName)
-
-               log:warn('!!! Drive ', self.mountedDevices[devName].deviceName, 
' was unsafely ejected.')
-               local window = Window("text_list", 
self:string("DEVICE_REMOVAL_WARNING"))
-               window:setAllowScreensaver(false)
-               local menu = SimpleMenu("menu")
-               menu:addItem({
-                       text = self:string("OK"),
-                       style = 'item',
-                       sound = "WINDOWSHOW",           
-                       callback = function ()
-                               if self.ejectWarningWindow then
-                                       self.ejectWarningWindow:hide()
-                                       self.ejectWarningWindow = nil
-                               end
-                               window:hide()
-                       end
-               })
-
-               local token = 'DEVICE_REMOVAL_WARNING_INFO'
-               if self.mountedDevices[devName].devType then
-                       token = token .. '_' .. 
self.mountedDevices[devName].devType
-               end
-       
-               menu:setHeaderWidget( Textarea("help_text", self:string(token) 
) )
-               window:addWidget(menu)
-
-               if self.mountedDevices[devName].SCDrive then
-                       log:warn('SqueezeCenter drive was improperly ejected. 
Stopping SqueezeCenter')
-                       self:_stopServer(silent)
-               end
-
-               self.mountedDevices[devName] = nil
-               self:getSettings()['mountedDevices'] = self.mountedDevices
-               self:storeSettings()
-               
-               self:tieAndShowWindow(window)
-               return window
-       end
-
-end
-
-
-function _unmountActions(self, devName, silent, force)
-
-       local item = self:_getItemFromDevName(devName)
-       if item.SCDrive then
-               self:_stopServer(silent)
+
+function mmStopSqueezeCenter(self, devName)
+
+       if devName == self:_scDrive() then
+               log:warn('stopping server pointed to ', devName)
+               self:_stopServer()
        else
-               log:debug('This is not the SCDrive, so ')
-       end
-       if force then
-               os.execute("umount -l /media/" .. devName)
-       else
-               os.execute("umount /media/" .. devName)
+               log:warn('devName ', devName, ' does not equal ', self.SCDrive)
        end
 
 end
@@ -523,285 +452,9 @@
 end
 
 
--- _unmountingDrive
--- full screen popup that appears until unmounting is complete or failed
-function _unmountDrive(self, devName, force)
-       
-       log:warn('_unmountDrive() ', devName)
-
-       local item = self:_getItemFromDevName(devName)
-
-
-       -- require that we have an item.devPath to eject
-       if not item.mountPath then
-               log:warn("no mountPath to eject item")
-               return EVENT_UNUSED
-       end
-
-       self:_unmountActions(devName, _, force)
-
-       if self.popupUnmountWaiting then
-               return
-       end
-
-        local popup = Popup("waiting_popup")
-        local icon  = Icon("icon_connecting")
-
-       -- set self.devType var based on devName during the _mountingDrive 
method
-       self.devType = self:mediaType(devName)
-       self.unmountingDriveTimeout = 0
-
-       icon:addTimer(1000,
-               function()
-                       _unmountingDriveTimer(self, devName)
-               end)
-
-        popup:addWidget(icon)
-
-       local label = Label("text", self:string('EJECTING') )
-       popup:addWidget(label)
-
-       local token = 'DEVICE'
-       if self.devType then
-               token = self.devType
-       end
-       local sublabel = Label("subtext", self:string(token) )
-       popup:addWidget(sublabel)
-
-       -- Bug: 15741 - Media ejection SD and USB unreliable
-       -- Make sure this popup remains on screen until drive
-       -- is successfully ejected or a timeout occurs.
-       popup:setAllowScreensaver(false)
-       popup:setAlwaysOnTop(true)
-       popup:setAutoHide(false)
-       popup:setTransparent(false)
-       popup:ignoreAllInputExcept()
-
-       self.popupUnmountWaiting = popup
-       self:tieAndShowWindow(popup)
-       return popup
-end
-
-
-function _mountingDriveTimer(self, devName)
-       local mounted = false
-
-       Task("mountingDrive", self, function()
-               log:debug("mountingDriveTimeout=", self.mountingDriveTimeout)
-
-               mounted = self:checkDriveMounted(devName)
-
-               if mounted then
-                       -- success
-                       log:debug("*** Device mounted sucessfully.")
-
-
-                       -- store device in self.mountedDevices
-                       local isScDrive = true
-                       for k, v in pairs (self.mountedDevices) do
-                               if v.SCDrive then
-                                       isScDrive = false
-                               end
-                       end
-
-                       self:addMountedDevice(devName, isScDrive)
-
-                       self:_addEjectDeviceItem(devName)
-                       self:_ejectWarning(devName)
-               else
-                       -- Not yet mounted
-                       self.mountingDriveTimeout = self.mountingDriveTimeout + 
1
-                       if self.mountingDriveTimeout <= 
self.MOUNTING_DRIVE_TIMEOUT then
-                               return
-                       end
-
-                       -- failure
-                       log:warn("*** Device failed to mount.")
-
-                       self:_unsupportedDiskFormat()
-               end
-
-               self.popupMountWaiting:hide()
-               self.popupMountWaiting = nil
-
-       end):addTask()
-end
-
-
-function _unmountingDriveTimer(self, devName)
-       local unmounted = false
-
-       Task("unmountingDrive", self, function()
-               log:debug("unmountingDriveTimeout=", 
self.unmountingDriveTimeout)
-
-               unmounted = not self:checkDriveMounted(devName)
-
-               if unmounted then
-                       -- success
-                       log:warn("*** Device ", devName, " unmounted 
sucessfully.")
-
-                       self:_removeEjectDeviceItem(devName)
-
-                       -- rmdir cleanup of /media/devName, as stale dirs 
appear to be a problem after umount
-                       if self:_mediaDirExists(devName) then
-                               lfs.rmdir("/media/" .. devName)
-                       end
-
-                       self:_unmountSuccess(devName)
-
-               else
-                       -- Not yet unmounted
-                       self.unmountingDriveTimeout = 
self.unmountingDriveTimeout + 1
-                       if self.unmountingDriveTimeout <= 
self.UNMOUNTING_DRIVE_TIMEOUT then
-                               log:warn("*** Device failed to unmount. try 
again")
-                               log:warn("*** self.unmountingDriveTimeout: ", 
self.unmountingDriveTimeout)
-                               log:warn("*** self.UNMOUNTING_DRIVE_TIMEOUT: ", 
self.UNMOUNTING_DRIVE_TIMEOUT)
-                               -- try again
-                               self:_unmountActions(devName, true)
-                               return
-                       end
-
-                       -- failure
-                       log:warn("*** Device failed to unmount.")
-
-                       self:_unmountFailure(devName)
-               end
-
-               self.popupUnmountWaiting:hide()
-               self.popupUnmountWaiting = nil
-
-       end):addTask()
-end
-
-
-function _unmountSuccess(self, devName)
-       log:debug('_unmountSuccess()')
-       local item = self:_getItemFromDevName(devName)
-       local token = 'DEVICE_EJECTED_INFO'
-       if item.devType then
-               token = token .. "_" .. item.devType
-       end
-
-       if self.confirmEjectWindow then
-               self.confirmEjectWindow:hide()
-               self.confirmEjectWindow = nil
-       end
-
-
-       -- clear device from self.mountedDevices
-       if self.mountedDevices and self.mountedDevices[devName] then
-               self.mountedDevices[devName] = nil
-       end
-
-
-       local window = Window("text_list", self:string("DEVICE_EJECTED"))
-       window:setAllowScreensaver(false)
-       window:setButtonAction("rbutton", nil)
-
-       local menu = SimpleMenu("menu")
-
-       menu:addItem({
-               text = self:string("OK"),
-               style = 'item',
-               sound = "WINDOWSHOW",           
-               callback = function ()
-                       if self.ejectWarningWindow then
-                               self.ejectWarningWindow:hide()
-                               self.ejectWarningWindow = nil
-                       end
-                       window:hide()
-               end
-       })
-
-       menu:setHeaderWidget( Textarea("help_text", self:string(token) ) )
-
-       window:addWidget(menu)
-
-       self:tieAndShowWindow(window)
-       return window
-end
-
-
--- TODO
-function _unmountFailure(self, devName)
-       log:warn('_unmountFailure()')
-
-       local window = Window("text_list", self:string("EJECT_FAILURE"))
-       window:setAllowScreensaver(false)
-       window:setButtonAction("rbutton", nil)
-
-       local menu = SimpleMenu("menu")
-
-       menu:addItem({
-               text = self:string("OK"),
-               style = 'item',
-               sound = "WINDOWSHOW",           
-               callback = function ()
-                       window:hide()
-               end
-       })
-       menu:addItem({
-               text = self:string("EJECT_TRY_AGAIN"),
-               style = 'item',
-               sound = "WINDOWSHOW",           
-               callback = function ()
-                       -- force the umount with -l
-                       window:hide()
-                       self:_unmountDrive(devName, true)
-               end
-       })
-
-
-       menu:setHeaderWidget( Textarea("help_text", 
self:string('EJECT_FAILURE_INFO') ) )
-
-       window:addWidget(menu)
-
-       self:tieAndShowWindow(window)
-       return window
-end
-
-
-function _removeEjectDeviceItem(self, devName)
-       log:debug('_removeEjectDeviceItem()')
-       if self.ejectItems and self.ejectItems[devName] then
-               log:debug('removing menu item for ', devName)
-               jiveMain:removeItem(self.ejectItems[devName])
-               self.ejectItems[devName] = nil
-       else
-               -- bug 15739: since self.ejectItems can be freed from memory, 
try to remove the item by the home menu id, which is devName
-               log:warn('attempt to remove item by id: ', devName)
-               jiveMain:removeItemById(devName)
-       end
-end
-
-
-function _addEjectDeviceItem(self, devName)
-
-       log:debug('_addEjectDeviceItem(): ', devName)
-
-       local item = self.mountedDevices and self.mountedDevices[devName]
-
-       local token = 'EJECT_CONFIRM_ITEM'
-       if item.devType then
-               token = 'EJECT_' .. item.devType
-       end
-
-       self.ejectItems[devName] = {
-                id = item.devName,
-                node = "home",
-                text = self:string(token),
-                iconStyle = 'hm_eject',
-                weight = 5,
-               sound = "WINDOWSHOW",           
-                --weight = 1000,
-               -- TODO: add a method to eject the device (that works!)
-               callback = function()
-                       self:_confirmEject(devName)
-               end,
-        }
-       jiveMain:addItem(self.ejectItems[devName])
-end
-
+function startSqueezeCenter(self)
+       self:_startServerWindow()
+end
 
 function _confirmWipeRescan(self)
        log:debug('confirmWipeRescan()')
@@ -896,7 +549,8 @@
 function _startServerWindow(self)
 
        local mountedDrives = 0
-       for k, v in pairs(self.mountedDevices) do
+       local mountedDevices = appletManager:callService("mmGetMountedDevices")
+       for k, v in pairs(mountedDevices) do
                mountedDrives = mountedDrives + 1
        end
 
@@ -919,6 +573,11 @@
                menu:setHeaderWidget( Textarea("help_text", 
self:string('NO_DRIVES_DETECTED_INFO')))
 
        elseif mountedDrives == 1 then
+               for devName, item in pairs(mountedDevices) do
+                       log:warn('writing ', devName, ' to SC prefs file')
+                       self:_writeSCPrefsFile(devName)
+                       break --table is 1 element long, but breaking here 
can't hurt
+               end
                self:_squeezecenterAction("icon_connecting", 
"STARTING_SQUEEZECENTER", nil, 5000, "start")
                return EVENT_CONSUMED
 
@@ -934,7 +593,7 @@
                        },
                })
 
-               for devName, item in pairs(self.mountedDevices) do
+               for devName, item in pairs(mountedDevices) do
                        local iconStyle = 'hm_usbdrive'
                        local menuItemToken = 'USE_DRIVE_USB'
                        if self:mediaType(devName) == 'SD' then
@@ -991,49 +650,10 @@
 end
 
 
-function _confirmEject(self, devName)
-       log:debug('confirmEject()')
-       local item = self:_getItemFromDevName(devName)
-
-       local titleToken   = 'EJECT_CONFIRM'
-       local confirmToken = 'EJECT_CONFIRM_INFO'
-       local ejectToken   = 'EJECT_REMOVABLE_MEDIA'
-
-       if item and item.devType then
-               titleToken   = 'EJECT_CONFIRM_' .. item.devType
-               confirmToken = 'EJECT_CONFIRM_INFO_' .. item.devType
-               ejectToken   = 'EJECT_DRIVE_' .. item.devType
-       end
-       local window = Window("text_list", self:string(titleToken) )
-       local menu = SimpleMenu("menu", {
-                       {
-                               text = self:string("CANCEL"),
-                               sound = "WINDOWHIDE",
-                               callback = function() 
-                                       window:hide()
-                               end
-                       },
-                       {
-                               text = self:string(ejectToken, item.devName),
-                               sound = "WINDOWSHOW",
-                               callback = function() 
-                                       -- eject drive
-                                       self:_unmountDrive(devName)
-                               end
-                       },
-       })
-
-       menu:setHeaderWidget( Textarea("help_text", self:string(confirmToken, 
item.devName) ) )
-       window:addWidget(menu)
-       self.confirmEjectWindow = window
-       self:tieAndShowWindow(window)
-       return window
-end
-
-
 function _getItemFromDevName(self, devName)
-       return self.mountedDevices and 
-               self.mountedDevices[devName]
+       local mountedDevices = appletManager:callService("mmGetMountedDevices")
+       return mountedDevices and 
+               mountedDevices[devName]
 end
 
 
@@ -1075,12 +695,12 @@
        for f in lfs.dir(scDrive) do
                present = string.match(f, "^\.Squeezebox")
                if present then
-                       log:warn("squeezeboxDirPresent(), found it: ", present)
+                       log:info("squeezeboxDirPresent(), found it: ", present)
                        break
                end
        end
 
-       log:warn(scDrive, "/.Squeezebox present: ", present)
+       log:info(scDrive, "/.Squeezebox present: ", present)
 
        if present then
                return true
@@ -1107,7 +727,7 @@
        for file in lfs.dir("/media") do
                local dummy = string.match(file, devName)
                if dummy then
-                       log:warn("media dir found: ", dummy)
+                       log:info("media dir found: ", dummy)
                        return true
                end
        end
@@ -1116,53 +736,8 @@
 end
 
 
--- Not supported disk format error message
-function _unsupportedDiskFormat(self)
-       local window = Window("text_list", 
self:string("UNSUPPORTED_DISK_FORMAT"))
-       window:setAllowScreensaver(false)
-       window:setButtonAction("rbutton", nil)
-
-       local menu = SimpleMenu("menu")
-
-       menu:addItem({
-               text = self:string("OK"),
-               style = 'item',
-               sound = "WINDOWSHOW",           
-               callback = function ()
-                       window:hide()
-               end
-       })
-
-       local formatsString = table.concat(self.supportedFormats, ", ")
-
-       local token = 'UNSUPPORTED_DISK_FORMAT_INFO'
-       if self.devType then
-               token = 'UNSUPPORTED_DISK_FORMAT_INFO_' .. self.devType
-       end
-       menu:setHeaderWidget( Textarea("help_text", self:string(token, 
formatsString) ) )
-
-       window:addWidget(menu)
-
-       self:tieAndShowWindow(window)
-       return window
-end
-
-
--- Ejection Warning for new USB/SD drives
-function _ejectWarning(self, devName)
-
-       local item = self:_getItemFromDevName(devName)
-
-       local window = Window("text_list", self:string("EJECT_WARNING"))
-       window:setAllowScreensaver(false)
-       window:setButtonAction("rbutton", nil)
-
-       local menu = SimpleMenu("menu")
-
-
-       if item.SCDrive then
-
-
+
+--[[
                -- Server status
                menu:addItem({
                        text = self:string("SERVER_STATUS"),
@@ -1173,6 +748,7 @@
                                window:hide()
                        end,
                })
+--]]
 
                -- My Music
                --[[ FIXME: does not provide a positive user experience yet. 
Going to My Music when scan is just starting yields not good behavior
@@ -1195,75 +771,45 @@
                })
                --]]
 
-               -- Eject item
-               local ejectToken = 'EJECT_CONFIRM_ITEM'
-               if item.devType then
-                       ejectToken = 'EJECT_' .. item.devType
-               end
-               menu:addItem({
-                       text = self:string(ejectToken),
-                       iconStyle = 'hm_eject',
-                       sound = "WINDOWSHOW",           
-                       callback = function()
-                               self:_confirmEject(devName)
-                       end,
-               })
-       else
-               menu:addItem({
-                       text = self:string("OK"),
-                       style = 'item',
-                       sound = "WINDOWSHOW",           
-                       callback = function()
-                               window:hide()
-                       end,
-               })
-       end
-
-       menu:setHeaderWidget(Textarea("help_text", 
self:string("EJECT_WARNING_INFO")))
-
-       window:addWidget(menu)
-       self.ejectWarningWindow = window
-       self:tieAndShowWindow(window)
-
+
+--[[
        -- restart the server
        if item.SCDrive then
                log:warn('!! Writing prefs.json file and starting scan')
                self:_writeSCPrefsFile(devName)
                self:restartServer()
        end
-
-       return window
-end
+--]]
 
 function _writeSCPrefsFile(self, devName)
-       local item = self:_getItemFromDevName(devName)
-       if not item then
-               self:addMountedDevice(devName, true)
-               item = self:_getItemFromDevName(devName)
-       end
-       if item.mountPath then
-               local exportTable = {
-                       audiodir = item.mountPath, -- audiodir could be changed 
in the future to a user-configured subdir of the mounted drive
-                       mountpath = item.mountPath
-               }
-               local forExport = json.encode(exportTable)
-               
-               local fh = io.open(self.prefsFile, "w")
-
-               if fh == nil then
-                       return false
-               end
-
-               fh:write(forExport)
-               fh:close()
-       end
+
+       if not devName then
+               log:error('_writeSCPrefsFile requires devName ', devName)
+               return
+       end
+
+       local exportTable = {
+               audiodir = "/media/" .. devName, -- audiodir could be changed 
in the future to a user-configured subdir of the mounted drive
+               mountpath = "/media/" .. devName,
+               devName   = devName 
+       }
+       local forExport = json.encode(exportTable)
+       
+       local fh = io.open(self.prefsFile, "w")
+
+       if fh == nil then
+               return false
+       end
+
+       fh:write(forExport)
+       fh:close()
 end
 
 
 function _scDrive(self)
        local prefsData = self:readSCPrefsFile()
-       if prefsData.mountpath then
-               return prefsData.mountpath
+       if prefsData.devName then
+               return prefsData.devName
        else
                return false
        end

Modified: 
7.5/trunk/squeezeplay/src/squeezeplay_fab4/share/applets/SqueezeCenter/SqueezeCenterMeta.lua
URL: 
http://svn.slimdevices.com/jive/7.5/trunk/squeezeplay/src/squeezeplay_fab4/share/applets/SqueezeCenter/SqueezeCenterMeta.lua?rev=8717&r1=8716&r2=8717&view=diff
==============================================================================
--- 
7.5/trunk/squeezeplay/src/squeezeplay_fab4/share/applets/SqueezeCenter/SqueezeCenterMeta.lua
 (original)
+++ 
7.5/trunk/squeezeplay/src/squeezeplay_fab4/share/applets/SqueezeCenter/SqueezeCenterMeta.lua
 Mon Apr 19 13:39:28 2010
@@ -24,23 +24,40 @@
 
 
 function registerApplet(meta)
-       jiveMain:addItem(meta:menuItem('appletSqueezeCenter', 
'advancedSettings', "Squeezebox Server", function(applet, ...) 
applet:settingsShow(...) end))
-       meta:registerService("udevEventHandler")
+       meta:registerService("mmSqueezeCenterMenu")
        meta:registerService("squeezecenterStartupCheck")
        meta:registerService("isBuiltInSCRunning")
        meta:registerService("stopSqueezeCenter")
+       meta:registerService("startSqueezeCenter")
+       meta:registerService("mmStopSqueezeCenter")
+       jiveMain:addItem(meta:menuItem('appletSqueezeCenter', 
'advancedSettings', "Squeezebox Server", function(applet, ...) 
applet:settingsShow(...) end))
+
 end
 
 function configureApplet(meta)
 
+       appletManager:callService("mmRegisterMenuItem", 
+               {
+               serviceMethod = "mmSqueezeCenterMenu",
+               menuText      = meta:string('SQUEEZEBOX_SERVER'),
+               onlyIfTrue    = "isBuiltInSCRunning",
+               weight        = 20,
+               }
+       )
+       appletManager:callService("mmRegisterMenuItem", 
+               {
+               serviceMethod = "startSqueezeCenter",
+               menuText      = meta:string('START'),
+               onlyIfFalse   = "isBuiltInSCRunning",
+               weight        = 20,
+               }
+       )
+       appletManager:callService("mmRegisterOnEjectHandler", 
+               {
+               serviceMethod = "mmStopSqueezeCenter"
+               }
+       )
        appletManager:callService("squeezecenterStartupCheck")
-
-       -- listen for attached drives after boot
-       appletManager:callService("addUeventListener", "", 
-               function(evt, msg)
-                       appletManager:callService("udevEventHandler", evt, msg)
-               end
-       )
 
 end
 

Modified: 
7.5/trunk/squeezeplay/src/squeezeplay_fab4/share/applets/SqueezeCenter/strings.txt
URL: 
http://svn.slimdevices.com/jive/7.5/trunk/squeezeplay/src/squeezeplay_fab4/share/applets/SqueezeCenter/strings.txt?rev=8717&r1=8716&r2=8717&view=diff
==============================================================================
--- 
7.5/trunk/squeezeplay/src/squeezeplay_fab4/share/applets/SqueezeCenter/strings.txt
 (original)
+++ 
7.5/trunk/squeezeplay/src/squeezeplay_fab4/share/applets/SqueezeCenter/strings.txt
 Mon Apr 19 13:39:28 2010
@@ -1606,3 +1606,9 @@
        PL      Uruchom pokaz slajdów
        RU      Запустить слайд-шоу
        SV      Påbörja bildspel
+
+SWITCH_MEDIA_HELP
+       EN      Squeezebox Server is running but is currently configured to 
serve music from a different device. From this menu you can choose to point to 
a different drive.
+
+SWITCH_MEDIA
+       EN      Use %s for Squeezebox Server 

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

Reply via email to