Author: bklaas
Date: Mon May  5 15:09:05 2008
New Revision: 2419

URL: http://svn.slimdevices.com?rev=2419&root=Jive&view=rev
Log:
Bug: 5366
Description: Add customize home menu applet

This applet should now be fully functional according to what is requested in 
the bug

Modified:
    7.1/trunk/squeezeplay/src/squeezeplay/Makefile.am
    
7.1/trunk/squeezeplay/src/squeezeplay/share/applets/CustomizeHomeMenu/CustomizeHomeMenuApplet.lua
    
7.1/trunk/squeezeplay/src/squeezeplay/share/applets/CustomizeHomeMenu/strings.txt
    7.1/trunk/squeezeplay/src/squeezeplay/share/jive/ui/HomeMenu.lua

Modified: 7.1/trunk/squeezeplay/src/squeezeplay/Makefile.am
URL: 
http://svn.slimdevices.com/7.1/trunk/squeezeplay/src/squeezeplay/Makefile.am?rev=2419&root=Jive&r1=2418&r2=2419&view=diff
==============================================================================
--- 7.1/trunk/squeezeplay/src/squeezeplay/Makefile.am (original)
+++ 7.1/trunk/squeezeplay/src/squeezeplay/Makefile.am Mon May  5 15:09:05 2008
@@ -284,6 +284,12 @@
        share/applets/InfoBrowser/InfoBrowserApplet.lua \
        share/applets/InfoBrowser/InfoBrowserMeta.lua \
        share/applets/InfoBrowser/strings.txt
+
+applets_customizehomemenudir = $(pkgdatadir)/applets/CustomizeHomeMenu
+dist_applets_customizehomemenu_DATA = \
+       share/applets/CustomizeHomeMenu/CustomizeHomeMenuApplet.lua \
+       share/applets/CustomizeHomeMenu/CustomizeHomeMenuMeta.lua \
+       share/applets/CustomizeHomeMenu/strings.txt
 
 applets_nowplayingdir = $(pkgdatadir)/applets/NowPlaying
 dist_applets_nowplaying_DATA = \

Modified: 
7.1/trunk/squeezeplay/src/squeezeplay/share/applets/CustomizeHomeMenu/CustomizeHomeMenuApplet.lua
URL: 
http://svn.slimdevices.com/7.1/trunk/squeezeplay/src/squeezeplay/share/applets/CustomizeHomeMenu/CustomizeHomeMenuApplet.lua?rev=2419&root=Jive&r1=2418&r2=2419&view=diff
==============================================================================
--- 
7.1/trunk/squeezeplay/src/squeezeplay/share/applets/CustomizeHomeMenu/CustomizeHomeMenuApplet.lua
 (original)
+++ 
7.1/trunk/squeezeplay/src/squeezeplay/share/applets/CustomizeHomeMenu/CustomizeHomeMenuApplet.lua
 Mon May  5 15:09:05 2008
@@ -24,16 +24,11 @@
 
 local Applet                 = require("jive.Applet")
 local Checkbox               = require("jive.ui.Checkbox")
-local Choice                 = require("jive.ui.Choice")
-local RadioButton            = require("jive.ui.RadioButton")
-local RadioGroup             = require("jive.ui.RadioGroup")
 local Window                 = require("jive.ui.Window")
-local Popup                  = require("jive.ui.Popup")
 local Textarea               = require('jive.ui.Textarea')
 local Framework              = require('jive.ui.Framework')
 
 local SimpleMenu             = require("jive.ui.SimpleMenu")
-local RadioGroup             = require("jive.ui.RadioGroup")
 local log                    = 
require("jive.utils.log").addCategory("customizeHome", jive.utils.log.DEBUG)
 
 local debug                  = require("jive.utils.debug")
@@ -48,7 +43,6 @@
 function menu(self, menuItem)
 
        log:info("menu")
-       local group = RadioGroup()
        self.currentSettings = self:getSettings()
 
        -- get the menu table from jiveMain
