gui: Begin creating playqueue tabs

I've been putting this off for a while since it seemed like a lot of
work.  Time to get it done!

Signed-off-by: Anna Schumaker <schumaker.anna@gmail.com>
This commit is contained in:
Anna Schumaker 2014-02-23 17:04:39 -05:00 committed by Anna Schumaker
parent 6ecb8f6b7f
commit d465c2e894
5 changed files with 166 additions and 46 deletions

114
gui/queue.cpp Normal file
View File

@ -0,0 +1,114 @@
/*
* Copyright 2014 (c) Anna Schumaker.
*/
#include <callback.h>
#include <tabs.h>
class QueueTab : public Tab {
private:
/*
* Queue tab variables
*/
Gtk::HBox q_tab_box;
Gtk::Label q_tab_number;
Gtk::Label q_tab_size;
Gtk::Button q_tab_close;
Gtk::Image q_tab_close_img;
/*
* Queue page variables
*/
Gtk::ToggleButton q_random;
Gtk::SearchEntry q_search;
Gtk::TreeView q_treeview;
Gtk::VBox q_vbox;
public:
QueueTab(Playqueue *, unsigned int num);
~QueueTab();
void on_post_init();
void tab_set_size();
void queue_set_number(unsigned int);
};
QueueTab :: QueueTab(Playqueue *pq, unsigned int num)
: Tab(pq)
{
/*
* Create our tab widget
*/
q_tab_close_img.set_from_icon_name("window-close", Gtk::ICON_SIZE_MENU);
q_tab_close.set_image(q_tab_close_img);
q_tab_close.set_relief(Gtk::RELIEF_NONE);
q_tab_size.set_justify(Gtk::JUSTIFY_CENTER);
q_tab_box.pack_start(q_tab_number, false, false);
q_tab_box.pack_start(q_tab_size, true, true);
q_tab_box.pack_start(q_tab_close, false, false);
tab_set_size();
queue_set_number(num);
q_tab_box.show_all();
/*
* Finish generic init
*/
tab_random = &q_random;
tab_search = &q_search;
tab_size = &q_tab_size;
tab_treeview = &q_treeview;
tab_widget = &q_vbox;
tab_finish_init();
get_widget<Gtk::Notebook>("o_notebook")->insert_page(q_vbox, q_tab_box, num);
q_vbox.show_all();
}
QueueTab :: ~QueueTab()
{
tab_unmap();
}
void QueueTab :: on_post_init()
{
tab_init_random();
}
void QueueTab :: tab_set_size()
{
std::stringstream ss;
ss << "<span size='x-large'>" << tab_pq->size() << "</span>";
q_tab_size.set_markup(ss.str());
}
void QueueTab :: queue_set_number(unsigned int num)
{
std::stringstream ss;
ss << "<span size='x-large'>" << num << ". </span>";
q_tab_number.set_markup(ss.str());
}
static void on_pq_created(Playqueue *pq, unsigned int num)
{
QueueTab *tab = new QueueTab(pq, num);
tab->on_post_init();
}
static void on_pq_removed(Playqueue *pq)
{
}
void init_queue_tabs()
{
struct Callbacks *cb = get_callbacks();
cb->on_pq_created = on_pq_created;
cb->on_pq_removed = on_pq_removed;
}

View File

