From 5d365afae15e5aeaad72769cbce48915fb36692f Mon Sep 17 00:00:00 2001 From: Anna Schumaker Date: Mon, 17 Feb 2014 17:40:18 -0500 Subject: [PATCH] gui: Reenable filtering in the history tab Signed-off-by: Anna Schumaker --- gui/history.cpp | 43 ++++++++++++++++++++++++++++++++++++++++++- gui/ocarina6.glade | 2 +- 2 files changed, 43 insertions(+), 2 deletions(-) diff --git a/gui/history.cpp b/gui/history.cpp index 1720b5b8..16973cbc 100644 --- a/gui/history.cpp +++ b/gui/history.cpp @@ -2,8 +2,13 @@ * Copyright 2014 (c) Anna Schumaker. */ #include +#include #include +#include + +static std::set visible_ids; +static Glib::RefPtr history_filter; static Glib::RefPtr model; @@ -15,6 +20,11 @@ static inline Playqueue *history_pq() return audio::get_recent_pq(); } +static Gtk::SearchEntry *get_entry() +{ + return get_widget("o_history_entry"); +} + static void set_queue_size() { Gtk::Label *label = get_widget("o_history_size"); @@ -27,6 +37,30 @@ static void set_queue_size() * Gtk signal functions */ +static void on_history_entry_changed() +{ + filter :: search(get_entry()->get_text(), visible_ids); + history_filter->refilter(); +} + +static bool on_history_entry_key_released(GdkEventKey *event) +{ + std::string key = gdk_keyval_name(event->keyval); + return key == "space"; +} + +bool on_history_filter_visible(const Gtk::TreeIter &iter) +{ + unsigned int pq_id; + std::set::iterator it; + + if (get_entry()->get_text().size() == 0) + return true; + + pq_id = model->iter_to_id(iter); + return visible_ids.find(history_pq()->operator[](pq_id)) != visible_ids.end(); +} + @@ -77,7 +111,14 @@ static struct TabFuncs history_funcs = { struct TabFuncs *init_history_tab() { model = Glib::RefPtr(new PlayqueueModel(history_pq())); - get_widget("o_history_treeview")->set_model(model); + history_filter = Gtk::TreeModelFilter::create(model); + get_widget("o_history_treeview")->set_model(history_filter); + + Gtk::SearchEntry *entry = get_entry(); + entry->signal_changed().connect(sigc::ptr_fun(on_history_entry_changed)); + entry->signal_key_release_event().connect(sigc::ptr_fun(on_history_entry_key_released)); + + history_filter->set_visible_func(sigc::ptr_fun(on_history_filter_visible)); return &history_funcs; } diff --git a/gui/ocarina6.glade b/gui/ocarina6.glade index ce596f70..e5f88941 100644 --- a/gui/ocarina6.glade +++ b/gui/ocarina6.glade @@ -471,7 +471,7 @@ 1 vertical - + True True 5