Print.cxx 2.03 KB
Newer Older
1
/*
Max Kellermann's avatar
Max Kellermann committed
2
 * Copyright (C) 2003-2015 The Music Player Daemon Project
3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19
 * http://www.musicpd.org
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License along
 * with this program; if not, write to the Free Software Foundation, Inc.,
 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
 */

20
#include "config.h"
21
#include "Print.hxx"
22 23
#include "PlaylistAny.hxx"
#include "PlaylistSong.hxx"
24
#include "SongEnumerator.hxx"
25
#include "SongPrint.hxx"
26
#include "DetachedSong.hxx"
27
#include "SongLoader.hxx"
Max Kellermann's avatar
Max Kellermann committed
28
#include "fs/Traits.hxx"
29
#include "thread/Mutex.hxx"
30
#include "thread/Cond.hxx"
31
#include "client/Client.hxx"
32

33 34 35
static void
playlist_provider_print(Client &client, const char *uri,
			SongEnumerator &e, bool detail)
36
{
Max Kellermann's avatar
Max Kellermann committed
37
	const std::string base_uri = uri != nullptr
38
		? PathTraitsUTF8::GetParent(uri)
Max Kellermann's avatar
Max Kellermann committed
39
		: std::string(".");
40

41 42
	const SongLoader loader(client);

43
	DetachedSong *song;
44 45
	while ((song = e.NextSong()) != nullptr) {
		if (playlist_check_translate_song(*song, base_uri.c_str(),
46 47 48 49 50 51 52
						  loader) &&
		    detail)
			song_print_info(client, *song);
		else
			/* fallback if no detail was requested or no
			   detail was available */
			song_print_uri(client, *song);
53

54
		delete song;
55 56 57
	}
}

58 59
bool
playlist_file_print(Client &client, const char *uri, bool detail)
60
{
61 62
	Mutex mutex;
	Cond cond;
63

64 65 66 67 68
	SongEnumerator *playlist = playlist_open_any(uri,
#ifdef ENABLE_DATABASE
						     client.GetStorage(),
#endif
						     mutex, cond);
69
	if (playlist == nullptr)
70
		return false;
71

72
	playlist_provider_print(client, uri, *playlist, detail);
73
	delete playlist;
74
	return true;
75
}