2023-03-06 14:42:04 +01:00
|
|
|
// SPDX-License-Identifier: GPL-2.0-or-later
|
|
|
|
// Copyright The Music Player Daemon Project
|
2013-10-22 00:36:48 +02:00
|
|
|
|
|
|
|
#include "Playlist.hxx"
|
2014-02-19 22:54:52 +01:00
|
|
|
#include "db/Interface.hxx"
|
2018-08-02 13:45:43 +02:00
|
|
|
#include "song/LightSong.hxx"
|
|
|
|
#include "song/DetachedSong.hxx"
|
2016-10-27 22:19:26 +02:00
|
|
|
|
2013-10-22 00:36:48 +02:00
|
|
|
static bool
|
2014-01-07 21:39:47 +01:00
|
|
|
UpdatePlaylistSong(const Database &db, DetachedSong &song)
|
2013-10-22 00:36:48 +02:00
|
|
|
{
|
2014-01-18 18:20:54 +01:00
|
|
|
if (!song.IsInDatabase() || !song.IsFile())
|
2013-10-22 00:36:48 +02:00
|
|
|
/* only update Songs instances that are "detached"
|
|
|
|
from the Database */
|
|
|
|
return false;
|
|
|
|
|
2016-03-18 18:20:20 +01:00
|
|
|
const LightSong *original;
|
|
|
|
try {
|
2016-03-19 00:13:57 +01:00
|
|
|
original = db.GetSong(song.GetURI());
|
2017-12-19 10:56:23 +01:00
|
|
|
} catch (...) {
|
2013-10-22 00:36:48 +02:00
|
|
|
/* not found - shouldn't happen, because the update
|
|
|
|
thread should ensure that all stale Song instances
|
|
|
|
have been purged */
|
|
|
|
return false;
|
2017-02-08 09:53:14 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
assert(original != nullptr);
|
2013-10-22 00:36:48 +02:00
|
|
|
|
2014-01-07 21:39:47 +01:00
|
|
|
if (original->mtime == song.GetLastModified()) {
|
2013-10-22 00:36:48 +02:00
|
|
|
/* not modified */
|
|
|
|
db.ReturnSong(original);
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2014-01-07 21:39:47 +01:00
|
|
|
song.SetLastModified(original->mtime);
|
2023-10-05 19:27:22 +02:00
|
|
|
song.SetAdded(original->added);
|
2018-07-06 16:43:11 +02:00
|
|
|
song.SetTag(original->tag);
|
2013-10-22 00:36:48 +02:00
|
|
|
|
|
|
|
db.ReturnSong(original);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2014-02-01 00:45:58 +01:00
|
|
|
playlist::DatabaseModified(const Database &db)
|
2013-10-22 00:36:48 +02:00
|
|
|
{
|
|
|
|
bool modified = false;
|
|
|
|
|
|
|
|
for (unsigned i = 0, n = queue.GetLength(); i != n; ++i) {
|
2014-02-01 00:45:58 +01:00
|
|
|
if (UpdatePlaylistSong(db, queue.Get(i))) {
|
2013-10-22 00:36:48 +02:00
|
|
|
queue.ModifyAtPosition(i);
|
|
|
|
modified = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-03-10 20:03:01 +01:00
|
|
|
if (modified)
|
|
|
|
OnModified();
|
2013-10-22 00:36:48 +02:00
|
|
|
}
|