From f167f968ba50ba2f1b890a38753553db1910ec89 Mon Sep 17 00:00:00 2001 From: Anna Schumaker Date: Wed, 2 May 2018 10:41:19 -0400 Subject: [PATCH] gui/audio: Add a popover menu to clear automatic pausing The popover is shown whenever the user pauses manually with automatic pausing enabled. This will give the user a chance to disable pausing if it is no longer needed. Implements #113: Cancel "pause after" configuration when user manually pauses Signed-off-by: Anna Schumaker --- gui/audio.c | 21 ++++++++++++++++ include/gui/audio.h | 5 ++++ share/ocarina/ocarina.ui | 53 +++++++++++++++++++++++++++++++++++++++- tests/gui/audio.c | 21 ++++++++++++++++ 4 files changed, 99 insertions(+), 1 deletion(-) diff --git a/gui/audio.c b/gui/audio.c index e71cd698..04d90262 100644 --- a/gui/audio.c +++ b/gui/audio.c @@ -86,6 +86,13 @@ struct audio_callbacks audio_cb = { }; +void __gui_audio_pause(GtkButton *button, gpointer data) +{ + audio_pause(); + if (audio_get_pause_count() > -1) + gtk_popover_popup(gui_pause_popover()); +} + void __gui_audio_pause_change_text(GtkEntry *entry, gpointer data) { const gchar *text = gtk_entry_get_text(entry); @@ -123,6 +130,20 @@ void __gui_audio_pause_dec(GtkButton *button, gpointer data) audio_pause_after(audio_get_pause_count() - 1); } +void __gui_audio_pause_popover_popdown(GtkButton *button, gpointer data) +{ + gtk_popover_popdown(gui_pause_popover()); +#ifdef CONFIG_TESTING + gtk_widget_hide(GTK_WIDGET(gui_pause_popover())); +#endif /* CONFIG_TESTING */ +} + +void __gui_audio_pause_popover_clear(GtkButton *button, gpointer data) +{ + audio_pause_after(-1); + __gui_audio_pause_popover_popdown(button, data); +} + void __gui_audio_seek(GtkRange *range, GtkScrollType type, double value, gpointer data) { diff --git a/include/gui/audio.h b/include/gui/audio.h index 742d0131..f00bb454 100644 --- a/include/gui/audio.h +++ b/include/gui/audio.h @@ -88,6 +88,11 @@ static inline GtkButton *gui_pause_up(void) return GTK_BUTTON(gui_builder_widget("pause_up")); } +static inline GtkPopover *gui_pause_popover(void) +{ + return GTK_POPOVER(gui_builder_widget("pause_popover")); +} + /* Called to get the seeking GtkAdjustment. */ static inline GtkAdjustment *gui_seek(void) { diff --git a/share/ocarina/ocarina.ui b/share/ocarina/ocarina.ui index dc2a7075..08ed48b7 100644 --- a/share/ocarina/ocarina.ui +++ b/share/ocarina/ocarina.ui @@ -266,7 +266,7 @@ center center - + True @@ -1143,4 +1143,55 @@ audio-volume-medium + + False + play_button + bottom + + + True + False + True + True + + + True + False + Cancel "pause after" configuration? + + + 0 + 0 + 2 + + + + + No + True + True + True + + + + 1 + 1 + + + + + Yes + True + True + True + + + + 0 + 1 + + + + + diff --git a/tests/gui/audio.c b/tests/gui/audio.c index 5dda8224..158dcd90 100644 --- a/tests/gui/audio.c +++ b/tests/gui/audio.c @@ -28,6 +28,7 @@ static void test_audio_init() ==, 100); g_assert_true( gtk_widget_is_visible(GTK_WIDGET(gui_play_button()))); g_assert_false(gtk_widget_is_visible(GTK_WIDGET(gui_pause_button()))); + g_assert_false(gtk_widget_is_visible(GTK_WIDGET(gui_pause_popover()))); } static void test_audio_load() @@ -66,6 +67,7 @@ static void test_audio_buttons() g_assert_false(gtk_widget_is_visible(GTK_WIDGET(gui_pause_button()))); g_assert_cmpstr(gtk_entry_get_text(gui_pause_entry()), ==, "Paused"); g_assert_false(gtk_widget_get_sensitive(GTK_WIDGET(gui_pause_down()))); + g_assert_false(gtk_widget_is_visible(GTK_WIDGET(gui_pause_popover()))); gtk_button_clicked(gui_play_button()); test_main_loop(); @@ -108,6 +110,25 @@ static void test_audio_buttons() g_assert_cmpuint(audio_cur_state(), ==, GST_STATE_PAUSED); g_assert_cmpstr(gtk_entry_get_text(gui_pause_entry()), ==, "Pause after next track"); g_assert_true(gtk_widget_get_sensitive(GTK_WIDGET(gui_pause_down()))); + g_assert_true(gtk_widget_is_visible(GTK_WIDGET(gui_pause_popover()))); + + gtk_button_clicked(GTK_BUTTON(gui_builder_widget("pause_popover_yes"))); + test_main_loop(); + g_assert_cmpint(audio_get_pause_count(), ==, -1); + g_assert_cmpstr(gtk_entry_get_text(gui_pause_entry()), ==, "Paused"); + g_assert_false(gtk_widget_is_visible(GTK_WIDGET(gui_pause_popover()))); + + gtk_button_clicked(gui_play_button()); + gtk_button_clicked(gui_pause_up()); + gtk_button_clicked(gui_pause_up()); + gtk_button_clicked(gui_pause_button()); + g_assert_true(gtk_widget_is_visible(GTK_WIDGET(gui_pause_popover()))); + + gtk_button_clicked(GTK_BUTTON(gui_builder_widget("pause_popover_no"))); + g_assert_cmpint(audio_get_pause_count(), ==, 1); + g_assert_cmpstr(gtk_entry_get_text(gui_pause_entry()), ==, "Pause after next track"); + g_assert_false(gtk_widget_is_visible(GTK_WIDGET(gui_pause_popover()))); + gtk_button_clicked(gui_play_button()); test_main_loop(); g_assert_cmpuint(audio_cur_state(), ==, GST_STATE_PLAYING);