Index: /Users/mh/Documents/workspace/slimpy/Slim/Web/Pages/LiveSearch.pm =================================================================== --- /Users/mh/Documents/workspace/slimpy/Slim/Web/Pages/LiveSearch.pm (revision 12732) +++ /Users/mh/Documents/workspace/slimpy/Slim/Web/Pages/LiveSearch.pm (working copy) @@ -26,6 +26,7 @@ my $query = shift; my $rsList = shift; my $player = shift; + my $params = shift; my @xml = ( '<?xml version="1.0" encoding="utf-8" ?>', @@ -43,9 +44,34 @@ if ($count <= MAXRESULTS) { - my $rowType = $count % 2 ? 'even' : 'odd'; + my %form = ( + 'hreftype' => 'browseDb', + 'odd' => ($count+1) % 2, + 'player' => $player, + 'itemobj' => $item, + 'level' => 1, + 'descend' => $type ne 'track', + 'artwork' => 0, + 'attributes' => sprintf('&%s.id=%d', $type, $item->id) + ); + + if ($type eq 'contributor') { + + $form{'attributes'} .= '&contributor.role=ALL'; + $form{'hierarchy'} = 'contributor,album,track'; + + } elsif ($type eq 'album') { + + $form{'hierarchy'} = 'album,track'; + } + + $item->displayAsHTML(\%form, $type ne 'track'); + + my $anchor = substr($item->namesort, 0, 1); + + $params->{item} = \%form; - push @output, renderItem($rowType, $type, $item, $player); + push @output, ${Slim::Web::HTTP::filltemplatefile("browsedbitems_list.html", $params)}; } $count++; @@ -71,6 +97,7 @@ return \join('', @xml); } + sub outputAsXML { my $class = shift; my $query = shift; @@ -91,8 +118,6 @@ while (my $item = $rs->next) { - my $rowType = $count % 2 ? 'even' : 'odd'; - if ($count <= MAXRESULTS) { push @output, sprintf('<livesearchitem id="%s">%s</livesearchitem>', $item->id, $item->name); @@ -120,98 +145,6 @@ return \join('', @xml); } - -sub renderItem { - my ($rowType, $type, $item, $player) = @_; - - my $id = $item->id, - my @xml = (); - my $name = ''; - my $showExtra = ''; - - # Track case, followed by album & artist. - if (blessed($item) eq 'Slim::Schema::Track') { - - $name = Slim::Music::Info::standardTitle(undef, $item) || ''; - - # Starting work on the standard track list format, but its a work in progress. - my $webFormat = $prefs->get('titleFormat')->[ $prefs->get('titleFormatWeb') ] || ''; - - # This is rather redundant from Pages.pm - if ($webFormat !~ /ARTIST/ && $item->can('artist') && $item->artist) { - - $showExtra .= sprintf( - ' %s <a href="browsedb.html?hierarchy=contributor,album,track&level=1\&contributor.id=%d&player=%s">%s</a>', - string('BY'), $item->artist->id, $player, $item->artist->name, - ); - } - - if ($webFormat !~ /ALBUM/ && $item->can('album') && $item->album) { - - $showExtra .= sprintf( - ' %s <a href="browsedb.html?hierarchy=album,track&level=1&album.id=%d&player=%s">%s</a>', - string('FROM'), $item->album->id, $player, $item->album->title, - ); - } - - } elsif (blessed($item) eq 'Slim::Schema::Album') { - - $name = $item->name; - - # This is rather redundant from the Album displayAsHTML Schema - if ($prefs->get('showYear') && $item->can('year') && $item->year) { - - $showExtra .= sprintf( - ' %s<a href="browsedb.html?hierarchy=year,album,track&level=1&year.id=%d&player=%s">%s</a>%s ', - '(', $item->year, $player, $item->year, ')', - ); - } - - # This is rather redundant from the Album displayAsHTML Schema - if ($prefs->get('showArtist') && $item->can('artists') && $item->artists) { - my @artists = $item->artists; - - $showExtra .= sprintf( - ' %s <a href="browsedb.html?hierarchy=contributor,album,track&level=1&contributor.id=%d&player=%s">%s</a>', - string('BY'), $artists[0]->id, $player, $artists[0]->name, - ); - } - - } else { - - $name = $item->name; - } - - # We need to handle the different urls that are needed for different result types - my $url; - - if ($type eq 'track') { - - $url = "songinfo.html?item=$id"; - - } elsif ($type eq 'album') { - - $url = "browsedb.html?hierarchy=album,track&level=1&album.id=$id"; - - } elsif ($type eq 'contributor') { - - $url = "browsedb.html?hierarchy=contributor,album,track&level=1&contributor.id=$id&contributor.role=ALL"; - } - - push @xml,"\n<div class=\"$rowType\">\n<div class=\"browsedbListItem\"> - <a href=\"$url\&player=$player\">$name</a>$showExtra"; - - push @xml,"<div class=\"browsedbControls\"> - - <a href=\"status_header.html?command=playlist&subcommand=loadtracks\&$type.id=$id\&player=$player\" target=\"status\">\n - <img src=\"html/images/b_play.gif\" width=\"13\" height=\"13\" alt=\"Play\" title=\"Play\"/></a>\n\n - - <a href=\"status_header.html?command=playlist&subcommand=addtracks\&$type.id=$id\&player=$player\" target=\"status\">\n - <img src=\"html/images/b_add.gif\" width=\"13\" height=\"13\" alt=\"Add to playlist\" title=\"Add to playlist\"/></a> \n - </div>\n</div>\n</div>\n"; - - return join('', @xml); -} 1; __END__ Index: /Users/mh/Documents/workspace/slimpy/Slim/Web/Pages/Search.pm =================================================================== --- /Users/mh/Documents/workspace/slimpy/Slim/Web/Pages/Search.pm (revision 12732) +++ /Users/mh/Documents/workspace/slimpy/Slim/Web/Pages/Search.pm (working copy) @@ -94,7 +94,7 @@ # do it live - and send back the div # this should be replaced with a call to filltemplatefile() - return Slim::Web::Pages::LiveSearch->outputAsXHTML($query, \@rsList, $player); + return Slim::Web::Pages::LiveSearch->outputAsXHTML($query, \@rsList, $player, $params); } }