diff --git a/gui/queue.c b/gui/queue.c index fa75c368..35409402 100644 --- a/gui/queue.c +++ b/gui/queue.c @@ -63,6 +63,7 @@ void gui_queue_show(struct gui_queue *queue) { GtkButton *random = GTK_BUTTON(gui_builder_widget("o_random")); GtkButton *repeat = GTK_BUTTON(gui_builder_widget("o_repeat")); + GtkEntry *search = GTK_ENTRY(gui_builder_widget("o_search")); bool has_random = false, has_repeat = false; gq_queue = queue; @@ -84,4 +85,7 @@ void gui_queue_show(struct gui_queue *queue) */ gtk_widget_set_sensitive(gtk_button_get_image(random), has_random); gtk_widget_set_sensitive(gtk_button_get_image(repeat), has_repeat); + + gtk_widget_set_sensitive(GTK_WIDGET(search), queue != NULL); + gtk_entry_set_text(search, ""); } diff --git a/gui/tabs.cpp b/gui/tabs.cpp index 3af9059a..20eeb1f5 100644 --- a/gui/tabs.cpp +++ b/gui/tabs.cpp @@ -405,6 +405,16 @@ static void on_switch_page(Gtk::Widget *page, int num) Glib :: wrap(GTK_LABEL(gui_builder_widget("o_queue_time")), false)->set_text(""); } +static void on_search_changed() +{ + Gtk::SearchEntry *search = Glib :: wrap(GTK_SEARCH_ENTRY(gui_builder_widget("o_search")), false); + std::string text = search->get_text(); + Tab *tab = cur_tab(); + + if (tab) + tab->tab_window->filter(text); +} + void tab_focus_search() { int page = Glib :: wrap(GTK_NOTEBOOK(gui_builder_widget("o_notebook")), false)->get_current_page(); @@ -485,6 +495,10 @@ void init_tabs() struct Gtk::Notebook *notebook = Glib :: wrap(GTK_NOTEBOOK(gui_builder_widget("o_notebook")), false); notebook->signal_switch_page().connect(sigc::ptr_fun(on_switch_page)); + /* Search signals */ + Gtk::SearchEntry *search = Glib :: wrap(GTK_SEARCH_ENTRY(gui_builder_widget("o_search")), false); + search->signal_search_changed().connect(sigc::ptr_fun(on_search_changed)); + /* Menu signals */ Glib :: wrap(GTK_MENU(gui_builder_widget("o_rc_menu")), false)->show_all(); Glib :: wrap(GTK_MENU_ITEM(gui_builder_widget("o_new_pq")), false)->signal_activate().connect( diff --git a/include/gui/tabs.h b/include/gui/tabs.h index 853da87b..60214dfa 100644 --- a/include/gui/tabs.h +++ b/include/gui/tabs.h @@ -22,7 +22,6 @@ protected: Gtk::VBox tab_vbox; QueueToolbar *tab_toolbar; - QueueWindow *tab_window; QueueLabel *tab_label; /** @@ -32,6 +31,7 @@ protected: void tab_unmap(); public: + QueueWindow *tab_window; Tab(queue *); virtual ~Tab(); diff --git a/share/ocarina/ocarina6.glade b/share/ocarina/ocarina6.glade index 59dcef6c..221c4b79 100644 --- a/share/ocarina/ocarina6.glade +++ b/share/ocarina/ocarina6.glade @@ -842,6 +842,34 @@ False 1 vertical + + + True + False + + + True + True + center + edit-find-symbolic + False + False + Type here to filter + + + + True + True + 0 + + + + + False + True + 0 + + True @@ -951,7 +979,7 @@ Manager True True - 0 + 1 @@ -1057,7 +1085,7 @@ Manager False True - 1 + 2 @@ -1142,4 +1170,11 @@ Manager + + vertical + + + + + diff --git a/tests/gui/queue.c b/tests/gui/queue.c index 8338e744..b0808800 100644 --- a/tests/gui/queue.c +++ b/tests/gui/queue.c @@ -30,11 +30,13 @@ static void test_queue() GtkToggleButton *random, *repeat; GtkWidget *random_img, *repeat_img; struct gui_queue *gq; + GtkEntry *search; struct queue q; int argc = 0; gtk_init(&argc, NULL); gui_builder_init("share/ocarina/ocarina6.glade"); + search = GTK_ENTRY(gui_builder_widget("o_search")); random = GTK_TOGGLE_BUTTON(gui_builder_widget("o_random")); repeat = GTK_TOGGLE_BUTTON(gui_builder_widget("o_repeat")); random_img = gtk_button_get_image(GTK_BUTTON(random)); @@ -50,6 +52,8 @@ static void test_queue() test_equal(gui_queue_can_random(NULL), (bool)false); test_equal(gui_queue_can_repeat(NULL), (bool)false); + gtk_entry_set_text(search, "Test text"); + /* Show a queue where random and repeat are disabled */ gui_queue_show(gq); test_equal(gtk_widget_get_sensitive(GTK_WIDGET(random)), false); @@ -58,6 +62,7 @@ static void test_queue() test_equal(gtk_toggle_button_get_active(repeat), false); test_equal(gtk_widget_get_sensitive(random_img), false); test_equal(gtk_widget_get_sensitive(repeat_img), false); + test_equal(gtk_entry_get_text(search), ""); /* Test clicking random button. */ gtk_toggle_button_set_active(random, true); @@ -90,6 +95,7 @@ static void test_queue() /* Attempt to show a NULL pointer */ gui_queue_show(NULL); + test_equal(gtk_widget_get_sensitive(GTK_WIDGET(search)), false); test_equal(gtk_widget_get_sensitive(GTK_WIDGET(random)), false); test_equal(gtk_widget_get_sensitive(GTK_WIDGET(repeat)), false); test_equal(gtk_toggle_button_get_active(random), false);