From eb81fa2e20bafbfb2ae28cf6bc816993ba299bd0 Mon Sep 17 00:00:00 2001 From: Anna Schumaker Date: Tue, 29 Dec 2015 09:45:15 -0500 Subject: [PATCH] gui/collection: Add sidebar widget showing Collection header And make it non-selectable. Signed-off-by: Anna Schumaker --- gui/collection.c | 44 ++++++++++++++++++ gui/ocarina.cpp | 2 + include/gui/collection.h | 10 ++++ share/ocarina/ocarina6.glade | 90 ++++++++++++++++++++++++++++++++++-- tests/gui/.gitignore | 1 + tests/gui/Sconscript | 11 +++-- tests/gui/collection.c | 39 ++++++++++++++++ 7 files changed, 188 insertions(+), 9 deletions(-) create mode 100644 gui/collection.c create mode 100644 include/gui/collection.h create mode 100644 tests/gui/collection.c diff --git a/gui/collection.c b/gui/collection.c new file mode 100644 index 00000000..f18d7b0e --- /dev/null +++ b/gui/collection.c @@ -0,0 +1,44 @@ +/* + * Copyright 2015 (c) Anna Schumaker. + */ +#include +#include + +enum collection_sidebar_columns { + C_SB_IMAGE, + C_SB_IMAGE_SZ, + C_SB_ENABLED, + C_SB_SHOW_ENABLED, + C_SB_PATH, + C_SB_LIBRARY, +}; + +static GtkTreeModel *c_model; + +static gboolean __collection_select(GtkTreeSelection *selection, + GtkTreeModel *model, GtkTreePath *path, + gboolean selected, gpointer data) +{ + return gtk_tree_path_get_depth(path) != 1; +} + +void gui_collection_init() +{ + GtkTreeView *treeview; + GtkTreeIter parent; + + c_model = GTK_TREE_MODEL(gui_builder_object("o_collection_store")); + + /* Add "Collection" header. */ + gtk_tree_store_insert(GTK_TREE_STORE(c_model), &parent, NULL, -1); + gtk_tree_store_set(GTK_TREE_STORE(c_model), &parent, + C_SB_IMAGE, "system-file-manager", + C_SB_IMAGE_SZ, GTK_ICON_SIZE_LARGE_TOOLBAR, + C_SB_PATH, "Collection", + -1); + + treeview = GTK_TREE_VIEW(gui_builder_widget("o_collection_view")); + gtk_tree_selection_set_select_function( + gtk_tree_view_get_selection(treeview), + __collection_select, NULL, NULL); +} diff --git a/gui/ocarina.cpp b/gui/ocarina.cpp index 7d3bee1d..0859cc3b 100644 --- a/gui/ocarina.cpp +++ b/gui/ocarina.cpp @@ -6,6 +6,7 @@ extern "C" { #include #include #include +#include #include #include #include @@ -67,6 +68,7 @@ int main(int argc, char **argv) gui_settings_init(); gui_window_init(gui :: share_file("ocarina.png").c_str()); gui_sidebar_init(); + gui_collection_init(); gui_audio_init(); plist :: init(); diff --git a/include/gui/collection.h b/include/gui/collection.h new file mode 100644 index 00000000..8f92d948 --- /dev/null +++ b/include/gui/collection.h @@ -0,0 +1,10 @@ +/* + * Copyright 2015 (c) Anna Schumaker. + */ +#ifndef OCARINA_GUI_COLLECTION_H +#define OCARINA_GUI_COLLECTION_H + +/* Called to initialize the GUI collection code. */ +void gui_collection_init(); + +#endif /* OCARINA_GUI_COLLECTION_H */ diff --git a/share/ocarina/ocarina6.glade b/share/ocarina/ocarina6.glade index e918ef49..a476de0e 100644 --- a/share/ocarina/ocarina6.glade +++ b/share/ocarina/ocarina6.glade @@ -205,6 +205,22 @@ False window-close + + + + + + + + + + + + + + + + 100000000000 1000000000 @@ -582,11 +598,77 @@ True - + True - False - Future -Sidebar + True + in + + + True + False + + + True + False + vertical + + + True + True + o_collection_store + False + False + 10 + True + + + + + + Image + + + + 0 + 1 + + + + + + + Enabled + + + + 3 + 2 + + + + + + + Path + + + + 4 + + + + + + + True + True + 0 + + + + + + False diff --git a/tests/gui/.gitignore b/tests/gui/.gitignore index 395f2071..5aa10961 100644 --- a/tests/gui/.gitignore +++ b/tests/gui/.gitignore @@ -2,4 +2,5 @@ builder settings window sidebar +collection audio diff --git a/tests/gui/Sconscript b/tests/gui/Sconscript index d3a6a289..f4ffdc61 100644 --- a/tests/gui/Sconscript +++ b/tests/gui/Sconscript @@ -24,11 +24,12 @@ def GuiTest(name): env.UsePackage("gmodule-export-2.0") -res += [ GuiTest("builder") ] -res += [ GuiTest("settings") ] -res += [ GuiTest("window") ] -res += [ GuiTest("sidebar") ] -res += [ GuiTest("audio") ] +res += [ GuiTest("builder") ] +res += [ GuiTest("settings") ] +res += [ GuiTest("window") ] +res += [ GuiTest("sidebar") ] +res += [ GuiTest("collection") ] +res += [ GuiTest("audio") ] ignore.close() Return("res") diff --git a/tests/gui/collection.c b/tests/gui/collection.c new file mode 100644 index 00000000..b38e5921 --- /dev/null +++ b/tests/gui/collection.c @@ -0,0 +1,39 @@ +/* + * Copyright 2015 (c) Anna Schumaker. + */ +#define TEST_NEED_AUDIO +#include +#include +#include +#include + +static void test_collection_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_collection_init(); + + treeview = GTK_TREE_VIEW(gui_builder_widget("o_collection_view")); + selection = gtk_tree_view_get_selection(treeview); + model = GTK_TREE_MODEL(gui_builder_object("o_collection_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("Collection Sidebar", test_collection_sidebar), +);