/* * Copyright 2014 (c) Anna Schumaker. */ #include #include #include #include #include #include #include #include static sigc::connection fav_connection; static sigc::connection ban_connection; Gtk::SpinButton *count; Gtk::CheckButton *enabled; /* * Control functions */ static void on_config_pause_enabled() { audio :: pause_after(enabled->get_active(), count->get_value()); } static void on_config_pause_count() { enabled->set_active(true); } static void set_label_text(Gtk::Label *label, const std::string &size, const std::string &text) { label->set_markup("" + Glib::Markup::escape_text(text) + ""); } void on_track_loaded(Track *track) { Gtk::ToggleButton *ban = lib :: get_widget("o_ban"); Gtk::ToggleButton *fav = lib :: get_widget("o_favorite"); Gtk::Label *title = lib :: get_widget("o_title"); Gtk::Label *artist = lib :: get_widget("o_artist"); Gtk::Label *album = lib :: get_widget("o_album"); Gtk::Label *duration = lib :: get_widget("o_duration"); set_label_text(title, "xx-large", track->name()); set_label_text(artist, "x-large", "By: " + track->artist()->name()); set_label_text(album, "x-large", "From: " + track->album()->name()); duration->set_text(track->length_str()); bool banned = playlist :: has(track, "Banned"); bool favorite = playlist :: has(track, "Favorites"); ban_connection.block(); fav_connection.block(); if (ban->get_active() != banned) ban->set_active(banned); if (fav->get_active() != favorite) fav->set_active(favorite); ban_connection.unblock(); fav_connection.unblock(); } void on_pause_count_changed(bool enabled, unsigned int count) { Gtk::CheckButton *p_enabled = lib :: get_widget("o_pause_enabled"); Gtk::SpinButton *p_count = lib :: get_widget("o_pause_count");; if (p_enabled->get_active() != enabled) p_enabled->set_active(enabled); if (p_count->get_value() != count) p_count->set_value(count); } static void on_ban_toggled() { Gtk::ToggleButton *ban = lib :: get_widget("o_ban"); if (ban->get_active() == true) { playlist :: add(audio :: current_track(), "Banned"); on_next(); } else playlist :: del(audio::current_track(), "Banned"); } static void on_fav_toggled() { Gtk::ToggleButton *fav = lib :: get_widget("o_favorite"); if (fav->get_active() == true) playlist :: add(audio::current_track(), "Favorites"); else playlist :: del(audio::current_track(), "Favorites"); } /* * Ocarina functions */ void connect_button(const std::string &name, void (*func)()) { lib :: get_widget(name)->signal_clicked().connect(sigc::ptr_fun(func)); } Gtk::Window *setup_gui() { /* Controls */ count = lib :: get_widget("o_pause_count"); enabled = lib :: get_widget("o_pause_enabled"); count->signal_changed().connect(sigc::ptr_fun(on_config_pause_count)); enabled->signal_toggled().connect(sigc::ptr_fun(on_config_pause_enabled)); /* Favorite and ban buttons */ Gtk::ToggleButton *ban = lib :: get_widget("o_ban"); Gtk::ToggleButton *fav = lib :: get_widget("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)); if (audio :: current_track()) on_track_loaded(audio :: current_track()); /* Set up other tabs */ collection_mgr_init(); init_tabs(); return window_init(); }