gui: Set up the switch from inside the toolbar

Signed-off-by: Anna Schumaker <Anna@OcarinaProject.net>
This commit is contained in:
Anna Schumaker 2015-04-16 15:21:44 -04:00
parent 343426ddc3
commit 3d89bf2563
8 changed files with 53 additions and 49 deletions

View File

@ -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);

View File

@ -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);

View File

@ -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);

View File

@ -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<Gtk::Widget *, QueueTab *> 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<unsigned int> 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);
}
}
/**

View File

@ -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);
}

View File

@ -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);
}

View File

@ -14,6 +14,7 @@ protected:
public:
QueueLabel(BaseObjectType *, const Glib::RefPtr<Gtk::Builder>);
~QueueLabel();
virtual void set_sensitive(bool) {};
};
@ -49,6 +50,7 @@ public:
Gtk::Button *temp_close;
TempLabel(BaseObjectType *, const Glib::RefPtr<Gtk::Builder>);
void set_sensitive(bool);
};
#endif /* OCARINA_GUI_QUEUE_LABEL_H */

View File

@ -5,6 +5,8 @@
#define OCARINA_GUI_QUEUE_TOOLBAR_H
#include <core/queue.h>
#include <gui/queue/label.h>
#include <gui/queue/window.h>
#include <gtkmm.h>
enum toolbar_flags {
@ -18,21 +20,25 @@ class QueueToolbar : public Gtk::HBox {
private:
Glib::RefPtr<Gtk::Builder> _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<Gtk::Builder>);
~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 */