diff options
author | Max Kellermann <max@duempel.org> | 2013-01-29 18:56:35 +0100 |
---|---|---|
committer | Max Kellermann <max@duempel.org> | 2013-01-29 18:56:35 +0100 |
commit | a8b75dc4df3bf3ba9a1554249cf6d07527184864 (patch) | |
tree | 30749b1aa56a0b8fd1f869ad96d2869b4e639b31 /src/playlist/PlsPlaylistPlugin.cxx | |
parent | e4455962c640bd157713002b1d8d74fe64cecf67 (diff) | |
download | mpd-a8b75dc4df3bf3ba9a1554249cf6d07527184864.tar.gz mpd-a8b75dc4df3bf3ba9a1554249cf6d07527184864.tar.xz mpd-a8b75dc4df3bf3ba9a1554249cf6d07527184864.zip |
playlist/{asx,rss,soundcloud,xspf}: merge code to MemoryPlaylistProvider
Diffstat (limited to 'src/playlist/PlsPlaylistPlugin.cxx')
-rw-r--r-- | src/playlist/PlsPlaylistPlugin.cxx | 53 |
1 files changed, 7 insertions, 46 deletions
diff --git a/src/playlist/PlsPlaylistPlugin.cxx b/src/playlist/PlsPlaylistPlugin.cxx index 8cb8b4f1d..cecabc88e 100644 --- a/src/playlist/PlsPlaylistPlugin.cxx +++ b/src/playlist/PlsPlaylistPlugin.cxx @@ -19,7 +19,7 @@ #include "config.h" #include "PlsPlaylistPlugin.hxx" -#include "PlaylistPlugin.hxx" +#include "MemoryPlaylistProvider.hxx" #include "input_stream.h" #include "uri.h" #include "song.h" @@ -28,8 +28,6 @@ #include <glib.h> struct PlsPlaylist { - struct playlist_provider base; - GSList *songs; }; @@ -112,7 +110,6 @@ pls_open_stream(struct input_stream *is) char buffer[1024]; bool success; GKeyFile *keyfile; - PlsPlaylist *playlist; GString *kf_data = g_string_new(""); do { @@ -153,49 +150,13 @@ pls_open_stream(struct input_stream *is) return NULL; } - playlist = g_new(PlsPlaylist, 1); - playlist_provider_init(&playlist->base, &pls_playlist_plugin); - playlist->songs = NULL; - - pls_parser(keyfile, playlist); + PlsPlaylist playlist; + playlist.songs = nullptr; + pls_parser(keyfile, &playlist); g_key_file_free(keyfile); - return &playlist->base; -} - - -static void -song_free_callback(gpointer data, G_GNUC_UNUSED gpointer user_data) -{ - struct song *song = (struct song *)data; - song_free(song); -} - -static void -pls_close(struct playlist_provider *_playlist) -{ - PlsPlaylist *playlist = (PlsPlaylist *)_playlist; - - g_slist_foreach(playlist->songs, song_free_callback, NULL); - g_slist_free(playlist->songs); - - g_free(playlist); - -} - -static struct song * -pls_read(struct playlist_provider *_playlist) -{ - PlsPlaylist *playlist = (PlsPlaylist *)_playlist; - - if (playlist->songs == NULL) - return NULL; - - struct song *song = (struct song *)playlist->songs->data; - playlist->songs = g_slist_remove(playlist->songs, song); - - return song; + return new MemoryPlaylistProvider(g_slist_reverse(playlist.songs)); } static const char *const pls_suffixes[] = { @@ -215,8 +176,8 @@ const struct playlist_plugin pls_playlist_plugin = { nullptr, nullptr, pls_open_stream, - pls_close, - pls_read, + nullptr, + nullptr, nullptr, pls_suffixes, |