From 64291ff02c17e8c9c9ce4846103ed6e32c7b63d9 Mon Sep 17 00:00:00 2001 From: Anna Schumaker Date: Fri, 6 Feb 2015 14:31:37 -0500 Subject: [PATCH] playlist: Add an "unplayed tracks" dynamic playlist Unplayed tracks is a dynamic playlist generated whenever we are asked to select the "Unplayed" playlist. Note that dynamic playlists aren't hooked up to the other playlist functions (has, add, del, or get_tracks). This is to avoid adding them to the index and potentially writing out to disk. Signed-off-by: Anna Schumaker --- core/playlist.cpp | 25 ++++++++++++++++++++----- tests/core/playlist.cpp | 5 +++++ 2 files changed, 25 insertions(+), 5 deletions(-) diff --git a/core/playlist.cpp b/core/playlist.cpp index d2af5879..aacc08bc 100644 --- a/core/playlist.cpp +++ b/core/playlist.cpp @@ -32,6 +32,21 @@ public: add(tags :: get_track(*it)); } + void dynamic_fill(const std::string &name) + { + Track *track; + + if (name != "Unplayed") + return; + + clear(); + for (unsigned int i = 0; i < tags :: track_size(); i++) { + track = tags :: get_track(i); + if ((track != NULL) && (track->count() == 0)) + add(track); + } + } + }; @@ -89,13 +104,13 @@ void playlist :: del(Track *track, const std::string &name) void playlist :: select(const std::string &name) { - IndexEntry *ent; + IndexEntry *ent = playlist_db.find(name); - ent = playlist_db.find(name); - if (ent == NULL) - return; + if (ent != NULL) + playlist_q.fill(ent); + else + playlist_q.dynamic_fill(name); - playlist_q.fill(ent); cur_plist = name; } diff --git a/tests/core/playlist.cpp b/tests/core/playlist.cpp index 3d428891..2a43e63c 100644 --- a/tests/core/playlist.cpp +++ b/tests/core/playlist.cpp @@ -45,6 +45,9 @@ static void test_queue() playlist :: select("Favorites"); test_equal(q->size(), (unsigned)8); + + playlist :: select("Unplayed"); + test_equal(q->size(), (unsigned)3); } static void test_add() @@ -53,6 +56,8 @@ static void test_add() Queue *q = playlist :: get_queue(); Queue *l = library :: get_queue(); + playlist :: select("Favorites"); + playlist :: add(tags :: get_track(5), "Banned"); ent = playlist :: get_tracks("Banned"); test_equal(ent->size(), (size_t)5);