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 <schumaker.anna@gmail.com>
This commit is contained in:
parent
bc3220ae85
commit
a865ac36a3
|
@ -722,11 +722,10 @@ Manager</property>
|
|||
</packing>
|
||||
</child>
|
||||
<child>
|
||||
<object class="GtkLabel" id="label6">
|
||||
<object class="GtkLabel" id="o_queue_time">
|
||||
<property name="visible">True</property>
|
||||
<property name="can_focus">False</property>
|
||||
<property name="xalign">1</property>
|
||||
<property name="label" translatable="yes">S Songs: D days, H hours, M minutes, S seconds</property>
|
||||
</object>
|
||||
<packing>
|
||||
<property name="expand">False</property>
|
||||
|
|
51
gui/tabs.cpp
51
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<PlayqueueModel> 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("<big>" + text + "</big>", 1, 0.5),
|
||||
tab_size("0", 1, 0.5)
|
||||
{
|
||||
Gtk::Notebook *notebook;
|
||||
get_builder()->get_widget("o_notebook", notebook);
|
||||
model = Glib::RefPtr<PlayqueueModel>(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<Playqueue *, OcarinaTab *>::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()
|
||||
|
|
Loading…
Reference in New Issue