[Slim-Checkins] r10809 - in /trunk/server/Plugins/MusicMagic:
HTML/EN/plugins/MusicMagic/settings/
HTML/EN/plugins/MusicMagic/settings/musicmagic.html PlayerSettings.pm
Plugin.pm Settings.pm
kdf at svn.slimdevices.com
kdf at svn.slimdevices.com
Fri Dec 1 00:44:28 PST 2006
Author: kdf
Date: Fri Dec 1 00:44:28 2006
New Revision: 10809
URL: http://svn.slimdevices.com?rev=10809&view=rev
Log:
Bug: 3267
Description: move musicmagic to new settings api
- old Settings.pm changed to PlayerSettings.pm so that the web side can be consistenly Settings.pm
Added:
trunk/server/Plugins/MusicMagic/HTML/EN/plugins/MusicMagic/settings/
trunk/server/Plugins/MusicMagic/HTML/EN/plugins/MusicMagic/settings/musicmagic.html
trunk/server/Plugins/MusicMagic/PlayerSettings.pm
Modified:
trunk/server/Plugins/MusicMagic/Plugin.pm
trunk/server/Plugins/MusicMagic/Settings.pm
Added: trunk/server/Plugins/MusicMagic/HTML/EN/plugins/MusicMagic/settings/musicmagic.html
URL: http://svn.slimdevices.com/trunk/server/Plugins/MusicMagic/HTML/EN/plugins/MusicMagic/settings/musicmagic.html?rev=10809&view=auto
==============================================================================
--- trunk/server/Plugins/MusicMagic/HTML/EN/plugins/MusicMagic/settings/musicmagic.html (added)
+++ trunk/server/Plugins/MusicMagic/HTML/EN/plugins/MusicMagic/settings/musicmagic.html Fri Dec 1 00:44:28 2006
@@ -1,0 +1,135 @@
+[% PROCESS settings/header.html %]
+
+ <div class="settingSection">
+ <div class="prefHead">[% "MUSICMAGIC" | string | upper %]</div>
+ <div class="prefDesc">[% "SETUP_MUSICMAGIC_DESC" | string %]</div>
+
+ <input type="checkbox" [% IF prefs.musicmagic %]checked [% END %] class="stdedit" name="musicmagic" id="musicmagic" />
+
+ <!--
+ <option [% IF NOT prefs.musicmagic %]selected [% END %]value="0">[% 'DONT_USE_MUSICMAGIC' | getstring %]</option>
+ <option [% IF prefs.musicmagic %]selected [% END %]value="1">[% 'USE_MUSICMAGIC' | getstring %]</option>
+ -->
+ </div>
+
+ <div class="settingSection">
+ <div class="prefHead">[% "SETUP_MMMPLAYERSETTINGS" | string | upper %]</div>
+ <div class="prefDesc">[% "SETUP_MMMPLAYERSETTINGS_DESC" | string %]</div>
+
+ <select class="stdedit" name="MMMPlayerSettings" id="MMMPlayerSettings">
+
+ <option [% IF NOT MMMPlayerSettings %]selected [% END %]value="0">[% 'NO' | getstring %]</option>
+ <option [% IF MMMPlayerSettings %]selected [% END %]value="1">[% 'YES' | getstring %]</option>
+
+ </select>
+
+ </div>
+
+ <div class="settingSection">
+ <div class="prefHead">[% "SETUP_MMMSIZE" | string | upper %]</div>
+ <div class="prefDesc">[% "SETUP_MMMSIZE_DESC" | string %]</div>
+
+ <input type="text" class="stdedit" name="MMMSize" id="MMMSize" value="[% prefs.MMMSize %]" size="5">
+ </div>
+
+ <div class="settingSection">
+ <div class="prefHead">[% "SETUP_MMMMIXTYPE" | string | upper %]</div>
+ <div class="prefDesc">[% "SETUP_MMMMIXTYPE_DESC" | string %]</div>
+
+ <select class="stdedit" name="MMMMixType" id="MMMMixType">
+
+ <option [% IF MMMMixType == prefs.MMMMixType %]selected [% END %]value="0">[% 'MMMMIXTYPE_TRACKS' | getstring %]</option>
+ <option [% IF MMMMixType == prefs.MMMMixType %]selected [% END %]value="1">[% 'MMMMIXTYPE_MIN' | getstring %]</option>
+ <option [% IF MMMMixType == prefs.MMMMixType %]selected [% END %]value="2">[% 'MMMMIXTYPE_MBYTES' | getstring %]</option>
+
+ </select>
+
+ </div>
+
+ <div class="settingSection">
+ <div class="prefHead">[% "SETUP_MMMSTYLE" | string | upper %]</div>
+ <div class="prefDesc">[% "SETUP_MMMSTYLE_DESC" | string %]</div>
+
+ <input type="text" class="stdedit" name="MMMStyle" id="MMMStyle" value="[% prefs.MMMStyle %]" size="5">
+ </div>
+
+ <div class="settingSection">
+ <div class="prefHead">[% "SETUP_MMMVARIETY" | string | upper %]</div>
+ <div class="prefDesc">[% "SETUP_MMMVARIETY_DESC" | string %]</div>
+
+ <input type="text" class="stdedit" name="MMMVariety" id="MMMVariety" value="[% prefs.MMMVariety %]" size="5">
+ </div>
+
+ <div class="settingSection">
+ <div class="prefHead">[% "SETUP_MMMMIXGENRE" | string | upper %]</div>
+ <div class="prefDesc">[% "SETUP_MMMMIXGENRE_DESC" | string %]</div>
+
+ <select class="stdedit" name="MMMMixGenre" id="MMMMixGenre">
+
+ <option [% IF NOT MMMMixGenre %]selected [% END %]value="0">[% 'NO' | getstring %]</option>
+ <option [% IF MMMMixGenre %]selected [% END %]value="1">[% 'YES' | getstring %]</option>
+
+ </select>
+ </div>
+
+ <div class="settingSection">
+ <div class="prefHead">[% "SETUP_MMMREJECTTYPE" | string | upper %]</div>
+ <div class="prefDesc">[% "SETUP_MMMREJECTTYPE_DESC" | string %]</div>
+
+ <select class="stdedit" name="MMMRejectType" id="MMMRejectType">
+
+ <option [% IF MMMRejectType == prefs.MMMRejectType %]selected [% END %]value="0">[% 'MMMMIXTYPE_TRACKS' | getstring %]</option>
+ <option [% IF MMMRejectType == prefs.MMMRejectType %]selected [% END %]value="1">[% 'MMMMIXTYPE_MIN' | getstring %]</option>
+ <option [% IF MMMRejectType == prefs.MMMRejectType %]selected [% END %]value="2">[% 'MMMMIXTYPE_MBYTES' | getstring %]</option>
+
+ </select>
+
+ </div>
+
+ <div class="settingSection">
+ <div class="prefHead">[% "SETUP_MMMREJECTSIZE" | string | upper %]</div>
+ <div class="prefDesc">[% "SETUP_MMMREJECTSIZE_DESC" | string %]</div>
+
+ <input type="text" class="stdedit" name="MMMRejectSize" id="MMMRejectSize" value="[% prefs.MMMRejectSize %]" size="5">
+ </div>
+
+ <div class="settingSection">
+ <div class="prefHead">[% "SETUP_MMMFILTER" | string | upper %]</div>
+ <div class="prefDesc">[% "SETUP_MMMFILTER_DESC" | string %]</div>
+
+ <select class="stdedit" name="MMMFilter" id="MMMFilter">
+
+ [% FOREACH option = filters.keys %]
+
+ <option [% IF MMMFilter == option %]selected [% END %]value="[% option %]">[% filters.$option %]</option>
+
+ [%- END -%]
+
+ </select>
+
+ </div>
+
+ <div class="settingSection">
+ <div class="prefHead">[% "SETUP_MUSICMAGICSCANINTERVAL" | string | upper %]</div>
+ <div class="prefDesc">[% "SETUP_MUSICMAGICSCANINTERVAL_DESC" | string %]</div>
+
+ <input type="text" class="stdedit" name="musicmagicscaninterval" id="musicmagicscaninterval" value="[% prefs.musicmagicscaninterval %]" size="5">
+ </div>
+
+ <div class="settingSection">
+ <div class="prefHead">[% "SETUP_MMSPORT" | string | upper %]</div>
+ <div class="prefDesc">[% "SETUP_MMSPORT_DESC" | string %]</div>
+
+ <input type="text" class="stdedit" name="MMSport" id="MMSport" value="[% prefs.MMSport %]" size="5">
+ </div>
+
+ <div class="settingSection">
+ <div class="groupHead">[% "SETUP_MUSICMAGICPLAYLISTFORMAT" | string | upper %]</div>
+ <div class="groupDesc">[% "SETUP_MUSICMAGICPLAYLISTFORMAT_DESC" | string %]</div>
+
+ [% "SETUP_ITUNESPLAYLISTPREFIX_CHOOSE" | string %]<input type="text" class="stdedit" name="MusicMagicplaylistprefix" id="MusicMagicplaylistprefix" value="[% prefs.MusicMagicplaylistprefix %]" size="40">
+ <br>
+ [% "SETUP_ITUNESPLAYLISTSUFFIX_CHOOSE" | string %]<input type="text" class="stdedit" name="MusicMagicplaylistsuffix" id="MusicMagicplaylistsuffix" value="[% prefs.MusicMagicplaylistsuffix %]" size="40">
+ </div>
+
+[% PROCESS settings/footer.html %]
Added: trunk/server/Plugins/MusicMagic/PlayerSettings.pm
URL: http://svn.slimdevices.com/trunk/server/Plugins/MusicMagic/PlayerSettings.pm?rev=10809&view=auto
==============================================================================
--- trunk/server/Plugins/MusicMagic/PlayerSettings.pm (added)
+++ trunk/server/Plugins/MusicMagic/PlayerSettings.pm Fri Dec 1 00:44:28 2006
@@ -1,0 +1,272 @@
+package Plugins::MusicMagic::PlayerSettings;
+
+# SlimServer Copyright (c) 2001-2004 Sean Adams, Slim Devices Inc.
+# This program is free software; you can redistribute it and/or
+# modify it under the terms of the GNU General Public License,
+# version 2.
+
+use strict;
+
+# button functions for browse directory
+our @defaultSettingsChoices = qw(MMMSize MMMMixType MMMStyle MMMVariety MMMFilter MMMMixGenre MMMRejectType MMMRejectSize);
+
+our @settingsChoices = ();
+our %current = ();
+our %menuParams = ();
+our %functions = ();
+
+sub init {
+ Slim::Buttons::Common::addMode('MMMsettings',getFunctions(),\&setMode);
+
+ %functions = (
+ 'right' => sub {
+ my ($client,$funct,$functarg) = @_;
+ if (defined($client->modeParam('useMode'))) {
+ #in a submenu of settings, which is passing back a button press
+ Slim::Buttons::Common::popMode($client);
+ Plugins::MusicMagic::Plugin::mixerFunction($client,1);
+ } else {
+ #handle passback of button presses
+ settingsExitHandler($client,'RIGHT');
+ }
+ },
+ 'play' => sub {
+ my $client = shift;
+ my @oldlines = Slim::Display::Display::curLines($client);
+
+ Slim::Buttons::Common::popMode($client);
+ Plugins::MusicMagic::Plugin::mixerFunction($client,1);
+ },
+ );
+
+ %menuParams = (
+
+ 'MMMsettings' => {
+ 'listRef' => \@defaultSettingsChoices,
+ 'stringExternRef' => 1,
+ 'header' => 'SETUP_MMMSETTINGS',
+ 'stringHeader' => 1,
+ 'headerAddCount' => 1,
+ 'callback' => \&settingsExitHandler,
+ 'overlayRef' => sub {
+ return (undef,Slim::Display::Display::symbol('rightarrow'));
+ },
+ 'overlayRefArgs' => 'C',
+ },
+
+ 'MMMsettings/MMMSize' => {
+ 'useMode' => 'INPUT.Bar',
+ 'header' => 'SETUP_MMMSIZE',
+ 'stringHeader' => 1,
+ 'headerValue' =>'unscaled',
+ 'min' => 0,
+ 'max' => 200,
+ 'increment' => 1,
+ 'onChange' => \&setPref,
+ 'pref' => "MMMSize",
+ 'initialValue' => "MMMSize",
+ 'overlayRef' => sub { return ($_[0]->string('MUSICMAGIC_MIXRIGHT'),undef) },
+ 'overlayRefArgs' => 'C',
+ },
+
+ 'MMMsettings/MMMMixType' => {
+ 'useMode' => 'INPUT.List',
+ 'header' => 'SETUP_MMMMIXTYPE',
+ 'stringHeader' => 1,
+ 'listRef' => [0,1,2],
+ 'externRef' => {
+ '0' => Slim::Utils::Strings::string('MMMMIXTYPE_TRACKS'),
+ '1' => Slim::Utils::Strings::string('MMMMIXTYPE_MIN'),
+ '2' => Slim::Utils::Strings::string('MMMMIXTYPE_MBYTES'),
+ },
+ 'onChange' => \&setPref,
+ 'pref' => "MMMMixType",
+ 'initialValue' => "MMMStyle",
+ 'overlayRef' => sub { return ($_[0]->string('MUSICMAGIC_MIXRIGHT'),undef) },
+ 'overlayRefArgs' => 'C',
+ },
+
+ 'MMMsettings/MMMStyle' => {
+ 'useMode' => 'INPUT.Bar',
+ 'header' => 'SETUP_MMMSTYLE',
+ 'stringHeader' => 1,
+ 'headerValue' => 'unscaled',
+ 'min' => 0,
+ 'max' => 200,
+ 'onChange' => \&setPref,
+ 'pref' => "MMMStyle",
+ 'initialValue' => "MMMStyle",
+ 'overlayRef' => sub { return ($_[0]->string('MUSICMAGIC_MIXRIGHT'),undef) },
+ 'overlayRefArgs' => 'C',
+ },
+
+ 'MMMsettings/MMMVariety' => {
+ 'useMode' => 'INPUT.Bar',
+ 'header' => 'SETUP_MMMVARIETY',
+ 'stringHeader' => 1,
+ 'headerValue' =>'unscaled',
+ 'min' => 0,
+ 'max' => 9,
+ 'increment' => 1,
+ 'onChange' => \&setPref,
+ 'pref' => "MMMVariety",
+ 'initialValue' => "MMMVariety",
+ 'overlayRef' => sub { return ($_[0]->string('MUSICMAGIC_MIXRIGHT'),undef) },
+ 'overlayRefArgs' => 'C',
+ },
+
+ 'MMMsettings/MMMFilter' => {
+ 'useMode' => 'INPUT.List',
+ 'header' => 'SETUP_MMMFILTER',
+ 'stringHeader' => 1,
+ 'listRef' => undef,
+ 'externRef' => undef,
+ 'onChange' => \&setPref,
+ 'pref' => "MMMFilter",
+ 'initialValue' => "MMMFilter",
+ 'overlayRef' => sub { return ($_[0]->string('MUSICMAGIC_MIXRIGHT'),undef) },
+ 'overlayRefArgs' => 'C',
+ },
+
+ 'MMMsettings/MMMMixGenre' => {
+ 'useMode' => 'INPUT.List',
+ 'header' => 'SETUP_MMMMIXGENRE',
+ 'stringHeader' => 1,
+ 'listRef' => [0,1],
+ 'externRef' => {
+ '0' => Slim::Utils::Strings::string('NO'),
+ '1' => Slim::Utils::Strings::string('YES'),
+ },
+ 'onChange' => \&setPref,
+ 'pref' => "MMMMixGenre",
+ 'initialValue' => "MMMMixGenre",
+ 'overlayRef' => sub { return ($_[0]->string('MUSICMAGIC_MIXRIGHT'),undef) },
+ 'overlayRefArgs' => 'C',
+ },
+
+ 'MMMsettings/MMMRejectType' => {
+ 'useMode' => 'INPUT.List',
+ 'header' => 'SETUP_MMMREJECTTYPE',
+ 'stringHeader' => 1,
+ 'listRef' => [0,1,2],
+ 'externRef' => {
+ '0' => Slim::Utils::Strings::string('MMMMIXTYPE_TRACKS'),
+ '1' => Slim::Utils::Strings::string('MMMMIXTYPE_MIN'),
+ '2' => Slim::Utils::Strings::string('MMMMIXTYPE_MBYTES'),
+ },
+ 'onChange' => \&setPref,
+ 'pref' => "MMMRejectType",
+ 'initialValue' => "MMMRejectType",
+ 'overlayRef' => sub { return ($_[0]->string('MUSICMAGIC_MIXRIGHT'),undef) },
+ 'overlayRefArgs' => 'C',
+ },
+
+ 'MMMsettings/MMMRejectSize' => {
+ 'useMode' => 'INPUT.Bar',
+ 'header' => 'SETUP_MMMREJECTSIZE',
+ 'stringHeader' => 1,
+ 'headerValue' =>'unscaled',
+ 'min' => 0,
+ 'max' => 200,
+ 'increment' => 1,
+ 'onChange' => \&setPref,
+ 'pref' => "MMMRejectSize",
+ 'initialValue' => "MMMRejectSize",
+ 'overlayRef' => sub { return ($_[0]->string('MUSICMAGIC_MIXRIGHT'),undef) },
+ 'overlayRefArgs' => 'C',
+ },
+ );
+}
+
+sub setPref {
+ my $client = shift;
+ my $value = shift;
+
+ my $pref = $client->modeParam('pref');
+
+ $client->prefSet($pref,$value);
+}
+
+sub executeCommand {
+ my $client = shift;
+ my $value = shift;
+
+ my $command = $client->modeParam('command');
+ my $subcmd = $client->modeParam('subcommand');
+
+ $client->execute([$command, $subcmd, $value]);
+}
+
+sub settingsExitHandler {
+ my ($client,$exittype) = @_;
+ $exittype = uc($exittype);
+ if ($exittype eq 'LEFT') {
+ Slim::Buttons::Common::popModeRight($client);
+ } elsif ($exittype eq 'RIGHT') {
+ my $nextmenu = 'MMMsettings/'.$current{$client};
+ if (defined($client->modeParam('useMode'))) {
+ #in a submenu of settings and exiting right.
+ Plugins::MusicMagic::Plugin::mixerFunction($client,1);
+ } elsif (exists($menuParams{$nextmenu})) {
+ my %nextParams = %{$menuParams{$nextmenu}};
+ $nextParams{'callback'} = \&settingsExitHandler;
+ $nextParams{'parentParams'} = $client->modeParam('parentParams');
+ if (($nextParams{'useMode'} eq 'INPUT.List' || $nextParams{'useMode'} eq 'INPUT.Bar') && exists($nextParams{'initialValue'})) {
+ #set up valueRef for current pref
+ my $value;
+ if (ref($nextParams{'initialValue'}) eq 'CODE') {
+ $value = $nextParams{'initialValue'}->($client);
+ } else {
+ $value = $client->prefGet($nextParams{'initialValue'});
+ }
+ $nextParams{'valueRef'} = \$value;
+ }
+ if ($nextmenu eq 'MMMsettings/MMMFilter') {
+ my %filters = Plugins::MusicMagic::Plugin::grabFilters();
+
+ $nextParams{'listRef'} = [keys %filters];
+ $nextParams{'externRef'} = {Plugins::MusicMagic::Plugin::grabFilters()};
+ $nextParams{'listIndex'} = $client->prefGet('MMMFilter');
+
+ }
+
+ Slim::Buttons::Common::pushModeLeft(
+ $client
+ ,$nextParams{'useMode'}
+ ,\%nextParams
+ );
+ } else {
+ Plugins::MusicMagic::Plugin::mixerFunction($client,1);
+ }
+ } else {
+ return;
+ }
+}
+
+sub getFunctions {
+ return \%functions;
+}
+
+sub setMode {
+ my $client = shift;
+ my $method = shift;
+ if ($method eq 'pop') {
+ Slim::Buttons::Common::popMode($client);
+ return;
+ }
+
+ $current{$client} = $defaultSettingsChoices[0] unless exists($current{$client});
+ my %params = %{$menuParams{'MMMsettings'}};
+ $params{'valueRef'} = \$current{$client};
+ $params{'parentParams'} = $client->modeParam('parentParams');
+
+ my @settingsChoices = @defaultSettingsChoices;
+
+ $params{'listRef'} = \@settingsChoices;
+
+ Slim::Buttons::Common::pushMode($client,'INPUT.List',\%params);
+}
+
+1;
+
+__END__
Modified: trunk/server/Plugins/MusicMagic/Plugin.pm
URL: http://svn.slimdevices.com/trunk/server/Plugins/MusicMagic/Plugin.pm?rev=10809&r1=10808&r2=10809&view=diff
==============================================================================
--- trunk/server/Plugins/MusicMagic/Plugin.pm (original)
+++ trunk/server/Plugins/MusicMagic/Plugin.pm Fri Dec 1 00:44:28 2006
@@ -13,8 +13,10 @@
use Slim::Utils::OSDetect;
use Slim::Utils::Strings;
+use Plugins::MusicMagic::Settings;
+
use Plugins::MusicMagic::Common;
-use Plugins::MusicMagic::Settings;
+use Plugins::MusicMagic::PlayerSettings;
my $initialized = 0;
my $MMSHost;
@@ -160,7 +162,7 @@
$http->close;
- Plugins::MusicMagic::Settings::init();
+ Plugins::MusicMagic::PlayerSettings::init();
# Note: Check version restrictions if any
$initialized = $content;
@@ -177,7 +179,7 @@
Slim::Player::ProtocolHandlers->registerHandler('musicmagicplaylist', 0);
- addGroups();
+ Plugins::MusicMagic::Settings->new;
if (scalar @{grabMoods()}) {
@@ -245,18 +247,6 @@
}, { 'duration' => 2});
$client->execute(["playlist", $playAddInsert, "listref", $client->modeParam('listRef')]);
-}
-
-sub addGroups {
- my $category = setupCategory();
-
- Slim::Web::Setup::addCategory('MUSICMAGIC',$category);
-
- my ($groupRef, $prefRef) = setupUse();
-
- Slim::Web::Setup::addGroup('BASIC_SERVER_SETTINGS', 'musicmagic', $groupRef, undef, $prefRef);
-
- Slim::Web::Setup::addChildren('BASIC_SERVER_SETTINGS', 'MUSICMAGIC');
}
sub isMusicLibraryFileChanged {
@@ -339,65 +329,6 @@
# Call ourselves again after 120 seconds
Slim::Utils::Timers::setTimer(0, (Time::HiRes::time() + 120), \&checker);
-}
-
-sub grabFilters {
- my @filters = ();
- my %filterHash = ();
-
- if (!$initialized) {
- return;
- }
-
- if (grep {$_ eq 'MusicMagic::Plugin'} Slim::Utils::Prefs::getArray('disabledplugins')) {
-
- $log->debug("Don't get filters list, it's disabled");
-
- return %filterHash;
- }
-
- $MMSport = Slim::Utils::Prefs::get('MMSport') unless $MMSport;
- $MMSHost = Slim::Utils::Prefs::get('MMSHost') unless $MMSHost;
-
- $log->debug("Get filters list");
-
- my $http = Slim::Player::Protocols::HTTP->new({
- 'url' => "http://$MMSHost:$MMSport/api/filters",
- 'create' => 0,
- });
-
- if ($http) {
-
- @filters = split(/\n/, $http->content);
- $http->close;
-
- if ($log->is_debug && scalar @filters) {
-
- $log->debug("Found filters:");
-
- for my $filter (@filters) {
-
- $log->debug("\t$filter");
- }
- }
- }
-
- my $none = sprintf('(%s)', Slim::Utils::Strings::string('NONE'));
-
- push @filters, $none;
-
- foreach my $filter ( @filters ) {
-
- if ($filter eq $none) {
-
- $filterHash{0} = $filter;
- next
- }
-
- $filterHash{$filter} = $filter;
- }
-
- return %filterHash;
}
sub prefName {
@@ -1000,203 +931,6 @@
return \%group;
}
-sub setupUse {
- my $client = shift;
-
- my %setupGroup = (
- 'PrefOrder' => ['musicmagic'],
- 'PrefsInTable' => 0,
- 'Suppress_PrefLine' => 1,
- 'Suppress_PrefSub' => 1,
- 'GroupLine' => 1,
- 'GroupSub' => 1,
- );
-
- my %setupPrefs = (
-
- 'musicmagic' => {
- 'validate' => \&Slim::Utils::Validate::trueFalse,
- 'changeIntro' => "",
-
- 'options' => {
- '1' => Slim::Utils::Strings::string('USE_MUSICMAGIC'),
- '0' => Slim::Utils::Strings::string('DONT_USE_MUSICMAGIC'),
- },
-
- 'onChange' => sub {
- my ($client,$changeref,$paramref,$pageref) = @_;
-
- foreach my $client (Slim::Player::Client::clients()) {
- Slim::Buttons::Home::updateMenu($client);
- }
-
- Slim::Music::Import->useImporter('Plugins::MusicMagic::Plugin', $changeref->{'musicmagic'}{'new'});
- },
-
- 'optionSort' => 'KR',
- 'inputTemplate' => 'setup_input_radio.html',
- }
- );
-
- return (\%setupGroup, \%setupPrefs);
-}
-
-sub setupGroup {
- my $category = setupCategory();
- my $group = playerGroup();
-
- $category->{'parent'} = 'BASIC_PLAYER_SETTINGS';
- $category->{'GroupOrder'} = ['Default'];
- $category->{'Groups'} = $group->{'Groups'};
-
- return ($category->{'Groups'}->{'Default'}, $category->{'Prefs'},1);
-}
-
-sub setupPort {
- my $client = shift;
-
- my $category = setupCategory();
-
- my %setupGroup = (
- 'PrefOrder' => [qw(MMSport)]
- );
-
- my %setupPrefs = (
- 'MMSport' => $category->{'Prefs'}->{'MMSport'}
- );
-
- return (\%setupGroup, \%setupPrefs);
-}
-
-sub setupCategory {
-
- my %setupCategory = (
-
- 'title' => Slim::Utils::Strings::string('SETUP_MUSICMAGIC'),
- 'parent' => 'BASIC_SERVER_SETTINGS',
- 'GroupOrder' => ['Default','MusicMagicPlaylistFormat'],
- 'Groups' => {
-
- 'Default' => {
- 'PrefOrder' => [qw(MMMPlayerSettings MMMSize MMMMixType MMMStyle MMMVariety MMMMixGenre MMMRejectType MMMRejectSize MMMFilter musicmagicscaninterval MMSport)]
-
- # disable remote host access, its confusing and only works in specific cases
- # leave it here for hackers who really want to try it
- #'PrefOrder' => [qw(MMMSize MMMMixType MMMStyle MMMVariety musicmagicscaninterval MMSport MMSHost MMSremoteRoot)]
- },
-
- 'MusicMagicPlaylistFormat' => {
- 'PrefOrder' => ['MusicMagicplaylistprefix','MusicMagicplaylistsuffix'],
- 'PrefsInTable' => 1,
- 'Suppress_PrefHead' => 1,
- 'Suppress_PrefDesc' => 1,
- 'Suppress_PrefLine' => 1,
- 'Suppress_PrefSub' => 1,
- 'GroupHead' => Slim::Utils::Strings::string('SETUP_MUSICMAGICPLAYLISTFORMAT'),
- 'GroupDesc' => Slim::Utils::Strings::string('SETUP_MUSICMAGICPLAYLISTFORMAT_DESC'),
- 'GroupLine' => 1,
- 'GroupSub' => 1,
- }
- },
-
- 'Prefs' => {
- 'MMMPlayerSettings' => {
- 'validate' => \&Slim::Utils::Validate::trueFalse,
- ,'options' => {
- '1' => Slim::Utils::Strings::string('YES')
- ,'0' => Slim::Utils::Strings::string('NO')
- }
- },
-
- 'MusicMagicplaylistprefix' => {
- 'validate' => \&Slim::Utils::Validate::acceptAll,
- 'PrefSize' => 'large',
- },
-
- 'MusicMagicplaylistsuffix' => {
- 'validate' => \&Slim::Utils::Validate::acceptAll,
- 'PrefSize' => 'large',
- },
-
- 'musicmagicscaninterval' => {
- 'validate' => \&Slim::Utils::Validate::number,
- 'validateArgs' => [0,undef,1000],
- },
-
- ,'MMMFilter' => {
- 'validate' => \&Slim::Utils::Validate::inHash
- ,'validateArgs' => [\&grabFilters]
- ,'options' => {grabFilters()}
- },
-
- 'MMMSize' => {
- 'validate' => \&Slim::Utils::Validate::isInt,
- 'validateArgs' => [1,undef,1]
- },
-
- 'MMMRejectSize' => {
- 'validate' => \&Slim::Utils::Validate::isInt,
- 'validateArgs' => [1,undef,1]
- },
-
- 'MMMMixType' => {
- 'validate' => \&Slim::Utils::Validate::inList,
- 'validateArgs' => [0,1,2],
- 'options' => {
- '0' => Slim::Utils::Strings::string('MMMMIXTYPE_TRACKS'),
- '1' => Slim::Utils::Strings::string('MMMMIXTYPE_MIN'),
- '2' => Slim::Utils::Strings::string('MMMMIXTYPE_MBYTES'),
- }
- },
-
- 'MMMRejectType' => {
- 'validate' => \&Slim::Utils::Validate::inList,
- 'validateArgs' => [0,1,2],
- 'options' => {
- '0' => Slim::Utils::Strings::string('MMMMIXTYPE_TRACKS'),
- '1' => Slim::Utils::Strings::string('MMMMIXTYPE_MIN'),
- '2' => Slim::Utils::Strings::string('MMMMIXTYPE_MBYTES'),
- }
- },
-
- 'MMMMixGenre' => {
- 'validate' => \&Slim::Utils::Validate::trueFalse,
- ,'options' => {
- '1' => Slim::Utils::Strings::string('YES')
- ,'0' => Slim::Utils::Strings::string('NO')
- }
- },
-
- 'MMMStyle' => {
- 'validate' => \&Slim::Utils::Validate::isInt,
- 'validateArgs' => [0,200,1,1],
- },
-
- 'MMMVariety' => {
- 'validate' => \&Slim::Utils::Validate::isInt,
- 'validateArgs' => [0,9,1,1],
- },
-
- 'MMSport' => {
- 'validate' => \&Slim::Utils::Validate::isInt,
- 'validateArgs' => [1025,65535,undef,1],
- },
-
- 'MMSHost' => {
- 'validate' => \&Slim::Utils::Validate::acceptAll,
- 'PrefSize' => 'large'
- },
-
- 'MMSremoteRoot'=> {
- 'validate' => \&Slim::Utils::Validate::acceptAll,
- 'PrefSize' => 'large'
- }
- }
- );
-
- return (\%setupCategory);
-};
-
1;
__END__
Modified: trunk/server/Plugins/MusicMagic/Settings.pm
URL: http://svn.slimdevices.com/trunk/server/Plugins/MusicMagic/Settings.pm?rev=10809&r1=10808&r2=10809&view=diff
==============================================================================
--- trunk/server/Plugins/MusicMagic/Settings.pm (original)
+++ trunk/server/Plugins/MusicMagic/Settings.pm Fri Dec 1 00:44:28 2006
@@ -1,271 +1,135 @@
package Plugins::MusicMagic::Settings;
-# SlimServer Copyright (c) 2001-2004 Sean Adams, Slim Devices Inc.
+# SlimServer Copyright (C) 2001-2006 Slim Devices Inc.
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License,
# version 2.
use strict;
+use base qw(Slim::Web::Settings);
-# button functions for browse directory
-our @defaultSettingsChoices = qw(MMMSize MMMMixType MMMStyle MMMVariety MMMFilter MMMMixGenre MMMRejectType MMMRejectSize);
+use Slim::Utils::Log;
+use Slim::Utils::Misc;
+use Slim::Utils::Strings qw(string);
-our @settingsChoices = ();
-our %current = ();
-our %menuParams = ();
-our %functions = ();
+my $log = Slim::Utils::Log->addLogCategory({
+ 'category' => 'plugin.musicmagic',
+ 'defaultLevel' => 'WARN',
+});
-sub init {
- Slim::Buttons::Common::addMode('MMMsettings',getFunctions(),\&setMode);
+sub name {
+ return 'MUSICMAGIC';
+}
- %functions = (
- 'right' => sub {
- my ($client,$funct,$functarg) = @_;
- if (defined($client->modeParam('useMode'))) {
- #in a submenu of settings, which is passing back a button press
- Slim::Buttons::Common::popMode($client);
- Plugins::MusicMagic::Plugin::mixerFunction($client,1);
- } else {
- #handle passback of button presses
- settingsExitHandler($client,'RIGHT');
- }
- },
- 'play' => sub {
- my $client = shift;
- my @oldlines = Slim::Display::Display::curLines($client);
-
- Slim::Buttons::Common::popMode($client);
- Plugins::MusicMagic::Plugin::mixerFunction($client,1);
- },
+sub page {
+ return 'plugins/MusicMagic/settings/musicmagic.html';
+}
+
+sub handler {
+ my ($class, $client, $params) = @_;
+
+ # These are lame preference names.
+ my @prefs = qw(
+ musicmagic
+ MMMPlayerSettings
+ MMMSize
+ MMMMixType
+ MMMStyle
+ MMMVariety
+ MMMMixGenre
+ MMMRejectType
+ MMMRejectSize
+ MMMFilter
+ musicmagicscaninterval
+ MMSport
+ MusicMagicplaylistprefix
+ MusicMagicplaylistsuffix
);
- %menuParams = (
+ # Cleanup the checkbox
+ $params->{'musicmagic'} = defined $params->{'musicmagic'} ? 1 : 0;
- 'MMMsettings' => {
- 'listRef' => \@defaultSettingsChoices,
- 'stringExternRef' => 1,
- 'header' => 'SETUP_MMMSETTINGS',
- 'stringHeader' => 1,
- 'headerAddCount' => 1,
- 'callback' => \&settingsExitHandler,
- 'overlayRef' => sub {
- return (undef,Slim::Display::Display::symbol('rightarrow'));
- },
- 'overlayRefArgs' => 'C',
- },
-
- 'MMMsettings/MMMSize' => {
- 'useMode' => 'INPUT.Bar',
- 'header' => 'SETUP_MMMSIZE',
- 'stringHeader' => 1,
- 'headerValue' =>'unscaled',
- 'min' => 0,
- 'max' => 200,
- 'increment' => 1,
- 'onChange' => \&setPref,
- 'pref' => "MMMSize",
- 'initialValue' => "MMMSize",
- 'overlayRef' => sub { return ($_[0]->string('MUSICMAGIC_MIXRIGHT'),undef) },
- 'overlayRefArgs' => 'C',
- },
+ if ($params->{'submit'}) {
- 'MMMsettings/MMMMixType' => {
- 'useMode' => 'INPUT.List',
- 'header' => 'SETUP_MMMMIXTYPE',
- 'stringHeader' => 1,
- 'listRef' => [0,1,2],
- 'externRef' => {
- '0' => Slim::Utils::Strings::string('MMMMIXTYPE_TRACKS'),
- '1' => Slim::Utils::Strings::string('MMMMIXTYPE_MIN'),
- '2' => Slim::Utils::Strings::string('MMMMIXTYPE_MBYTES'),
- },
- 'onChange' => \&setPref,
- 'pref' => "MMMMixType",
- 'initialValue' => "MMMStyle",
- 'overlayRef' => sub { return ($_[0]->string('MUSICMAGIC_MIXRIGHT'),undef) },
- 'overlayRefArgs' => 'C',
- },
+ if ($params->{'musicmagic'} != Slim::Utils::Prefs::get('musicmagic')) {
- 'MMMsettings/MMMStyle' => {
- 'useMode' => 'INPUT.Bar',
- 'header' => 'SETUP_MMMSTYLE',
- 'stringHeader' => 1,
- 'headerValue' => 'unscaled',
- 'min' => 0,
- 'max' => 200,
- 'onChange' => \&setPref,
- 'pref' => "MMMStyle",
- 'initialValue' => "MMMStyle",
- 'overlayRef' => sub { return ($_[0]->string('MUSICMAGIC_MIXRIGHT'),undef) },
- 'overlayRefArgs' => 'C',
- },
+ for my $c (Slim::Player::Client::clients()) {
- 'MMMsettings/MMMVariety' => {
- 'useMode' => 'INPUT.Bar',
- 'header' => 'SETUP_MMMVARIETY',
- 'stringHeader' => 1,
- 'headerValue' =>'unscaled',
- 'min' => 0,
- 'max' => 9,
- 'increment' => 1,
- 'onChange' => \&setPref,
- 'pref' => "MMMVariety",
- 'initialValue' => "MMMVariety",
- 'overlayRef' => sub { return ($_[0]->string('MUSICMAGIC_MIXRIGHT'),undef) },
- 'overlayRefArgs' => 'C',
- },
+ Slim::Buttons::Home::updateMenu($c);
+ }
- 'MMMsettings/MMMFilter' => {
- 'useMode' => 'INPUT.List',
- 'header' => 'SETUP_MMMFILTER',
- 'stringHeader' => 1,
- 'listRef' => undef,
- 'externRef' => undef,
- 'onChange' => \&setPref,
- 'pref' => "MMMFilter",
- 'initialValue' => "MMMFilter",
- 'overlayRef' => sub { return ($_[0]->string('MUSICMAGIC_MIXRIGHT'),undef) },
- 'overlayRefArgs' => 'C',
- },
+ Slim::Music::Import->useImporter('Plugin::MusicMagic::Plugin', $params->{'musicmagic'});
+ }
- 'MMMsettings/MMMMixGenre' => {
- 'useMode' => 'INPUT.List',
- 'header' => 'SETUP_MMMMIXGENRE',
- 'stringHeader' => 1,
- 'listRef' => [0,1],
- 'externRef' => {
- '0' => Slim::Utils::Strings::string('NO'),
- '1' => Slim::Utils::Strings::string('YES'),
- },
- 'onChange' => \&setPref,
- 'pref' => "MMMMixGenre",
- 'initialValue' => "MMMMixGenre",
- 'overlayRef' => sub { return ($_[0]->string('MUSICMAGIC_MIXRIGHT'),undef) },
- 'overlayRefArgs' => 'C',
- },
-
- 'MMMsettings/MMMRejectType' => {
- 'useMode' => 'INPUT.List',
- 'header' => 'SETUP_MMMREJECTTYPE',
- 'stringHeader' => 1,
- 'listRef' => [0,1,2],
- 'externRef' => {
- '0' => Slim::Utils::Strings::string('MMMMIXTYPE_TRACKS'),
- '1' => Slim::Utils::Strings::string('MMMMIXTYPE_MIN'),
- '2' => Slim::Utils::Strings::string('MMMMIXTYPE_MBYTES'),
- },
- 'onChange' => \&setPref,
- 'pref' => "MMMRejectType",
- 'initialValue' => "MMMRejectType",
- 'overlayRef' => sub { return ($_[0]->string('MUSICMAGIC_MIXRIGHT'),undef) },
- 'overlayRefArgs' => 'C',
- },
-
- 'MMMsettings/MMMRejectSize' => {
- 'useMode' => 'INPUT.Bar',
- 'header' => 'SETUP_MMMREJECTSIZE',
- 'stringHeader' => 1,
- 'headerValue' =>'unscaled',
- 'min' => 0,
- 'max' => 200,
- 'increment' => 1,
- 'onChange' => \&setPref,
- 'pref' => "MMMRejectSize",
- 'initialValue' => "MMMRejectSize",
- 'overlayRef' => sub { return ($_[0]->string('MUSICMAGIC_MIXRIGHT'),undef) },
- 'overlayRefArgs' => 'C',
- },
- );
+ for my $pref (@prefs) {
+
+ # XXX - need validation!
+ #'itunesscaninterval' => { 'validate' => \&Slim::Utils::Validate::number, },
+ #'itunes_library_xml_path' => { 'validate' => \&Slim::Utils::Validate::isFile, },
+ #'itunes_library_music_path' => { 'validate' => \&Slim::Utils::Validate::isDir, },
+
+ Slim::Utils::Prefs::set($pref, $params->{$pref});
+ }
+ }
+
+ for my $pref (@prefs) {
+
+ $params->{'prefs'}->{$pref} = Slim::Utils::Prefs::get($pref);
+ }
+ $params->{'filters'} = grabFilters();
+
+ return $class->SUPER::handler($client, $params);
}
-sub setPref {
- my $client = shift;
- my $value = shift;
+sub grabFilters {
+ my @filters = ();
+ my %filterHash = ();
- my $pref = $client->modeParam('pref');
-
- $client->prefSet($pref,$value);
+ my $MMSport = Slim::Utils::Prefs::get('MMSport');
+ my $MMSHost = Slim::Utils::Prefs::get('MMSHost');
+
+ $log->debug("Get filters list");
+
+ my $http = Slim::Player::Protocols::HTTP->new({
+ 'url' => "http://$MMSHost:$MMSport/api/filters",
+ 'create' => 0,
+ });
+
+ if ($http) {
+
+ @filters = split(/\n/, $http->content);
+ $http->close;
+
+ if ($log->is_debug && scalar @filters) {
+
+ $log->debug("Found filters:");
+
+ for my $filter (@filters) {
+
+ $log->debug("\t$filter");
+ }
+ }
+ }
+
+ my $none = sprintf('(%s)', Slim::Utils::Strings::string('NONE'));
+
+ push @filters, $none;
+
+ foreach my $filter ( @filters ) {
+
+ if ($filter eq $none) {
+
+ $filterHash{0} = $filter;
+ next
+ }
+
+ $filterHash{$filter} = $filter;
+ }
+
+ return \%filterHash;
}
-sub executeCommand {
- my $client = shift;
- my $value = shift;
-
- my $command = $client->modeParam('command');
- my $subcmd = $client->modeParam('subcommand');
-
- $client->execute([$command, $subcmd, $value]);
-}
-
-sub settingsExitHandler {
- my ($client,$exittype) = @_;
- $exittype = uc($exittype);
- if ($exittype eq 'LEFT') {
- Slim::Buttons::Common::popModeRight($client);
- } elsif ($exittype eq 'RIGHT') {
- my $nextmenu = 'MMMsettings/'.$current{$client};
- if (defined($client->modeParam('useMode'))) {
- #in a submenu of settings and exiting right.
- Plugins::MusicMagic::Plugin::mixerFunction($client,1);
- } elsif (exists($menuParams{$nextmenu})) {
- my %nextParams = %{$menuParams{$nextmenu}};
- $nextParams{'callback'} = \&settingsExitHandler;
- $nextParams{'parentParams'} = $client->modeParam('parentParams');
- if (($nextParams{'useMode'} eq 'INPUT.List' || $nextParams{'useMode'} eq 'INPUT.Bar') && exists($nextParams{'initialValue'})) {
- #set up valueRef for current pref
- my $value;
- if (ref($nextParams{'initialValue'}) eq 'CODE') {
- $value = $nextParams{'initialValue'}->($client);
- } else {
- $value = $client->prefGet($nextParams{'initialValue'});
- }
- $nextParams{'valueRef'} = \$value;
- }
- if ($nextmenu eq 'MMMsettings/MMMFilter') {
- my %filters = Plugins::MusicMagic::Plugin::grabFilters();
-
- $nextParams{'listRef'} = [keys %filters];
- $nextParams{'externRef'} = {Plugins::MusicMagic::Plugin::grabFilters()};
- $nextParams{'listIndex'} = $client->prefGet('MMMFilter');
-
- }
-
- Slim::Buttons::Common::pushModeLeft(
- $client
- ,$nextParams{'useMode'}
- ,\%nextParams
- );
- } else {
- Plugins::MusicMagic::Plugin::mixerFunction($client,1);
- }
- } else {
- return;
- }
-}
-sub getFunctions {
- return \%functions;
-}
-
-sub setMode {
- my $client = shift;
- my $method = shift;
- if ($method eq 'pop') {
- Slim::Buttons::Common::popMode($client);
- return;
- }
-
- $current{$client} = $defaultSettingsChoices[0] unless exists($current{$client});
- my %params = %{$menuParams{'MMMsettings'}};
- $params{'valueRef'} = \$current{$client};
- $params{'parentParams'} = $client->modeParam('parentParams');
-
- my @settingsChoices = @defaultSettingsChoices;
-
- $params{'listRef'} = \@settingsChoices;
-
- Slim::Buttons::Common::pushMode($client,'INPUT.List',\%params);
-}
1;
More information about the checkins
mailing list