diff --git a/gui/collection.cpp b/gui/collection.cpp index bc7405c1..d33ca3c9 100644 --- a/gui/collection.cpp +++ b/gui/collection.cpp @@ -29,7 +29,7 @@ public: builder->get_widget_derived("CollectionLabel", collection_label); builder->get_widget_derived("QueueToolbar", collection_toolbar); builder->get_widget_derived("QueueWindow", collection_window); - collection_toolbar->init(tab_pq, T_RANDOM); + collection_toolbar->init(tab_pq, collection_label, collection_window, T_RANDOM); collection_vbox.set_margin_left(1); collection_vbox.set_margin_right(1); diff --git a/gui/history.cpp b/gui/history.cpp index fa1eea2e..4e21993e 100644 --- a/gui/history.cpp +++ b/gui/history.cpp @@ -28,7 +28,7 @@ public: builder->get_widget_derived("HistoryLabel", history_label); builder->get_widget_derived("QueueToolbar", history_toolbar); builder->get_widget_derived("QueueWindow", history_window); - history_toolbar->init(tab_pq, 0); + history_toolbar->init(tab_pq, history_label, history_window, 0); history_vbox.set_margin_left(1); history_vbox.set_margin_right(1); diff --git a/gui/playlist.cpp b/gui/playlist.cpp index e041eb72..44a32033 100644 --- a/gui/playlist.cpp +++ b/gui/playlist.cpp @@ -93,7 +93,7 @@ public: builder->get_widget_derived("PlaylistWindow", playlist_window); builder->get_widget_derived("QueueToolbar", playlist_toolbar); builder->get_widget_derived("QueueWindow", playlist_tracks); - playlist_toolbar->init(tab_pq, 0); + playlist_toolbar->init(tab_pq, playlist_label, playlist_tracks, 0); playlist_hbox.pack_start(*playlist_window, false, true); playlist_hbox.pack_start(*playlist_tracks, true, true); diff --git a/gui/queue.cpp b/gui/queue.cpp index 4e0fc866..105c65ec 100644 --- a/gui/queue.cpp +++ b/gui/queue.cpp @@ -65,20 +65,16 @@ public: /** * Helper functions */ - void setup_treeview(); - void on_post_init(); bool on_key_press_event(const std::string &); void tab_set_size(); 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; @@ -104,18 +100,19 @@ QueueTab :: QueueTab(Queue *pq, unsigned int num) queue_set_number(num); - /* - * Now set up the toolbar - */ - builder->get_widget_derived("QueueToolbar", q_toolbar); - q_toolbar->init(pq, T_RANDOM | T_REPEAT | T_SWITCH); - /* * And the treeview with scrolled window */ builder->get_widget_derived("QueueWindow", q_window); + /* + * Now set up the toolbar + */ + builder->get_widget_derived("QueueToolbar", q_toolbar); + q_toolbar->init(pq, q_label, q_window, T_RANDOM | T_REPEAT | T_SWITCH); + + /* * Fill in the page! */ @@ -167,15 +164,6 @@ void QueueTab :: on_track_removed(unsigned int row) * */ -void QueueTab :: on_post_init() -{ - bool active = (tab_pq->has_flag(Q_ENABLED)); - q_toolbar->q_switch->set_active(active); - q_toolbar->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) { std::vector ids; @@ -221,13 +209,6 @@ void QueueTab :: on_move_queue(int num) deck :: move(tab_pq, num); } -void QueueTab :: queue_set_sensitive(bool sensitive) -{ - q_label->temp_number->set_sensitive(sensitive); - q_label->temp_size->set_sensitive(sensitive); - q_window->q_treeview->set_sensitive(sensitive); -} - /** @@ -242,17 +223,6 @@ void QueueTab :: on_close_clicked() delete this; } -void QueueTab :: on_switch_changed() -{ - if (q_toolbar->q_switch->get_active()) { - tab_pq->set_flag(Q_ENABLED); - queue_set_sensitive(true); - } else { - tab_pq->unset_flag(Q_ENABLED); - queue_set_sensitive(false); - } -} - /** diff --git a/gui/queue/label.cpp b/gui/queue/label.cpp index c6f420fc..573ceb96 100644 --- a/gui/queue/label.cpp +++ b/gui/queue/label.cpp @@ -51,3 +51,9 @@ TempLabel :: TempLabel(BaseObjectType *cobject, _builder->get_widget("temp_size", temp_size); _builder->get_widget("temp_close", temp_close); } + +void TempLabel :: set_sensitive(bool sensitive) +{ + temp_number->set_sensitive(sensitive); + temp_size->set_sensitive(sensitive); +} diff --git a/gui/queue/toolbar.cpp b/gui/queue/toolbar.cpp index b7ecdfb9..41ec4179 100644 --- a/gui/queue/toolbar.cpp +++ b/gui/queue/toolbar.cpp @@ -8,7 +8,7 @@ QueueToolbar :: QueueToolbar(BaseObjectType *cobject, : Gtk::HBox(cobject), _builder(builder) { _builder->get_widget("q_search", q_search); - _builder->get_widget("q_switch", q_switch); + _builder->get_widget("q_switch", _q_switch); _builder->get_widget("q_repeat", _q_repeat); _builder->get_widget("q_random", _q_random); } @@ -17,25 +17,32 @@ QueueToolbar :: ~QueueToolbar() { } -void QueueToolbar :: init(Queue *queue, unsigned int flags) +void QueueToolbar :: init(Queue *queue, QueueLabel *label, + QueueWindow *window, unsigned int flags) { - _queue = queue; + _queue = queue; + _q_label = label; + _q_window = window; - if (flags & T_SWITCH) - q_switch->show(); + if (flags & T_SWITCH) { + _q_switch->property_active().signal_changed().connect( + sigc::mem_fun(*this, &QueueToolbar::on_switch_toggled)); + _q_switch->set_active(_queue->has_flag(Q_ENABLED)); + _q_switch->show(); + } if (flags & T_RANDOM) { - _q_random->set_active(_queue->has_flag(Q_RANDOM)); _q_random->signal_toggled().connect(sigc::mem_fun(*this, &QueueToolbar::on_random_toggled)); + _q_random->set_active(_queue->has_flag(Q_RANDOM)); _q_random->show(); } if (flags & T_REPEAT) { - _q_repeat->set_active(_queue->has_flag(Q_REPEAT)); _q_repeat->signal_toggled().connect(sigc::mem_fun(*this, &QueueToolbar::on_repeat_toggled)); + _q_repeat->set_active(_queue->has_flag(Q_REPEAT)); _q_repeat->show(); } } @@ -55,3 +62,16 @@ void QueueToolbar :: on_repeat_toggled() else _queue->unset_flag(Q_REPEAT); } + +void QueueToolbar :: on_switch_toggled() +{ + bool active = _q_switch->get_active(); + + if (active) + _queue->set_flag(Q_ENABLED); + else + _queue->unset_flag(Q_ENABLED); + + _q_label->set_sensitive(active); + _q_window->set_sensitive(active); +} diff --git a/include/gui/queue/label.h b/include/gui/queue/label.h index d5cee273..328eb86d 100644 --- a/include/gui/queue/label.h +++ b/include/gui/queue/label.h @@ -14,6 +14,7 @@ protected: public: QueueLabel(BaseObjectType *, const Glib::RefPtr); ~QueueLabel(); + virtual void set_sensitive(bool) {}; }; @@ -49,6 +50,7 @@ public: Gtk::Button *temp_close; TempLabel(BaseObjectType *, const Glib::RefPtr); + void set_sensitive(bool); }; #endif /* OCARINA_GUI_QUEUE_LABEL_H */ diff --git a/include/gui/queue/toolbar.h b/include/gui/queue/toolbar.h index bf867ac8..81933d90 100644 --- a/include/gui/queue/toolbar.h +++ b/include/gui/queue/toolbar.h @@ -5,6 +5,8 @@ #define OCARINA_GUI_QUEUE_TOOLBAR_H #include +#include +#include #include enum toolbar_flags { @@ -18,21 +20,25 @@ class QueueToolbar : public Gtk::HBox { private: Glib::RefPtr _builder; Queue *_queue; + QueueLabel *_q_label; + QueueWindow *_q_window; + Gtk::ToggleButton *_q_random; Gtk::ToggleButton *_q_repeat; + Gtk::Switch *_q_switch; public: Gtk::SearchEntry *q_search; - Gtk::Switch *q_switch; QueueToolbar(BaseObjectType *, const Glib::RefPtr); ~QueueToolbar(); - void init(Queue *, unsigned int); + void init(Queue *, QueueLabel*, QueueWindow*, unsigned int); void on_random_toggled(); void on_repeat_toggled(); + void on_switch_toggled(); }; #endif /* OCARINA_GUI_QUEUE_TOOLBAR_H */