From a865ac36a360e15ae8b327d877dd9e739627f1f3 Mon Sep 17 00:00:00 2001 From: Anna Schumaker Date: Wed, 22 Jan 2014 21:19:18 -0500 Subject: [PATCH] gui: Respond to changing current tab I display the runtime of the currently visible playqueue in the bottom right of the screen. When the collection manager is visible, I hide this label. Signed-off-by: Anna Schumaker --- gui/ocarina6.glade | 3 +-- gui/tabs.cpp | 51 ++++++++++++++++++++++++++++++++++++++++++---- 2 files changed, 48 insertions(+), 6 deletions(-) diff --git a/gui/ocarina6.glade b/gui/ocarina6.glade index 59d91e66..46193733 100644 --- a/gui/ocarina6.glade +++ b/gui/ocarina6.glade @@ -722,11 +722,10 @@ Manager - + True False 1 - S Songs: D days, H hours, M minutes, S seconds False diff --git a/gui/tabs.cpp b/gui/tabs.cpp index ff7894d8..ebd2cf9e 100644 --- a/gui/tabs.cpp +++ b/gui/tabs.cpp @@ -39,6 +39,7 @@ static unsigned int q_col_width[] = { 20, 300, 60, 125, 125, 1, 125, 60, 1 }; class OcarinaTab { private: Glib::RefPtr model; + Gtk::Notebook *notebook; /* Tab widgets */ Gtk::VBox tab_box; @@ -60,9 +61,12 @@ private: public: OcarinaTab(const std::string &, Playqueue *); ~OcarinaTab(); + bool is_current_tab(); + bool is_current_tab(unsigned int); void on_row_inserted(unsigned int); void on_row_deleted(unsigned int); + void on_runtime_changed(); }; @@ -70,7 +74,6 @@ OcarinaTab::OcarinaTab(const std::string &text, Playqueue *pq) : tab_name("" + text + "", 1, 0.5), tab_size("0", 1, 0.5) { - Gtk::Notebook *notebook; get_builder()->get_widget("o_notebook", notebook); model = Glib::RefPtr(new PlayqueueModel(pq)); @@ -118,10 +121,7 @@ OcarinaTab::OcarinaTab(const std::string &text, Playqueue *pq) OcarinaTab::~OcarinaTab() { - Gtk::Notebook *notebook; - get_builder()->get_widget("o_notebook", notebook); notebook->remove_page(page_box); - tab_map.erase(model->queue); } @@ -135,6 +135,16 @@ void OcarinaTab::setup_columns() } } +bool OcarinaTab::is_current_tab() +{ + return notebook->page_num(page_box) == notebook->get_current_page(); +} + +bool OcarinaTab::is_current_tab(unsigned int tab) +{ + return notebook->page_num(page_box) == (int)tab; +} + void OcarinaTab::set_tab_size() { std::stringstream ss; @@ -146,12 +156,23 @@ void OcarinaTab::on_row_inserted(unsigned int row) { model->on_row_inserted(row); set_tab_size(); + if (is_current_tab()) + on_runtime_changed(); } void OcarinaTab::on_row_deleted(unsigned int row) { model->on_row_deleted(row); set_tab_size(); + if (is_current_tab()) + on_runtime_changed(); +} + +void OcarinaTab::on_runtime_changed() +{ + Gtk::Label *label; + get_builder()->get_widget("o_queue_time", label); + label->set_text(model->queue->get_length_str()); } @@ -170,11 +191,33 @@ static void on_track_deleted(Playqueue *pq, unsigned int row) tab_map[pq]->on_row_deleted(row); } +static void on_switch_page(Gtk::Widget *page, unsigned int num) +{ + Gtk::Label *label; + std::map::iterator it; + get_builder()->get_widget("o_queue_time", label); + + for (it = tab_map.begin(); it != tab_map.end(); it++) { + if (it->second->is_current_tab(num)) { + it->second->on_runtime_changed(); + label->show(); + return; + } + } + + label->hide(); +} + void init_tabs() { + Gtk::Notebook *notebook; + get_builder()->get_widget("o_notebook", notebook); + new OcarinaTab("Collection", deck::get_library_pq()); get_callbacks()->on_queue_track_add = on_track_added; get_callbacks()->on_queue_track_del = on_track_deleted; + + notebook->signal_switch_page().connect(sigc::ptr_fun(on_switch_page)); } void cleanup_tabs()