Index: Slim/Utils/Prefs.pm =================================================================== --- Slim/Utils/Prefs.pm (revision 13783) +++ Slim/Utils/Prefs.pm (working copy) @@ -186,6 +186,7 @@ 'timeFormat' => q(|%I:%M %p), 'showArtist' => 0, 'showYear' => 0, + 'sortAlbumsByYear' => 0, 'guessFileFormats' => [ '(ARTIST - ALBUM) TRACKNUM - TITLE', '/ARTIST/ALBUM/TRACKNUM - TITLE', Index: Slim/Schema/ResultSet/Contributor.pm =================================================================== --- Slim/Schema/ResultSet/Contributor.pm (revision 13783) +++ Slim/Schema/ResultSet/Contributor.pm (working copy) @@ -7,6 +7,31 @@ use Slim::Utils::Prefs; +my $prefs = preferences('server'); + +my @albumSortRules = ( + # 0: No special sorting + "concat('0', album.titlesort), album.disc", + + # 1: Sort by year ascending, unset years last + "CASE album.year " . + " WHEN 0 THEN 9999" . + " ELSE album.year " . + "END, concat('0', album.titlesort), album.disc", + + # 2: Sort by year ascending, unset years first + "album.year, concat('0', album.titlesort), album.disc", + + # 3: Sort by year descending, unset years last + "album.year DESC, concat('0', album.titlesort), album.disc", + + # 4: Sort by year ascending, unset years first + "CASE album.year " . + " WHEN 0 THEN 9999" . + " ELSE album.year " . + "END DESC, concat('0', album.titlesort), album.disc" +); + sub pageBarResults { my $self = shift; @@ -111,8 +136,9 @@ $sort = $rs->fixupSortKeys($sort); } else { - - $sort = "concat('0', album.titlesort), album.disc"; + + my $sortByYear = $prefs->get('sortAlbumsByYear') || 0; + $sort = $albumSortRules[$sortByYear] || $albumSortRules[0]; } my $attr = { Index: Slim/Web/Settings/Server/TextFormatting.pm =================================================================== --- Slim/Web/Settings/Server/TextFormatting.pm (revision 13783) +++ Slim/Web/Settings/Server/TextFormatting.pm (working copy) @@ -23,7 +23,7 @@ } sub prefs { - return ($prefs, qw(longdateFormat shortdateFormat timeFormat showArtist showYear titleFormatWeb) ); + return ($prefs, qw(longdateFormat shortdateFormat timeFormat showArtist showYear sortAlbumsByYear titleFormatWeb) ); } sub handler { Index: HTML/EN/settings/server/formatting.html =================================================================== --- HTML/EN/settings/server/formatting.html (revision 13783) +++ HTML/EN/settings/server/formatting.html (working copy) @@ -64,6 +64,23 @@