From f2597a8e6c7feff49f51733d5431543aacf52364 Mon Sep 17 00:00:00 2001 From: Anna Schumaker Date: Wed, 11 May 2016 08:09:27 -0400 Subject: [PATCH] gui/playlist: Add library playlists to the playlist sidebar Signed-off-by: Anna Schumaker --- gui/collection.c | 7 ++++++- gui/playlist.c | 33 +++++++++++++++++++++++++++------ include/gui/playlist.h | 3 +++ include/tests/gui.h | 1 + tests/gui/.gitignore | 2 +- tests/gui/Sconscript | 2 +- tests/gui/collection.c | 1 - tests/gui/playlist.c | 1 + 8 files changed, 40 insertions(+), 10 deletions(-) diff --git a/gui/collection.c b/gui/collection.c index 66e9b3e3..942485a9 100644 --- a/gui/collection.c +++ b/gui/collection.c @@ -8,6 +8,7 @@ #include #include #include +#include #include enum collection_sidebar_columns { @@ -137,6 +138,7 @@ bool __collection_buttonpress(GtkWidget *widget, GdkEventButton *event, gpointer void __collection_add(GtkButton *button, GtkFileChooser *chooser) { gchar *filename = gtk_file_chooser_get_filename(chooser); + struct library *library; GtkTreeIter iter, last; gtk_tree_model_get_iter_first(c_model, &iter); @@ -144,8 +146,10 @@ void __collection_add(GtkButton *button, GtkFileChooser *chooser) while (__collection_get_library(&last) != NULL) gtk_tree_model_iter_next(c_model, &last); + library = collection_add(filename); gtk_tree_store_insert_before(GTK_TREE_STORE(c_model), &iter, NULL, &last); - __collection_set_library(&iter, collection_add(filename)); + __collection_set_library(&iter, library); + gui_playlist_add_library(library); gui_idle_enable(); g_free(filename); @@ -184,6 +188,7 @@ bool __gui_collection_init_idle() db_for_each(library, next, library_db_get()) { gtk_tree_store_insert_before(GTK_TREE_STORE(c_model), &iter, &parent, &last); __collection_set_library(&iter, LIBRARY(library)); + gui_playlist_add_library(LIBRARY(library)); } return true; } diff --git a/gui/playlist.c b/gui/playlist.c index 85b83622..6508366f 100644 --- a/gui/playlist.c +++ b/gui/playlist.c @@ -36,7 +36,7 @@ static void __playlist_set(GtkTreeIter *iter, const gchar *name, static void __playlist_set_size(GtkTreeIter *iter, const gchar *name) { GtkTreePath *path = gtk_tree_model_get_path(GTK_TREE_MODEL(p_store), iter); - unsigned int size = playlist_size(PL_SYSTEM, name); + unsigned int size = playlist_size(__playlist_type(iter), name); const gchar *fmt = "%s\n%d track%s"; gchar *text; @@ -81,6 +81,7 @@ void __playlist_selection_changed(GtkTreeSelection *selection, gpointer data) { GtkStack *stack = GTK_STACK(gui_builder_widget("o_stack")); GtkTreeModel *model = GTK_TREE_MODEL(p_store); + struct queue *queue; GtkTreeIter iter; if (gtk_tree_selection_get_selected(selection, &model, &iter)) { @@ -89,8 +90,8 @@ void __playlist_selection_changed(GtkTreeSelection *selection, gpointer data) p_name = __playlist_name(&iter); gtk_stack_set_visible_child_name(stack, "queues"); - gui_sidebar_selected(SB_PLAYLIST, - gui_queue(playlist_get_queue(PL_SYSTEM, p_name))); + queue = playlist_get_queue(__playlist_type(&iter), p_name); + gui_sidebar_selected(SB_PLAYLIST, gui_queue(queue)); } } @@ -104,7 +105,7 @@ gboolean __playlist_on_select(GtkTreeSelection *selection, GtkTreeModel *model, gtk_tree_model_get_iter(model, &iter, path); name = __playlist_name(&iter); - queue = playlist_get_queue(PL_SYSTEM, name); + queue = playlist_get_queue(__playlist_type(&iter), name); g_free(name); return queue != NULL; @@ -212,12 +213,15 @@ void gui_playlist_init() __playlist_add(&parent, "Least Played", "go-down", PL_SYSTEM); __playlist_add(&parent, "Unplayed", "audio-x-generic", PL_SYSTEM); + /* Add "Library" header. */ + gtk_tree_store_insert(p_store, &parent, NULL, -1); + gtk_tree_store_insert(p_store, &parent, NULL, -1); + __playlist_set(&parent, "Library", "system-file-manager", 0); + gtk_tree_view_expand_all(treeview); gtk_tree_selection_set_select_function( gtk_tree_view_get_selection(treeview), __playlist_on_select, NULL, NULL); - - gtk_tree_store_insert(p_store, &parent, NULL, -1); } gchar *gui_playlist_cur() @@ -225,6 +229,23 @@ gchar *gui_playlist_cur() return p_name; } +void gui_playlist_add_library(struct library *library) +{ + GtkTreeIter parent; + gchar *name; + + gtk_tree_model_get_iter_first(GTK_TREE_MODEL(p_store), &parent); + while (gtk_tree_model_iter_next(GTK_TREE_MODEL(p_store), &parent)) { + name = __playlist_name(&parent); + if (string_match(name, "Library")) + __playlist_add(&parent, library->li_path, "folder", PL_LIBRARY); + g_free(name); + } + + gtk_tree_view_expand_all( + GTK_TREE_VIEW(gui_builder_widget("o_playlist_view"))); +} + struct queue_ops playlist_ops = { .qop_init = __playlist_init, .qop_deinit = gui_queue_free, diff --git a/include/gui/playlist.h b/include/gui/playlist.h index 073fa291..1021f12e 100644 --- a/include/gui/playlist.h +++ b/include/gui/playlist.h @@ -12,6 +12,9 @@ void gui_playlist_init(); /* Called to get the currently selected playlist. */ gchar *gui_playlist_cur(); +/* Called to add a library playlist. */ +void gui_playlist_add_library(struct library *); + /* Playlist operations passed to core_init() */ extern struct queue_ops playlist_ops; diff --git a/include/tests/gui.h b/include/tests/gui.h index f8b462b9..8cf55be8 100644 --- a/include/tests/gui.h +++ b/include/tests/gui.h @@ -24,6 +24,7 @@ void __sidebar_selection_changed() {} void __collection_activated() {} void __collection_add() {} void __collection_buttonpress() {} +void __collection_choose() {} void __collection_keypress() {} void __collection_selection_changed() {} void __collection_toggled() {} diff --git a/tests/gui/.gitignore b/tests/gui/.gitignore index 0e060262..ed99c226 100644 --- a/tests/gui/.gitignore +++ b/tests/gui/.gitignore @@ -6,6 +6,6 @@ queue window idle sidebar -collection playlist +collection audio diff --git a/tests/gui/Sconscript b/tests/gui/Sconscript index 5585b68b..b3caf072 100644 --- a/tests/gui/Sconscript +++ b/tests/gui/Sconscript @@ -32,8 +32,8 @@ res += [ GuiTest("queue") ] res += [ GuiTest("window") ] res += [ GuiTest("idle") ] res += [ GuiTest("sidebar") ] -res += [ GuiTest("collection") ] res += [ GuiTest("playlist") ] +res += [ GuiTest("collection") ] gui_objs += [ env.Object("../../gui/artwork.c") ] res += [ GuiTest("audio") ] diff --git a/tests/gui/collection.c b/tests/gui/collection.c index aa9ac16f..43262b76 100644 --- a/tests/gui/collection.c +++ b/tests/gui/collection.c @@ -2,7 +2,6 @@ * Copyright 2015 (c) Anna Schumaker. */ #define TEST_NEED_AUDIO -#define TEST_NEED_PLAYLIST #include #include #include diff --git a/tests/gui/playlist.c b/tests/gui/playlist.c index b29bf8f6..b3a8824f 100644 --- a/tests/gui/playlist.c +++ b/tests/gui/playlist.c @@ -2,6 +2,7 @@ * Copyright 2016 (c) Anna Schumaker. */ #define TEST_NEED_AUDIO +#define TEST_NEED_COLLECTION #include #include #include