gui/playlist: Add support for deleting playlists

System playlists cannot be deleted, but library playlists can.  Deleting
a library playlist removes the library and associated tracks from the database.

Signed-off-by: Anna Schumaker <Anna@OcarinaProject.net>
This commit is contained in:
Anna Schumaker 2016-05-11 10:18:45 -04:00 committed by Anna Schumaker
parent 382ee79c2e
commit 62e1b27b6c
3 changed files with 31 additions and 0 deletions

View File

@ -112,6 +112,35 @@ gboolean __playlist_on_select(GtkTreeSelection *selection, GtkTreeModel *model,
return queue != NULL;
}
bool __playlist_keypress(GtkTreeView *treeview, GdkEventKey *event,
gpointer data)
{
GtkTreeSelection *selection = gtk_tree_view_get_selection(treeview);
GtkTreeModel *model = GTK_TREE_MODEL(p_store);
gchar *name = NULL;
GtkTreePath *path;
GtkTreeIter iter;
GList *rows;
if (event->keyval != GDK_KEY_Delete)
return false;
rows = gtk_tree_selection_get_selected_rows(selection, &model);
path = rows->data;
if (gtk_tree_model_get_iter(model, &iter, path))
name = __playlist_name(&iter);
if (!name)
goto out;
if (playlist_delete(__playlist_type(&iter), name))
gtk_tree_store_remove(GTK_TREE_STORE(model), &iter);
g_free(name);
out:
g_list_free_full(rows, (GDestroyNotify)gtk_tree_path_free);
return true;
}
static bool __playlist_queue_set_size(struct queue *queue, GtkTreeIter *iter)
{
struct gui_queue *gq = gui_queue(queue);

View File

@ -31,6 +31,7 @@ void __collection_toggled() {}
#endif /* TEST_NEED_COLLECTION */
#ifdef TEST_NEED_PLAYLIST
void __playlist_keypress() {}
void __playlist_selection_changed() {}
#endif /* TEST_NEED_PLAYLIST */

View File

@ -954,6 +954,7 @@
<property name="headers_visible">False</property>
<property name="search_column">1</property>
<property name="enable_tree_lines">True</property>
<signal name="key-press-event" handler="__playlist_keypress" swapped="no"/>
<child internal-child="selection">
<object class="GtkTreeSelection" id="treeview-selection3">
<signal name="changed" handler="__playlist_selection_changed" swapped="no"/>