From 58d61f52e240402a6a224475bf09e9d57fc3fd7f Mon Sep 17 00:00:00 2001 From: Anna Schumaker Date: Tue, 29 Dec 2015 09:11:51 -0500 Subject: [PATCH] gui/sidebar: Add new sidebar widget This is a GtkPaned that remembers its size between Ocarina sessions. Signed-off-by: Anna Schumaker --- gui/ocarina.cpp | 2 + gui/sidebar.c | 22 ++ include/gui/sidebar.h | 10 + include/tests/gui.h | 18 + share/ocarina/ocarina6.glade | 615 +++++++++++++++++++---------------- tests/gui/.gitignore | 1 + tests/gui/Sconscript | 1 + tests/gui/sidebar.c | 42 +++ tests/gui/window.c | 8 +- 9 files changed, 425 insertions(+), 294 deletions(-) create mode 100644 gui/sidebar.c create mode 100644 include/gui/sidebar.h create mode 100644 include/tests/gui.h create mode 100644 tests/gui/sidebar.c diff --git a/gui/ocarina.cpp b/gui/ocarina.cpp index 1ee71308..7d3bee1d 100644 --- a/gui/ocarina.cpp +++ b/gui/ocarina.cpp @@ -7,6 +7,7 @@ extern "C" { #include #include #include +#include #include } #include @@ -65,6 +66,7 @@ int main(int argc, char **argv) core_init(&argc, &argv, &init_data); gui_settings_init(); gui_window_init(gui :: share_file("ocarina.png").c_str()); + gui_sidebar_init(); gui_audio_init(); plist :: init(); diff --git a/gui/sidebar.c b/gui/sidebar.c new file mode 100644 index 00000000..d5dbe3f8 --- /dev/null +++ b/gui/sidebar.c @@ -0,0 +1,22 @@ +/* + * Copyright 2015 (c) Anna Schumaker. + */ +#include +#include +#include + +const gchar *SIDEBAR_SETTING = "gui.sidebar.pos"; + +void __sidebar_resize(GtkPaned *pane, GParamSpec *pspec, gpointer data) +{ + gui_settings_set(SIDEBAR_SETTING, gtk_paned_get_position(pane)); +} + +void gui_sidebar_init() +{ + GtkPaned *pane = GTK_PANED(gui_builder_widget("o_sidebar")); + int pos = gui_settings_get(SIDEBAR_SETTING); + + if (pos > 0) + gtk_paned_set_position(pane, pos); +} diff --git a/include/gui/sidebar.h b/include/gui/sidebar.h new file mode 100644 index 00000000..add25c61 --- /dev/null +++ b/include/gui/sidebar.h @@ -0,0 +1,10 @@ +/* + * Copyright 2015 (c) Anna Schumaker. + */ +#ifndef OCARINA_GUI_SIDEBAR_H +#define OCARINA_GUI_SIDEBAR_H + +/* Called to initialize the sidebar. */ +void gui_sidebar_init(); + +#endif /* OCARINA_GUI_SIDEBAR_H */ diff --git a/include/tests/gui.h b/include/tests/gui.h new file mode 100644 index 00000000..ea22c924 --- /dev/null +++ b/include/tests/gui.h @@ -0,0 +1,18 @@ +/* + * Copyright 2016 (c) Anna Schumaker. + */ +#ifndef TESTS_GUI_H +#define TESTS_GUI_H + +#ifdef TEST_NEED_AUDIO +void __audio_can_accel() {} +void __audio_pause_count() {} +void __audio_pause_enabled() {} +void __audio_seek() {} +#endif + +#ifdef TEST_NEED_SIDEBAR +void __sidebar_resize() {} +#endif /* TEST_NEED_SIDEBAR */ + +#endif /* TESTS_GUI_H */ diff --git a/share/ocarina/ocarina6.glade b/share/ocarina/ocarina6.glade index 8b0d4d11..e918ef49 100644 --- a/share/ocarina/ocarina6.glade +++ b/share/ocarina/ocarina6.glade @@ -260,8 +260,8 @@ media-skip-backward - + False @@ -295,8 +295,8 @@ 5 - + False @@ -329,8 +329,8 @@ 5 - + False @@ -363,8 +363,8 @@ media-playback-stop - + False @@ -397,8 +397,8 @@ media-skip-forward - + False @@ -574,190 +574,231 @@ - + True True - left - True - True + 125 + True + True + - + + True + False + Future +Sidebar + + + False + True + + + + True False vertical - + True - False - 5 - 5 - 5 - select-folder - False - filefilter1 - False - False - - - True - True - 0 - - - - - True - False + True + left + True + True - - True - True - in - - - True - True - natural - natural - colmgr_list - False - False - - - - - - 20 - - - - 1 - - - - - - - 60 - Size - - - - 2 - - - - - - - Collection - - - - 3 - - - - - - - - - True - True - 5 - 0 - - - - + True False vertical - True - + True - True - True - Add the selected directory to the collection. - - - True - False - True - - - True - False - dialog-ok - - - False - True - 0 - - - - - True - False - Add - center - - - False - True - 1 - - - - + False + 5 + 5 + 5 + select-folder + False + filefilter1 + False + False - False + True True - 5 0 - + True - True - True - Update all collections. + False - + + True + True + in + + + True + True + natural + natural + colmgr_list + False + False + + + + + + 20 + + + + 1 + + + + + + + 60 + Size + + + + 2 + + + + + + + Collection + + + + 3 + + + + + + + + + True + True + 5 + 0 + + + + True False + vertical True - + True - False - view-refresh + True + True + Add the selected directory to the collection. + + + True + False + True + + + True + False + dialog-ok + + + False + True + 0 + + + + + True + False + Add + center + + + False + True + 1 + + + + False True + 5 0 - + True - False - Update - center + True + True + Update all collections. + + + True + False + True + + + True + False + view-refresh + + + False + True + 0 + + + + + True + False + Update + center + + + False + True + 1 + + + + False True + 5 1 + + False + True + 5 + 1 + @@ -768,59 +809,162 @@ + + + + True + False + 5 + + + True + False + system-file-manager + 1 + + + False + True + 0 + + + + + True + False + 1 + Collection +Manager + center + + + True + True + 1 + + + + + False + + + + + True + True + 0 + + + + + True + False + 2 + + + True + False + True + center + 15 + 5 + <span size='large'>0:00</span> + True + False True - 5 1 + + + True + False + center + o_progress + 0 + False + left + + + + True + True + 2 + + + + + True + False + center + 5 + 15 + <span size='large'>0:00</span> + True + + + False + True + 3 + + + + + Pause after + True + False + False + False + True + + + + False + True + 4 + + + + + True + True + False + adjustment1 + True + + + + False + True + 5 + + + + + True + False + 5 + songs + + + False + True + 6 + + False True - 5 - 1 - - - - - - - True - False - 5 - - - True - False - system-file-manager - 1 - - - False - True - 0 - - - - - True - False - 1 - Collection -Manager - center - - - True - True 1 - False + True + True @@ -830,113 +974,6 @@ Manager 1 - - - True - False - 2 - - - True - False - True - center - 15 - 5 - <span size='large'>0:00</span> - True - - - False - True - 3 - - - - - True - False - center - o_progress - 0 - False - left - - - - True - True - 4 - - - - - True - False - center - 5 - 15 - <span size='large'>0:00</span> - True - - - False - True - 5 - - - - - Pause after - True - False - False - False - True - - - - False - True - 6 - - - - - True - True - False - digits - adjustment1 - True - - - - False - True - 7 - - - - - True - False - 5 - songs - - - False - True - 8 - - - - - False - True - 2 - - True diff --git a/tests/gui/.gitignore b/tests/gui/.gitignore index 5f91d870..395f2071 100644 --- a/tests/gui/.gitignore +++ b/tests/gui/.gitignore @@ -1,4 +1,5 @@ builder settings window +sidebar audio diff --git a/tests/gui/Sconscript b/tests/gui/Sconscript index fd18774c..d3a6a289 100644 --- a/tests/gui/Sconscript +++ b/tests/gui/Sconscript @@ -27,6 +27,7 @@ env.UsePackage("gmodule-export-2.0") res += [ GuiTest("builder") ] res += [ GuiTest("settings") ] res += [ GuiTest("window") ] +res += [ GuiTest("sidebar") ] res += [ GuiTest("audio") ] ignore.close() diff --git a/tests/gui/sidebar.c b/tests/gui/sidebar.c new file mode 100644 index 00000000..6eaa0eaa --- /dev/null +++ b/tests/gui/sidebar.c @@ -0,0 +1,42 @@ +/* + * Copyright 2015 (c) Anna Schumaker. + */ +#define TEST_NEED_AUDIO +#include +#include +#include +#include +#include + +static void test_sidebar() +{ + GtkPaned *paned; + int argc = 0; + + test_equal(gui_settings_has("gui.sidebar.pos"), (bool)false); + + gtk_init(&argc, NULL); + gui_builder_init("share/ocarina/ocarina6.glade"); + gui_settings_init(); + gui_sidebar_init(); + paned = GTK_PANED(gui_builder_widget("o_sidebar")); + + test_equal(gui_settings_has("gui.sidebar.pos"), (bool)false); + test_equal(gtk_paned_get_position(paned), 125); + + gtk_paned_set_position(paned, 300); + test_equal(gui_settings_has("gui.sidebar.pos"), (bool)true); + test_equal(gui_settings_get("gui.sidebar.pos"), 300); + + gui_settings_set("gui.sidebar.pos", 250); + gui_sidebar_init(); + test_equal(gui_settings_get("gui.sidebar.pos"), 250); + test_equal(gtk_paned_get_position(paned), 250); + + gui_settings_deinit(); + gui_builder_deinit(); +} + +DECLARE_UNIT_TESTS( + UNIT_TEST("Sidebar", test_sidebar), +); diff --git a/tests/gui/window.c b/tests/gui/window.c index 03a913cf..b9b23637 100644 --- a/tests/gui/window.c +++ b/tests/gui/window.c @@ -1,18 +1,16 @@ /* * Copyright 2015 (c) Anna Schumaker. */ +#define TEST_NEED_AUDIO +#define TEST_NEED_SIDEBAR #include #include #include +#include #include GMainLoop *main_loop; -void __audio_can_accel() {} -void __audio_pause_count() {} -void __audio_pause_enabled() {} -void __audio_seek() {} - static int test_on_idle(gpointer data) { g_main_loop_quit(main_loop);