Code

command: added CMD_LOCATE to locate song in database
authorMax Kellermann <max@duempel.org>
Tue, 18 Nov 2008 20:51:57 +0000 (21:51 +0100)
committerMax Kellermann <max@duempel.org>
Tue, 18 Nov 2008 20:51:57 +0000 (21:51 +0100)
Pressing 'l' switches to the file browser (screen_file) and locates
the previously selected song in the server's database.

src/command.c
src/command.h
src/screen.h
src/screen_browser.c
src/screen_file.c
src/screen_help.c
src/screen_lyrics.c
src/screen_play.c

index 92ee27ea072f22e797798d87585f8a40207a0c99..0168b057b37ceaa68efda15cdf97034acb9cbd79 100644 (file)
@@ -142,6 +142,9 @@ static command_definition_t cmds[] = {
        { { '"', 0, 0 }, 0, CMD_GO_PARENT_DIRECTORY, "go-parent-directory",
          N_("Go to parent directory") },
 
+       { { 'l', 0, 0 }, 0, CMD_LOCATE, "locate",
+         N_("Locate song in browser") },
+
        /* lists */
        { { 11, 0, 0 }, 0, CMD_LIST_MOVE_UP, "move-up",
          N_("Move item up") },
index 8cfe9d03b62a909c6d363ad61a386e928bfd11b3..6bfcb027ed79ff911926ad739d98bcc54cc3e33c 100644 (file)
@@ -62,6 +62,7 @@ typedef enum {
        CMD_INTERRUPT,
        CMD_GO_ROOT_DIRECTORY,
        CMD_GO_PARENT_DIRECTORY,
+       CMD_LOCATE,
        CMD_QUIT
 } command_t;
 
index 404d0a8d565ce49fed7142d4a56a35fac0d7f26f..5eb6cba207b98929db3ad8d5f5b92f7349fcbc74 100644 (file)
@@ -95,6 +95,8 @@ screen_is_visible(const struct screen_functions *sf);
 
 int screen_get_mouse_event(mpdclient_t *c, unsigned long *bstate, int *row);
 
+bool
+screen_file_goto_song(struct mpdclient *c, const struct mpd_song *song);
 
 #ifdef ENABLE_LYRICS_SCREEN
 void
index 6a5bbd2331f549b57edb25b3e645e0bbc24a29b2..63e8c1c71a3e872f4cc7f0eca4bd9300fba25eab 100644 (file)
@@ -531,6 +531,15 @@ browser_cmd(struct screen_browser *browser,
                return true;
 #endif
 
+       case CMD_LOCATE:
+               entry = browser_get_selected(browser);
+               if (entry == NULL || entry->entity == NULL ||
+                   entry->entity->type != MPD_INFO_ENTITY_TYPE_SONG)
+                       return false;
+
+               screen_file_goto_song(c, entry->entity->info.song);
+               return true;
+
 #ifdef ENABLE_LYRICS_SCREEN
        case CMD_SCREEN_LYRICS:
                entry = browser_get_selected(browser);
index aabac7afa9cc1da019dd3124f27a4eea74e6c574..a934ef2763ffa79c271be662cf05154045d3ef5e 100644 (file)
@@ -219,6 +219,12 @@ browse_cmd(mpdclient_t *c, command_t cmd)
                file_repaint();
                return 1;
 
+       case CMD_LOCATE:
+               /* don't let browser_cmd() evaluate the locate command
+                  - it's a no-op, and by the way, leads to a
+                  segmentation fault in the current implementation */
+               return false;
+
        case CMD_DELETE:
                handle_delete(c);
                file_repaint();
@@ -283,3 +289,44 @@ const struct screen_functions screen_browse = {
        .cmd = browse_cmd,
        .get_title = browse_title,
 };
+
+bool
+screen_file_goto_song(struct mpdclient *c, const struct mpd_song *song)
+{
+       const char *slash, *parent;
+       char *allocated = NULL;
+       bool ret;
+       int i;
+
+       assert(song != NULL);
+       assert(song->file != NULL);
+
+       if (strstr(song->file, "//") != NULL)
+               /* an URL? */
+               return false;
+
+       /* determine the song's parent directory and go there */
+
+       slash = strrchr(song->file, '/');
+       if (slash != NULL)
+               parent = allocated = g_strndup(song->file, slash - song->file);
+       else
+               parent = "";
+
+       ret = browser_change_directory(&browser, c, NULL, parent);
+       g_free(allocated);
+       if (!ret)
+               return false;
+
+       /* select the specified song */
+
+       i = filelist_find_song(browser.filelist, song);
+       if (i < 0)
+               i = 0;
+
+       list_window_set_selected(browser.lw, i);
+
+       /* finally, switch to the file screen */
+       screen_switch(&screen_browse, c);
+       return true;
+}
index 1f0043c094b719ba06deeb91ff95d52bf6770a0f..e462ddc907897d86dfdd109e72f121015ba0c41e 100644 (file)
@@ -81,6 +81,7 @@ static help_text_row_t help_text[] = {
        { 0, CMD_LIST_FIND_NEXT, NULL },
        { 0, CMD_LIST_RFIND_NEXT, NULL },
        { 0, CMD_TOGGLE_FIND_WRAP, NULL },
+       { 0, CMD_LOCATE, NULL },
        { 0, CMD_NONE, NULL },
        { 0, CMD_QUIT, NULL },
 
index ab9dfdedaefbaf9c0f3b8faa830279eb799b907c..30a89a163973ddaf8f29143bf2bd5c88fdea20f1 100644 (file)
@@ -329,6 +329,15 @@ lyrics_cmd(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;
        }
index 4c21a17697b8b657ab6299fdb7c00d9c641bcec5..1e0dcaa280759c05d74fd02246f1ac1ab592c895 100644 (file)
@@ -554,6 +554,14 @@ play_cmd(mpdclient_t *c, command_t cmd)
                return handle_mouse_event(c);
 #endif
 
+       case CMD_LOCATE:
+               if (lw->selected < playlist_length(&c->playlist)) {
+                       screen_file_goto_song(c, playlist_get(&c->playlist, lw->selected));
+                       return true;
+               }
+
+               break;
+
 #ifdef ENABLE_LYRICS_SCREEN
        case CMD_SCREEN_LYRICS:
                if (lw->selected < playlist_length(&c->playlist)) {