Code

command: added CMD_LOCATE to locate song in database
[ncmpc.git] / src / screen_lyrics.c
index b1812de31154764efee7db1925bef9296f7d4f2f..30a89a163973ddaf8f29143bf2bd5c88fdea20f1 100644 (file)
@@ -33,7 +33,6 @@
 #include <stdlib.h>
 #include <string.h>
 #include <glib.h>
-#include <ncurses.h>
 #include <unistd.h>
 #include <stdio.h>
 
@@ -42,7 +41,7 @@ static list_window_t *lw = NULL;
 static const struct mpd_song *next_song;
 
 static struct {
-       const struct mpd_song *song;
+       struct mpd_song *song;
 
        char *artist, *title;
 
@@ -69,7 +68,10 @@ screen_lyrics_abort(void)
                current.artist = NULL;
        }
 
-       current.song = NULL;
+       if (current.song != NULL) {
+               mpd_freeSong(current.song);
+               current.song = NULL;
+       }
 }
 
 static void
@@ -84,7 +86,7 @@ screen_lyrics_clear(void)
 }
 
 static void
-lyrics_paint(mpdclient_t *c);
+lyrics_paint(void);
 
 /**
  * Repaint and update the screen.
@@ -92,7 +94,7 @@ lyrics_paint(mpdclient_t *c);
 static void
 lyrics_repaint(void)
 {
-       lyrics_paint(NULL);
+       lyrics_paint();
        wrefresh(lw->w);
 }
 
@@ -176,7 +178,7 @@ screen_lyrics_load(const struct mpd_song *song)
        screen_lyrics_abort();
        screen_lyrics_clear();
 
-       current.song = song;
+       current.song = mpd_songDup(song);
 
        strfsong(buffer, sizeof(buffer), "%artist%", song);
        current.artist = g_strdup(buffer);
@@ -264,12 +266,14 @@ lyrics_exit(void)
 }
 
 static void
-lyrics_open(mpd_unused screen_t *screen, mpdclient_t *c)
+lyrics_open(mpdclient_t *c)
 {
        if (next_song == NULL)
                next_song = c->song;
 
-       if (next_song != NULL && next_song != current.song)
+       if (next_song != NULL &&
+           (current.song == NULL ||
+            strcmp(next_song->file, current.song->file) != 0))
                screen_lyrics_load(next_song);
 
        next_song = NULL;
@@ -279,25 +283,28 @@ lyrics_open(mpd_unused screen_t *screen, mpdclient_t *c)
 static const char *
 lyrics_title(char *str, size_t size)
 {
-       if (current.loader != NULL)
-               return "Lyrics (loading)";
-       else if (current.artist != NULL && current.title != NULL &&
-                current.lines->len > 0) {
-               snprintf(str, size, "Lyrics: %s - %s",
+       if (current.loader != NULL) {
+               snprintf(str, size, "%s (%s)",
+                        _("Lyrics"), _("loading..."));
+               return str;
+       } else if (current.artist != NULL && current.title != NULL &&
+                  current.lines->len > 0) {
+               snprintf(str, size, "%s: %s - %s",
+                        _("Lyrics"),
                         current.artist, current.title);
                return str;
        } else
-               return "Lyrics";
+               return _("Lyrics");
 }
 
 static void
-lyrics_paint(mpd_unused mpdclient_t *c)
+lyrics_paint(void)
 {
        list_window_paint(lw, list_callback, NULL);
 }
 
 static int
-lyrics_cmd(screen_t *screen, mpdclient_t *c, command_t cmd)
+lyrics_cmd(mpdclient_t *c, command_t cmd)
 {
        if (list_window_scroll_cmd(lw, current.lines->len, cmd)) {
                lyrics_repaint();
@@ -322,13 +329,21 @@ lyrics_cmd(screen_t *screen, mpdclient_t *c, command_t cmd)
                        lyrics_repaint();
                }
                return 1;
+
+       case CMD_LOCATE:
+               if (current.song != NULL) {
+                       screen_file_goto_song(c, current.song);
+                       return true;
+               }
+
+               return false;
+
        default:
                break;
        }
 
        lw->selected = lw->start+lw->rows;
-       if (screen_find(screen,
-                       lw, current.lines->len,
+       if (screen_find(lw, current.lines->len,
                        cmd, list_callback, NULL)) {
                /* center the row */
                list_window_center(lw, current.lines->len, lw->selected);