diff --git a/gui/queue.cpp b/gui/queue.cpp new file mode 100644 index 00000000..a5db0895 --- /dev/null +++ b/gui/queue.cpp @@ -0,0 +1,114 @@ +/* + * Copyright 2014 (c) Anna Schumaker. + */ +#include +#include + +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("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 << "" << tab_pq->size() << ""; + q_tab_size.set_markup(ss.str()); +} + +void QueueTab :: queue_set_number(unsigned int num) +{ + std::stringstream ss; + ss << "" << num << ". "; + 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; +} diff --git a/gui/tabs.cpp b/gui/tabs.cpp index fe1851cf..d43793b8 100644 --- a/gui/tabs.cpp +++ b/gui/tabs.cpp @@ -2,6 +2,7 @@ * Copyright 2014 (c) Anna Schumaker. */ #include +#include #include #include @@ -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 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 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::iterator it; - Glib::RefPtr sel = page_view.get_selection(); - - if (sel->count_selected_rows() == 0) - return; - - pq = deck::create(random); - std::vector 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::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); }*/ diff --git a/gui/wires.cpp b/gui/wires.cpp index be27bd00..70f62769 100644 --- a/gui/wires.cpp +++ b/gui/wires.cpp @@ -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; diff --git a/include/ocarina.h b/include/ocarina.h index 9519b910..9ed53418 100644 --- a/include/ocarina.h +++ b/include/ocarina.h @@ -55,10 +55,6 @@ public: }; -/* tabs.cpp */ -//void queue_selected(bool); - - /* wires.cpp */ void enable_idle(); void connect_button(const std::string &, void (*func)()); diff --git a/include/tabs.h b/include/tabs.h index 31e80dab..6f7c9240 100644 --- a/include/tabs.h +++ b/include/tabs.h @@ -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 */