From 82243cfdd160d98a2ca56ef5fe1bd7d232878587 Mon Sep 17 00:00:00 2001 From: Anna Schumaker Date: Sun, 2 Feb 2014 10:45:09 -0500 Subject: [PATCH] gui: Add tracks to playqueue I added tab numbers to make it easier to specify what playqueue to add tracks to. Signed-off-by: Anna Schumaker --- gui/model.cpp | 7 ++++- gui/tabs.cpp | 73 +++++++++++++++++++++++++++++++++++++++++++++-- include/ocarina.h | 1 + 3 files changed, 77 insertions(+), 4 deletions(-) diff --git a/gui/model.cpp b/gui/model.cpp index 30753574..32e383e4 100644 --- a/gui/model.cpp +++ b/gui/model.cpp @@ -57,7 +57,7 @@ void PlayqueueModel::on_row_changed(unsigned int row) void PlayqueueModel::on_path_selected(const Gtk::TreePath &path) { - audio :: load_trackid(queue->operator[](path[0])); + audio :: load_trackid(path_to_id(path)); queue->set_cur(path[0]); audio :: play(); } @@ -67,6 +67,11 @@ unsigned int PlayqueueModel :: iter_to_id(const Gtk::TreeIter &iter) return GPOINTER_TO_UINT(iter.gobj()->user_data); } +unsigned int PlayqueueModel::path_to_id(const Gtk::TreePath &path) +{ + return queue->operator[](path[0]); +} + /* diff --git a/gui/tabs.cpp b/gui/tabs.cpp index 136acfd0..c2230fb0 100644 --- a/gui/tabs.cpp +++ b/gui/tabs.cpp @@ -64,6 +64,7 @@ public: OcarinaTab(); ~OcarinaTab(); virtual void set_size(unsigned int) = 0; + virtual void set_number(unsigned int) = 0; }; OcarinaTab::OcarinaTab() {} @@ -81,6 +82,7 @@ public: PresetTab(const std::string &, const std::string &); ~PresetTab(); void set_size(unsigned int); + void set_number(unsigned int); }; PresetTab::PresetTab(const std::string &name, const std::string &icon) @@ -102,6 +104,7 @@ PresetTab::PresetTab(const std::string &name, const std::string &icon) } PresetTab::~PresetTab() {} +void PresetTab::set_number(unsigned int num) {} void PresetTab::set_size(unsigned int size) { @@ -114,20 +117,23 @@ void PresetTab::set_size(unsigned int size) class PQTab : public OcarinaTab { public: + Gtk::Label number_label; Gtk::Label size_label; Gtk::Image close_icon; Gtk::Button close_button; PQTab(); ~PQTab(); void set_size(unsigned int); + void set_number(unsigned int); }; -PQTab::PQTab() : size_label("0", 0.5, 0.5) +PQTab::PQTab() : number_label("0", 0, 0.5), size_label("0", 0.5, 0.5) { close_icon.set_from_icon_name("window-close", Gtk::ICON_SIZE_MENU); close_button.set_image(close_icon); close_button.set_relief(Gtk::RELIEF_NONE); + pack_start(number_label, false, false); pack_start(size_label, true, true); pack_start(close_button, false, false); show_all(); @@ -142,6 +148,13 @@ void PQTab::set_size(unsigned int size) size_label.set_markup(ss.str()); } +void PQTab::set_number(unsigned int num) +{ + std::stringstream ss; + ss << "" << num << ". "; + number_label.set_markup(ss.str()); +} + @@ -197,6 +210,8 @@ public: void on_entry_changed(); bool on_entry_key_released(GdkEventKey *); bool on_filter_visible(const Gtk::TreeIter &); + void on_page_renumbered(); + bool on_view_key_pressed(GdkEventKey *); }; @@ -292,6 +307,9 @@ void OcarinaPage::setup_treeview() page_view.signal_row_activated().connect(sigc::mem_fun(*this, &OcarinaPage::on_row_activated)); + page_view.signal_key_press_event().connect(sigc::mem_fun(*this, + &OcarinaPage::on_view_key_pressed)); + page_view.set_model(filter); page_view.set_rules_hint(); page_view.set_enable_search(false); @@ -354,7 +372,7 @@ void OcarinaPage::queue_selected(bool random) pq = deck::create(random); std::vector rows = sel->get_selected_rows(); for (it = rows.begin(); it != rows.end(); it++) { - track_id = (*model->queue)[(*it)[0]]; + track_id = model->path_to_id(filter->convert_path_to_child_path(*it)); pq->add(track_id); } } @@ -456,6 +474,41 @@ bool OcarinaPage::on_filter_visible(const Gtk::TreeIter &iter) return visible_ids.find(model->queue->operator[](pq_id)) != visible_ids.end(); } +void OcarinaPage::on_page_renumbered() +{ + tab->set_number(notebook->page_num(*this)); +} + +bool OcarinaPage::on_view_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); + } + + if (key >= "0" && key <= "9") { + unsigned int n = atoi(key.c_str()); + 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; + } + return false; +} + /* @@ -504,6 +557,13 @@ static void on_switch_page(Gtk::Widget *page, int num) sort_timeout_count = 0; } +static void renumber_pqs() +{ + std::map::iterator it; + for (it = tab_map.begin(); it != tab_map.end(); it++) + it->second->on_page_renumbered(); +} + static void on_page_reordered(Gtk::Widget *page, int num) { Gtk::Notebook *notebook; @@ -513,14 +573,17 @@ static void on_page_reordered(Gtk::Widget *page, int num) if ((unsigned int)num >= deck :: size()) notebook->reorder_child(*page, deck::size() - 1); - else + else { deck :: move(tab->model->queue, num); + renumber_pqs(); + } } static void on_pq_created(Playqueue *pq, unsigned int num) { OcarinaPage *page = new OcarinaPage(pq, PQ_RANDOM | PQ_REPEAT, num); page->check_pq_flags(); + renumber_pqs(); } static void on_pq_removed(Playqueue *pq) @@ -529,11 +592,15 @@ static void on_pq_removed(Playqueue *pq) it = tab_map.find(pq); if (it != tab_map.end()) delete it->second; + 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); diff --git a/include/ocarina.h b/include/ocarina.h index 617c4ff4..7a65b045 100644 --- a/include/ocarina.h +++ b/include/ocarina.h @@ -45,6 +45,7 @@ public: void on_row_changed(unsigned int); void on_path_selected(const Gtk::TreePath &); unsigned int iter_to_id(const Gtk::TreeIter &); + unsigned int path_to_id(const Gtk::TreePath &); }; /* tabs.cpp */