diff --git a/gui/playlist.c b/gui/playlist.c index 20dd7824..665c52f6 100644 --- a/gui/playlist.c +++ b/gui/playlist.c @@ -1,6 +1,7 @@ /* * Copyright 2016 (c) Anna Schumaker. */ +#include #include #include @@ -8,23 +9,42 @@ enum playlist_sidebar_columns { P_SB_IMAGE, P_SB_IMAGE_SZ, P_SB_NAME, + P_SB_PLAYLIST, }; -static GtkTreeStore *p_store; +static GtkTreeStore *p_store; +static enum playlist_t p_cur; static void __playlist_set(GtkTreeIter *iter, const gchar *name, - const gchar *image, GtkIconSize size) + const gchar *image, GtkIconSize size, + enum playlist_t plist) { - gtk_tree_store_set(p_store, iter, P_SB_NAME, name, P_SB_IMAGE, image, - P_SB_IMAGE_SZ, size, -1); + gtk_tree_store_set(p_store, iter, P_SB_NAME, name, + P_SB_IMAGE, image, + P_SB_IMAGE_SZ, size, + P_SB_PLAYLIST, plist, -1); } static void __playlist_add(GtkTreeIter *parent, const gchar *name, - const gchar *image) + const gchar *image, enum playlist_t plist) { GtkTreeIter iter; gtk_tree_store_insert(p_store, &iter, parent, -1); - __playlist_set(&iter, name, image, GTK_ICON_SIZE_MENU); + __playlist_set(&iter, name, image, GTK_ICON_SIZE_MENU, plist); +} + +void __playlist_selection_changed(GtkTreeSelection *selection, gpointer data) +{ + GtkNotebook *notebook = GTK_NOTEBOOK(gui_builder_widget("o_notebook")); + GtkTreeModel *model = GTK_TREE_MODEL(p_store); + GtkTreeIter iter; + + if (gtk_tree_selection_get_selected(selection, &model, &iter)) { + gtk_tree_model_get(model, &iter, P_SB_PLAYLIST, &p_cur, -1); + + gtk_notebook_set_current_page(notebook, tempq_count() + 2); + playlist_select(p_cur); + } } static gboolean __playlist_select(GtkTreeSelection *selection, @@ -44,14 +64,14 @@ void gui_playlist_init() /* Add "Playlist" header. */ gtk_tree_store_insert(p_store, &parent, NULL, -1); __playlist_set(&parent, "Playlists", - "emblem-documents", GTK_ICON_SIZE_LARGE_TOOLBAR); + "emblem-documents", GTK_ICON_SIZE_LARGE_TOOLBAR, 0); /* Add playlists. */ - __playlist_add(&parent, "Favorites", "emblem-favorite"); - __playlist_add(&parent, "Banned", "face-sad"); - __playlist_add(&parent, "Most Played", "go-up"); - __playlist_add(&parent, "Least Played", "go-down"); - __playlist_add(&parent, "Unplayed", "audio-x-generic"); + __playlist_add(&parent, "Favorites", "emblem-favorite", PL_FAVORITED); + __playlist_add(&parent, "Banned", "face-sad",PL_HIDDEN); + __playlist_add(&parent, "Most Played", "go-up", PL_MOST_PLAYED); + __playlist_add(&parent, "Least Played", "go-down", PL_LEAST_PLAYED); + __playlist_add(&parent, "Unplayed", "audio-x-generic", PL_UNPLAYED); treeview = GTK_TREE_VIEW(gui_builder_widget("o_playlist_view")); gtk_tree_view_expand_all(treeview); @@ -61,3 +81,8 @@ void gui_playlist_init() gtk_tree_store_insert(p_store, &parent, NULL, -1); } + +enum playlist_t gui_playlist_cur() +{ + return p_cur; +} diff --git a/include/gui/playlist.h b/include/gui/playlist.h index bc4bc09a..9f2ef994 100644 --- a/include/gui/playlist.h +++ b/include/gui/playlist.h @@ -4,7 +4,12 @@ #ifndef OCARINA_GUI_PLAYLIST_H #define OCARINA_GUI_PLAYLIST_H +#include + /* Called to initialize the GUI playlist code. */ void gui_playlist_init(); +/* Called to get the currently selected playlist. */ +enum playlist_t gui_playlist_cur(); + #endif /* OCARINA_GUI_PLAYLIST_H */ diff --git a/include/tests/gui.h b/include/tests/gui.h index cbd3120a..0e2bf1a0 100644 --- a/include/tests/gui.h +++ b/include/tests/gui.h @@ -23,4 +23,8 @@ void __collection_selection_changed() {} void __collection_toggled() {} #endif /* TEST_NEED_COLLECTION */ +#ifdef TEST_NEED_PLAYLIST +void __playlist_selection_changed() {} +#endif /* TEST_NEED_PLAYLIST */ + #endif /* TESTS_GUI_H */ diff --git a/share/ocarina/ocarina6.glade b/share/ocarina/ocarina6.glade index 327cc982..8a2e5a19 100644 --- a/share/ocarina/ocarina6.glade +++ b/share/ocarina/ocarina6.glade @@ -237,6 +237,8 @@ + + @@ -640,7 +642,9 @@ 10 True - + + + diff --git a/tests/gui/collection.c b/tests/gui/collection.c index e3f2c9a2..a80a460f 100644 --- a/tests/gui/collection.c +++ b/tests/gui/collection.c @@ -2,6 +2,7 @@ * 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 62df06a9..89579bdb 100644 --- a/tests/gui/playlist.c +++ b/tests/gui/playlist.c @@ -2,11 +2,14 @@ * Copyright 2016 (c) Anna Schumaker. */ #define TEST_NEED_AUDIO +#include #include #include #include #include +struct core_init_data init_data; + static void test_playlist_sidebar() { GtkTreeSelection *selection; @@ -18,20 +21,41 @@ static void test_playlist_sidebar() gtk_init(&argc, NULL); gui_builder_init("share/ocarina/ocarina6.glade"); + core_init(&argc, NULL, &init_data); gui_playlist_init(); treeview = GTK_TREE_VIEW(gui_builder_widget("o_playlist_view")); selection = gtk_tree_view_get_selection(treeview); model = GTK_TREE_MODEL(gui_builder_object("o_playlist_store")); + test_equal(gtk_tree_model_get_iter_first(model, &iter), true); - - path = gtk_tree_model_get_path(model, &iter); - gtk_tree_view_set_cursor(treeview, path, NULL, false); - gtk_tree_path_free(path); - test_equal(gtk_tree_selection_count_selected_rows(selection), 0); - test_equal(gtk_tree_model_iter_n_children(model, &iter), 5); + path = gtk_tree_model_get_path(model, &iter); + gtk_tree_selection_select_path(selection, path); + test_equal(gtk_tree_selection_count_selected_rows(selection), 0); + + gtk_tree_path_down(path); + gtk_tree_selection_select_path(selection, path); + test_equal(gui_playlist_cur(), PL_FAVORITED); + + gtk_tree_path_next(path); + gtk_tree_selection_select_path(selection, path); + test_equal(gui_playlist_cur(), PL_HIDDEN); + + gtk_tree_path_next(path); + gtk_tree_selection_select_path(selection, path); + test_equal(gui_playlist_cur(), PL_MOST_PLAYED); + + gtk_tree_path_next(path); + gtk_tree_selection_select_path(selection, path); + test_equal(gui_playlist_cur(), PL_LEAST_PLAYED); + + gtk_tree_path_next(path); + gtk_tree_selection_select_path(selection, path); + test_equal(gui_playlist_cur(), PL_UNPLAYED); + + gtk_tree_path_free(path); gui_builder_deinit(); } diff --git a/tests/gui/sidebar.c b/tests/gui/sidebar.c index b29bdb79..5888d090 100644 --- a/tests/gui/sidebar.c +++ b/tests/gui/sidebar.c @@ -3,6 +3,7 @@ */ #define TEST_NEED_AUDIO #define TEST_NEED_COLLECTION +#define TEST_NEED_PLAYLIST #include #include #include diff --git a/tests/gui/window.c b/tests/gui/window.c index 9742bcd1..30b1deca 100644 --- a/tests/gui/window.c +++ b/tests/gui/window.c @@ -4,6 +4,7 @@ #define TEST_NEED_AUDIO #define TEST_NEED_SIDEBAR #define TEST_NEED_COLLECTION +#define TEST_NEED_PLAYLIST #include #include #include