diff --git a/gui/ocarina.cpp b/gui/ocarina.cpp index 6c27b7bb..4a11e0f5 100644 --- a/gui/ocarina.cpp +++ b/gui/ocarina.cpp @@ -7,6 +7,7 @@ extern "C" { #include #include #include +#include #include #include #include @@ -69,6 +70,7 @@ int main(int argc, char **argv) gui_window_init(gui :: share_file("ocarina.png").c_str()); gui_sidebar_init(); gui_collection_init(); + gui_playlist_init(); gui_audio_init(); plist :: init(); diff --git a/gui/playlist.c b/gui/playlist.c new file mode 100644 index 00000000..caed9572 --- /dev/null +++ b/gui/playlist.c @@ -0,0 +1,41 @@ +/* + * Copyright 2016 (c) Anna Schumaker. + */ +#include +#include + +enum playlist_sidebar_columns { + P_SB_IMAGE, + P_SB_IMAGE_SZ, + P_SB_NAME, +}; + +static GtkTreeModel *p_model; + +static gboolean __playlist_select(GtkTreeSelection *selection, + GtkTreeModel *model, GtkTreePath *path, + gboolean selected, gpointer data) +{ + return gtk_tree_path_get_depth(path) != 1; +} + +void gui_playlist_init() +{ + GtkTreeView *treeview; + GtkTreeIter iter; + + p_model = GTK_TREE_MODEL(gui_builder_object("o_playlist_store")); + + /* Add "Playlist" header. */ + gtk_tree_store_insert(GTK_TREE_STORE(p_model), &iter, NULL, -1); + gtk_tree_store_set(GTK_TREE_STORE(p_model), &iter, + P_SB_IMAGE, "emblem-documents", + P_SB_IMAGE_SZ, GTK_ICON_SIZE_LARGE_TOOLBAR, + P_SB_NAME, "Playlists", + -1); + + treeview = GTK_TREE_VIEW(gui_builder_widget("o_playlist_view")); + gtk_tree_selection_set_select_function( + gtk_tree_view_get_selection(treeview), + __playlist_select, NULL, NULL); +} diff --git a/include/gui/playlist.h b/include/gui/playlist.h new file mode 100644 index 00000000..bc4bc09a --- /dev/null +++ b/include/gui/playlist.h @@ -0,0 +1,10 @@ +/* + * Copyright 2016 (c) Anna Schumaker. + */ +#ifndef OCARINA_GUI_PLAYLIST_H +#define OCARINA_GUI_PLAYLIST_H + +/* Called to initialize the GUI playlist code. */ +void gui_playlist_init(); + +#endif /* OCARINA_GUI_PLAYLIST_H */ diff --git a/share/ocarina/ocarina6.glade b/share/ocarina/ocarina6.glade index 836a5db1..327cc982 100644 --- a/share/ocarina/ocarina6.glade +++ b/share/ocarina/ocarina6.glade @@ -212,6 +212,7 @@ False window-close + @@ -228,6 +229,16 @@ + + + + + + + + + + 100000000000 1000000000 @@ -618,6 +629,49 @@ True False vertical + + + True + True + start + o_playlist_store + False + False + 10 + True + + + + + + Image + + + + 0 + 1 + + + + + + + column + + + + 2 + + + + + + + False + True + 0 + + True @@ -675,7 +729,7 @@ True True - 0 + 1 diff --git a/tests/gui/.gitignore b/tests/gui/.gitignore index 5aa10961..eb2d2716 100644 --- a/tests/gui/.gitignore +++ b/tests/gui/.gitignore @@ -3,4 +3,5 @@ settings window sidebar collection +playlist audio diff --git a/tests/gui/Sconscript b/tests/gui/Sconscript index f4ffdc61..801c74ac 100644 --- a/tests/gui/Sconscript +++ b/tests/gui/Sconscript @@ -29,6 +29,7 @@ res += [ GuiTest("settings") ] res += [ GuiTest("window") ] res += [ GuiTest("sidebar") ] res += [ GuiTest("collection") ] +res += [ GuiTest("playlist") ] res += [ GuiTest("audio") ] ignore.close() diff --git a/tests/gui/playlist.c b/tests/gui/playlist.c new file mode 100644 index 00000000..4d4f949d --- /dev/null +++ b/tests/gui/playlist.c @@ -0,0 +1,39 @@ +/* + * Copyright 2016 (c) Anna Schumaker. + */ +#define TEST_NEED_AUDIO +#include +#include +#include +#include + +static void test_playlist_sidebar() +{ + GtkTreeSelection *selection; + GtkTreeView *treeview; + GtkTreeModel *model; + GtkTreePath *path; + GtkTreeIter iter; + int argc = 0; + + gtk_init(&argc, NULL); + gui_builder_init("share/ocarina/ocarina6.glade"); + 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); + + gui_builder_deinit(); +} + +DECLARE_UNIT_TESTS( + UNIT_TEST("Playlist Sidebar", test_playlist_sidebar), +);