@@ -72,69 +66,61 @@
                }
        )
 
-       table.insert(homeMenuItems,  
-               {
-                       text = self:string('SETTINGS'),
-                       weight = 100,
-                       callback = function()
-                               self:warnHide('settings')
-                       end
-               }
-       )
-
-       table.insert(homeMenuItems, 
-               {
-                       text = self:string('CUSTOMIZE_HOME'),
-                       weight = 101,
-                       callback = function()
-                               self:warnHide('appletCustomizeHome')
-                       end
-               }
-       )
-
-
        for id, item in pairs(self.menuTable) do
                if id ~= 'hidden' and
                        id ~= 'nowhere' and
-                       id ~= 'appletCustomizeHome' and
                        id ~= 'settings' then
                        
-               local selected
-               local choices = { self:string('CUSTOMIZE_HIDDEN'), 
self:string('HOME') }
+               local title, selected, weight
 
-               -- add the item's node to the list of choices if it's not home 
or hidden
-               if item.node ~= 'home' and item.node ~= 'hidden' then
-                       table.insert(choices, 
self.nodeTable[item.node]['item']['text'])
+               local defaultNode = jiveMain:getNodeText(item.node)
+               if defaultNode then
+                       title = tostring(item.text) .. ' (' .. 
tostring(defaultNode) .. ')'
+               else
+                       title = item.text
                end
 
-               if self.currentSettings[id] and self.currentSettings[id] == 
'hidden' then
-                       selected = 1
-               elseif self.currentSettings[id] and self.currentSettings[id] == 
'home' then
-                       selected = 2
+               -- if this is a home item and setting = 'hidden', then unselect
+               if self.currentSettings[id] and self.currentSettings[id] == 
'hidden' and item.node == 'home' then
+                       selected = false
+               -- elseif setting = 'home' or item.node = 'home', then select
+               elseif (self.currentSettings[id] and self.currentSettings[id] 
== 'home') or item.node == 'home' then
+                       selected = true
+               -- anything else is unselect
                else
