DatabasePrint: move PrintSongCount() to Count.cxx
This commit is contained in:
@@ -168,54 +168,6 @@ db_selection_print(Client &client, const DatabaseSelection &selection,
|
||||
return db->Visit(selection, d, s, p, error);
|
||||
}
|
||||
|
||||
struct SearchStats {
|
||||
unsigned n_songs;
|
||||
unsigned long total_time_s;
|
||||
};
|
||||
|
||||
static void
|
||||
PrintSearchStats(Client &client, const SearchStats &stats)
|
||||
{
|
||||
client_printf(client,
|
||||
"songs: %u\n"
|
||||
"playtime: %lu\n",
|
||||
stats.n_songs, stats.total_time_s);
|
||||
}
|
||||
|
||||
static bool
|
||||
stats_visitor_song(SearchStats &stats, const LightSong &song)
|
||||
{
|
||||
stats.n_songs++;
|
||||
stats.total_time_s += song.GetDuration();
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool
|
||||
PrintSongCount(Client &client, const char *name,
|
||||
const SongFilter *filter,
|
||||
Error &error)
|
||||
{
|
||||
const Database *db = client.GetDatabase(error);
|
||||
if (db == nullptr)
|
||||
return false;
|
||||
|
||||
const DatabaseSelection selection(name, true, filter);
|
||||
|
||||
SearchStats stats;
|
||||
stats.n_songs = 0;
|
||||
stats.total_time_s = 0;
|
||||
|
||||
using namespace std::placeholders;
|
||||
const auto f = std::bind(stats_visitor_song, std::ref(stats),
|
||||
_1);
|
||||
if (!db->Visit(selection, f, error))
|
||||
return false;
|
||||
|
||||
PrintSearchStats(client, stats);
|
||||
return true;
|
||||
}
|
||||
|
||||
static bool
|
||||
PrintSongURIVisitor(Client &client, const LightSong &song)
|
||||
{
|
||||
|
Reference in New Issue
Block a user