diff options
Diffstat (limited to '')
-rw-r--r-- | src/QueueSave.cxx | 48 |
1 files changed, 22 insertions, 26 deletions
diff --git a/src/QueueSave.cxx b/src/QueueSave.cxx index 6a1a51992..30dae37e3 100644 --- a/src/QueueSave.cxx +++ b/src/QueueSave.cxx @@ -1,5 +1,5 @@ /* - * Copyright (C) 2003-2013 The Music Player Daemon Project + * Copyright (C) 2003-2014 The Music Player Daemon Project * http://www.musicpd.org * * This program is free software; you can redistribute it and/or modify @@ -21,37 +21,35 @@ #include "QueueSave.hxx" #include "Queue.hxx" #include "PlaylistError.hxx" -#include "Song.hxx" +#include "DetachedSong.hxx" #include "SongSave.hxx" #include "DatabasePlugin.hxx" #include "DatabaseGlue.hxx" -#include "TextFile.hxx" +#include "fs/TextFile.hxx" +#include "util/StringUtil.hxx" #include "util/UriUtil.hxx" #include "util/Error.hxx" #include "fs/Traits.hxx" #include "Log.hxx" -#include <glib.h> - #include <stdlib.h> #define PRIO_LABEL "Prio: " static void -queue_save_database_song(FILE *fp, int idx, const Song &song) +queue_save_database_song(FILE *fp, int idx, const DetachedSong &song) { - const auto uri = song.GetURI(); - fprintf(fp, "%i:%s\n", idx, uri.c_str()); + fprintf(fp, "%i:%s\n", idx, song.GetURI()); } static void -queue_save_full_song(FILE *fp, const Song &song) +queue_save_full_song(FILE *fp, const DetachedSong &song) { song_save(fp, song); } static void -queue_save_song(FILE *fp, int idx, const Song &song) +queue_save_song(FILE *fp, int idx, const DetachedSong &song) { if (song.IsInDatabase()) queue_save_database_song(fp, idx, song); @@ -78,7 +76,7 @@ queue_load_song(TextFile &file, const char *line, queue &queue) return; uint8_t priority = 0; - if (g_str_has_prefix(line, PRIO_LABEL)) { + if (StringStartsWith(line, PRIO_LABEL)) { priority = strtoul(line + sizeof(PRIO_LABEL) - 1, nullptr, 10); line = file.ReadLine(); @@ -86,16 +84,15 @@ queue_load_song(TextFile &file, const char *line, queue &queue) return; } - const Database *db = nullptr; - Song *song; + DetachedSong *song; - if (g_str_has_prefix(line, SONG_BEGIN)) { + if (StringStartsWith(line, SONG_BEGIN)) { const char *uri = line + sizeof(SONG_BEGIN) - 1; - if (!uri_has_scheme(uri) && !PathTraits::IsAbsoluteUTF8(uri)) + if (!uri_has_scheme(uri) && !PathTraitsUTF8::IsAbsolute(uri)) return; Error error; - song = song_load(file, nullptr, uri, error); + song = song_load(file, uri, error); if (song == nullptr) { LogError(error); return; @@ -112,22 +109,21 @@ queue_load_song(TextFile &file, const char *line, queue &queue) const char *uri = endptr + 1; if (uri_has_scheme(uri)) { - song = Song::NewRemote(uri); + song = new DetachedSong(uri); } else { - db = GetDatabase(); + const Database *db = GetDatabase(); if (db == nullptr) return; - song = db->GetSong(uri, IgnoreError()); - if (song == nullptr) + Song *tmp = db->GetSong(uri, IgnoreError()); + if (tmp == nullptr) return; + + song = new DetachedSong(*tmp); + db->ReturnSong(tmp); } } - queue.Append(song, priority); - - if (db != nullptr) - db->ReturnSong(song); - else - song->Free(); + queue.Append(std::move(*song), priority); + delete song; } |