ocarina: Delete selected songs from playlists

If the current playlist is the library or banned list, I toggle the
banned state.  Otherwise, I remove them from the current playlist.

Signed-off-by: Bryan Schumaker <bjschuma@gmail.com>
This commit is contained in:
Bryan Schumaker 2012-09-04 10:39:23 -04:00
parent ba9ecd258b
commit 7d4977aab8
1 changed files with 42 additions and 0 deletions

View File

@ -177,6 +177,20 @@ static void list_selected_tracks(GtkTreeView *treeview, list<libsaria::Track *>
gtk_tree_selection_selected_foreach(selection, selected_foreach_list, tracks);
}
static void selected_foreach_index(GtkTreeModel *model, GtkTreePath *path,
GtkTreeIter *iter, gpointer data)
{
list<unsigned int> *indices = (list<unsigned int> *)data;
unsigned int *index = (unsigned int *)gtk_tree_path_get_indices(path);
indices->push_back(*index);
}
static void list_selected_indices(GtkTreeView *treeview, list<unsigned int> *indices)
{
GtkTreeSelection *selection = gtk_tree_view_get_selection(treeview);
gtk_tree_selection_selected_foreach(selection, selected_foreach_index, indices);
}
static void new_playlist(string &key, GtkTreeView *treeview, bool front)
{
list<libsaria::Track *> tracks;
@ -205,6 +219,32 @@ static void add_to_playlist(GtkTreeView *treeview, int n)
playlist->add_tracks(tracks);
}
static void ban_selected(GtkTreeView *treeview, bool state)
{
list<libsaria::Track *> tracks;
list<libsaria::Track *>::iterator it;
list_selected_tracks(treeview, &tracks);
for (it = tracks.begin(); it != tracks.end(); it++)
(*it)->set_banned(state);
}
static void delete_from_playlist(GtkTreeView *treeview)
{
list<unsigned int> indices;
libsaria::Playlist *playlist = current_playlist();
string name = playlist->get_name();
if (name == "Library" || name == "Banned") {
ban_selected(treeview, name == "Library");
return;
}
list_selected_indices(treeview, &indices);
playlist->remove_indices(indices);
libsaria::deck::garbage_collect();
}
static bool on_escape_key(GtkTreeView *treeview)
{
GtkTreeSelection *selection = gtk_tree_view_get_selection(treeview);
@ -235,6 +275,8 @@ bool playlist_key_pressed(GtkTreeView *treeview, string &key)
new_playlist(key, treeview, true);
else if (key >= "0" && key <= "9")
add_to_playlist(treeview, atoi(key.c_str()));
else if (key == "Delete")
delete_from_playlist(treeview);
else if (key == "Return")
on_return_key(treeview);
else if (key == "Escape")