From: Max Kellermann Date: Tue, 18 Nov 2008 20:51:57 +0000 (+0100) Subject: command: added CMD_LOCATE to locate song in database X-Git-Tag: v0.12_beta1~42 X-Git-Url: https://git.tokkee.org/?a=commitdiff_plain;h=299a27c8dee0e7eeab3448ed7cdfe1ac7c97ebaf;p=ncmpc.git command: added CMD_LOCATE to locate song in database Pressing 'l' switches to the file browser (screen_file) and locates the previously selected song in the server's database. --- diff --git a/src/command.c b/src/command.c index 92ee27e..0168b05 100644 --- a/src/command.c +++ b/src/command.c @@ -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") }, diff --git a/src/command.h b/src/command.h index 8cfe9d0..6bfcb02 100644 --- a/src/command.h +++ b/src/command.h @@ -62,6 +62,7 @@ typedef enum { CMD_INTERRUPT, CMD_GO_ROOT_DIRECTORY, CMD_GO_PARENT_DIRECTORY, + CMD_LOCATE, CMD_QUIT } command_t; diff --git a/src/screen.h b/src/screen.h index 404d0a8..5eb6cba 100644 --- a/src/screen.h +++ b/src/screen.h @@ -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 diff --git a/src/screen_browser.c b/src/screen_browser.c index 6a5bbd2..63e8c1c 100644 --- a/src/screen_browser.c +++ b/src/screen_browser.c @@ -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); diff --git a/src/screen_file.c b/src/screen_file.c index aabac7a..a934ef2 100644 --- a/src/screen_file.c +++ b/src/screen_file.c @@ -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; +} diff --git a/src/screen_help.c b/src/screen_help.c index 1f0043c..e462ddc 100644 --- a/src/screen_help.c +++ b/src/screen_help.c @@ -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 }, diff --git a/src/screen_lyrics.c b/src/screen_lyrics.c index ab9dfde..30a89a1 100644 --- a/src/screen_lyrics.c +++ b/src/screen_lyrics.c @@ -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; } diff --git a/src/screen_play.c b/src/screen_play.c index 4c21a17..1e0dcaa 100644 --- a/src/screen_play.c +++ b/src/screen_play.c @@ -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)) {