QueuePrint.cxx 2.9 KB
Newer Older
1
/*
2
 * Copyright (C) 2003-2013 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"
Max Kellermann's avatar
Max Kellermann committed
25
#include "Mapper.hxx"
Max Kellermann's avatar
Max Kellermann committed
26
#include "Client.hxx"
27 28

extern "C" {
29
#include "Song.hxx"
30
}
31

32 33 34 35 36 37 38 39 40
/**
 * 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
41
queue_print_song_info(Client *client, const struct queue *queue,
42 43
		      unsigned position)
{
44
	song_print_info(client, queue->Get(position));
45
	client_printf(client, "Pos: %u\nId: %u\n",
46
		      position, queue->PositionToId(position));
47

48
	uint8_t priority = queue->GetPriorityAtPosition(position);
49 50
	if (priority != 0)
		client_printf(client, "Prio: %u\n", priority);
51 52 53
}

void
54
queue_print_info(Client *client, const struct queue *queue,
55 56 57
		 unsigned start, unsigned end)
{
	assert(start <= end);
58
	assert(end <= queue->GetLength());
59 60 61 62 63 64

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

void
65
queue_print_uris(Client *client, const struct queue *queue,
66 67 68
		 unsigned start, unsigned end)
{
	assert(start <= end);
69
	assert(end <= queue->GetLength());
70 71

	for (unsigned i = start; i < end; ++i) {
72
		client_printf(client, "%i:", i);
73
		song_print_uri(client, queue->Get(i));
74 75 76 77
	}
}

void
78
queue_print_changes_info(Client *client, const struct queue *queue,
79 80
			 uint32_t version)
{
81 82
	for (unsigned i = 0; i < queue->GetLength(); i++) {
		if (queue->IsNewerAtPosition(i, version))
83 84 85 86 87
			queue_print_song_info(client, queue, i);
	}
}

void
88
queue_print_changes_position(Client *client, const struct queue *queue,
89 90
			     uint32_t version)
{
91 92
	for (unsigned i = 0; i < queue->GetLength(); i++)
		if (queue->IsNewerAtPosition(i, version))
93
			client_printf(client, "cpos: %i\nId: %i\n",
94
				      i, queue->PositionToId(i));
95
}
96 97

void
98
queue_find(Client *client, const struct queue *queue,
99
	   const SongFilter &filter)
100
{
101
	for (unsigned i = 0; i < queue->GetLength(); i++) {
102
		const Song *song = queue->Get(i);
103

104
		if (filter.Match(*song))
105 106 107
			queue_print_song_info(client, queue, i);
	}
}