PDA

View Full Version : plugin web interface question



stinkingpig
2005-05-14, 22:04
Hi,

I'm slowly building a plugin to manage my USB radio from the Slimserver.
I'm leaning toward (at least in the first version) having the user enter
stations through the web interface, then select stations to play via the
remote control. I'm copying the web interface from RssNews.pm, which
separates title and URL nicely.

However, it presents a single entry form for new URLs and then gets the
title by visiting the RSS feed at that URL and parsing it. That's
obviously not going to work in my situation.

I think I get how the %Prefs are parsed by setup_input_array_txt.html,
but I'm not getting the result I want. Here's my current problems:

1) The detection of existing preferences is not working -- every time I
load the script, I get another insertion of my defaults. Here's the code:
sub initPlugin {
@stationFreqPrefs =
Slim::Utils::Prefs::getArray("plugin_slimfm_stations");
@stationNamePrefs =
Slim::Utils::Prefs::getArray("plugin_slimfm_names");
$stationModified =
Slim::Utils::Prefs::get("plugin_slimfm_station_modified");
# No prefs set so we'll use the defaults
if (scalar(@stationFreqPrefs) == 0 || (!$stationModified)) {
foreach my $key (sort keys %default_stations) {
@stationNamePrefs = (@stationNamePrefs,$key);
@stationFreqPrefs =
(@stationFreqPrefs,$default_stations{$key});
}
Slim::Utils::Prefs::set("plugin_slimfm_stations",
\@stationFreqPrefs);
Slim::Utils::Prefs::set("plugin_slimfm_names", \@stationNamePrefs);
}
}

2) while my debugging shows the right values, the web page just shows
frequency twice (once as the label, once in the text box). Here's the code:
my %Prefs = (
plugin_slimfm_stations => {
'isArray' => 1
,'arrayAddExtra' => 1
,'arrayDeleteNull' => 1
,'arrayDeleteValue' => ''
,'arrayBasicValue' => 0
,'PrefSize' => 'large'
,'inputTemplate' => 'setup_input_array_txt.html'
,'PrefInTable' => 1
,'showTextExtValue' => 1
,'externalValue' => sub {
my ($client, $value, $key) = @_;
if ($key =~ /^(\D*)(\d+)$/ && ($2 <
scalar(@stationFreqPrefs))) {
msg "$stationNamePrefs[$2], $stationFreqPrefs[$2]\n";
return ($stationNamePrefs[$2], $stationFreqPrefs[$2]);
}
return '';
}
,'onChange' => sub {
my ($client,$changeref,$paramref,$pageref) = @_;
if
(exists($changeref->{'plugin_slimfm_names'}{'Processed'})) {
return;
}
Slim::Web::Setup::processArrayChange($client,
'plugin_slimfm_names', $paramref, $pageref);
if
(exists($changeref->{'plugin_slimfm_names'}{'Processed'})) {
return;
}
Slim::Web::Setup::processArrayChange($client,
'plugin_slimfm_stations', $paramref, $pageref);
initPlugin();
$changeref->{'plugin_slimfm_stations'}{'Processed'} = 1;
}
,'changeMsg' =>
Slim::Utils::Strings::string('SETUP_PLUGIN_SLIMFM_ STATIONS_CHANGE')
},
);


--
Jack at Monkeynoodle dot Org: It's a Scientific Venture...
Riding the Emergency Third Rail Power Trip since 1996!

Robert Moser
2005-05-16, 07:32
Jack Coates wrote:
> 1) The detection of existing preferences is not working -- every time I
> load the script, I get another insertion of my defaults. Here's the code:
> sub initPlugin {
> @stationFreqPrefs =
> Slim::Utils::Prefs::getArray("plugin_slimfm_stations");
> @stationNamePrefs =
> Slim::Utils::Prefs::getArray("plugin_slimfm_names");
> $stationModified =
> Slim::Utils::Prefs::get("plugin_slimfm_station_modified");
> # No prefs set so we'll use the defaults
> if (scalar(@stationFreqPrefs) == 0 || (!$stationModified)) {
> foreach my $key (sort keys %default_stations) {
> @stationNamePrefs = (@stationNamePrefs,$key);
> @stationFreqPrefs =
> (@stationFreqPrefs,$default_stations{$key});
> }
> Slim::Utils::Prefs::set("plugin_slimfm_stations",
> \@stationFreqPrefs);
> Slim::Utils::Prefs::set("plugin_slimfm_names", \@stationNamePrefs);
> }
> }

Do you set plugin_slimfm_station_modified anywhere? If that preference
isn't defined, you'll reload your defaults every time.

> 2) while my debugging shows the right values, the web page just shows
> frequency twice (once as the label, once in the text box). Here's the code:
> my %Prefs = (
> plugin_slimfm_stations => {
> 'isArray' => 1
> ,'arrayAddExtra' => 1
> ,'arrayDeleteNull' => 1
> ,'arrayDeleteValue' => ''
> ,'arrayBasicValue' => 0
> ,'PrefSize' => 'large'
> ,'inputTemplate' => 'setup_input_array_txt.html'
> ,'PrefInTable' => 1
> ,'showTextExtValue' => 1
> ,'externalValue' => sub {
> my ($client, $value, $key) = @_;
> if ($key =~ /^(\D*)(\d+)$/ && ($2 <
> scalar(@stationFreqPrefs))) {
> msg "$stationNamePrefs[$2], $stationFreqPrefs[$2]\n";
> return ($stationNamePrefs[$2], $stationFreqPrefs[$2]);
> }
> return '';
> }
> ,'onChange' => sub {
> my ($client,$changeref,$paramref,$pageref) = @_;
> if
> (exists($changeref->{'plugin_slimfm_names'}{'Processed'})) {
> return;
> }
> Slim::Web::Setup::processArrayChange($client,
> 'plugin_slimfm_names', $paramref, $pageref);
> if
> (exists($changeref->{'plugin_slimfm_names'}{'Processed'})) {
> return;
> }
> Slim::Web::Setup::processArrayChange($client,
> 'plugin_slimfm_stations', $paramref, $pageref);
> initPlugin();
> $changeref->{'plugin_slimfm_stations'}{'Processed'} = 1;
> }
> ,'changeMsg' =>
> Slim::Utils::Strings::string('SETUP_PLUGIN_SLIMFM_ STATIONS_CHANGE')
> },
> );

You should just return $stationNamePrefs[$2] from your externalValue
function. The caller is expecting a scalar, not a list.