00ff9cd08f
This happens if we try to use the Banned playlist before it exists in the database. Signed-off-by: Anna Schumaker <Anna@OcarinaProject.net>
112 lines
2.0 KiB
C++
112 lines
2.0 KiB
C++
/*
|
|
* Copyright 2013 (c) Anna Schumaker.
|
|
*/
|
|
#include <core/library.h>
|
|
#include <core/playlist.h>
|
|
|
|
|
|
class PlaylistQueue : public Queue {
|
|
public:
|
|
|
|
PlaylistQueue() : Queue(Q_ENABLED | Q_REPEAT)
|
|
{
|
|
sort(SORT_ARTIST, true);
|
|
sort(SORT_YEAR, false);
|
|
sort(SORT_TRACK, false);
|
|
set_flag(Q_NO_SORT);
|
|
}
|
|
|
|
void fill(IndexEntry *ent)
|
|
{
|
|
std::set<unsigned int>::iterator it;
|
|
|
|
while (size() > 0)
|
|
del((unsigned)0);
|
|
|
|
for (it = ent->values.begin(); it != ent->values.end(); it++)
|
|
add(tagdb :: lookup(*it));
|
|
}
|
|
|
|
};
|
|
|
|
|
|
static Index playlist_db("playlist.db", true);
|
|
static PlaylistQueue playlist_q;
|
|
static std::string cur_plist;
|
|
|
|
|
|
void playlist :: init()
|
|
{
|
|
std::set<unsigned int>::iterator it;
|
|
|
|
playlist_db.load();
|
|
|
|
IndexEntry *ent = get_tracks("Banned");
|
|
if (!ent)
|
|
return;
|
|
|
|
for (it = ent->values.begin(); it != ent->values.end(); it++)
|
|
library :: get_queue()->del(tagdb :: lookup(*it));
|
|
}
|
|
|
|
bool playlist :: has(Track *track, const std::string &name)
|
|
{
|
|
std::set<unsigned int>::iterator it;
|
|
IndexEntry *ent = playlist_db.find(name);
|
|
|
|
if (ent == NULL)
|
|
return false;
|
|
|
|
it = ent->values.find(track->id);
|
|
return it != ent->values.end();
|
|
}
|
|
|
|
void playlist :: add(Track *track, const std::string &name)
|
|
{
|
|
if (!( (name == "Banned") || (name == "Favorites") ))
|
|
return;
|
|
|
|
if (!has(track, name)) {
|
|
playlist_db.insert(name, track->id);
|
|
if (cur_plist == name)
|
|
playlist_q.add(track);
|
|
if (name == "Banned")
|
|
library :: get_queue()->del(track);
|
|
}
|
|
}
|
|
|
|
void playlist :: del(Track *track, const std::string &name)
|
|
{
|
|
playlist_db.remove(name, track->id);
|
|
if (cur_plist == name)
|
|
playlist_q.del(track);
|
|
if (name == "Banned")
|
|
library :: get_queue()->add(track);
|
|
|
|
}
|
|
|
|
void playlist :: select(const std::string &name)
|
|
{
|
|
IndexEntry *ent;
|
|
|
|
if (cur_plist == name)
|
|
return;
|
|
|
|
ent = playlist_db.find(name);
|
|
if (ent == NULL)
|
|
return;
|
|
|
|
playlist_q.fill(ent);
|
|
cur_plist = name;
|
|
}
|
|
|
|
IndexEntry *playlist :: get_tracks(const std::string &name)
|
|
{
|
|
return playlist_db.find(name);
|
|
}
|
|
|
|
Queue *playlist :: get_queue()
|
|
{
|
|
return &playlist_q;
|
|
}
|