PDA

View Full Version : Dynamic upper line with Input::Choice ?



erland
2007-05-01, 04:30
Is there a good way of having the upper line updated for each item when you navigate a Input::Choice based menu ?

I set the 'header' at initialization and it can contain a {count} which will be replaced with "(1 of 16)" when the menu is entered.

However, I like to have my own dynamic parameters. Is there any way to get a callback of my own called when it needs the 'header' text ?
It doesn't look so from the SlimServer source, but I thought I ask just to make sure.

At the moment I hook into the 'onChange' handler in Input::Choice and my callback writes to $client->param('header',...) and puts the correct value there. This almost works, the problem is that onChange isn't called the first time when the menu is entered and an initial menu item is selected, the dynamic text will not be shown until I hit up/down to goto the next item.

An ugly workaround, is to update the 'header' value from outside directly after I have called Slim::Buttons::Common::pushModeLeft, but this doesn't feel good.

So, is there any way to do this in a better way ? Or could something be changed in 7.0 to make this simplier ?

Some sample code follows (with a lot of uninteresting stuff removed, getHeaderText returns the value I like to show)


my %params = (
header => $menuTitle.' {count}',
listRef => \@listRef,
onChange =>
sub {
my ($client, $item) = @_;
$client->param('header',getHeaderText($self,$client,$item)) ;
},
);
Slim::Buttons::Common::pushModeLeft($client, 'PLUGIN.CustomBrowse.Choice', \%params);

# This code is needed to show the correct getHeaderText value for the default selected item
my $listRef = $client->param('listRef');
my $listIndex = $client->param('listIndex');
if(scalar(@$listRef)>$listIndex) {
my $item = $listRef->[$listIndex];
my $menuText = getHeaderText($self,$client,$item);
$client->param('header',$menuText);
}

erland
2007-05-05, 00:12
Is there a good way of having the upper line updated for each item when you navigate a Input::Choice based menu ?

I set the 'header' at initialization and it can contain a {count} which will be replaced with "(1 of 16)" when the menu is entered.

However, I like to have my own dynamic parameters. Is there any way to get a callback of my own called when it needs the 'header' text ?
It doesn't look so from the SlimServer source, but I thought I ask just to make sure.Problem solved.
I just realized that 'header' can be a function reference to a callback of mine and then everything works as I wanted.