Code

screen_lyrics, screen_song: duplicate "next_song"
[ncmpc.git] / src / screen_song.c
index 29c0f2df7a140d554241df6ddcb1b88f9cbb5b4b..a7d6f8ee4c087c4dbdae4b189c4c528465bd7985 100644 (file)
@@ -1,7 +1,7 @@
 /* ncmpc (Ncurses MPD Client)
  * (c) 2004-2009 The Music Player Daemon Project
  * Project homepage: http://musicpd.org
+
  * This program is free software; you can redistribute it and/or modify
  * it under the terms of the GNU General Public License as published by
  * the Free Software Foundation; either version 2 of the License, or
@@ -28,7 +28,7 @@
 
 static list_window_t *lw;
 
-static const struct mpd_song *next_song;
+static struct mpd_song *next_song;
 
 static struct {
        struct mpd_song *selected_song;
@@ -69,7 +69,7 @@ screen_song_repaint(void)
 
 static const char *
 screen_song_list_callback(unsigned idx, G_GNUC_UNUSED bool *highlight,
-                         G_GNUC_UNUSED void *data)
+                         G_GNUC_UNUSED char** sc, G_GNUC_UNUSED void *data)
 {
        static char buffer[256];
        char *value;
@@ -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);
@@ -284,6 +299,8 @@ screen_song_add_stats(const mpdclient_t *c)
                g_date_strftime(buf, sizeof(buf), "%x", date);
                screen_song_append(labels[DBUPTIME], buf, max_label_width);
                g_date_free(date);
+
+               mpd_freeStats(mpd_stats);
        }
 }
 
@@ -298,7 +315,7 @@ screen_song_update(mpdclient_t *c)
        /* If a song was selected before the song screen was opened */
        if (next_song != NULL) {
                assert(current.selected_song == NULL);
-               current.selected_song = mpd_songDup(next_song);
+               current.selected_song = next_song;
                next_song = NULL;
        }
 
@@ -356,11 +373,11 @@ screen_song_cmd(mpdclient_t *c, command_t cmd)
 #ifdef ENABLE_LYRICS_SCREEN
        case CMD_SCREEN_LYRICS:
                if (current.selected_song != NULL) {
-                       screen_lyrics_switch(c, current.selected_song);
+                       screen_lyrics_switch(c, current.selected_song, false);
                        return true;
                }
                if (current.played_song != NULL) {
-                       screen_lyrics_switch(c, current.played_song);
+                       screen_lyrics_switch(c, current.played_song, true);
                        return true;
                }
                return false;
@@ -409,6 +426,6 @@ screen_song_switch(mpdclient_t *c, const struct mpd_song *song)
        assert(current.selected_song == NULL);
        assert(current.played_song == NULL);
 
-       next_song = song;
+       next_song = mpd_songDup(song);
        screen_switch(&screen_song, c);
 }