From 45c83ed2fd4ab2f58feec00e2df269708a41b1d1 Mon Sep 17 00:00:00 2001 From: Anna Schumaker Date: Mon, 1 Dec 2014 09:36:37 -0500 Subject: [PATCH] Track: Add a function for removing all tracks from a given library This function will be called when doing library removals. Signed-off-by: Anna Schumaker --- core/tags/track.cpp | 11 +++++++++++ include/core/tags/track.h | 7 +++++++ tests/core/tags/track.cpp | 15 +++++++++++++++ 3 files changed, 33 insertions(+) diff --git a/core/tags/track.cpp b/core/tags/track.cpp index f669b7dc..a80422ad 100644 --- a/core/tags/track.cpp +++ b/core/tags/track.cpp @@ -175,6 +175,17 @@ void tags :: remove_track(Track *track) track_db.remove(track->index()); } +void tags :: remove_library_tracks(Library *library) +{ + Database::iterator it; + + for (it = track_db.begin(); it != track_db.end(); it = track_db.next(it)) { + if ((*it)->library() == library) + track_db.remove((*it)->index()); + } + tags :: commit_track_db(); +} + void tags :: commit_track_db() { track_db.save(); diff --git a/include/core/tags/track.h b/include/core/tags/track.h index 10c9c6b3..0d2ae068 100644 --- a/include/core/tags/track.h +++ b/include/core/tags/track.h @@ -158,6 +158,13 @@ namespace tags */ void remove_track(Track *); + /** + * Called to remove all tracks associated with a specific Library. + * + * @param library The Library tag that will be matched. + */ + void remove_library_tracks(Library *); + /** Called to write the track_db to disk. */ void commit_track_db(); } diff --git a/tests/core/tags/track.cpp b/tests/core/tags/track.cpp index 21561467..4e0b8ea9 100644 --- a/tests/core/tags/track.cpp +++ b/tests/core/tags/track.cpp @@ -108,6 +108,8 @@ static void test_track_tag_lookup() MUSIC_DIR + "/Hyrule Symphony/12 - Ocarina Medley.mp3", "Ocarina Medley", 232, 12); test_not_equal(b, a); + test_equal(library->size(), (unsigned)2); + test_equal(tags :: get_track(a->index()), a); test_equal(tags :: get_track(a->index() + 1), b); @@ -117,12 +119,25 @@ static void test_track_tag_lookup() tags :: commit_track_db(); test_track_tag_load_db(2); + index = a->index(); tags :: remove_track(a); test_equal(tags :: get_track(index), (Track *)NULL); test_track_tag_load_db(2); tags :: commit_track_db(); test_track_tag_load_db(1); + test_equal(library->size(), (unsigned)1); + + + a = tags :: add_track(album, artist, genre, library, + MUSIC_DIR + "/Hyrule Symphony/13 - Legend of Zelda Medley.mp3", + "Legend of Zelda Medley", 288, 13); + test_not_equal(a, (Track *)NULL); + verify_track_tag(a, 2); + + tags :: remove_library_tracks(library); + test_track_tag_load_db(0); + test_equal(library->size(), (unsigned)0); } static void test_track_tag_functional()