db/DatabasePrint: support sorting by "modified-since"

Closes #172
This commit is contained in:
Max Kellermann
2017-12-18 21:36:47 +01:00
parent 7a55ab6acc
commit 5582367d68
5 changed files with 40 additions and 11 deletions

View File

@@ -220,13 +220,21 @@ db_selection_print(Response &r, Partition &partition,
db.Visit(selection, d, collect_songs, p);
}
std::stable_sort(songs.begin(), songs.end(),
[sort, descending](const DetachedSong &a,
const DetachedSong &b){
return CompareTags(sort, descending,
a.GetTag(),
b.GetTag());
});
if (sort == TagType(SORT_TAG_LAST_MODIFIED))
std::stable_sort(songs.begin(), songs.end(),
[descending](const DetachedSong &a, const DetachedSong &b){
return descending
? a.GetLastModified() > b.GetLastModified()
: a.GetLastModified() < b.GetLastModified();
});
else
std::stable_sort(songs.begin(), songs.end(),
[sort, descending](const DetachedSong &a,
const DetachedSong &b){
return CompareTags(sort, descending,
a.GetTag(),
b.GetTag());
});
if (window_end < songs.size())
songs.erase(std::next(songs.begin(), window_end),

View File

@@ -38,6 +38,10 @@ db_selection_print(Response &r, Partition &partition,
const DatabaseSelection &selection,
bool full, bool base);
/**
* @param sort the sort tag; TAG_NUM_OF_ITEM_TYPES means don't sort;
* LOCATE_TAG_MODIFIED_SINCE means sort by file modification time
*/
void
db_selection_print(Response &r, Partition &partition,
const DatabaseSelection &selection,