From 3da4eec23c413240b093c8e9a79f1a1899bab328 Mon Sep 17 00:00:00 2001 From: Patrick Hallen Date: Fri, 4 Sep 2009 13:12:57 +0200 Subject: [PATCH] screen_song: Added the length of the song to the song screen. --- src/screen_song.c | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/src/screen_song.c b/src/screen_song.c index 6f1c8b8..8328415 100644 --- a/src/screen_song.c +++ b/src/screen_song.c @@ -184,12 +184,13 @@ screen_song_add_song(const struct mpd_song *song, const mpdclient_t *c) { unsigned i, max_label_width; enum label { - ARTIST, TITLE, ALBUM, COMPOSER, NAME, DISC, TRACK, + ARTIST, TITLE, ALBUM, LENGTH, COMPOSER, NAME, DISC, TRACK, DATE, GENRE, COMMENT, PATH, BITRATE }; const char *labels[] = { [ARTIST] = _("Artist"), [TITLE] = _("Title"), [ALBUM] = _("Album"), + [LENGTH] = _("Length"), [COMPOSER] = _("Composer"), [NAME] = _("Name"), [DISC] = _("Disc"), @@ -212,6 +213,20 @@ screen_song_add_song(const struct mpd_song *song, const mpdclient_t *c) screen_song_append(labels[ARTIST], song->artist, max_label_width); screen_song_append(labels[TITLE], song->title, max_label_width); screen_song_append(labels[ALBUM], song->album, max_label_width); + /* create time string and add it */ + if (song->time != MPD_SONG_NO_TIME) { + char length[16]; + /*write out the time, using hours if time over 60 minutes*/ + if (song->time > 3600) { + g_snprintf(length, sizeof(length), + "%i:%02i:%02i", + song->time/3600, (song->time%3600)/60, song->time%60); + } else { + g_snprintf(length, sizeof(length), + "%i:%02i", song->time/60, song->time%60); + } + screen_song_append(labels[LENGTH], length, max_label_width); + } screen_song_append(labels[COMPOSER], song->composer, max_label_width); screen_song_append(labels[NAME], song->name, max_label_width); screen_song_append(labels[DISC], song->disc, max_label_width); -- 2.30.2