-                       selected = #choices
+                       selected = false
+               end
+
+               if item.node == 'home' then
+                       weight = 2
+               else
+                       weight = 5
                end
 
                local menuItem = {
-                       text = item.text,
-                       weight = 5,
-                       icon = Choice(
-                               "choice",
-                               choices,
-                               function(object, selectedIndex)
-                                       local node
-                                       if selectedIndex == 1 then
-                                               node = 'hidden'
-                                               self:getSettings()[item.id] = 
node
-                                       elseif selectedIndex == 2 then
-                                               node = 'home'
-                                               self:getSettings()[item.id] = 
node
-                                       elseif selectedIndex == 3 then
-                                               node = 
self.menuTable[id]['node']
-                                               self:getSettings()[item.id] = 
nil
+                       text = title,
+                       weight = weight,
+                       icon = Checkbox(
+                               "checkbox",
+                               function(object, isSelected)
+                                       if isSelected then
+                                               if item.node == 'home' then
+                                                       
self:getSettings()[item.id] = nil
+                                                       jiveMain:setNode(item, 
'home')
+                                               else
+                                                       
self:getSettings()[item.id] = 'home'
+                                                       
jiveMain:addItemToNode(item, 'home')
+                                               end
+                                       else
+                                               if item.node == 'home' then
+                                                       
self:getSettings()[item.id] = 'hidden'
+                                                       jiveMain:setNode(item, 
'hidden')
+                                               else
+                                                       
self:getSettings()[item.id] = nil
+                                                       
jiveMain:removeItemFromNode(item, 'home')
+                                               end
                                        end
                                        self:storeSettings()
-                                       jiveMain:setNode(item, node)
                                end,
                                selected
                        ),
@@ -184,67 +170,6 @@
        window:show()
 end
 
-function warnHide(self, id)
-       local item = self.menuTable[id]
-       local window = Window("window", item.text, 'settingstitle')
-
-       local selected
-       local choices = { self:string('CUSTOMIZE_HIDDEN'), self:string('HOME') }
-
-       -- add the item's (default) node to the list of choices if it's not 
home or hidden
-       if item.node ~= 'home' and item.node ~= 'hidden' then
-               table.insert(choices, self.nodeTable[item.node]['item']['text'])
-       end
-
-       if self.currentSettings[id] and self.currentSettings[id] == 'hidden' 
then
-               selected = 1
-       elseif self.currentSettings[id] and self.currentSettings[id] == 'home' 
then
-               selected = 2
-       else
-               selected = #choices
-       end
-
-       local menuItem = {
-               text = item.text,
-               icon = Choice(
-                       "choice",
-                       choices,
-                       function(object, selectedIndex)
-                               local node
-                               if selectedIndex == 1 then
-                                       node = 'hidden'
-                                       self:getSettings()[item.id] = node
-                               elseif selectedIndex == 2 then
-                                       node = 'home'
-                                       self:getSettings()[item.id] = node
-                               elseif selectedIndex == 3 then
-                                       node = self.menuTable[id]['node']
-                                       self:getSettings()[item.id] = nil
-                               end
-                               self:storeSettings()
-                               jiveMain:setNode(item, node)
-                       end,
-                       selected
-               ),
-       }
-
-        local menu = SimpleMenu("menu", {
-               {
-                       text = self:string("CUSTOMIZE_CANCEL"),
-                       sound = "WINDOWHIDE",
-                       callback = function()
-                               window:hide()
-                       end
-               },
-               menuItem
-       })
-
-
-       window:addWidget(Textarea("help", 
self:string("CUSTOMIZE_HIDDEN_WARNING")))
-        window:addWidget(menu)
-       window:show()
-end
-
 -- goHome
 -- pushes the home window to the top
 function _goHome()

Modified: 
7.1/trunk/squeezeplay/src/squeezeplay/share/applets/CustomizeHomeMenu/strings.txt
URL: 
http://svn.slimdevices.com/7.1/trunk/squeezeplay/src/squeezeplay/share/applets/CustomizeHomeMenu/strings.txt?rev=2419&root=Jive&r1=2418&r2=2419&view=diff
==============================================================================
--- 
7.1/trunk/squeezeplay/src/squeezeplay/share/applets/CustomizeHomeMenu/strings.txt
 (original)
+++ 
7.1/trunk/squeezeplay/src/squeezeplay/share/applets/CustomizeHomeMenu/strings.txt
 Mon May  5 15:09:05 2008
@@ -32,5 +32,3 @@
 CUSTOMIZE_RESTORE_DEFAULTS_HELP
        EN      Select "Continue" to remove all custom menu organization 
settings
 
-CUSTOMIZE_HIDDEN_WARNING
-       EN      Warning: setting this item to 'Hidden' could block your ability 
to get back to this applet for further customization.

Modified: 7.1/trunk/squeezeplay/src/squeezeplay/share/jive/ui/HomeMenu.lua
URL: 
http://svn.slimdevices.com/7.1/trunk/squeezeplay/src/squeezeplay/share/jive/ui/HomeMenu.lua?rev=2419&root=Jive&r1=2418&r2=2419&view=diff
==============================================================================
--- 7.1/trunk/squeezeplay/src/squeezeplay/share/jive/ui/HomeMenu.lua (original)
+++ 7.1/trunk/squeezeplay/src/squeezeplay/share/jive/ui/HomeMenu.lua Mon May  5 
15:09:05 2008
@@ -53,6 +53,15 @@
        return self.nodeTable
 end
 
+function getNodeText(self, node)
+       assert(node)
+       if self.nodeTable[node] and self.nodeTable[node]['item'] and 
self.nodeTable[node]['item']['text'] then
+               return self.nodeTable[node]['item']['text']
+       else
+               return nil
+       end
+end
+
 function setTitle(self, title)
        if title then
                self.window:setTitle(title)
@@ -64,8 +73,11 @@
 function setCustomNode(self, id, node)
        if self.menuTable[id] then
                local item = self.menuTable[id]
-               self:removeItem(item)
-               self:addItem(item)
+               -- an item from home that is set for 'hidden' should be removed 
from home
+               if item.node == 'home' and node == 'hidden' then
+                       self:removeItemFromNode(item, 'home')
+               end
+               self:addItemToNode(item, node)
        end
        self.customNodes[id] = node
 end
@@ -127,9 +139,6 @@
        if not item.weight then 
                item.weight = 100
        end
-       if not item.defaultNode then
-               item.defaultNode = item.node
-       end
 
        -- remove/update node from previous node (if changed)
        if self.menuTable[item.id] then
@@ -175,6 +184,22 @@
        end
 end
 
+-- add an item to a node
+function addItemToNode(self, item, node)
+       assert(item.id)
+       if node then
+               self.customNodes[item.id] = node
+       else
+               node = item.node
+       end
+       assert(node)
+
+       if self.nodeTable[node] then
+               self.nodeTable[node].items[item.id] = item
+               self.nodeTable[node].menu:addItem(item)
+       end
+
+end
 
 -- add an item to a menu. the menu is ordered by weight, then item name
 function addItem(self, item)
@@ -184,27 +209,29 @@
        if not item.weight then 
                item.weight = 100
        end
-       if not item.defaultNode then
-               item.defaultNode = item.node
-       end
-
-       local whichNode
-       if self.customNodes[item.id] then
-               whichNode = self.customNodes[item.id]
-       else
-               whichNode = item.node
-       end
 
        -- add or update the item from the menuTable
        self.menuTable[item.id] = item
 
-       if self.nodeTable[whichNode] then
-               self.nodeTable[whichNode].items[item.id] = item
-               self.nodeTable[whichNode].menu:addItem(item)
-       end
+       -- add item to its custom node
+       local customNode = self.customNodes[item.id]
+       if customNode then
+               if customNode == 'hidden' and item.node == 'home' then
+                       self:addItemToNode(item, customNode)
+                       self:removeItemFromNode(item, 'home')
+                       return
+               elseif customNode == 'home' then
+                       self:addItemToNode(item, customNode)
+               end
+       end
+
+       -- add item to its default node
+       self:addItemToNode(item)
 
        -- add parent node?
-       local nodeEntry = self.nodeTable[whichNode]
+       local nodeEntry = self.nodeTable[item.node]
+
+       -- FIXME: this looks like a bug...shouldn't we be adding a node entry 
also when nodeEntry is false?
        if nodeEntry and nodeEntry.item then
                local hasItem = self.menuTable[nodeEntry.item.id] ~= nil
 
@@ -245,6 +272,19 @@
        end
 end
 
+-- remove an item from a node
+function removeItemFromNode(self, item, node)
+       assert(item)
+       if not node then
+               node = item.node
+       end
+       assert(node)
+       if self.nodeTable[node] then
+               self.nodeTable[node].items[item.id] = nil
+               self.nodeTable[node].menu:removeItem(item)
+               self:_checkRemoveNode(node)
+       end
+end
 
 -- remove an item from a menu by its index
 function removeItem(self, item)
@@ -255,18 +295,10 @@
                self.menuTable[item.id] = nil
        end
 
-       local node
-       if self.customNodes[item.id] then
-               node = self.customNodes[item.id]
-       elseif self.nodeTable[item.node] then
-               node = item.node
-       end
-
-       if self.nodeTable[node] then
-               self.nodeTable[node].items[item.id] = nil
-               self.nodeTable[node].menu:removeItem(item)
-               self:_checkRemoveNode(node)
-       end
+       self:removeItemFromNode(item)
+       -- if this item is co-located in home, get rid of it there too
+       self:removeItemFromNode(item, 'home')
+
 end
 
 -- remove an item from a menu by its id

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

Reply via email to