gui: More widget and spacing cleanups

Signed-off-by: Anna Schumaker <Schumaker.anna@gmail.com>
This commit is contained in:
Anna Schumaker 2014-02-17 11:04:09 -05:00 committed by Anna Schumaker
parent be60f9bff3
commit 1434618381
1 changed files with 28 additions and 47 deletions

View File

@ -23,11 +23,8 @@ void enable_timeout();
*/
static void on_config_pause()
{
Gtk::SpinButton *count;
Gtk::CheckButton *enabled;
builder->get_widget("o_pause_count", count);
builder->get_widget("o_pause_enabled", enabled);
Gtk::SpinButton *count = get_widget<Gtk::SpinButton>("o_pause_count");
Gtk::CheckButton *enabled = get_widget<Gtk::CheckButton>("o_pause_enabled");
audio :: pause_after(enabled->get_active(), count->get_value());
}
@ -68,15 +65,12 @@ static void set_label_text(Gtk::Label *label, const std::string &size,
static void on_track_loaded(library :: Song &song)
{
Gtk::ToggleButton *ban, *fav;
Gtk::Label *title, *artist, *album, *duration;
builder->get_widget("o_title", title);
builder->get_widget("o_artist", artist);
builder->get_widget("o_album", album);
builder->get_widget("o_total_time", duration);
builder->get_widget("o_ban", ban);
builder->get_widget("o_favorite", fav);
Gtk::ToggleButton *ban = get_widget<Gtk::ToggleButton>("o_ban");
Gtk::ToggleButton *fav = get_widget<Gtk::ToggleButton>("o_favorite");
Gtk::Label *title = get_widget<Gtk::Label>("o_title");
Gtk::Label *artist = get_widget<Gtk::Label>("o_artist");
Gtk::Label *album = get_widget<Gtk::Label>("o_album");
Gtk::Label *duration = get_widget<Gtk::Label>("o_total_time");
set_label_text(title, "xx-large", song.track->title);
set_label_text(artist, "x-large", "By: " + song.artist->primary_key);
@ -101,10 +95,8 @@ static void on_track_loaded(library :: Song &song)
static void on_pause_count_changed(bool enabled, unsigned int count)
{
Gtk::CheckButton *p_enabled;
Gtk::SpinButton *p_count;
builder->get_widget("o_pause_enabled", p_enabled);
builder->get_widget("o_pause_count", p_count);
Gtk::CheckButton *p_enabled = get_widget<Gtk::CheckButton>("o_pause_enabled");
Gtk::SpinButton *p_count = get_widget<Gtk::SpinButton>("o_pause_count");;
if (p_enabled->get_active() != enabled)
p_enabled->set_active(enabled);
@ -114,8 +106,7 @@ static void on_pause_count_changed(bool enabled, unsigned int count)
static void on_ban_toggled()
{
Gtk::ToggleButton *ban;
builder->get_widget("o_ban", ban);
Gtk::ToggleButton *ban = get_widget<Gtk::ToggleButton>("o_pan");
if (ban->get_active() == true)
playlist :: add("Banned", audio::current_trackid());
@ -125,8 +116,7 @@ static void on_ban_toggled()
static void on_fav_toggled()
{
Gtk::ToggleButton *fav;
builder->get_widget("o_favorite", fav);
Gtk::ToggleButton *fav = get_widget<Gtk::ToggleButton>("o_favorite");
if (fav->get_active() == true)
playlist :: add("Favorites", audio::current_trackid());
@ -141,13 +131,10 @@ static void on_fav_toggled()
*/
static bool on_window_key_pressed(GdkEventKey *event)
{
Gtk::Notebook *notebook;
Gtk::Window *window;
Gtk::Notebook *notebook = get_widget<Gtk::Notebook>("o_notebook");
Gtk::Window *window = get_widget<Gtk::Window>("o_window");
std::string key = gdk_keyval_name(event->keyval);
builder->get_widget("o_window", window);
builder->get_widget("o_notebook", notebook);
if (key.size() >= 3) {
if (key.substr(0, 3) == "KP_")
key = key.substr(3);
@ -184,9 +171,7 @@ static bool on_window_key_pressed(GdkEventKey *event)
static bool on_window_key_released(GdkEventKey *event)
{
Gtk::Window *window;
std::string key = gdk_keyval_name(event->keyval);
builder->get_widget("o_window", window);
if (key == "space")
audio :: toggle_play();
@ -202,10 +187,9 @@ static bool on_window_key_released(GdkEventKey *event)
*/
bool on_idle()
{
Gtk::ProgressBar *prog;
Gtk::ProgressBar *prog = get_widget<Gtk::ProgressBar>("o_idle_progress");
bool ret = idle::run_task();
builder->get_widget("o_idle_progress", prog);
if (ret == false)
prog->hide();
else {
@ -258,48 +242,45 @@ void connect_button(const std::string &name, void (*func)())
Gtk::Window *connect_wires()
{
Gtk::Window *window;
struct Callbacks *cb = get_callbacks();
Gtk::SpinButton *count;
Gtk::CheckButton *enabled;
Gtk::Scale *position;
Gtk::ToggleButton *ban;
Gtk::ToggleButton *fav;
builder = Gtk::Builder::create();
builder->add_from_file("gui/ocarina6.glade");
builder->get_widget("o_window", window);
/* Controls */
Gtk::SpinButton *count = get_widget<Gtk::SpinButton>("o_pause_count");
Gtk::CheckButton *enabled = get_widget<Gtk::CheckButton>("o_pause_enabled");
Gtk::Scale *position = get_widget<Gtk::Scale>("o_position_scale");
cb->on_play = on_play;
cb->on_pause = on_pause;
cb->on_track_loaded = on_track_loaded;
cb->on_pause_count_changed = on_pause_count_changed;
count = get_widget<Gtk::SpinButton>("o_pause_count");
builder->get_widget("o_pause_enabled", enabled);
builder->get_widget("o_position_scale", position);
count->signal_changed().connect(sigc::ptr_fun(on_config_pause));
enabled->signal_toggled().connect(sigc::ptr_fun(on_config_pause));
position->signal_change_value().connect(sigc::ptr_fun(on_seek));
connect_button("o_play", audio::play);
connect_button("o_pause", audio::pause);
connect_button("o_stop", audio::stop);
connect_button("o_prev", audio::previous);
connect_button("o_next", on_next);
count->signal_changed().connect(sigc::ptr_fun(on_config_pause));
enabled->signal_toggled().connect(sigc::ptr_fun(on_config_pause));
position->signal_change_value().connect(sigc::ptr_fun(on_seek));
/* Keyboard shortcuts */
Gtk::Window *window = get_widget<Gtk::Window>("o_window");
window->signal_key_press_event().connect(sigc::ptr_fun(on_window_key_pressed));
window->signal_key_release_event().connect(sigc::ptr_fun(on_window_key_released));
window->set_can_focus();
/* Favorite and ban buttons */
builder->get_widget("o_ban", ban);
builder->get_widget("o_favorite", fav);
Gtk::ToggleButton *ban = get_widget<Gtk::ToggleButton>("o_ban");
Gtk::ToggleButton *fav = get_widget<Gtk::ToggleButton>("o_favorite");
ban_connection = ban->signal_toggled().connect(sigc::ptr_fun(on_ban_toggled));
fav_connection = fav->signal_toggled().connect(sigc::ptr_fun(on_fav_toggled));