2013-12-22 17:24:09 -05:00
|
|
|
/*
|
|
|
|
* Copyright 2013 (c) Anna Schumaker.
|
|
|
|
*/
|
2013-12-31 15:44:44 -05:00
|
|
|
#include <database.h>
|
2013-12-31 16:58:40 -05:00
|
|
|
#include <error.h>
|
|
|
|
#include <playlist.h>
|
2013-12-22 17:24:09 -05:00
|
|
|
|
2013-12-31 15:44:44 -05:00
|
|
|
static std::set<unsigned int> empty_set;
|
2013-12-31 16:58:40 -05:00
|
|
|
static Database<IndexEntry> playlist_db("playlist.db");
|
2013-12-22 18:12:57 -05:00
|
|
|
|
2013-12-31 16:58:40 -05:00
|
|
|
void playlist :: init()
|
2013-12-22 17:24:09 -05:00
|
|
|
{
|
2013-12-31 16:58:40 -05:00
|
|
|
playlist_db.load();
|
2013-12-22 17:53:58 -05:00
|
|
|
}
|
|
|
|
|
2013-12-31 16:58:40 -05:00
|
|
|
void playlist :: add(const std::string &name, unsigned int track_id)
|
2013-12-22 17:53:58 -05:00
|
|
|
{
|
2013-12-31 16:58:40 -05:00
|
|
|
if ((name == "Banned") || (name == "Favorites")) {
|
|
|
|
index_insert(playlist_db, name, track_id);
|
|
|
|
playlist_db.save();
|
|
|
|
} else
|
2014-01-04 11:55:52 -05:00
|
|
|
throw -E_EXIST;
|
2013-12-22 17:53:58 -05:00
|
|
|
}
|
|
|
|
|
2013-12-31 16:58:40 -05:00
|
|
|
void playlist :: del(const std::string &name, unsigned int track_id)
|
2013-12-22 17:53:58 -05:00
|
|
|
{
|
2013-12-31 16:58:40 -05:00
|
|
|
if ((name == "Banned") || (name == "Favorites")) {
|
|
|
|
index_remove(playlist_db, name, track_id);
|
|
|
|
playlist_db.save();
|
|
|
|
} else
|
2014-01-04 11:55:52 -05:00
|
|
|
throw -E_EXIST;
|
2013-12-22 17:53:58 -05:00
|
|
|
}
|
2013-12-22 20:53:06 -05:00
|
|
|
|
2013-12-31 16:58:40 -05:00
|
|
|
const std::set<unsigned int> &playlist :: get_tracks(const std::string &name)
|
2013-12-22 20:53:06 -05:00
|
|
|
{
|
2013-12-31 16:58:40 -05:00
|
|
|
if ((name == "Banned") || (name == "Favorites")) {
|
|
|
|
try {
|
|
|
|
return playlist_db.find(name).values;
|
|
|
|
} catch (int error) {
|
|
|
|
return empty_set;
|
|
|
|
}
|
2013-12-22 20:53:06 -05:00
|
|
|
}
|
2014-01-04 11:55:52 -05:00
|
|
|
throw -E_EXIST;
|
2013-12-31 16:58:40 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
#ifdef CONFIG_TEST
|
|
|
|
void playlist :: clear()
|
|
|
|
{
|
|
|
|
playlist_db.clear();
|
2013-12-22 20:53:06 -05:00
|
|
|
}
|
2013-12-31 16:58:40 -05:00
|
|
|
#endif /* CONFIG_TEST */
|