From f0006873b6af2d48c67c90f22959f3bb2140ac50 Mon Sep 17 00:00:00 2001 From: Anna Schumaker Date: Fri, 28 Feb 2014 16:31:36 -0500 Subject: [PATCH] gui: Use number keys to add tracks to a queue Signed-off-by: Anna Schumaker --- gui/tabs.cpp | 57 ++++++++++++++++++++++---------------------------- include/tabs.h | 1 + 2 files changed, 26 insertions(+), 32 deletions(-) diff --git a/gui/tabs.cpp b/gui/tabs.cpp index 424f89c3..8518b840 100644 --- a/gui/tabs.cpp +++ b/gui/tabs.cpp @@ -123,7 +123,28 @@ bool Tab :: tab_queue_selected(bool random) Playqueue *pq = deck :: create(random); std::vector rows = sel->get_selected_rows(); - for (unsigned int i = 0; i != rows.size(); i++) { + 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; +} + +bool Tab :: tab_add_to_queue(unsigned int n) +{ + Glib::RefPtr sel = tab_treeview->get_selection(); + if (sel->count_selected_rows() == 0) + return false; + + if (n >= deck :: size()) + return false; + + Playqueue *pq = deck :: get(n); + 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); @@ -165,7 +186,9 @@ void Tab :: on_track_changed(unsigned int row) bool Tab :: on_key_press_event(const std::string &key) { - if (key == "q" || key == "r") + if (key >= "0" && key <= "9") + return tab_add_to_queue(atoi(key.c_str())); + else if (key == "q" || key == "r") return tab_queue_selected(key == "r"); else return false; @@ -520,25 +543,6 @@ void OcarinaPage::on_column_clicked(unsigned int col_index) sigc::ptr_fun(dec_sort_timeout), 2); } -bool OcarinaPage::on_add_to_pq(unsigned int n) -{ - if (n >= deck :: size()) - return true; - - Glib::RefPtr sel = page_view.get_selection(); - if (sel->count_selected_rows() == 0) - return true; - - Playqueue *pq = deck :: get(n); - std::vector::iterator it; - std::vector rows = sel->get_selected_rows(); - for (it = rows.begin(); it != rows.end(); it++) { - unsigned int track_id = model->path_to_id(filter->convert_path_to_child_path(*it)); - pq->add(track_id); - } - return true; -} - bool OcarinaPage::on_delete_selected() { Glib::RefPtr sel = page_view.get_selection(); @@ -610,17 +614,6 @@ bool OcarinaPage::on_view_button_pressed(GdkEventButton *button) * Do stuff with tabs */ /* -static void on_add_to_queue(unsigned int num) -{ - std::map::iterator it; - for (it = tab_map.begin(); it != tab_map.end(); it++) { - if (it->second->is_current_tab()) { - it->second->on_add_to_pq(num); - return; - } - } -} - static void init_menu_item(const std::string &name, unsigned int num) { Glib::RefPtrmenu = Glib::RefPtr::cast_static(get_builder()->get_object(name)); diff --git a/include/tabs.h b/include/tabs.h index ff319ec6..7e55e1f6 100644 --- a/include/tabs.h +++ b/include/tabs.h @@ -55,6 +55,7 @@ public: void tab_runtime_changed(); void tab_focus_search(); bool tab_queue_selected(bool); + bool tab_add_to_queue(unsigned int); /** * internal callback functions that can be overridden if necessary