gui: Reenable filtering in the history tab

Signed-off-by: Anna Schumaker <schumaker.anna@gmail.com>
This commit is contained in:
Anna Schumaker 2014-02-17 17:40:18 -05:00 committed by Anna Schumaker
parent 1ac05c6b52
commit 5d365afae1
2 changed files with 43 additions and 2 deletions

View File

@ -2,8 +2,13 @@
* Copyright 2014 (c) Anna Schumaker.
*/
#include <audio.h>
#include <filter.h>
#include <ocarina.h>
#include <set>
static std::set<unsigned int> visible_ids;
static Glib::RefPtr<Gtk::TreeModelFilter> history_filter;
static Glib::RefPtr<PlayqueueModel> model;
@ -15,6 +20,11 @@ static inline Playqueue *history_pq()
return audio::get_recent_pq();
}
static Gtk::SearchEntry *get_entry()
{
return get_widget<Gtk::SearchEntry>("o_history_entry");
}
static void set_queue_size()
{
Gtk::Label *label = get_widget<Gtk::Label>("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<unsigned int>::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<PlayqueueModel>(new PlayqueueModel(history_pq()));
get_widget<Gtk::TreeView>("o_history_treeview")->set_model(model);
history_filter = Gtk::TreeModelFilter::create(model);
get_widget<Gtk::TreeView>("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;
}

View File

@ -471,7 +471,7 @@
<property name="margin_right">1</property>
<property name="orientation">vertical</property>
<child>
<object class="GtkSearchEntry" id="searchentry2">
<object class="GtkSearchEntry" id="o_history_entry">
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="margin_left">5</property>