QueuePrint.cxx 2.81 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
 * 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.
14 15 16 17
 *
 * 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.
18 19
 */

20
#include "config.h"
21
#include "QueuePrint.hxx"
22
#include "Queue.hxx"
23
#include "SongFilter.hxx"
Max Kellermann's avatar
Max Kellermann committed
24
#include "SongPrint.hxx"
25
#include "client/Client.hxx"
26

27 28 29 30 31 32 33 34 35
/**
 * Send detailed information about a range of songs in the queue to a
 * client.
 *
 * @param client the client which has requested information
 * @param start the index of the first song (including)
 * @param end the index of the last song (excluding)
 */
static void
36
queue_print_song_info(Client &client, const Queue &queue,
37 38
		      unsigned position)
{
39
	song_print_info(client, queue.Get(position));
40
	client_printf(client, "Pos: %u\nId: %u\n",
41
		      position, queue.PositionToId(position));
42

43
	uint8_t priority = queue.GetPriorityAtPosition(position);
44 45
	if (priority != 0)
		client_printf(client, "Prio: %u\n", priority);
46 47 48
}

void
49
queue_print_info(Client &client, const Queue &queue,
50 51 52
		 unsigned start, unsigned end)
{
	assert(start <= end);
53
	assert(end <= queue.GetLength());
54 55 56 57 58 59

	for (unsigned i = start; i < end; ++i)
		queue_print_song_info(client, queue, i);
}

void
60
queue_print_uris(Client &client, const Queue &queue,
61 62 63
		 unsigned start, unsigned end)
{
	assert(start <= end);
64
	assert(end <= queue.GetLength());
65 66

	for (unsigned i = start; i < end; ++i) {
67
		client_printf(client, "%i:", i);
68
		song_print_uri(client, queue.Get(i));
69 70 71 72
	}
}

void
73
queue_print_changes_info(Client &client, const Queue &queue,
74 75
			 uint32_t version)
{
76 77
	for (unsigned i = 0; i < queue.GetLength(); i++) {
		if (queue.IsNewerAtPosition(i, version))
78 79 80 81 82
			queue_print_song_info(client, queue, i);
	}
}

void
83
queue_print_changes_position(Client &client, const Queue &queue,
84 85
			     uint32_t version)
{
86 87
	for (unsigned i = 0; i < queue.GetLength(); i++)
		if (queue.IsNewerAtPosition(i, version))
88
			client_printf(client, "cpos: %i\nId: %i\n",
89
				      i, queue.PositionToId(i));
90
}
91 92

void
93
queue_find(Client &client, const Queue &queue,
94
	   const SongFilter &filter)
95
{
96
	for (unsigned i = 0; i < queue.GetLength(); i++) {
97
		const DetachedSong &song = queue.Get(i);
98

99
		if (filter.Match(song))
100 101 102
			queue_print_song_info(client, queue, i);
	}
}