libsaria: Garbage collect the playlist deck
I do this after choosing the next song and after tracks are removed from each playlist. This allows me to remove playlists as they empty. Signed-off-by: Bryan Schumaker <bjschuma@gmail.com>
This commit is contained in:
parent
8309c4a606
commit
5363cfac82
|
@ -19,6 +19,7 @@ namespace libsaria
|
|||
|
||||
void push_front(Playlist *);
|
||||
void push_back(Playlist *);
|
||||
void garbage_collect();
|
||||
|
||||
void next();
|
||||
void prev();
|
||||
|
|
|
@ -58,6 +58,22 @@ namespace libsaria
|
|||
playlist_deck.push_back(plist);
|
||||
}
|
||||
|
||||
void deck::garbage_collect()
|
||||
{
|
||||
int n = 0;
|
||||
list<libsaria::Playlist *>::iterator it;
|
||||
|
||||
for (it = playlist_deck.begin(); it != playlist_deck.end(); it++) {
|
||||
if ((*it)->get_size() == 0) {
|
||||
(*it)->prepare_for_removal();
|
||||
delete (*it);
|
||||
it = playlist_deck.erase(it);
|
||||
it--;
|
||||
} else
|
||||
(*it)->renumber(n++);
|
||||
}
|
||||
}
|
||||
|
||||
void deck::next()
|
||||
{
|
||||
Playlist *plist;
|
||||
|
@ -72,13 +88,7 @@ namespace libsaria
|
|||
if (track)
|
||||
track->load(check_play());
|
||||
|
||||
if ((plist->get_size() == 0) && (plist->is_static() == false)) {
|
||||
println("Removing non-static playlist");
|
||||
plist->prepare_for_removal();
|
||||
delete plist;
|
||||
playlist_deck.pop_front();
|
||||
renumber_playlists();
|
||||
};
|
||||
garbage_collect();
|
||||
}
|
||||
|
||||
void deck::prev()
|
||||
|
|
|
@ -66,6 +66,10 @@ namespace libsaria
|
|||
|
||||
if (number < 0)
|
||||
return;
|
||||
else if (get_size() == 0) {
|
||||
rm_file();
|
||||
return;
|
||||
}
|
||||
|
||||
filepath = plistdir + "/" + number_to_filename(number);
|
||||
app::save(filepath, save_playlist, &data_state, this);
|
||||
|
|
|
@ -100,6 +100,7 @@ gboolean key_pressed(GtkWidget *widget, GdkEvent *event, gpointer data)
|
|||
if (indices.size() == 0)
|
||||
return FALSE;
|
||||
plist->get_playlist()->remove_indices(indices);
|
||||
libsaria::deck::garbage_collect();
|
||||
} else if (key == "Escape") {
|
||||
plist->select_none();
|
||||
return FALSE;
|
||||
|
|
Loading…
Reference in New Issue