2010-07-21 08:58:15 +02:00
|
|
|
/*
|
2013-01-02 22:01:04 +01:00
|
|
|
* Copyright (C) 2003-2013 The Music Player Daemon Project
|
2010-07-21 08:58:15 +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 "config.h"
|
2013-01-02 20:25:20 +01:00
|
|
|
#include "PlaylistVector.hxx"
|
2013-01-02 20:56:21 +01:00
|
|
|
#include "DatabaseLock.hxx"
|
2010-07-21 08:58:15 +02:00
|
|
|
|
|
|
|
#include <assert.h>
|
|
|
|
#include <string.h>
|
|
|
|
#include <glib.h>
|
|
|
|
|
|
|
|
void
|
2012-02-12 17:50:30 +01:00
|
|
|
playlist_vector_deinit(struct list_head *pv)
|
2010-07-21 08:58:15 +02:00
|
|
|
{
|
|
|
|
assert(pv != NULL);
|
|
|
|
|
2013-01-02 22:04:03 +01:00
|
|
|
PlaylistInfo *pm, *n;
|
2012-02-12 17:50:30 +01:00
|
|
|
playlist_vector_for_each_safe(pm, n, pv)
|
2013-01-02 22:04:03 +01:00
|
|
|
delete pm;
|
2010-07-21 08:58:15 +02:00
|
|
|
}
|
|
|
|
|
2013-01-02 22:04:03 +01:00
|
|
|
PlaylistInfo *
|
2012-02-12 17:50:30 +01:00
|
|
|
playlist_vector_find(struct list_head *pv, const char *name)
|
2010-07-21 08:58:15 +02:00
|
|
|
{
|
2012-02-13 19:25:03 +01:00
|
|
|
assert(holding_db_lock());
|
2010-07-21 08:58:15 +02:00
|
|
|
assert(pv != NULL);
|
|
|
|
assert(name != NULL);
|
|
|
|
|
2013-01-02 22:04:03 +01:00
|
|
|
PlaylistInfo *pm;
|
2012-02-12 17:50:30 +01:00
|
|
|
playlist_vector_for_each(pm, pv)
|
2013-01-02 22:04:03 +01:00
|
|
|
if (pm->name.compare(name) == 0)
|
2012-02-12 17:50:30 +01:00
|
|
|
return pm;
|
2010-07-21 08:58:15 +02:00
|
|
|
|
2012-02-12 17:50:30 +01:00
|
|
|
return NULL;
|
2010-07-21 08:58:15 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2013-01-02 22:04:03 +01:00
|
|
|
playlist_vector_add(struct list_head *pv, PlaylistInfo &&pi)
|
2010-07-21 08:58:15 +02:00
|
|
|
{
|
2012-02-13 19:25:03 +01:00
|
|
|
assert(holding_db_lock());
|
|
|
|
|
2013-01-02 22:04:03 +01:00
|
|
|
PlaylistInfo *pm = new PlaylistInfo(std::move(pi));
|
2012-02-13 19:26:00 +01:00
|
|
|
list_add_tail(&pm->siblings, pv);
|
2010-07-21 08:58:15 +02:00
|
|
|
}
|
|
|
|
|
2010-09-07 20:21:19 +02:00
|
|
|
bool
|
2013-01-02 22:04:03 +01:00
|
|
|
playlist_vector_update_or_add(struct list_head *pv, PlaylistInfo &&pi)
|
2010-07-21 08:58:15 +02:00
|
|
|
{
|
2012-02-13 19:25:03 +01:00
|
|
|
assert(holding_db_lock());
|
|
|
|
|
2013-01-02 22:04:03 +01:00
|
|
|
PlaylistInfo *pm = playlist_vector_find(pv, pi.name.c_str());
|
2012-02-12 17:50:30 +01:00
|
|
|
if (pm != NULL) {
|
2013-01-02 22:04:03 +01:00
|
|
|
if (pi.mtime == pm->mtime)
|
2010-09-07 20:21:19 +02:00
|
|
|
return false;
|
|
|
|
|
2013-01-02 22:04:03 +01:00
|
|
|
pm->mtime = pi.mtime;
|
2010-07-21 08:58:15 +02:00
|
|
|
} else
|
2013-01-02 22:04:03 +01:00
|
|
|
playlist_vector_add(pv, std::move(pi));
|
2010-09-07 20:21:19 +02:00
|
|
|
|
|
|
|
return true;
|
2010-07-21 08:58:15 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
2012-02-12 17:50:30 +01:00
|
|
|
playlist_vector_remove(struct list_head *pv, const char *name)
|
2010-07-21 08:58:15 +02:00
|
|
|
{
|
2012-02-13 19:25:03 +01:00
|
|
|
assert(holding_db_lock());
|
|
|
|
|
2013-01-02 22:04:03 +01:00
|
|
|
PlaylistInfo *pm = playlist_vector_find(pv, name);
|
2012-02-12 17:50:30 +01:00
|
|
|
if (pm == NULL)
|
2010-07-21 08:58:15 +02:00
|
|
|
return false;
|
|
|
|
|
2012-02-12 17:50:30 +01:00
|
|
|
list_del(&pm->siblings);
|
2013-01-02 22:04:03 +01:00
|
|
|
delete pm;
|
2010-07-21 08:58:15 +02:00
|
|
|
return true;
|
|
|
|
}
|