configure.ac: Don't allow UNIX IPC to be configured for a native Windows build.
[mpd-mk.git] / src / playlist_print.c
blob020b0fa87a595a6ae2cc2187c4b1fc38f4186158
1 /*
2 * Copyright (C) 2003-2010 The Music Player Daemon Project
3 * http://www.musicpd.org
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License along
16 * with this program; if not, write to the Free Software Foundation, Inc.,
17 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
20 #include "config.h"
21 #include "playlist_print.h"
22 #include "playlist_list.h"
23 #include "playlist_plugin.h"
24 #include "playlist_mapper.h"
25 #include "playlist_song.h"
26 #include "queue_print.h"
27 #include "stored_playlist.h"
28 #include "song_print.h"
29 #include "song.h"
30 #include "database.h"
31 #include "client.h"
33 void
34 playlist_print_uris(struct client *client, const struct playlist *playlist)
36 const struct queue *queue = &playlist->queue;
38 queue_print_uris(client, queue, 0, queue_length(queue));
41 bool
42 playlist_print_info(struct client *client, const struct playlist *playlist,
43 unsigned start, unsigned end)
45 const struct queue *queue = &playlist->queue;
47 if (end > queue_length(queue))
48 /* correct the "end" offset */
49 end = queue_length(queue);
51 if (start > end)
52 /* an invalid "start" offset is fatal */
53 return false;
55 queue_print_info(client, queue, start, end);
56 return true;
59 bool
60 playlist_print_id(struct client *client, const struct playlist *playlist,
61 unsigned id)
63 const struct queue *queue = &playlist->queue;
64 int position;
66 position = queue_id_to_position(queue, id);
67 if (position < 0)
68 /* no such song */
69 return false;
71 return playlist_print_info(client, playlist, position, position + 1);
74 bool
75 playlist_print_current(struct client *client, const struct playlist *playlist)
77 int current_position = playlist_get_current_song(playlist);
79 if (current_position < 0)
80 return false;
82 queue_print_info(client, &playlist->queue,
83 current_position, current_position + 1);
84 return true;
87 void
88 playlist_print_find(struct client *client, const struct playlist *playlist,
89 const struct locate_item_list *list)
91 queue_find(client, &playlist->queue, list);
94 void
95 playlist_print_search(struct client *client, const struct playlist *playlist,
96 const struct locate_item_list *list)
98 queue_search(client, &playlist->queue, list);
101 void
102 playlist_print_changes_info(struct client *client,
103 const struct playlist *playlist,
104 uint32_t version)
106 queue_print_changes_info(client, &playlist->queue, version);
109 void
110 playlist_print_changes_position(struct client *client,
111 const struct playlist *playlist,
112 uint32_t version)
114 queue_print_changes_position(client, &playlist->queue, version);
117 bool
118 spl_print(struct client *client, const char *name_utf8, bool detail)
120 GPtrArray *list;
122 list = spl_load(name_utf8);
123 if (list == NULL)
124 return false;
126 for (unsigned i = 0; i < list->len; ++i) {
127 const char *temp = g_ptr_array_index(list, i);
128 bool wrote = false;
130 if (detail) {
131 struct song *song = db_get_song(temp);
132 if (song) {
133 song_print_info(client, song);
134 wrote = true;
138 if (!wrote) {
139 client_printf(client, SONG_FILE "%s\n", temp);
143 spl_free(list);
144 return true;
147 static void
148 playlist_provider_print(struct client *client, const char *uri,
149 struct playlist_provider *playlist, bool detail)
151 struct song *song;
152 char *base_uri = uri != NULL ? g_path_get_dirname(uri) : NULL;
154 while ((song = playlist_plugin_read(playlist)) != NULL) {
155 song = playlist_check_translate_song(song, base_uri);
156 if (song == NULL)
157 continue;
159 if (detail)
160 song_print_info(client, song);
161 else
162 song_print_uri(client, song);
165 g_free(base_uri);
168 bool
169 playlist_file_print(struct client *client, const char *uri, bool detail)
171 struct playlist_provider *playlist = playlist_mapper_open(uri);
172 if (playlist == NULL)
173 return false;
175 playlist_provider_print(client, uri, playlist, detail);
176 playlist_plugin_close(playlist);
177 return true;