aboutsummaryrefslogtreecommitdiffstats
path: root/src/PlaylistSave.cxx
diff options
context:
space:
mode:
Diffstat (limited to 'src/PlaylistSave.cxx')
-rw-r--r--src/PlaylistSave.cxx86
1 files changed, 20 insertions, 66 deletions
diff --git a/src/PlaylistSave.cxx b/src/PlaylistSave.cxx
index 29bf193fd..67f05267f 100644
--- a/src/PlaylistSave.cxx
+++ b/src/PlaylistSave.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,44 +21,44 @@
#include "PlaylistSave.hxx"
#include "PlaylistFile.hxx"
#include "PlaylistError.hxx"
-#include "Playlist.hxx"
-#include "Song.hxx"
+#include "queue/Playlist.hxx"
+#include "DetachedSong.hxx"
+#include "SongLoader.hxx"
#include "Mapper.hxx"
#include "Idle.hxx"
#include "fs/AllocatedPath.hxx"
#include "fs/Traits.hxx"
#include "fs/FileSystem.hxx"
+#include "util/Alloc.hxx"
#include "util/UriUtil.hxx"
#include "util/Error.hxx"
#include "Log.hxx"
-#include <glib.h>
-
#include <string.h>
void
-playlist_print_song(FILE *file, const Song &song)
+playlist_print_song(FILE *file, const DetachedSong &song)
{
- if (playlist_saveAbsolutePaths && song.IsInDatabase()) {
- const auto path = map_song_fs(song);
- if (!path.IsNull())
- fprintf(file, "%s\n", path.c_str());
- } else {
- const auto uri_utf8 = song.GetURI();
- const auto uri_fs = AllocatedPath::FromUTF8(uri_utf8.c_str());
-
- if (!uri_fs.IsNull())
- fprintf(file, "%s\n", uri_fs.c_str());
- }
+ const char *uri_utf8 = playlist_saveAbsolutePaths
+ ? song.GetRealURI()
+ : song.GetURI();
+
+ const auto uri_fs = AllocatedPath::FromUTF8(uri_utf8);
+ if (!uri_fs.IsNull())
+ fprintf(file, "%s\n", uri_fs.c_str());
}
void
playlist_print_uri(FILE *file, const char *uri)
{
- auto path = playlist_saveAbsolutePaths && !uri_has_scheme(uri) &&
- !PathTraits::IsAbsoluteUTF8(uri)
+ auto path =
+#ifdef ENABLE_DATABASE
+ playlist_saveAbsolutePaths && !uri_has_scheme(uri) &&
+ !PathTraitsUTF8::IsAbsolute(uri)
? map_uri_fs(uri)
- : AllocatedPath::FromUTF8(uri);
+ :
+#endif
+ AllocatedPath::FromUTF8(uri);
if (!path.IsNull())
fprintf(file, "%s\n", path.c_str());
@@ -99,49 +99,3 @@ spl_save_playlist(const char *name_utf8, const playlist &playlist)
{
return spl_save_queue(name_utf8, playlist.queue);
}
-
-bool
-playlist_load_spl(struct playlist &playlist, PlayerControl &pc,
- const char *name_utf8,
- unsigned start_index, unsigned end_index,
- Error &error)
-{
- PlaylistFileContents contents = LoadPlaylistFile(name_utf8, error);
- if (contents.empty() && error.IsDefined())
- return false;
-
- if (end_index > contents.size())
- end_index = contents.size();
-
- for (unsigned i = start_index; i < end_index; ++i) {
- const auto &uri_utf8 = contents[i];
-
- if (memcmp(uri_utf8.c_str(), "file:///", 8) == 0) {
- const char *path_utf8 = uri_utf8.c_str() + 7;
-
- if (playlist.AppendFile(pc, path_utf8) != PlaylistResult::SUCCESS)
- FormatError(playlist_domain,
- "can't add file \"%s\"", path_utf8);
- continue;
- }
-
- if ((playlist.AppendURI(pc, uri_utf8.c_str())) != PlaylistResult::SUCCESS) {
- /* for windows compatibility, convert slashes */
- char *temp2 = g_strdup(uri_utf8.c_str());
- char *p = temp2;
- while (*p) {
- if (*p == '\\')
- *p = '/';
- p++;
- }
-
- if (playlist.AppendURI(pc, temp2) != PlaylistResult::SUCCESS)
- FormatError(playlist_domain,
- "can't add file \"%s\"", temp2);
-
- g_free(temp2);
- }
- }
-
- return true;
-}