playlist: Remove banned songs from the library queue

And put them back when they are unbanned.

Signed-off-by: Anna Schumaker <Anna@OcarinaProject.net>
This commit is contained in:
Anna Schumaker 2014-05-24 13:31:45 -04:00
parent 9ba4dbc218
commit e4db93b8e2
3 changed files with 27 additions and 1 deletions

9
DESIGN
View File

@ -1133,7 +1133,8 @@ Playlist:
- API - API
void playlist :: init(): void playlist :: init():
Load the playlist index from file. Load the playlist index from file. Remove every banned song
from the LibraryQueue in the library layer.
void playlist :: add(Track *track, const std::string &name); void playlist :: add(Track *track, const std::string &name);
Add track->id to the playlist named "name" and return true. Add track->id to the playlist named "name" and return true.
@ -1142,6 +1143,9 @@ Playlist:
If "name" is the currently selected playlist, add the track If "name" is the currently selected playlist, add the track
to the PlaylistQueue. to the PlaylistQueue.
If "name" is "Banned", remove the track from the LibraryQueue
in the library layer.
void playlist :: del(Track *track, const std::string &name); void playlist :: del(Track *track, const std::string &name);
Remove track->id from the playlist named "name" and return true. Remove track->id from the playlist named "name" and return true.
Return false if the playlist does not exist or if the track Return false if the playlist does not exist or if the track
@ -1150,6 +1154,9 @@ Playlist:
If "name" is the currently selected playlist, remove the track If "name" is the currently selected playlist, remove the track
from the PlaylistQueue. from the PlaylistQueue.
If "name" is "Banned", add the track to the LibraryQueue in the
library layer.
bool playlist :: has(Track *track, const std::string &name); bool playlist :: has(Track *track, const std::string &name);
Return true if the chosen playlist has the given track. Return true if the chosen playlist has the given track.
Return false otherwise. Return false otherwise.

View File

@ -1,6 +1,7 @@
/* /*
* Copyright 2013 (c) Anna Schumaker. * Copyright 2013 (c) Anna Schumaker.
*/ */
#include <library.h>
#include <playlist.h> #include <playlist.h>
@ -36,7 +37,13 @@ static std::string cur_plist;
void playlist :: init() void playlist :: init()
{ {
std::set<unsigned int>::iterator it;
playlist_db.load(); playlist_db.load();
IndexEntry *ent = get_tracks("Banned");
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) bool playlist :: has(Track *track, const std::string &name)
@ -60,6 +67,8 @@ void playlist :: add(Track *track, const std::string &name)
playlist_db.insert(name, track->id); playlist_db.insert(name, track->id);
if (cur_plist == name) if (cur_plist == name)
playlist_q.add(track); playlist_q.add(track);
if (name == "Banned")
library :: get_queue()->del(track);
} }
} }
@ -68,6 +77,9 @@ void playlist :: del(Track *track, const std::string &name)
playlist_db.remove(name, track->id); playlist_db.remove(name, track->id);
if (cur_plist == name) if (cur_plist == name)
playlist_q.del(track); playlist_q.del(track);
if (name == "Banned")
library :: get_queue()->add(track);
} }
void playlist :: select(const std::string &name) void playlist :: select(const std::string &name)

View File

@ -1,6 +1,7 @@
/* /*
* Copyright 2013 (c) Anna Schumaker. * Copyright 2013 (c) Anna Schumaker.
*/ */
#include <library.h>
#include <playlist.h> #include <playlist.h>
#include "test.h" #include "test.h"
@ -18,10 +19,12 @@ static void test_init()
test_equal(q->has_flag(Q_NO_SORT), true); test_equal(q->has_flag(Q_NO_SORT), true);
tagdb :: init(); tagdb :: init();
library :: init();
playlist :: init(); playlist :: init();
ent = playlist :: get_tracks("Banned"); ent = playlist :: get_tracks("Banned");
test_equal(ent->values.size(), (size_t)4); test_equal(ent->values.size(), (size_t)4);
test_equal(library :: get_queue()->size(), (unsigned)20);
ent = playlist :: get_tracks("Favorites"); ent = playlist :: get_tracks("Favorites");
test_equal(ent->values.size(), (size_t)8); test_equal(ent->values.size(), (size_t)8);
ent = playlist :: get_tracks("No Such Playlist"); ent = playlist :: get_tracks("No Such Playlist");
@ -43,11 +46,13 @@ static void test_add()
{ {
IndexEntry *ent; IndexEntry *ent;
Queue *q = playlist :: get_queue(); Queue *q = playlist :: get_queue();
Queue *l = library :: get_queue();
playlist :: add(tagdb :: lookup(5), "Banned"); playlist :: add(tagdb :: lookup(5), "Banned");
ent = playlist :: get_tracks("Banned"); ent = playlist :: get_tracks("Banned");
test_equal(ent->values.size(), (size_t)5); test_equal(ent->values.size(), (size_t)5);
test_equal(q->size(), (unsigned)8); test_equal(q->size(), (unsigned)8);
test_equal(l->size(), (unsigned)19);
playlist :: add(tagdb :: lookup(16), "Favorites"); playlist :: add(tagdb :: lookup(16), "Favorites");
playlist :: add(tagdb :: lookup(5), "Favorites"); playlist :: add(tagdb :: lookup(5), "Favorites");
@ -63,11 +68,13 @@ static void test_delete()
{ {
IndexEntry *ent; IndexEntry *ent;
Queue *q = playlist :: get_queue(); Queue *q = playlist :: get_queue();
Queue *l = library :: get_queue();
playlist :: del(tagdb :: lookup(5), "Banned"); playlist :: del(tagdb :: lookup(5), "Banned");
ent = playlist :: get_tracks("Banned"); ent = playlist :: get_tracks("Banned");
test_equal(ent->values.size(), (size_t)4); test_equal(ent->values.size(), (size_t)4);
test_equal(q->size(), (unsigned)9); test_equal(q->size(), (unsigned)9);
test_equal(l->size(), (unsigned)20);
playlist :: del(tagdb :: lookup(5), "Favorites"); playlist :: del(tagdb :: lookup(5), "Favorites");
ent = playlist :: get_tracks("Favorites"); ent = playlist :: get_tracks("Favorites");