@ -2,6 +2,7 @@
* Copyright 2014 (c) Anna Schumaker.
*/
#include <callback.h>
#include <deck.h>
#include <filter.h>
#include <tabs.h>
@ -38,6 +39,8 @@ void Tab :: tab_finish_init()
tab_treeview->set_model(tab_filter);
tab_treeview->signal_row_activated().connect(sigc::mem_fun(*this,
&Tab :: on_row_activated));
tab_treeview->signal_key_press_event().connect(sigc::mem_fun(*this,
&Tab :: on_key_pressed));
}
@ -90,6 +93,27 @@ void Tab :: tab_focus_search()
tab_search->grab_focus();
}
bool Tab :: tab_queue_selected(bool random)
{
Glib::RefPtr<Gtk::TreeSelection> sel = tab_treeview->get_selection();
if (sel->count_selected_rows() == 0)
return false;
if (deck :: size() >= 10)
return true;
Playqueue *pq = deck :: create(random);
std::vector<Gtk::TreeModel::Path> rows = sel->get_selected_rows();
for (unsigned int i = 0; i != rows.size(); i++) {
Gtk::TreeModel::Path path = tab_filter->convert_path_to_child_path(rows[i]);
unsigned int track_id = tab_model->path_to_id(path);
pq->add(track_id);
}
sel->unselect_all();
return true;
}
/**
@ -118,6 +142,15 @@ void Tab :: on_track_changed(unsigned int row)
tab_runtime_changed();
}
bool Tab :: on_key_press_event(const std::string &key)
{
if (key == "q" || key == "r")
return tab_queue_selected(key == "r");
else
return false;
return true;
}
/**
@ -138,6 +171,18 @@ void Tab :: on_row_activated(const Gtk::TreePath &path, Gtk::TreeViewColumn *col
tab_model->on_path_selected(model_path);
}
bool Tab :: on_key_pressed(GdkEventKey *event)
{
std::string key = gdk_keyval_name(event->keyval);
if (key.size() >= 3) {
if (key.substr(0, 3) == "KP_")
key = key.substr(3);
}
return on_key_press_event(key);
}
/**
@ -247,6 +292,7 @@ void init_tabs()
init_collection_tab();
init_history_tab();
init_playlist_tab();
init_queue_tabs();
}
void post_init_tabs()
@ -628,24 +674,6 @@ void OcarinaPage::check_pq_flags()
}
}
void OcarinaPage::queue_selected(bool random)
{
Playqueue *pq;
unsigned int track_id;
std::vector<Gtk::TreeModel::Path>::iterator it;
Glib::RefPtr<Gtk::TreeSelection> sel = page_view.get_selection();
if (sel->count_selected_rows() == 0)
return;
pq = deck::create(random);
std::vector<Gtk::TreeModel::Path> rows = sel->get_selected_rows();
for (it = rows.begin(); it != rows.end(); it++) {
track_id = model->path_to_id(filter->convert_path_to_child_path(*it));
pq->add(track_id);
}
}
void OcarinaPage::on_close_clicked()
{
deck :: remove(notebook->page_num(*this));
@ -807,19 +835,6 @@ static void on_pq_removed(Playqueue *pq)
renumber_pqs();
}
void queue_selected(bool random)
{
std::map<Playqueue *, OcarinaPage *>::iterator it;
if (deck :: size() >= 10)
return;
for (it = tab_map.begin(); it != tab_map.end(); it++) {
if (it->second->is_current_tab()) {
it->second->queue_selected(random);
return;
}
}
}
*/
/*static void on_new_queue()
{
@ -850,8 +865,6 @@ void init_tabs()
Gtk::Notebook *notebook;
get_builder()->get_widget("o_notebook", notebook);
get_callbacks()->on_pq_created = on_pq_created;
get_callbacks()->on_pq_removed = on_pq_removed;
get_callbacks()->on_queue_track_changed = on_track_changed;
*/
@ -869,10 +882,7 @@ void init_tabs()
init_menu_item("o_pq_8", 8);
init_menu_item("o_pq_9", 9);*/
/*
init_history_tab();
init_playlist_tab();
notebook->signal_switch_page().connect(sigc::ptr_fun(on_switch_page));
notebook->signal_page_reordered().connect(sigc::ptr_fun(on_page_reordered));
notebook->set_current_page(0);
}*/

View File

@ -161,10 +161,6 @@ static bool on_window_key_pressed(GdkEventKey *event)
audio :: previous();
else if (key == "p")
notebook->set_current_page(deck::size() + 2);
//else if (key == "q")
// queue_selected(false);
//else if (key == "s")
// queue_selected(true);
else
return false;
return true;

View File

@ -55,10 +55,6 @@ public:
};
/* tabs.cpp */
//void queue_selected(bool);
/* wires.cpp */
void enable_idle();
void connect_button(const std::string &, void (*func)());

View File

@ -37,7 +37,7 @@ protected:
*/
void tab_init_random();
bool tab_is_cur();
void tab_set_size();
virtual void tab_set_size();
void tab_unmap();
public:
@ -51,20 +51,23 @@ public:
int tab_page_num();
void tab_runtime_changed();
void tab_focus_search();
bool tab_queue_selected(bool);
/**
* internal callback functions
* internal callback functions that can be overridden if necessary
*/
virtual void on_post_init();
virtual void on_track_added(unsigned int);
virtual void on_track_deleted(unsigned int);
virtual void on_track_changed(unsigned int);
virtual bool on_key_press_event(const std::string &);
/**
* GTK-MM callback functions
*/
void on_random_toggled();
void on_row_activated(const Gtk::TreePath &, Gtk::TreeViewColumn *);
bool on_key_pressed(GdkEventKey *key);
/* Filtering functions */
bool on_filter_visible(const Gtk::TreeIter &);
@ -82,5 +85,6 @@ void cleanup_tabs();
void init_collection_tab();
void init_history_tab();
void init_playlist_tab();
void init_queue_tabs();
#endif /* OCARINA_TABS_H */