Print.cxx 1.96 KB
Newer Older
1
/*
Max Kellermann's avatar
Max Kellermann committed
2
 * Copyright (C) 2003-2014 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
						  loader)) {
47 48 49 50
			if (detail)
				song_print_info(client, *song);
			else
				song_print_uri(client, *song);
51 52
		}

53
		delete song;
54 55 56
	}
}

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

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

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