Discman
Loading...
Searching...
No Matches
now_playing_component.cc
Go to the documentation of this file.
1
6
8
9NowPlayingComponent::NowPlayingComponent(Glib::RefPtr<Gtk::Builder> builder)
10 : _state(State::Stopped) {
11 _album_art_button = builder->get_widget<Gtk::Button>("albumArtButton");
12 _album_art_image = builder->get_widget<Gtk::Image>("albumArtImage");
13 _track_title_label = builder->get_widget<Gtk::Label>("trackTitleLabel");
14 _track_artist_label = builder->get_widget<Gtk::Label>("trackArtistLabel");
15 _seek_scale = builder->get_widget<Gtk::Scale>("seekScale");
16 _seek_scale = builder->get_widget<Gtk::Scale>("seekScale");
17 _prev_button = builder->get_widget<Gtk::Button>("prevButton");
18 _play_pause_button = builder->get_widget<Gtk::Button>("playPauseButton");
19 _stop_button = builder->get_widget<Gtk::Button>("stopButton");
20 _next_button = builder->get_widget<Gtk::Button>("nextButton");
21 _play_pause_image = builder->get_widget<Gtk::Image>("playPauseImage");
22
23 _album_art_button->set_has_frame(false);
24 _album_art_image->clear();
25
26 _prev_button->signal_clicked().connect(sigc::mem_fun(*this, &NowPlayingComponent::on_prev_button_clicked));
27 _play_pause_button->signal_clicked().connect(sigc::mem_fun(*this, &NowPlayingComponent::on_playpause_button_clicked));
28 _stop_button->signal_clicked().connect(sigc::mem_fun(*this, &NowPlayingComponent::on_stop_button_clicked));
29 _next_button->signal_clicked().connect(sigc::mem_fun(*this, &NowPlayingComponent::on_next_button_clicked));
30 _album_art_button->signal_clicked().connect(sigc::mem_fun(*this, &NowPlayingComponent::on_album_art_button_clicked));
31}
32
44
45void NowPlayingComponent::set_track(const DiscDB::Disc& disc, unsigned int track, const bool first, const bool last) {
46 _track_title_label->set_text(disc.tracks()[track - 1].title());
47 _track_artist_label->set_text(disc.artist());
48 _seek_scale->get_adjustment()->set_lower(0);
49 _seek_scale->get_adjustment()->set_upper(disc.track_length(track));
50 _seek_scale->get_adjustment()->set_value(0);
51 _prev_button->set_sensitive(!first);
52 _next_button->set_sensitive(!last);
53}
54
56 _state = state;
57
58 if (state == State::Cleared || state == State::Stopped || state == State::Disabled) {
59 if (state == State::Cleared)
60 _album_art_image->clear();
61 _track_title_label->set_text("");
62 _track_artist_label->set_text("");
63 _seek_scale->get_adjustment()->set_value(0);
64 _prev_button->set_sensitive(false);
65 _next_button->set_sensitive(false);
66 }
67
68 _play_pause_button->set_sensitive(state != State::Disabled && state != State::Cleared);
69 _play_pause_image->set_from_resource((state != State::Playing) ? "/ui/icons/play.png" : "/ui/icons/pause.png");
70 _stop_button->set_sensitive(state != State::Stopped && state != State::Disabled && state != State::Cleared);
71}
72
76
77void NowPlayingComponent::set_seconds(const float seconds) {
78 _seek_scale->get_adjustment()->set_value(seconds);
79}
80
81void NowPlayingComponent::set_album(const std::string& url) {
82 try {
84 _album_art_image->set(albumArt.art);
85 } catch (const AlbumArtProvider::NotFoundException& e) {
86 _album_art_image->clear();
87 }
88}
89
93
97
101
105
109
113
virtual std::vector< AlbumArt > album_art(const std::string &artist, const std::string &title, const int width, const int height)=0
Return all album art matching the criteria, at a specific width and height.
static AlbumArtProvider * instance()
Factory method to return the album art provider. It may be called one or more times....
void set_state(const State state)
Sets the state of the component.
sigc::signal< void(const Button)> sig_button
"Playback button clicked" signal type.
sig_album_art signal_album_art()
Getter for _signal_album_art.
NowPlayingComponent(Glib::RefPtr< Gtk::Builder > builder)
NowPlayingComponent constructor.
Gtk::Image * _play_pause_image
The current image displayed on the play/pause button. It will either be a "play" icon or a "pause" ic...
Gtk::Scale * _seek_scale
Display for elapsed time.
Gtk::Button * _album_art_button
Button that shows the album art.
~NowPlayingComponent()
NowPlayingComponent destructor.
Gtk::Image * _album_art_image
Album art image.
sig_album_art _signal_album_art
Emitted when the album art button is clicked.
void on_playpause_button_clicked()
Called when the play/pause button is clicked.
sigc::signal< void(void)> sig_album_art
"Album art clicked" signal type.
void on_prev_button_clicked()
Called when the previous track button is clicked.
Gtk::Button * _stop_button
Stop button.
void set_seconds(const float seconds)
Sets the elapsed seconds.
void set_track(const DiscDB::Disc &disc, unsigned int track, const bool first, const bool last)
Sets the information for the track currently playing.
Gtk::Label * _track_title_label
Track title label.
void on_album_art_button_clicked()
Called when the album art button is clicked.
Gtk::Button * _next_button
Next track button.
State get_state() const
Returns the state of the component.
Gtk::Button * _prev_button
Previous track button.
void on_stop_button_clicked()
Called when the stop button is clicked.
sig_button _signal_button
Emitted when a playback control button is clicked.
void set_album(const std::string &url)
Sets the album art image.
void on_next_button_clicked()
Called when the next track button is clicked.
Gtk::Button * _play_pause_button
Play/pause button.
State
The component has several states it can be put into.
State _state
State of the component.
Gtk::Label * _track_artist_label
Track artist label.
sig_button signal_button()
Getter for _signal_button.
An album art image and its URL.
Glib::RefPtr< Gdk::Pixbuf > art
Thrown when the provider cannot find album art images.