core/playlist: Add a function to remove banned tracks

This replaces the get_tracks() function.

Signed-off-by: Anna Schumaker <Anna@OcarinaProject.net>
This commit is contained in:
Anna Schumaker 2015-12-10 12:33:15 -05:00
parent 135e0d95d6
commit 88f6fc526c
4 changed files with 37 additions and 53 deletions

View File

@ -100,8 +100,6 @@ static void __playlist_fill_dynamic(const gchar *name)
void playlist_init(struct queue_ops *ops)
{
struct set_iter it;
queue_init(&playlist_q, Q_ENABLED | Q_REPEAT, ops);
queue_sort(&playlist_q, COMPARE_ARTIST, true);
queue_sort(&playlist_q, COMPARE_YEAR, false);
@ -110,14 +108,7 @@ void playlist_init(struct queue_ops *ops)
index_init(&playlist_db, "playlist.db", true);
db_load(&playlist_db);
index_entry *ent = playlist :: get_tracks("Banned");
if (!ent)
return;
set_for_each(&ent->ie_set, &it)
queue_remove_all(collection_get_queue(),
track_get(it.it_val));
playlist_fixup_collection();
}
void playlist_deinit()
@ -126,6 +117,18 @@ void playlist_deinit()
db_deinit(&playlist_db);
}
void playlist_fixup_collection()
{
struct index_entry *ent = INDEX_ENTRY(db_get(&playlist_db, "Banned"));
struct set_iter it;
if (!ent)
return;
set_for_each(&ent->ie_set, &it)
queue_remove_all(collection_get_queue(), track_get(it.it_val));
}
void playlist_add(const gchar *name, struct track *track)
{
if (!track || !__playlist_is_static(name))
@ -169,11 +172,6 @@ void playlist_select(const gchar *name)
__playlist_fill_dynamic(name);
}
index_entry *playlist :: get_tracks(const std::string &name)
{
return INDEX_ENTRY(db_get(&playlist_db, name.c_str()));
}
struct queue *playlist_get_queue()
{
return &playlist_q;

View File

@ -88,18 +88,6 @@ void update_paths()
}
}
static void remove_banned_tracks()
{
index_entry *ent = playlist :: get_tracks("Banned");
struct set_iter it;
if (!ent)
return;
set_for_each(&ent->ie_set, &it)
queue_remove_all(collection_get_queue(), track_get(it.it_val));
}
static bool on_idle()
@ -169,7 +157,7 @@ static void on_toggled(const Glib::ustring &str)
collection_set_enabled(lib, !lib->li_enabled);
row[c_cols.c_enabled] = lib->li_enabled;
if (lib->li_enabled)
remove_banned_tracks();
playlist_fixup_collection();
}

View File

@ -1,5 +1,19 @@
/**
* Copyright 2013 (c) Anna Schumaker.
*
* The playlist manager is in charge of the various playlists Ocarina
* knows about. This code also manages a special queue used by the GUI
* to display the tracks in each playlist.
*
* Currently supported playlists are:
*
* Name | Description
* -------------|------------
* Banned | Songs that the user doesn't like.
* Favorites | Songs that the user likes.
* Unplayed | Songs that have not been played yet.
* Most Played | Songs with an above average play count.
* Least Played | Songs with a below average play count.
*/
#ifndef OCARINA_CORE_PLAYLIST_H
#define OCARINA_CORE_PLAYLIST_H
@ -11,37 +25,15 @@ extern "C" {
#include <string>
/**
* The playlist namespace is in charge of managing the various playlists
* Ocarina knows aboit. It is also in charge of a special queue that the
* UI uses to display Tracks in each playlist.
*
* Currently supported playlists are:
*
* Name | Description
* ----------|------------
* Banned | Songs that the user doesn't like.
* Favorites | Songs that the user likes.
*/
namespace playlist
{
/**
* Use to access specific tracks in a playlist.
*
* @param name The playlist to access.
* @return The index_entry containing the tracks.
*/
index_entry *get_tracks(const std::string &);
};
/* Called to initialize the playlist manager. */
void playlist_init(struct queue_ops *);
/* Called to deinitialize the playlist manager. */
void playlist_deinit();
/* Called to remove banned tracks from the collection queue. */
void playlist_fixup_collection();
/* Called to add a track to a playlist. */
void playlist_add(const gchar *, struct track *);

View File

@ -75,6 +75,12 @@ static void test_add()
test_equal(playlist_has("Banned", track), true);
test_equal(queue_size(q), 1);
test_equal(queue_size(c), 12);
/* Check playlist_fixup_collection() while we're here. */
queue_add(c, track);
test_equal(queue_size(c), 13);
playlist_fixup_collection();
test_equal(queue_size(c), 12);
}
static void test_remove()