From fc4f311971b8847e7c3c8e30999c655405c5fe6e Mon Sep 17 00:00:00 2001 From: Bryan Schumaker Date: Fri, 28 Oct 2011 17:22:51 -0400 Subject: [PATCH] ocarina: Added a "now playing" panel This is just an initial implementation, so it's not very good right now. It does give all the information, though. That's a plus. I also set the artist / album / playlist whenever a SONG_LOADED callback is given. --- ocarina/callback.cpp | 9 +++++++ ocarina/footer/footer.cpp | 6 ++--- ocarina/footer/footer.h | 1 + ocarina/footer/now_playing.cpp | 48 ++++++++++++++++++++++++++++++++++ 4 files changed, 61 insertions(+), 3 deletions(-) create mode 100644 ocarina/footer/now_playing.cpp diff --git a/ocarina/callback.cpp b/ocarina/callback.cpp index a4060f21..4a8dc486 100644 --- a/ocarina/callback.cpp +++ b/ocarina/callback.cpp @@ -1,10 +1,12 @@ +#include #include #include #include #include #include #include +#include void cb_play() { @@ -33,6 +35,12 @@ void cb_library_refresh() library_settings_refresh(); } +void cb_track_loaded() +{ + println("Ocarina TRACK_LOADED callback!"); + libsaria::current_track(set_footer_track); +} + void setup_callbacks() { println("Ocarina setting up callbacks"); @@ -40,4 +48,5 @@ void setup_callbacks() register_callback(PAUSE, cb_pause); register_callback(IDLE_TASK_QUEUED, cb_idle_task_queued); register_callback(LIBRARY_REFRESH, cb_library_refresh); + register_callback(TRACK_LOADED, cb_track_loaded); } diff --git a/ocarina/footer/footer.cpp b/ocarina/footer/footer.cpp index 2af449d5..6489cc6d 100644 --- a/ocarina/footer/footer.cpp +++ b/ocarina/footer/footer.cpp @@ -1,6 +1,5 @@ #include -#include #include "footer.h" static GtkWidget *footer = NULL; @@ -17,8 +16,9 @@ static void make_footer() * this point, and then add the controls */ gtk_widget_show_all(footer); - box_pack_start(footer, sep, FALSE, FALSE, 0); - box_pack_start(footer, get_controls(), FALSE, FALSE, 0); + box_pack_start(footer, sep, FALSE, FALSE, 0); + box_pack_start(footer, get_controls(), FALSE, FALSE, 0); + box_pack_start(footer, get_nowplaying(), FALSE, FALSE, 0); } GtkWidget *get_footer() diff --git a/ocarina/footer/footer.h b/ocarina/footer/footer.h index 287844a5..8da6bb31 100644 --- a/ocarina/footer/footer.h +++ b/ocarina/footer/footer.h @@ -2,5 +2,6 @@ #define OCARINA_FOOTER_PRIVATE_H GtkWidget *get_controls(); +GtkWidget *get_nowplaying(); #endif /* OCARINA_FOOTER_PRIVATE_H */ diff --git a/ocarina/footer/now_playing.cpp b/ocarina/footer/now_playing.cpp new file mode 100644 index 00000000..2678e014 --- /dev/null +++ b/ocarina/footer/now_playing.cpp @@ -0,0 +1,48 @@ + +#include +#include +#include "footer.h" + +static GtkWidget *now_playing = NULL; +static GtkWidget *title = NULL; +static GtkWidget *artist = NULL; +static GtkWidget *album = NULL; + +static void make_nowplaying() +{ + GtkWidget *tag_box = gtk_vbox_new(FALSE, 0); + now_playing = gtk_hbox_new(FALSE, 0); + + title = gtk_label_new(""); + artist = gtk_label_new(""); + album = gtk_label_new(""); + + box_pack_start(tag_box, title, FALSE, FALSE, 0); + box_pack_start(tag_box, artist, FALSE, FALSE, 0); + box_pack_start(tag_box, album, FALSE, FALSE, 0); + + box_pack_start(now_playing, tag_box, FALSE, FALSE, 0); + gtk_widget_show_all(now_playing); +} + +GtkWidget *get_nowplaying() +{ + if (now_playing == NULL) + make_nowplaying(); + return now_playing; +} + +static void change_label(GtkWidget *label, string prefix, string text) +{ + if (text != "") + gtk_label_set_text(GTK_LABEL(label), (prefix + text).c_str()); + else + gtk_label_set_text(GTK_LABEL(label), ""); +} + +void set_footer_track(Track &track) +{ + change_label(title , "", track.get_title()); + change_label(artist, "by ", track.get_artist()); + change_label(album, "from ", track.get_album()); +}