diff options
Diffstat (limited to '')
-rw-r--r-- | src/QueueSave.cxx (renamed from src/queue_save.c) | 65 |
1 files changed, 36 insertions, 29 deletions
diff --git a/src/queue_save.c b/src/QueueSave.cxx index 16852d3c1..09b0645f8 100644 --- a/src/queue_save.c +++ b/src/QueueSave.cxx @@ -1,5 +1,5 @@ /* - * Copyright (C) 2003-2011 The Music Player Daemon Project + * Copyright (C) 2003-2013 The Music Player Daemon Project * http://www.musicpd.org * * This program is free software; you can redistribute it and/or modify @@ -18,13 +18,17 @@ */ #include "config.h" -#include "queue_save.h" -#include "queue.h" +#include "QueueSave.hxx" +#include "Playlist.hxx" #include "song.h" +#include "SongSave.hxx" +#include "DatabasePlugin.hxx" +#include "DatabaseGlue.hxx" +#include "TextFile.hxx" + +extern "C" { #include "uri.h" -#include "database.h" -#include "song_save.h" -#include "text_file.h" +} #include <stdlib.h> @@ -57,48 +61,40 @@ queue_save_song(FILE *fp, int idx, const struct song *song) void queue_save(FILE *fp, const struct queue *queue) { - for (unsigned i = 0; i < queue_length(queue); i++) { - uint8_t prio = queue_get_priority_at_position(queue, i); + for (unsigned i = 0; i < queue->GetLength(); i++) { + uint8_t prio = queue->GetPriorityAtPosition(i); if (prio != 0) fprintf(fp, PRIO_LABEL "%u\n", prio); - queue_save_song(fp, i, queue_get(queue, i)); + queue_save_song(fp, i, queue->Get(i)); } } -static struct song * -get_song(const char *uri) -{ - return uri_has_scheme(uri) - ? song_remote_new(uri) - : db_get_song(uri); -} - void -queue_load_song(FILE *fp, GString *buffer, const char *line, - struct queue *queue) +queue_load_song(TextFile &file, const char *line, queue *queue) { - struct song *song; - - if (queue_is_full(queue)) + if (queue->IsFull()) return; uint8_t priority = 0; if (g_str_has_prefix(line, PRIO_LABEL)) { priority = strtoul(line + sizeof(PRIO_LABEL) - 1, NULL, 10); - line = read_text_line(fp, buffer); + line = file.ReadLine(); if (line == NULL) return; } + const Database *db = nullptr; + struct song *song; + if (g_str_has_prefix(line, SONG_BEGIN)) { const char *uri = line + sizeof(SONG_BEGIN) - 1; if (!uri_has_scheme(uri) && !g_path_is_absolute(uri)) return; GError *error = NULL; - song = song_load(fp, NULL, uri, buffer, &error); + song = song_load(file, NULL, uri, &error); if (song == NULL) { g_warning("%s", error->message); g_error_free(error); @@ -112,12 +108,23 @@ queue_load_song(FILE *fp, GString *buffer, const char *line, return; } - line = endptr + 1; + const char *uri = endptr + 1; - song = get_song(line); - if (song == NULL) - return; + if (uri_has_scheme(uri)) { + song = song_remote_new(uri); + } else { + db = GetDatabase(nullptr); + if (db == nullptr) + return; + + song = db->GetSong(uri, nullptr); + if (song == nullptr) + return; + } } - queue_append(queue, song, priority); + queue->Append(song, priority); + + if (db != nullptr) + db->ReturnSong(song); } |