2013-10-22 00:36:48 +02:00
|
|
|
/*
|
2018-10-31 17:54:59 +01:00
|
|
|
* Copyright 2003-2018 The Music Player Daemon Project
|
2013-10-22 00:36:48 +02:00
|
|
|
* http://www.musicpd.org
|
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation; either version 2 of the License, or
|
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License along
|
|
|
|
* with this program; if not, write to the Free Software Foundation, Inc.,
|
|
|
|
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#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);
|
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
|
|
|
}
|