From 2e727ed7046e9896719367ab5b54bfd312544f74 Mon Sep 17 00:00:00 2001 From: Anna Schumaker Date: Sat, 1 Mar 2014 20:55:37 -0500 Subject: [PATCH] gui: Add a switch to enable / disable queues I also select the first enabled queue during startup. Signed-off-by: Anna Schumaker --- gui/queue.cpp | 28 ++++++++++++++++++++++++++++ gui/tabs.cpp | 8 +++++++- 2 files changed, 35 insertions(+), 1 deletion(-) diff --git a/gui/queue.cpp b/gui/queue.cpp index 71cff8e7..1d0686ed 100644 --- a/gui/queue.cpp +++ b/gui/queue.cpp @@ -55,6 +55,7 @@ private: Gtk::SearchEntry q_search; Gtk::ToggleButton q_random; Gtk::ToggleButton q_repeat; + Gtk::Switch q_switch; /* Treeview widgets */ Gtk::ScrolledWindow q_window; @@ -75,11 +76,13 @@ public: void queue_set_number(unsigned int); void on_tab_reordered(); void on_move_queue(int); + void queue_set_sensitive(bool); /** * GTK-MM Callbacks */ void on_close_clicked(); + void on_switch_changed(); }; static std::map queue_mapping; @@ -121,6 +124,7 @@ QueueTab :: QueueTab(Playqueue *pq, unsigned int num) q_toolbar_box.set_homogeneous(false); q_toolbar_box.pack_start(q_search, true, true); + q_toolbar_box.pack_start(q_switch, false, true); q_toolbar_box.pack_start(q_repeat, false, true); q_toolbar_box.pack_start(q_random, false, true); @@ -213,6 +217,12 @@ void QueueTab :: on_post_init() { tab_init_random(); tab_init_repeat(); + + bool active = (tab_pq->get_flags() & PQ_ENABLED) == PQ_ENABLED; + q_switch.set_active(active); + q_switch.property_active().signal_changed().connect( + sigc::mem_fun(*this, &QueueTab :: on_switch_changed)); + queue_set_sensitive(active); } bool QueueTab :: on_key_press_event(const std::string &key) @@ -264,6 +274,13 @@ void QueueTab :: on_move_queue(int num) deck :: move(tab_pq, num); } +void QueueTab :: queue_set_sensitive(bool sensitive) +{ + q_tab_number.set_sensitive(sensitive); + q_tab_size.set_sensitive(sensitive); + q_treeview.set_sensitive(sensitive); +} + /** @@ -277,6 +294,17 @@ void QueueTab :: on_close_clicked() deck :: remove(tab_page_num()); } +void QueueTab :: on_switch_changed() +{ + if (q_switch.get_active()) { + tab_pq->set_flag(PQ_ENABLED); + queue_set_sensitive(true); + } else { + tab_pq->unset_flag(PQ_ENABLED); + queue_set_sensitive(false); + } +} + /** diff --git a/gui/tabs.cpp b/gui/tabs.cpp index e34a2daf..d9776de6 100644 --- a/gui/tabs.cpp +++ b/gui/tabs.cpp @@ -519,7 +519,13 @@ void post_init_tabs() std::map::iterator it; for (it = queue_mapping.begin(); it != queue_mapping.end(); it++) it->second->on_post_init(); - get_widget("o_notebook")->set_current_page(0); + + unsigned int tab = 0; + for (tab = 0; tab < deck::size(); tab++) { + if ((deck :: get(tab)->get_flags() & PQ_ENABLED) == PQ_ENABLED) + break; + } + get_widget("o_notebook")->set_current_page(tab); } void cleanup_tabs()