aboutsummaryrefslogtreecommitdiffstats
path: root/src/playlist.c
diff options
context:
space:
mode:
authorMax Kellermann <max@duempel.org>2009-01-23 16:35:04 +0100
committerMax Kellermann <max@duempel.org>2009-01-23 16:35:04 +0100
commit349d24986755a9802606c42956129fab3f13fd95 (patch)
tree382a5dfa4a4a61b5e02f12780d001abf72b9932a /src/playlist.c
parent8afe24c1de70b69df58f1724ad5fd02c7af63ecb (diff)
downloadmpd-349d24986755a9802606c42956129fab3f13fd95.tar.gz
mpd-349d24986755a9802606c42956129fab3f13fd95.tar.xz
mpd-349d24986755a9802606c42956129fab3f13fd95.zip
playlist: moved saving/loading code to queue_save.c
Create a new library which saves/loads the queue to/from the state file.
Diffstat (limited to '')
-rw-r--r--src/playlist.c30
1 files changed, 4 insertions, 26 deletions
diff --git a/src/playlist.c b/src/playlist.c
index a1743d1ed..8be8b0553 100644
--- a/src/playlist.c
+++ b/src/playlist.c
@@ -19,6 +19,7 @@
#include "playlist.h"
#include "playlist_save.h"
#include "queue_print.h"
+#include "queue_save.h"
#include "player_control.h"
#include "command.h"
#include "ls.h"
@@ -158,16 +159,6 @@ void showPlaylist(struct client *client)
0, queue_length(&playlist.queue));
}
-static void playlist_save(FILE *fp)
-{
- for (unsigned i = 0; i < queue_length(&playlist.queue); i++) {
- const struct song *song = queue_get(&playlist.queue, i);
- char *uri = song_get_uri(song);
- fprintf(fp, "%i:%s\n", i, uri);
- g_free(uri);
- }
-}
-
void savePlaylistState(FILE *fp)
{
fprintf(fp, "%s", PLAYLIST_STATE_FILE_STATE);
@@ -195,14 +186,13 @@ void savePlaylistState(FILE *fp)
fprintf(fp, "%s%i\n", PLAYLIST_STATE_FILE_CROSSFADE,
(int)(getPlayerCrossFade()));
fprintf(fp, "%s\n", PLAYLIST_STATE_FILE_PLAYLIST_BEGIN);
- playlist_save(fp);
+ queue_save(fp, &playlist.queue);
fprintf(fp, "%s\n", PLAYLIST_STATE_FILE_PLAYLIST_END);
}
static void loadPlaylistFromStateFile(FILE *fp, char *buffer,
int state, int current, int seek_time)
{
- char *temp;
int song;
if (!fgets(buffer, PLAYLIST_BUFFER_SIZE, fp)) {
@@ -213,20 +203,8 @@ static void loadPlaylistFromStateFile(FILE *fp, char *buffer,
while (!g_str_has_prefix(buffer, PLAYLIST_STATE_FILE_PLAYLIST_END)) {
g_strchomp(buffer);
- temp = strtok(buffer, ":");
- if (temp == NULL) {
- g_warning("Malformed playlist line in state file");
- break;
- }
-
- song = atoi(temp);
- if (!(temp = strtok(NULL, ""))) {
- g_warning("Malformed playlist line in state file");
- break;
- }
-
- if (addToPlaylist(temp, NULL) == PLAYLIST_RESULT_SUCCESS
- && current == song) {
+ song = queue_load_song(&playlist.queue, buffer);
+ if (song >= 0 && song == current) {
if (state != PLAYER_STATE_STOP) {
playPlaylist(queue_length(&playlist.queue) - 1);
}