diff --git a/gui/queue.cpp b/gui/queue.cpp index a5db0895..21dc10fb 100644 --- a/gui/queue.cpp +++ b/gui/queue.cpp @@ -2,11 +2,14 @@ * Copyright 2014 (c) Anna Schumaker. */ #include +#include #include +#include + class QueueTab : public Tab { private: - /* + /** * Queue tab variables */ Gtk::HBox q_tab_box; @@ -15,7 +18,7 @@ private: Gtk::Button q_tab_close; Gtk::Image q_tab_close_img; - /* + /** * Queue page variables */ Gtk::ToggleButton q_random; @@ -26,12 +29,23 @@ private: public: QueueTab(Playqueue *, unsigned int num); ~QueueTab(); - void on_post_init(); + /** + * Helper functions + */ + void on_post_init(); void tab_set_size(); void queue_set_number(unsigned int); + void on_tab_reordered(); + + /** + * GTK-MM Callbacks + */ + void on_close_clicked(); }; +static std::map queue_mapping; + QueueTab :: QueueTab(Playqueue *pq, unsigned int num) : Tab(pq) @@ -42,6 +56,8 @@ QueueTab :: QueueTab(Playqueue *pq, unsigned int num) 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_close.signal_clicked().connect(sigc::mem_fun(*this, + &QueueTab::on_close_clicked)); q_tab_size.set_justify(Gtk::JUSTIFY_CENTER); q_tab_box.pack_start(q_tab_number, false, false); @@ -64,6 +80,7 @@ QueueTab :: QueueTab(Playqueue *pq, unsigned int num) tab_widget = &q_vbox; tab_finish_init(); + queue_mapping[pq] = this; get_widget("o_notebook")->insert_page(q_vbox, q_tab_box, num); q_vbox.show_all(); @@ -71,9 +88,18 @@ QueueTab :: QueueTab(Playqueue *pq, unsigned int num) QueueTab :: ~QueueTab() { + queue_mapping.erase(tab_pq); tab_unmap(); } + + +/** + * + * Queue tab helper functions + * + */ + void QueueTab :: on_post_init() { tab_init_random(); @@ -93,8 +119,38 @@ void QueueTab :: queue_set_number(unsigned int num) q_tab_number.set_markup(ss.str()); } +void QueueTab :: on_tab_reordered() +{ + queue_set_number(tab_page_num()); +} + +/** + * + * Gtk-MM Callback Functions + * + */ + +void QueueTab :: on_close_clicked() +{ + deck :: remove(tab_page_num()); +} + + + +/** + * + * Global functions + * + */ +static void renumber_queues() +{ + std::map::iterator it; + for (it = queue_mapping.begin(); it != queue_mapping.end(); it++) + it->second->on_tab_reordered(); +} + static void on_pq_created(Playqueue *pq, unsigned int num) { QueueTab *tab = new QueueTab(pq, num); @@ -103,7 +159,11 @@ static void on_pq_created(Playqueue *pq, unsigned int num) static void on_pq_removed(Playqueue *pq) { - + Tab *tab = find_tab(pq); + if (tab) { + delete tab; + renumber_queues(); + } } void init_queue_tabs() diff --git a/include/tabs.h b/include/tabs.h index 6f7c9240..21e0faea 100644 --- a/include/tabs.h +++ b/include/tabs.h @@ -76,6 +76,7 @@ public: }; +Tab *find_tab(Playqueue *); void tab_focus_search(); void init_tabs(); void post_init_tabs();