db/Selection: add sort and window

Remove them as parameters from `db_selection_print()`.
This commit is contained in:
Max Kellermann 2018-09-02 10:42:47 +02:00
parent 9894967fcb
commit e6a974a93e
5 changed files with 33 additions and 34 deletions

View File

@ -107,12 +107,13 @@ handle_match(Client &client, Request args, Response &r, bool fold_case)
}
filter.Optimize();
const DatabaseSelection selection("", true, &filter);
DatabaseSelection selection("", true, &filter);
selection.window = window;
selection.sort = sort;
selection.descending = descending;
db_selection_print(r, client.GetPartition(),
selection, true, false,
sort, descending,
window);
selection, true, false);
return CommandResult::OK;
}

View File

@ -1,5 +1,5 @@
/*
* Copyright 2003-2017 The Music Player Daemon Project
* Copyright 2003-2018 The Music Player Daemon Project
* http://www.musicpd.org
*
* This program is free software; you can redistribute it and/or modify
@ -179,9 +179,7 @@ CompareTags(TagType type, bool descending, const Tag &a, const Tag &b) noexcept
void
db_selection_print(Response &r, Partition &partition,
const DatabaseSelection &selection,
bool full, bool base,
TagType sort, bool descending,
RangeArg window)
bool full, bool base)
{
const Database &db = partition.GetDatabaseOrThrow();
@ -197,9 +195,11 @@ db_selection_print(Response &r, Partition &partition,
std::ref(r), base, _1, _2)
: VisitPlaylist();
if (sort == TAG_NUM_OF_ITEM_TYPES) {
const auto window = selection.window;
if (selection.sort == TAG_NUM_OF_ITEM_TYPES) {
unsigned i = 0;
if (!window.IsAll())
if (!selection.window.IsAll())
s = [s, window, &i](const LightSong &song){
if (window.Contains(i++))
s(song);
@ -223,6 +223,9 @@ db_selection_print(Response &r, Partition &partition,
db.Visit(selection, d, collect_songs, p);
}
const auto sort = selection.sort;
const auto descending = selection.descending;
if (sort == TagType(SORT_TAG_LAST_MODIFIED))
std::stable_sort(songs.begin(), songs.end(),
[descending](const DetachedSong &a, const DetachedSong &b){
@ -254,16 +257,6 @@ db_selection_print(Response &r, Partition &partition,
}
}
void
db_selection_print(Response &r, Partition &partition,
const DatabaseSelection &selection,
bool full, bool base)
{
db_selection_print(r, partition, selection, full, base,
TAG_NUM_OF_ITEM_TYPES, false,
RangeArg::All());
}
static void
PrintSongURIVisitor(Response &r, const LightSong &song) noexcept
{

View File

@ -1,5 +1,5 @@
/*
* Copyright 2003-2017 The Music Player Daemon Project
* Copyright 2003-2018 The Music Player Daemon Project
* http://www.musicpd.org
*
* This program is free software; you can redistribute it and/or modify
@ -39,17 +39,6 @@ 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,
bool full, bool base,
TagType sort, bool descending,
RangeArg window);
void
PrintSongUris(Response &r, Partition &partition,
const SongFilter *filter);

View File

@ -1,5 +1,5 @@
/*
* Copyright 2003-2017 The Music Player Daemon Project
* Copyright 2003-2018 The Music Player Daemon Project
* http://www.musicpd.org
*
* This program is free software; you can redistribute it and/or modify

View File

@ -1,5 +1,5 @@
/*
* Copyright 2003-2017 The Music Player Daemon Project
* Copyright 2003-2018 The Music Player Daemon Project
* http://www.musicpd.org
*
* This program is free software; you can redistribute it and/or modify
@ -20,6 +20,8 @@
#ifndef MPD_DATABASE_SELECTION_HXX
#define MPD_DATABASE_SELECTION_HXX
#include "protocol/RangeArg.hxx"
#include "tag/Type.h"
#include "util/Compiler.h"
#include <string>
@ -36,6 +38,20 @@ struct DatabaseSelection {
const SongFilter *filter;
RangeArg window = RangeArg::All();
/**
* Sort the result by the given tag. #TAG_NUM_OF_ITEM_TYPES
* means don't sort. #SORT_TAG_LAST_MODIFIED sorts by
* "Last-Modified" (not technically a tag).
*/
TagType sort = TAG_NUM_OF_ITEM_TYPES;
/**
* If #sort is set, this flag can reverse the sort order.
*/
bool descending = false;
/**
* Recursively search all sub directories?
*/