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 <Anna@OcarinaProject.net>
This commit is contained in:
Anna Schumaker 2014-12-01 09:36:37 -05:00
parent 9dfec9934c
commit 45c83ed2fd
3 changed files with 33 additions and 0 deletions

View File

@ -175,6 +175,17 @@ void tags :: remove_track(Track *track)
track_db.remove(track->index());
}
void tags :: remove_library_tracks(Library *library)
{
Database<Track>::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();

View File

@ -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();
}

View File

@ -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()