? bug72.diff Index: Rescan.pm =================================================================== RCS file: /home/cvs/cvsroot/slim/server/Plugins/Rescan.pm,v retrieving revision 1.3 diff -u -p -B -r1.3 Rescan.pm --- Rescan.pm 18 May 2004 01:57:48 -0000 1.3 +++ Rescan.pm 15 Jul 2004 04:15:06 -0000 @@ -1,5 +1,7 @@ # Rescan.pm by Andrew Hedges (andrew@hedges.me.uk) October 2002 -# +# Timer functions added by Kevin Deane-Freeman (kevindf@shaw.ca) June 2004 +# $Id: ScanTimer.pm,v 1.3 2004/05/10 07:02:27 fishbone Exp $ + # This code is derived from code with the following copyright message: # # SliMP3 Server Copyright (C) 2001 Sean Adams, Slim Devices Inc. @@ -16,47 +18,52 @@ package Plugins::Rescan; use Slim::Control::Command; use Slim::Utils::Strings qw (string); +use Time::HiRes; use vars qw($VERSION); $VERSION = substr(q$Revision: 1.3 $,10); -sub getDisplayName() {return string('PLUGIN_RESCAN_MUSIC_LIBRARY')} - -sub strings() { return ' -PLUGIN_RESCAN_MUSIC_LIBRARY - DE Musikverzeichnis erneut durchsuchen - EN Rescan Music Library - FR Répertorier musique - -PLUGIN_RESCAN_RESCANNING - DE Server durchsucht Verzeichnisse... - EN Server now rescanning... - FR En cours... +my $interval = 1; # check every x seconds +my @browseMenuChoices; +my %menuSelection; +my %searchCursor; -PLUGIN_RESCAN_PRESS_PLAY - DE PLAY drücken, um den Vorgang zu starten - EN Press PLAY to rescan your music folder - FR Appuyez sur PLAY pour répertorier votre dossier de musique -'}; +sub getDisplayName() {return string('PLUGIN_RESCAN_MUSIC_LIBRARY')} ################################################## ### Section 2. Your variables and code go here ### ################################################## -sub setMode() { +sub setMode { my $client = shift; + @browseMenuChoices = ( + string('PLUGIN_RESCAN_TIMER_SET'), + string('PLUGIN_RESCAN_TIMER_OFF'), + string('PLUGIN_RESCAN_PRESS_PLAY'), + ); + if (!defined($menuSelection{$client})) { $menuSelection{$client} = 0; }; $client->lines(\&lines); + #get previous alarm time or set a default + my $time = Slim::Utils::Prefs::get($client, "rescan-time"); + if (!defined($time)) { Slim::Utils::Prefs::get($client, "rescan-time", 9 * 60 * 60 ); } + } my %functions = ( 'up' => sub { my $client = shift; - Slim::Display::Animation::bumpUp($client); + my $newposition = Slim::Buttons::Common::scroll($client, -1, ($#browseMenuChoices + 1), $menuSelection{$client}); + + $menuSelection{$client} =$newposition; + $client->update(); }, 'down' => sub { - my $client = shift; - Slim::Display::Animation::bumpDown($client); + my $client = shift; + my $newposition = Slim::Buttons::Common::scroll($client, +1, ($#browseMenuChoices + 1), $menuSelection{$client}); + + $menuSelection{$client} =$newposition; + $client->update(); }, 'left' => sub { my $client = shift; @@ -64,24 +71,61 @@ my %functions = ( }, 'right' => sub { my $client = shift; - Slim::Display::Animation::bumpRight($client); + my @oldlines = Slim::Display::Display::curLines($client); + + if ($browseMenuChoices[$menuSelection{$client}] eq string('PLUGIN_RESCAN_TIMER_SET')) { + Slim::Buttons::Common::pushModeLeft($client, 'scantimerset'); + } + elsif ($browseMenuChoices[$menuSelection{$client}] eq string('PLUGIN_RESCAN_TIMER_OFF')) { + Slim::Utils::Prefs::set("rescan-scheduled", 1); + $browseMenuChoices[$menuSelection{$client}] = string('PLUGIN_RESCAN_TIMER_ON'); + Slim::Display::Animation::showBriefly($client,string('PLUGIN_RESCAN_TIMER_TURNING_ON'),''); + setTimer($client); + } + elsif ($browseMenuChoices[$menuSelection{$client}] eq string('PLUGIN_RESCAN_TIMER_ON')) { + Slim::Utils::Prefs::set("rescan-scheduled", 0); + $browseMenuChoices[$menuSelection{$client}] = string('PLUGIN_RESCAN_TIMER_OFF'); + Slim::Display::Animation::showBriefly($client,string('PLUGIN_RESCAN_TIMER_TURNING_OFF'),''); + setTimer($client); + } }, 'play' => sub { my $client = shift; - my @pargs=('rescan'); - my ($line1, $line2) = (string('PLUGIN_RESCAN_MUSIC_LIBRARY'), string('PLUGIN_RESCAN_RESCANNING')); - Slim::Control::Command::execute($client, \@pargs, undef, undef); - Slim::Display::Animation::showBriefly($client, $line1, $line2); + if ($browseMenuChoices[$menuSelection{$client}] eq string('PLUGIN_RESCAN_PRESS_PLAY')) { + my @pargs=('rescan'); + my ($line1, $line2) = (string('PLUGIN_RESCAN_MUSIC_LIBRARY'), string('PLUGIN_RESCAN_RESCANNING')); + Slim::Control::Command::execute($client, \@pargs, undef, undef); + Slim::Display::Animation::showBriefly($client, $line1, $line2); + } else { + Slim::Display::Animation::bumpRight($client); + } } ); sub lines { - my ($line1, $line2); + my $client = shift; + my ($line1, $line2, $overlay); + my $timeFormat = Slim::Utils::Prefs::get("timeFormat"); + + $overlay = overlay($client); $line1 = string('PLUGIN_RESCAN_MUSIC_LIBRARY'); - $line2 = string('PLUGIN_RESCAN_PRESS_PLAY'); - return ($line1, $line2); + + if (Slim::Utils::Prefs::get("rescan-scheduled") && $browseMenuChoices[$menuSelection{$client}] eq string('PLUGIN_RESCAN_TIMER_OFF')) { + $browseMenuChoices[$menuSelection{$client}] = string('PLUGIN_RESCAN_TIMER_ON'); + } + $line2 = ""; + + $line2 = $browseMenuChoices[$menuSelection{$client}]; + return ($line1, $line2, undef, $overlay); } +sub overlay { + my $client = shift; + + return Slim::Hardware::VFD::symbol('rightarrow'); + + return undef; +} ################################################ ### End of Section 2. ### @@ -95,4 +139,245 @@ sub getFunctions() { return \%functions; } + +sub setTimer { +#timer to check alarms on an interval + Slim::Utils::Timers::setTimer(0, Time::HiRes::time() + $interval, \&checkScanTimer); +} + +sub checkScanTimer +{ + my ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) = localtime(time); + + my $time = $hour * 60 * 60 + $min * 60; + + if ($sec == 0) { # once we've reached the beginning of a minute, only check every 60s + $interval = 60; + } + if ($sec >= 50) { # if we end up falling behind, go back to checking each second + $interval = 1; + } + + if (Slim::Utils::Prefs::get("rescan-scheduled")) { + my $scantime = Slim::Utils::Prefs::get("rescan-time"); + if ($scantime) { + if ($time == $scantime +60 ) {$interval=1;}; #alarm is done, so reset to find the beginning of a minute + if ($time == $scantime && !Slim::Music::MusicFolderScan::stillScanning()) { + Slim::Music::MusicFolderScan::startScan(); + } + } + } + setTimer(); +} + +################################################################################# + +my %timerSetFunctions = ( + 'up' => sub { + my $client = shift; + my $time = Slim::Utils::Prefs::get("rescan-time") || 0; + Slim::Utils::Prefs::set("rescan-time", Slim::Buttons::Common::scrollTime($client, +1,$time,$searchCursor{$client})); + $client->update(); + }, + 'down' => sub { + my $client = shift; + my $time = Slim::Utils::Prefs::get("rescan-time") || 0; + Slim::Utils::Prefs::set("rescan-time", Slim::Buttons::Common::scrollTime($client, -1,$time,$searchCursor{$client})); + $client->update(); + }, + + 'left' => sub { + my $client = shift; + $searchCursor{$client}--; + if ($searchCursor{$client} < 0) { + Slim::Buttons::Common::popModeRight($client); + } else { + $client->update(); + } + }, + 'right' => sub { + my $client = shift; + + my $time = Slim::Utils::Prefs::get("rescan-time"); + my ($h0, $h1, $m0, $m1, $p) = Slim::Buttons::Common::timeDigits($client,$time); + + $searchCursor{$client}++; + + my $max = defined($p) ? 4 : 3; + if ($searchCursor{$client} > $max) { + $searchCursor{$client} = $max; + } + $client->update(); + }, + + 'add' => sub { Slim::Display::Animation::bumpRight(shift); }, + 'play' => sub { Slim::Display::Animation::bumpRight(shift); }, + 'numberScroll' => sub { + my $client = shift; + my $button = shift; + my $digit = shift; + + my $time = Slim::Utils::Prefs::get("rescan-time"); + my ($h0, $h1, $m0, $m1, $p) = Slim::Buttons::Common::timeDigits($client,$time); + + my $h = $h0 * 10 + $h1; + if ($p && $h == 12) { $h = 0 }; + + my $c = $searchCursor{$client}; + if ($c == 0 && $digit < ($p ? 2:3)) { $h0 = $digit; $searchCursor{$client}++; }; + if ($c == 1 && (($h0 * 10 + $digit) < 24)) { $h1 = $digit; $searchCursor{$client}++; }; + if ($c == 2) { $m0 = $digit; $searchCursor{$client}++; }; + if ($c == 3) { $m1 = $digit }; + + $p = (defined $p && $p eq 'PM') ? 1 : 0; + if ($c == 4) { $p = $digit % 2; } + + $time = ($h0 * 10 + $h1) * 60 * 60 + $m0 * 10 * 60 + $m1 * 60 + $p * 12 * 60 * 60; + Slim::Utils::Prefs::set("rescan-time", $time); + $client->update(); + } +); + +sub getTimerSetFunctions { + return \%timerSetFunctions; +} + +sub setScanTimerSetMode { + my $client = shift; + $searchCursor{$client} = 0; + Slim::Utils::Prefs::set("rescan-scheduled", 0); + $client->lines(\&timerSettingsLines); +} + + sub timerSettingsLines { + my $client = shift; + + my $time = Slim::Utils::Prefs::get("rescan-time") || 0; + + my ($h0, $h1, $m0, $m1, $p) = Slim::Buttons::Common::timeDigits($client,$time); + + my $cs = Slim::Hardware::VFD::symbol('cursorpos'); + my $c = $searchCursor{$client}; + + my $timestring = ($c == 0 ? $cs : '') . ((defined($p) && $h0 == 0) ? ' ' : $h0) . ($c == 1 ? $cs : '') . $h1 . ":" . ($c == 2 ? $cs : '') . $m0 . ($c == 3 ? $cs : '') . $m1 . " " . ($c == 4 ? $cs : '') . (defined($p) ? $p : ''); + + return (string('PLUGIN_RESCAN_TIMER_SET'), $timestring); +} + +sub setupGroup +{ + my %group = + ( + PrefOrder => ['rescan-scheduled','rescan-time'], + PrefsInTable => 1, + GroupHead => string('PLUGIN_RESCAN_TIMER_NAME'), + GroupDesc => string('PLUGIN_RESCAN_TIMER_DESC'),, + GroupLine => 1, + GroupSub => 1, + Suppress_PrefSub => 1, + Suppress_PrefLine => 1, + Suppress_PrefHead => 1 + ); + + my %prefs = + ( + 'rescan-scheduled' => { + 'validate' => \&Slim::Web::Setup::validateTrueFalse + ,'PrefChoose' => string('PLUGIN_RESCAN_TIMER_NAME') + ,'changeIntro' => string('PLUGIN_RESCAN_TIMER_NAME') + ,'options' => { + '1' => string('ON') + ,'0' => string('OFF') + } + }, + 'rescan-time' => { + 'validate' => \&Slim::Web::Setup::validateAcceptAll + ,'validateArgs' => [0,undef] + ,'PrefChoose' => string('PLUGIN_RESCAN_TIMER_SET') + ,'changeIntro' => string('PLUGIN_RESCAN_TIMER_SET') + ,'currentValue' => sub { + my $client = shift; + my $time = Slim::Utils::Prefs::get("rescan-time"); + my ($h0, $h1, $m0, $m1, $p) = Slim::Buttons::Common::timeDigits($client,$time); + my $timestring = ((defined($p) && $h0 == 0) ? ' ' : $h0) . $h1 . ":" . $m0 . $m1 . " " . (defined($p) ? $p : ''); + return $timestring; + } + ,'onChange' => sub { + my ($client,$changeref,$paramref,$pageref) = @_; + my $time = $changeref->{'rescan-time'}{'new'}; + my $newtime = 0; + $time =~ s{ + ^(0?[0-9]|1[0-9]|2[0-4]):([0-5][0-9])\s*(P|PM|A|AM)?$ + }{ + if (defined $3) { + $newtime = ($1 == 12?0:$1 * 60 * 60) + ($2 * 60) + ($3 =~ /P/?12 * 60 * 60:0); + } else { + $newtime = ($1 * 60 * 60) + ($2 * 60); + } + }iegsx; + Slim::Utils::Prefs::set('rescan-time',$newtime); + } + }, + ); + #&checkDefaults; + return (\%group,\%prefs); +}; + +#sub checkDefaults +#{ +# if (!Slim::Utils::Prefs::isDefined('rescan-time')) +# { +# Slim::Utils::Prefs::set('rescan-time', 36000); +# } +#} +# some initialization code, adding modes for this module +Slim::Buttons::Common::addMode('scantimer', getFunctions(), \&Plugins::Rescan::setMode); +Slim::Buttons::Common::addMode('scantimerset', getTimerSetFunctions(), \&Plugins::Rescan::setScanTimerSetMode); +setTimer(); + +sub strings +{ + local $/ = undef; + ; +} + 1; + +__DATA__ + +PLUGIN_RESCAN_MUSIC_LIBRARY + DE Musikverzeichnis erneut durchsuchen + EN Rescan Music Library + FR Répertorier musique + +PLUGIN_RESCAN_RESCANNING + DE Server durchsucht Verzeichnisse... + EN Server now rescanning... + FR En cours... + +PLUGIN_RESCAN_PRESS_PLAY + DE PLAY drücken, um den Vorgang zu starten + EN Press PLAY to rescan your music folder + FR Appuyez sur PLAY pour répertorier votre dossier de musique + +PLUGIN_RESCAN_TIMER_NAME + EN Scan Timer + +PLUGIN_RESCAN_TIMER_SET + EN Set Scan Time + +PLUGIN_RESCAN_TIMER_ON + EN Scan Timer ON + +PLUGIN_RESCAN_TIMER_DESC + EN You can choose to allow a scheduled rescan of your music library every 24 hours. Set the time, and set the Scan Timer to ON to use this feature. + +PLUGIN_RESCAN_TIMER_OFF + EN Scan Timer OFF + +PLUGIN_RESCAN_TIMER_TURNING_ON + EN Scan Timer Turning On + +PLUGIN_RESCAN_TIMER_TURNING_OFF + EN Scan Timer Turning Off +