From 04a9dec9525a58d077da71a84655cb45b7838520 Mon Sep 17 00:00:00 2001 From: Max Kellermann Date: Wed, 29 Aug 2012 20:17:13 +0200 Subject: playlist_print: rename to PlaylistPrint.cxx --- src/PlayerCommands.cxx | 2 +- src/PlaylistCommands.cxx | 2 +- src/PlaylistPrint.cxx | 195 +++++++++++++++++++++++++++++++++++++++++++++++ src/PlaylistPrint.hxx | 110 ++++++++++++++++++++++++++ src/QueueCommands.cxx | 2 +- src/playlist_print.c | 192 ---------------------------------------------- src/playlist_print.h | 110 -------------------------- 7 files changed, 308 insertions(+), 305 deletions(-) create mode 100644 src/PlaylistPrint.cxx create mode 100644 src/PlaylistPrint.hxx delete mode 100644 src/playlist_print.c delete mode 100644 src/playlist_print.h (limited to 'src') diff --git a/src/PlayerCommands.cxx b/src/PlayerCommands.cxx index 6413b1aba..030e8016d 100644 --- a/src/PlayerCommands.cxx +++ b/src/PlayerCommands.cxx @@ -20,13 +20,13 @@ #include "config.h" #include "PlayerCommands.hxx" #include "CommandError.h" +#include "PlaylistPrint.hxx" extern "C" { #include "protocol/argparser.h" #include "protocol/result.h" #include "player_control.h" #include "playlist.h" -#include "playlist_print.h" #include "update.h" #include "volume.h" #include "client.h" diff --git a/src/PlaylistCommands.cxx b/src/PlaylistCommands.cxx index d74036ec3..d6be3ff30 100644 --- a/src/PlaylistCommands.cxx +++ b/src/PlaylistCommands.cxx @@ -21,12 +21,12 @@ #include "PlaylistCommands.hxx" #include "DatabasePlaylist.hxx" #include "CommandError.h" +#include "PlaylistPrint.hxx" extern "C" { #include "protocol/argparser.h" #include "protocol/result.h" #include "playlist.h" -#include "playlist_print.h" #include "playlist_save.h" #include "playlist_queue.h" #include "time_print.h" diff --git a/src/PlaylistPrint.cxx b/src/PlaylistPrint.cxx new file mode 100644 index 000000000..9ff7f270e --- /dev/null +++ b/src/PlaylistPrint.cxx @@ -0,0 +1,195 @@ +/* + * Copyright (C) 2003-2012 The Music Player Daemon Project + * 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. + */ + +#include "config.h" +#include "PlaylistPrint.hxx" + +extern "C" { +#include "playlist_list.h" +#include "playlist_plugin.h" +#include "playlist_any.h" +#include "playlist_song.h" +#include "playlist.h" +#include "queue_print.h" +#include "stored_playlist.h" +#include "song_print.h" +#include "song.h" +#include "database.h" +#include "client.h" +#include "input_stream.h" +} + +void +playlist_print_uris(struct client *client, const struct playlist *playlist) +{ + const struct queue *queue = &playlist->queue; + + queue_print_uris(client, queue, 0, queue_length(queue)); +} + +bool +playlist_print_info(struct client *client, const struct playlist *playlist, + unsigned start, unsigned end) +{ + const struct queue *queue = &playlist->queue; + + if (end > queue_length(queue)) + /* correct the "end" offset */ + end = queue_length(queue); + + if (start > end) + /* an invalid "start" offset is fatal */ + return false; + + queue_print_info(client, queue, start, end); + return true; +} + +bool +playlist_print_id(struct client *client, const struct playlist *playlist, + unsigned id) +{ + const struct queue *queue = &playlist->queue; + int position; + + position = queue_id_to_position(queue, id); + if (position < 0) + /* no such song */ + return false; + + return playlist_print_info(client, playlist, position, position + 1); +} + +bool +playlist_print_current(struct client *client, const struct playlist *playlist) +{ + int current_position = playlist_get_current_song(playlist); + + if (current_position < 0) + return false; + + queue_print_info(client, &playlist->queue, + current_position, current_position + 1); + return true; +} + +void +playlist_print_find(struct client *client, const struct playlist *playlist, + const struct locate_item_list *list) +{ + queue_find(client, &playlist->queue, list); +} + +void +playlist_print_changes_info(struct client *client, + const struct playlist *playlist, + uint32_t version) +{ + queue_print_changes_info(client, &playlist->queue, version); +} + +void +playlist_print_changes_position(struct client *client, + const struct playlist *playlist, + uint32_t version) +{ + queue_print_changes_position(client, &playlist->queue, version); +} + +bool +spl_print(struct client *client, const char *name_utf8, bool detail, + GError **error_r) +{ + GPtrArray *list; + + list = spl_load(name_utf8, error_r); + if (list == NULL) + return false; + + for (unsigned i = 0; i < list->len; ++i) { + const char *temp = (const char *)g_ptr_array_index(list, i); + bool wrote = false; + + if (detail) { + struct song *song = db_get_song(temp); + if (song) { + song_print_info(client, song); + db_return_song(song); + wrote = true; + } + } + + if (!wrote) { + client_printf(client, SONG_FILE "%s\n", temp); + } + } + + spl_free(list); + return true; +} + +static void +playlist_provider_print(struct client *client, const char *uri, + struct playlist_provider *playlist, bool detail) +{ + struct song *song; + char *base_uri = uri != NULL ? g_path_get_dirname(uri) : NULL; + + while ((song = playlist_plugin_read(playlist)) != NULL) { + song = playlist_check_translate_song(song, base_uri, false); + if (song == NULL) + continue; + + if (detail) + song_print_info(client, song); + else + song_print_uri(client, song); + + song_free(song); + } + + g_free(base_uri); +} + +bool +playlist_file_print(struct client *client, const char *uri, bool detail) +{ + GMutex *mutex = g_mutex_new(); + GCond *cond = g_cond_new(); + + struct input_stream *is; + struct playlist_provider *playlist = + playlist_open_any(uri, mutex, cond, &is); + if (playlist == NULL) { + g_cond_free(cond); + g_mutex_free(mutex); + return false; + } + + playlist_provider_print(client, uri, playlist, detail); + playlist_plugin_close(playlist); + + if (is != NULL) + input_stream_close(is); + + g_cond_free(cond); + g_mutex_free(mutex); + + return true; +} diff --git a/src/PlaylistPrint.hxx b/src/PlaylistPrint.hxx new file mode 100644 index 000000000..c6be5a93f --- /dev/null +++ b/src/PlaylistPrint.hxx @@ -0,0 +1,110 @@ +/* + * Copyright (C) 2003-2012 The Music Player Daemon Project + * 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. + */ + +#ifndef MPD_PLAYLIST_PRINT_HXX +#define MPD_PLAYLIST_PRINT_HXX + +#include +#include +#include + +struct client; +struct playlist; +struct locate_item_list; + +/** + * Sends the whole playlist to the client, song URIs only. + */ +void +playlist_print_uris(struct client *client, const struct playlist *playlist); + +/** + * Sends a range of the playlist to the client, including all known + * information about the songs. The "end" offset is decreased + * automatically if it is too large; passing UINT_MAX is allowed. + * This function however fails when the start offset is invalid. + */ +bool +playlist_print_info(struct client *client, const struct playlist *playlist, + unsigned start, unsigned end); + +/** + * Sends the song with the specified id to the client. + * + * @return true on suite, false if there is no such song + */ +bool +playlist_print_id(struct client *client, const struct playlist *playlist, + unsigned id); + +/** + * Sends the current song to the client. + * + * @return true on success, false if there is no current song + */ +bool +playlist_print_current(struct client *client, const struct playlist *playlist); + +/** + * Find songs in the playlist. + */ +void +playlist_print_find(struct client *client, const struct playlist *playlist, + const struct locate_item_list *list); + +/** + * Print detailed changes since the specified playlist version. + */ +void +playlist_print_changes_info(struct client *client, + const struct playlist *playlist, + uint32_t version); + +/** + * Print changes since the specified playlist version, position only. + */ +void +playlist_print_changes_position(struct client *client, + const struct playlist *playlist, + uint32_t version); + +/** + * Send the stored playlist to the client. + * + * @param client the client which requested the playlist + * @param name_utf8 the name of the stored playlist in UTF-8 encoding + * @param detail true if all details should be printed + * @return true on success, false if the playlist does not exist + */ +bool +spl_print(struct client *client, const char *name_utf8, bool detail, + GError **error_r); + +/** + * Send the playlist file to the client. + * + * @param client the client which requested the playlist + * @param uri the URI of the playlist file in UTF-8 encoding + * @param detail true if all details should be printed + * @return true on success, false if the playlist does not exist + */ +bool +playlist_file_print(struct client *client, const char *uri, bool detail); + +#endif diff --git a/src/QueueCommands.cxx b/src/QueueCommands.cxx index 4801d2326..c47454e08 100644 --- a/src/QueueCommands.cxx +++ b/src/QueueCommands.cxx @@ -22,12 +22,12 @@ #include "CommandError.h" #include "DatabaseQueue.hxx" #include "SongFilter.hxx" +#include "PlaylistPrint.hxx" extern "C" { #include "protocol/argparser.h" #include "protocol/result.h" #include "playlist.h" -#include "playlist_print.h" #include "ls.h" #include "uri.h" #include "client_internal.h" diff --git a/src/playlist_print.c b/src/playlist_print.c deleted file mode 100644 index b1b689893..000000000 --- a/src/playlist_print.c +++ /dev/null @@ -1,192 +0,0 @@ -/* - * Copyright (C) 2003-2011 The Music Player Daemon Project - * 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. - */ - -#include "config.h" -#include "playlist_print.h" -#include "playlist_list.h" -#include "playlist_plugin.h" -#include "playlist_any.h" -#include "playlist_song.h" -#include "playlist.h" -#include "queue_print.h" -#include "stored_playlist.h" -#include "song_print.h" -#include "song.h" -#include "database.h" -#include "client.h" -#include "input_stream.h" - -void -playlist_print_uris(struct client *client, const struct playlist *playlist) -{ - const struct queue *queue = &playlist->queue; - - queue_print_uris(client, queue, 0, queue_length(queue)); -} - -bool -playlist_print_info(struct client *client, const struct playlist *playlist, - unsigned start, unsigned end) -{ - const struct queue *queue = &playlist->queue; - - if (end > queue_length(queue)) - /* correct the "end" offset */ - end = queue_length(queue); - - if (start > end) - /* an invalid "start" offset is fatal */ - return false; - - queue_print_info(client, queue, start, end); - return true; -} - -bool -playlist_print_id(struct client *client, const struct playlist *playlist, - unsigned id) -{ - const struct queue *queue = &playlist->queue; - int position; - - position = queue_id_to_position(queue, id); - if (position < 0) - /* no such song */ - return false; - - return playlist_print_info(client, playlist, position, position + 1); -} - -bool -playlist_print_current(struct client *client, const struct playlist *playlist) -{ - int current_position = playlist_get_current_song(playlist); - - if (current_position < 0) - return false; - - queue_print_info(client, &playlist->queue, - current_position, current_position + 1); - return true; -} - -void -playlist_print_find(struct client *client, const struct playlist *playlist, - const struct locate_item_list *list) -{ - queue_find(client, &playlist->queue, list); -} - -void -playlist_print_changes_info(struct client *client, - const struct playlist *playlist, - uint32_t version) -{ - queue_print_changes_info(client, &playlist->queue, version); -} - -void -playlist_print_changes_position(struct client *client, - const struct playlist *playlist, - uint32_t version) -{ - queue_print_changes_position(client, &playlist->queue, version); -} - -bool -spl_print(struct client *client, const char *name_utf8, bool detail, - GError **error_r) -{ - GPtrArray *list; - - list = spl_load(name_utf8, error_r); - if (list == NULL) - return false; - - for (unsigned i = 0; i < list->len; ++i) { - const char *temp = g_ptr_array_index(list, i); - bool wrote = false; - - if (detail) { - struct song *song = db_get_song(temp); - if (song) { - song_print_info(client, song); - db_return_song(song); - wrote = true; - } - } - - if (!wrote) { - client_printf(client, SONG_FILE "%s\n", temp); - } - } - - spl_free(list); - return true; -} - -static void -playlist_provider_print(struct client *client, const char *uri, - struct playlist_provider *playlist, bool detail) -{ - struct song *song; - char *base_uri = uri != NULL ? g_path_get_dirname(uri) : NULL; - - while ((song = playlist_plugin_read(playlist)) != NULL) { - song = playlist_check_translate_song(song, base_uri, false); - if (song == NULL) - continue; - - if (detail) - song_print_info(client, song); - else - song_print_uri(client, song); - - song_free(song); - } - - g_free(base_uri); -} - -bool -playlist_file_print(struct client *client, const char *uri, bool detail) -{ - GMutex *mutex = g_mutex_new(); - GCond *cond = g_cond_new(); - - struct input_stream *is; - struct playlist_provider *playlist = - playlist_open_any(uri, mutex, cond, &is); - if (playlist == NULL) { - g_cond_free(cond); - g_mutex_free(mutex); - return false; - } - - playlist_provider_print(client, uri, playlist, detail); - playlist_plugin_close(playlist); - - if (is != NULL) - input_stream_close(is); - - g_cond_free(cond); - g_mutex_free(mutex); - - return true; -} diff --git a/src/playlist_print.h b/src/playlist_print.h deleted file mode 100644 index 20d3703d9..000000000 --- a/src/playlist_print.h +++ /dev/null @@ -1,110 +0,0 @@ -/* - * Copyright (C) 2003-2011 The Music Player Daemon Project - * 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. - */ - -#ifndef PLAYLIST_PRINT_H -#define PLAYLIST_PRINT_H - -#include -#include -#include - -struct client; -struct playlist; -struct locate_item_list; - -/** - * Sends the whole playlist to the client, song URIs only. - */ -void -playlist_print_uris(struct client *client, const struct playlist *playlist); - -/** - * Sends a range of the playlist to the client, including all known - * information about the songs. The "end" offset is decreased - * automatically if it is too large; passing UINT_MAX is allowed. - * This function however fails when the start offset is invalid. - */ -bool -playlist_print_info(struct client *client, const struct playlist *playlist, - unsigned start, unsigned end); - -/** - * Sends the song with the specified id to the client. - * - * @return true on suite, false if there is no such song - */ -bool -playlist_print_id(struct client *client, const struct playlist *playlist, - unsigned id); - -/** - * Sends the current song to the client. - * - * @return true on success, false if there is no current song - */ -bool -playlist_print_current(struct client *client, const struct playlist *playlist); - -/** - * Find songs in the playlist. - */ -void -playlist_print_find(struct client *client, const struct playlist *playlist, - const struct locate_item_list *list); - -/** - * Print detailed changes since the specified playlist version. - */ -void -playlist_print_changes_info(struct client *client, - const struct playlist *playlist, - uint32_t version); - -/** - * Print changes since the specified playlist version, position only. - */ -void -playlist_print_changes_position(struct client *client, - const struct playlist *playlist, - uint32_t version); - -/** - * Send the stored playlist to the client. - * - * @param client the client which requested the playlist - * @param name_utf8 the name of the stored playlist in UTF-8 encoding - * @param detail true if all details should be printed - * @return true on success, false if the playlist does not exist - */ -bool -spl_print(struct client *client, const char *name_utf8, bool detail, - GError **error_r); - -/** - * Send the playlist file to the client. - * - * @param client the client which requested the playlist - * @param uri the URI of the playlist file in UTF-8 encoding - * @param detail true if all details should be printed - * @return true on success, false if the playlist does not exist - */ -bool -playlist_file_print(struct client *client, const char *uri, bool detail); - -#endif -- cgit v1.2.3