aboutsummaryrefslogtreecommitdiffstats
path: root/src/PlaylistEdit.cxx
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--src/PlaylistEdit.cxx58
1 files changed, 24 insertions, 34 deletions
diff --git a/src/PlaylistEdit.cxx b/src/PlaylistEdit.cxx
index 668612a1a..87a64c5c9 100644
--- a/src/PlaylistEdit.cxx
+++ b/src/PlaylistEdit.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
@@ -29,10 +29,10 @@
#include "PlayerControl.hxx"
#include "util/UriUtil.hxx"
#include "util/Error.hxx"
-#include "Song.hxx"
+#include "DetachedSong.hxx"
+#include "Mapper.hxx"
#include "Idle.hxx"
-#include "DatabaseGlue.hxx"
-#include "DatabasePlugin.hxx"
+#include "db/DatabaseSong.hxx"
#include "Log.hxx"
#include <stdlib.h>
@@ -60,27 +60,25 @@ PlaylistResult
playlist::AppendFile(PlayerControl &pc,
const char *path_utf8, unsigned *added_id)
{
- Song *song = Song::LoadFile(path_utf8, nullptr);
- if (song == nullptr)
+ DetachedSong song(path_utf8);
+ if (!song.Update())
return PlaylistResult::NO_SUCH_SONG;
- const auto result = AppendSong(pc, song, added_id);
- song->Free();
- return result;
+ return AppendSong(pc, std::move(song), added_id);
}
PlaylistResult
playlist::AppendSong(PlayerControl &pc,
- Song *song, unsigned *added_id)
+ DetachedSong &&song, unsigned *added_id)
{
unsigned id;
if (queue.IsFull())
return PlaylistResult::TOO_LARGE;
- const Song *const queued_song = GetQueuedSong();
+ const DetachedSong *const queued_song = GetQueuedSong();
- id = queue.Append(song, 0);
+ id = queue.Append(std::move(song), 0);
if (queue.random) {
/* shuffle the new song into the list of remaining
@@ -110,25 +108,17 @@ playlist::AppendURI(PlayerControl &pc,
{
FormatDebug(playlist_domain, "add to playlist: %s", uri);
- const Database *db = nullptr;
- Song *song;
+ DetachedSong *song;
if (uri_has_scheme(uri)) {
- song = Song::NewRemote(uri);
+ song = new DetachedSong(uri);
} else {
- db = GetDatabase();
- if (db == nullptr)
- return PlaylistResult::NO_SUCH_SONG;
-
- song = db->GetSong(uri, IgnoreError());
+ song = DatabaseDetachSong(uri, IgnoreError());
if (song == nullptr)
return PlaylistResult::NO_SUCH_SONG;
}
- PlaylistResult result = AppendSong(pc, song, added_id);
- if (db != nullptr)
- db->ReturnSong(song);
- else
- song->Free();
+ PlaylistResult result = AppendSong(pc, std::move(*song), added_id);
+ delete song;
return result;
}
@@ -139,7 +129,7 @@ playlist::SwapPositions(PlayerControl &pc, unsigned song1, unsigned song2)
if (!queue.IsValidPosition(song1) || !queue.IsValidPosition(song2))
return PlaylistResult::BAD_RANGE;
- const Song *const queued_song = GetQueuedSong();
+ const DetachedSong *const queued_song = GetQueuedSong();
queue.SwapPositions(song1, song2);
@@ -193,7 +183,7 @@ playlist::SetPriorityRange(PlayerControl &pc,
/* remember "current" and "queued" */
const int current_position = GetCurrentPosition();
- const Song *const queued_song = GetQueuedSong();
+ const DetachedSong *const queued_song = GetQueuedSong();
/* apply the priority changes */
@@ -225,7 +215,7 @@ playlist::SetPriorityId(PlayerControl &pc,
void
playlist::DeleteInternal(PlayerControl &pc,
- unsigned song, const Song **queued_p)
+ unsigned song, const DetachedSong **queued_p)
{
assert(song < GetLength());
@@ -275,7 +265,7 @@ playlist::DeletePosition(PlayerControl &pc, unsigned song)
if (song >= queue.GetLength())
return PlaylistResult::BAD_RANGE;
- const Song *queued_song = GetQueuedSong();
+ const DetachedSong *queued_song = GetQueuedSong();
DeleteInternal(pc, song, &queued_song);
@@ -297,7 +287,7 @@ playlist::DeleteRange(PlayerControl &pc, unsigned start, unsigned end)
if (start >= end)
return PlaylistResult::SUCCESS;
- const Song *queued_song = GetQueuedSong();
+ const DetachedSong *queued_song = GetQueuedSong();
do {
DeleteInternal(pc, --end, &queued_song);
@@ -320,10 +310,10 @@ playlist::DeleteId(PlayerControl &pc, unsigned id)
}
void
-playlist::DeleteSong(PlayerControl &pc, const struct Song &song)
+playlist::DeleteSong(PlayerControl &pc, const char *uri)
{
for (int i = queue.GetLength() - 1; i >= 0; --i)
- if (SongEquals(song, queue.Get(i)))
+ if (queue.Get(i).IsURI(uri))
DeletePosition(pc, i);
}
@@ -341,7 +331,7 @@ playlist::MoveRange(PlayerControl &pc, unsigned start, unsigned end, int to)
/* nothing happens */
return PlaylistResult::SUCCESS;
- const Song *const queued_song = GetQueuedSong();
+ const DetachedSong *const queued_song = GetQueuedSong();
/*
* (to < 0) => move to offset from current song
@@ -401,7 +391,7 @@ playlist::Shuffle(PlayerControl &pc, unsigned start, unsigned end)
/* needs at least two entries. */
return;
- const Song *const queued_song = GetQueuedSong();
+ const DetachedSong *const queued_song = GetQueuedSong();
if (playing && current >= 0) {
unsigned current_position = queue.OrderToPosition(current);