gui: Add playqueue filtering!

I love tis feature, and I've been missing it the last few days of
Ocarina 6.0 preview testing.

Signed-off-by: Anna Schumaker <schumaker.anna@gmail.com>
This commit is contained in:
Anna Schumaker 2014-02-01 17:30:07 -05:00 committed by Anna Schumaker
parent 72accfd26d
commit 2f2b01100e
3 changed files with 50 additions and 2 deletions

View File

@ -62,6 +62,11 @@ void PlayqueueModel::on_path_selected(const Gtk::TreePath &path)
audio :: play();
}
unsigned int PlayqueueModel :: iter_to_id(const Gtk::TreeIter &iter)
{
return GPOINTER_TO_UINT(iter.gobj()->user_data);
}
/*

View File

@ -4,10 +4,12 @@
#include <audio.h>
#include <callback.h>
#include <deck.h>
#include <filter.h>
#include <ocarina.h>
#include <playqueue.h>
#include <map>
#include <set>
#include <sstream>
#include <string>
@ -151,6 +153,9 @@ private:
unsigned int init_flags;
Gtk::Notebook *notebook;
/* Filter state */
std::set<unsigned int> visible_ids;
OcarinaTab *tab;
/* Page widgets */
@ -170,6 +175,7 @@ private:
public:
Gtk::ToggleButton page_random;
Glib::RefPtr<PlayqueueModel> model;
Glib::RefPtr<Gtk::TreeModelFilter> filter;
OcarinaPage(const std::string &, const std::string &,
Playqueue *, unsigned int);
@ -188,6 +194,9 @@ public:
void on_repeat_toggled();
void on_row_activated(const Gtk::TreePath &, Gtk::TreeViewColumn *);
void on_column_clicked(unsigned int);
void on_entry_changed();
bool on_entry_key_released(GdkEventKey *);
bool on_filter_visible(const Gtk::TreeIter &);
};
@ -221,6 +230,9 @@ void OcarinaPage::setup_common(Playqueue *pq, unsigned int pg)
{
get_builder()->get_widget("o_notebook", notebook);
model = Glib::RefPtr<PlayqueueModel>(new PlayqueueModel(pq));
filter = Gtk::TreeModelFilter::create(model);
filter->set_visible_func(sigc::mem_fun(*this,
&OcarinaPage::on_filter_visible));
set_margin_left(1);
set_margin_right(1);
@ -239,8 +251,14 @@ void OcarinaPage::setup_toolbar()
{
page_toolbar.set_spacing(5);
page_toolbar.pack_start(page_entry);
/* Set up entry */
page_entry.set_margin_top(5);
page_entry.set_margin_bottom(5);
page_entry.signal_changed().connect(sigc::mem_fun(*this,
&OcarinaPage::on_entry_changed));
page_entry.signal_key_release_event().connect(sigc::mem_fun(*this,
&OcarinaPage::on_entry_key_released));
/* Make buttons */
if (init_flags & PQ_RANDOM) {
@ -272,7 +290,7 @@ void OcarinaPage::setup_treeview()
page_view.signal_row_activated().connect(sigc::mem_fun(*this,
&OcarinaPage::on_row_activated));
page_view.set_model(model);
page_view.set_model(filter);
page_view.set_rules_hint();
page_view.set_enable_search(false);
page_view.get_selection()->set_mode(Gtk::SELECTION_MULTIPLE);
@ -393,7 +411,8 @@ void OcarinaPage::on_repeat_toggled()
void OcarinaPage::on_row_activated(const Gtk::TreePath &path, Gtk::TreeViewColumn *col)
{
model->on_path_selected(path);
Gtk::TreePath model_path = filter->convert_path_to_child_path(path);
model->on_path_selected(model_path);
}
void OcarinaPage::on_column_clicked(unsigned int col_index)
@ -411,6 +430,29 @@ void OcarinaPage::on_column_clicked(unsigned int col_index)
sigc::ptr_fun(dec_sort_timeout), 2);
}
void OcarinaPage::on_entry_changed()
{
filter :: search(page_entry.get_text(), visible_ids);
filter->refilter();
}
bool OcarinaPage::on_entry_key_released(GdkEventKey *event)
{
std::string key = gdk_keyval_name(event->keyval);
return key == "space";
}
bool OcarinaPage::on_filter_visible(const Gtk::TreeIter &iter)
{
unsigned int pq_id;
std::set<unsigned int>::iterator it;
if (page_entry.get_text().size() == 0)
return true;
pq_id = model->iter_to_id(iter);
return visible_ids.find(model->queue->operator[](pq_id)) != visible_ids.end();
}

View File

@ -44,6 +44,7 @@ public:
void on_row_deleted(unsigned int);
void on_row_changed(unsigned int);
void on_path_selected(const Gtk::TreePath &);
unsigned int iter_to_id(const Gtk::TreeIter &);
};
/* tabs.cpp */