=== Slim/Control/Queries.pm ================================================================== --- Slim/Control/Queries.pm (revision 29935) +++ Slim/Control/Queries.pm (local) @@ -655,7 +655,7 @@ my $chunkCount = 0; my @data = $rs->slice($start, $end); - $request->addResult('offset', $start) if $menuMode; + $request->addResult( 'offset', $request->getParam('_index') ) if $menuMode; # Various artist handling. Don't do if pref is off, or if we're # searching, or if we have a track @@ -697,7 +697,14 @@ $chunkCount++; } - ($chunkCount, $totalCount) = _jiveAddToFavorites(start => $start, listCount => $totalCount, chunkCount => $chunkCount, request => $request, loopname => $loopname, favorites => \%favorites); + + # Add Favorites as the last item, if applicable + my $lastChunk; + if ( $end == $count - 1 ) { + $lastChunk = 1; + } + + ($chunkCount, $totalCount) = _jiveAddToFavorites(lastChunk => $lastChunk, listCount => $totalCount, chunkCount => $chunkCount, request => $request, loopname => $loopname, favorites => \%favorites); } if ($totalCount == 0 && $menuMode) { @@ -4515,23 +4522,34 @@ my $request = $args{'request'}; my $favorites = $args{'favorites'}; my $start = $args{'start'}; + my $lastChunk = $args{'lastChunk'}; my $includeArt = defined($args{'includeArt'}) ? 1 : 0; return ($chunkCount, $listCount) unless $loopname && $favorites; + + # Do nothing unless Favorites are enabled + if ( !Slim::Utils::PluginManager->isEnabled('Slim::Plugin::Favorites::Plugin') ) { + return ($chunkCount, $listCount); + } - if ($start == 0) { + # we need %favorites populated or else we don't want this item + if (!$favorites->{'title'} || !$favorites->{'url'}) { + return ($chunkCount, $listCount); + } + + # We'll add a Favorites item to this request. + # We always bump listCount to indicate this request list will contain one more item at the end + $listCount++; - # we need %favorites populated or else we don't want this item - if (!$favorites->{'title'} || !$favorites->{'url'}) { - return ($chunkCount, $listCount); - } - + # Add the actual favorites item if we're in the last chunk + # or if a start value was passed and it's 0 + if ( $lastChunk || $start == 0 ) { my $action = 'add'; my $token = 'JIVE_ADD_TO_FAVORITES'; # first we check to see if the URL exists in favorites already my $client = $request->client(); my $favIndex = undef; - if ( blessed($client) && Slim::Utils::PluginManager->isEnabled('Slim::Plugin::Favorites::Plugin') ) { + if ( blessed($client) ) { my $favs = Slim::Utils::Favorites->new($client); $favIndex = $favs->findUrl($favorites->{'url'}); if (defined($favIndex)) { @@ -4561,12 +4579,11 @@ # FIXME, this needs to change to a favorites image after it is provided $request->addResultLoop($loopname, $chunkCount, 'icon', '/html/images/favorites.png'); } + $chunkCount++; - $listCount++; - } - return($chunkCount, $listCount); + return ($chunkCount, $listCount); } sub _songData {