diff options
-rw-r--r-- | command.c | 18 | ||||
-rw-r--r-- | command.h | 5 | ||||
-rw-r--r-- | list_window.c | 52 | ||||
-rw-r--r-- | list_window.h | 12 | ||||
-rw-r--r-- | options.c | 2 | ||||
-rw-r--r-- | options.h | 1 | ||||
-rw-r--r-- | screen_file.c | 34 | ||||
-rw-r--r-- | screen_help.c | 61 | ||||
-rw-r--r-- | screen_play.c | 29 | ||||
-rw-r--r-- | screen_utils.c | 69 | ||||
-rw-r--r-- | screen_utils.h | 10 |
11 files changed, 198 insertions, 95 deletions
@@ -43,7 +43,7 @@ static command_definition_t cmds[] = { { { 13, 0, 0 }, CMD_PLAY, "Play/Enter directory" }, - { { 'p', 0, 0 }, CMD_PAUSE, "Pause" }, + { { 'P', 0, 0 }, CMD_PAUSE, "Pause" }, { { BS, ESC, 0 }, CMD_STOP, "Stop" }, { { '>', 0, 0 }, CMD_TRACK_NEXT, "Next song" }, { { '<', 0, 0 }, CMD_TRACK_PREVIOUS, "Previous song" }, @@ -51,12 +51,16 @@ static command_definition_t cmds[] = { { '+', RGHT, 0 }, CMD_VOLUME_UP, "Increase volume" }, { { '-', LEFT, 0 }, CMD_VOLUME_DOWN, "Decrease volume" }, - { { ' ', 0, 0 }, CMD_SELECT, "Select/deselect song in playlist" }, + { { 'w', 0, 0 }, CMD_TOGGLE_FIND_WRAP, "Toggle find mode" }, + + { { ' ', 0, 0 }, CMD_SELECT, "Select/deselect song in playlist" }, { { DEL, 0, 0 }, CMD_DELETE, "Delete song from playlist" }, { { 's', 0, 0 }, CMD_SHUFFLE, "Shuffle playlist" }, { { 'c', 0, 0 }, CMD_CLEAR, "Clear playlist" }, { { 'r', 0, 0 }, CMD_REPEAT, "Toggle repeat mode" }, { { 'z', 0, 0 }, CMD_RANDOM, "Toggle random mode" }, + { { 'S', 0, 0 }, CMD_SAVE_PLAYLIST, "Save playlist" }, + { { 'D', 0, 0 }, CMD_DELETE_PLAYLIST, "Delete playlist" }, { { UP, 0, 0 }, CMD_LIST_PREVIOUS, "Move: Up" }, { { DWN, 0, 0 }, CMD_LIST_NEXT, "Move: Down" }, @@ -64,8 +68,10 @@ static command_definition_t cmds[] = { { END, 0, 0 }, CMD_LIST_LAST, "Move: End" }, { { PGUP, 0, 0 }, CMD_LIST_PREVIOUS_PAGE, "Move: Page Up" }, { { PGDN, 0, 0 }, CMD_LIST_NEXT_PAGE, "Move: Page Down" }, - { { '/', 0, 0 }, CMD_LIST_FIND, "Find" }, - { { 'n', 0, 0 }, CMD_LIST_FIND_NEXT, "Find Next" }, + { { '/', 0, 0 }, CMD_LIST_FIND, "Forward Find" }, + { { 'n', 0, 0 }, CMD_LIST_FIND_NEXT, "Forward Find Next" }, + { { '?', 0, 0 }, CMD_LIST_RFIND, "Backward Find" }, + { { 'p', 0, 0 }, CMD_LIST_RFIND_NEXT, "Backward Find Previous" }, { { TAB, 0, 0 }, CMD_SCREEN_NEXT, "Next screen" }, { { STAB, 0, 0 }, CMD_SCREEN_PREVIOUS, "Previous screen" }, @@ -204,8 +210,8 @@ get_keyboard_command(void) DK(fprintf(stderr, "key = 0x%02X\t", key)); - if( isalpha(key) ) - key=tolower(key); + // if( isalpha(key) ) + // key=tolower(key); i=0; while( cmds[i].description ) @@ -15,6 +15,9 @@ typedef enum CMD_REPEAT, CMD_VOLUME_UP, CMD_VOLUME_DOWN, + CMD_SAVE_PLAYLIST, + CMD_DELETE_PLAYLIST, + CMD_TOGGLE_FIND_WRAP, CMD_LIST_PREVIOUS, CMD_LIST_NEXT, CMD_LIST_FIRST, @@ -23,6 +26,8 @@ typedef enum CMD_LIST_PREVIOUS_PAGE, CMD_LIST_FIND, CMD_LIST_FIND_NEXT, + CMD_LIST_RFIND, + CMD_LIST_RFIND_NEXT, CMD_SCREEN_PREVIOUS, CMD_SCREEN_NEXT, CMD_SCREEN_PLAY, diff --git a/list_window.c b/list_window.c index 21ee9119f..ee08a8b81 100644 --- a/list_window.c +++ b/list_window.c @@ -150,20 +150,58 @@ int list_window_find(list_window_t *lw, list_window_callback_fn_t callback, void *callback_data, - char *str) + char *str, + int wrap) { int h; int i = lw->selected+1; char *label; + + while( wrap || i==lw->selected+1 ) + { + while( (label=(callback) (i,&h,callback_data)) ) + { + if( str && label && strcasestr(label, str) ) + { + lw->selected = i; + return 0; + } + i++; + if( wrap && i==lw->selected ) + return 1; + } + i=0; /* first item */ + } + return 1; +} - while( (label=(callback) (i,&h,callback_data)) ) + +int +list_window_rfind(list_window_t *lw, + list_window_callback_fn_t callback, + void *callback_data, + char *str, + int wrap, + int rows) +{ + int h; + int i = lw->selected-1; + char *label; + + while( wrap || i==lw->selected-1 ) { - if( str && label && strcasestr(label, str) ) + while( i>=0 && (label=(callback) (i,&h,callback_data)) ) { - lw->selected = i; - return 0; + if( str && label && strcasestr(label, str) ) + { + lw->selected = i; + return 0; + } + i--; + if( wrap && i==lw->selected ) + return 1; } - i++; + i=rows-1; /* last item */ } return 1; } @@ -204,3 +242,5 @@ list_window_cmd(list_window_t *lw, int rows, command_t cmd) } return 1; } + + diff --git a/list_window.h b/list_window.h index 87bbf826d..ce799c1bd 100644 --- a/list_window.h +++ b/list_window.h @@ -49,6 +49,16 @@ void list_window_next_page(list_window_t *lw, int length); int list_window_find(list_window_t *lw, list_window_callback_fn_t callback, void *callback_data, - char *str); + char *str, + int wrap); + +/* find a string in a list window (reversed) */ +int +list_window_rfind(list_window_t *lw, + list_window_callback_fn_t callback, + void *callback_data, + char *str, + int wrap, + int rows); #endif @@ -105,7 +105,9 @@ options_init( void ) options.port = atoi(value); else options.port = DEFAULT_PORT; + options.reconnect = 1; + options.find_wrap = 1; options.bg_color = COLOR_BLACK; options.title_color = COLOR_BLUE; @@ -11,6 +11,7 @@ typedef struct int port; int reconnect; int debug; + int find_wrap; int enable_colors; int bg_color; diff --git a/screen_file.c b/screen_file.c index 9d2dffbc8..e3de2d051 100644 --- a/screen_file.c +++ b/screen_file.c @@ -31,7 +31,7 @@ list_callback(int index, int *highlight, void *data) if( entity == NULL ) { - return "[Back]"; + return "[..]"; } if( entity->type==MPD_INFO_ENTITY_TYPE_DIRECTORY ) { @@ -52,7 +52,7 @@ list_callback(int index, int *highlight, void *data) mpd_PlaylistFile *plf = entity->info.playlistFile; char *filename = utf8_to_locale(basename(plf->path)); - snprintf(buf, BUFSIZE, "%s*", filename); + snprintf(buf, BUFSIZE, "*%s*", filename); free(filename); return buf; } @@ -342,29 +342,17 @@ file_cmd(screen_t *screen, mpd_client_t *c, command_t cmd) cmd = CMD_LIST_NEXT; } break; + case CMD_DELETE_PLAYLIST: + screen_status_printf("Sorry, command not implemented yet!"); + return 1; + break; case CMD_LIST_FIND: - if( screen->findbuf ) - { - free(screen->findbuf); - screen->findbuf=NULL; - } - /* continue... */ + case CMD_LIST_RFIND: case CMD_LIST_FIND_NEXT: - if( !screen->findbuf ) - screen->findbuf=screen_readln(screen->status_window.w, "/"); - if( list_window_find(screen->filelist, - list_callback, - c, - screen->findbuf) == 0 ) - { - screen->filelist->repaint = 1; - } - else - { - screen_status_printf("Unable to find \'%s\'", screen->findbuf); - beep(); - } - return 1; + case CMD_LIST_RFIND_NEXT: + return screen_find(screen, c, + screen->filelist, c->filelist_length, + cmd, list_callback); default: break; } diff --git a/screen_help.c b/screen_help.c index 5320647be..34a007c0a 100644 --- a/screen_help.c +++ b/screen_help.c @@ -32,7 +32,10 @@ static help_text_row_t help_text[] = { 0, CMD_LIST_NEXT, "Move cursor up" }, { 0, CMD_LIST_PREVIOUS, "Move cursor down" }, { 0, CMD_LIST_FIND, "Find" }, - { 0, CMD_LIST_FIND_NEXT, "Find again" }, + { 0, CMD_LIST_RFIND, "find backward" }, + { 0, CMD_LIST_FIND_NEXT, "Find next" }, + { 0, CMD_LIST_RFIND_NEXT,"Find previuos" }, + { 0, CMD_TOGGLE_FIND_WRAP, "Toggle find mode" }, { 0, CMD_NONE, " " }, { 0, CMD_SCREEN_NEXT, "Change screen" }, { 0, CMD_SCREEN_HELP, "Help screen" }, @@ -43,18 +46,20 @@ static help_text_row_t help_text[] = { 0, CMD_NONE, " " }, { 1, CMD_NONE, " Keys - Playlist screen " }, { 0, CMD_NONE, " --------------------------" }, - { 0, CMD_PLAY, "Play selected entry" }, - { 0, CMD_DELETE, "Delete selected entry from platlist" }, - { 0, CMD_SHUFFLE, "Shuffle playlist" }, - { 0, CMD_CLEAR, "Clear playlist" }, - { 0, CMD_REPEAT, "Toggle repeat mode" }, - { 0, CMD_RANDOM, "Toggle random mode" }, + { 0, CMD_PLAY, "Play selected entry" }, + { 0, CMD_DELETE, "Delete selected entry from playlist" }, + { 0, CMD_SHUFFLE, "Shuffle playlist" }, + { 0, CMD_CLEAR, "Clear playlist" }, + { 0, CMD_SAVE_PLAYLIST, "Save playlist" }, + { 0, CMD_REPEAT, "Toggle repeat mode" }, + { 0, CMD_RANDOM, "Toggle random mode" }, { 0, CMD_NONE, " " }, { 0, CMD_NONE, " " }, { 1, CMD_NONE, " Keys - Browse screen " }, { 0, CMD_NONE, " ------------------------" }, - { 0, CMD_PLAY, "Change to selected directory" }, - { 0, CMD_SELECT, "Add/Remove selected file" }, + { 0, CMD_PLAY, "Enter directory/Load playlist" }, + { 0, CMD_SELECT, "Add/remove song from playlist" }, + { 0, CMD_DELETE_PLAYLIST, "Delete playlist" }, { 0, CMD_NONE, " " }, { 0, CMD_NONE, " " }, { 1, CMD_NONE, " " PACKAGE " version " VERSION }, @@ -131,33 +136,13 @@ help_update(screen_t *screen, mpd_client_t *c) int help_cmd(screen_t *screen, mpd_client_t *c, command_t cmd) { - switch(cmd) - { - case CMD_LIST_FIND: - if( screen->findbuf ) - { - free(screen->findbuf); - screen->findbuf=NULL; - } - /* continue... */ - case CMD_LIST_FIND_NEXT: - if( !screen->findbuf ) - screen->findbuf=screen_readln(screen->status_window.w, "/"); - if( list_window_find(screen->helplist, - list_callback, - c, - screen->findbuf) == 0 ) - { - screen->helplist->repaint = 1; - } - else - { - screen_status_printf("Unable to find \'%s\'", screen->findbuf); - beep(); - } - return 1; - default: - break; - } - return list_window_cmd(screen->helplist, help_text_rows, cmd); + int retval; + + retval = list_window_cmd(screen->helplist, help_text_rows, cmd); + if( !retval ) + return screen_find(screen, c, + screen->helplist, help_text_rows, + cmd, list_callback); + + return retval; } diff --git a/screen_play.c b/screen_play.c index 48dc86961..c52c2d165 100644 --- a/screen_play.c +++ b/screen_play.c @@ -92,29 +92,16 @@ play_cmd(screen_t *screen, mpd_client_t *c, command_t cmd) screen_status_printf("Removed \'%s\' from playlist!", mpc_get_song_name(song)); return 1; + case CMD_SAVE_PLAYLIST: + screen_status_printf("Sorry, playlist saving not implemented yet!"); + return 1; case CMD_LIST_FIND: - if( screen->findbuf ) - { - free(screen->findbuf); - screen->findbuf=NULL; - } - /* continue... */ + case CMD_LIST_RFIND: case CMD_LIST_FIND_NEXT: - if( !screen->findbuf ) - screen->findbuf=screen_readln(screen->status_window.w, "/"); - if( list_window_find(screen->playlist, - list_callback, - c, - screen->findbuf) == 0 ) - { - screen->playlist->repaint = 1; - } - else - { - screen_status_printf("Unable to find \'%s\'", screen->findbuf); - beep(); - } - return 1; + case CMD_LIST_RFIND_NEXT: + return screen_find(screen, c, + screen->playlist, c->playlist_length, + cmd, list_callback); default: break; } diff --git a/screen_utils.c b/screen_utils.c index 648291f03..9feda742a 100644 --- a/screen_utils.c +++ b/screen_utils.c @@ -9,8 +9,12 @@ #include "support.h" #include "command.h" #include "options.h" +#include "list_window.h" #include "screen.h" +#define FIND_PROMPT "Find: " +#define RFIND_PROMPT "Find backward: " + char * screen_readln(WINDOW *w, char *prompt) { @@ -34,6 +38,70 @@ screen_readln(WINDOW *w, char *prompt) return line; } + +/* query user for a string and find it in a list window */ +int +screen_find(screen_t *screen, + mpd_client_t *c, + list_window_t *lw, + int rows, + command_t findcmd, + list_window_callback_fn_t callback_fn) +{ + int reversed = 0; + int retval = 0; + char *prompt = FIND_PROMPT; + + if( findcmd==CMD_LIST_RFIND ||findcmd==CMD_LIST_RFIND_NEXT ) + { + prompt = RFIND_PROMPT; + reversed = 1; + } + + switch(findcmd) + { + case CMD_LIST_FIND: + case CMD_LIST_RFIND: + if( screen->findbuf ) + { + free(screen->findbuf); + screen->findbuf=NULL; + } + /* continue... */ + case CMD_LIST_FIND_NEXT: + case CMD_LIST_RFIND_NEXT: + if( !screen->findbuf ) + screen->findbuf=screen_readln(screen->status_window.w, prompt); + if( reversed ) + retval = list_window_rfind(lw, + callback_fn, + c, + screen->findbuf, + options.find_wrap, + rows); + else + retval = list_window_find(lw, + callback_fn, + c, + screen->findbuf, + options.find_wrap); + if( retval == 0 ) + { + lw->repaint = 1; + } + else + { + screen_status_printf("Unable to find \'%s\'", screen->findbuf); + beep(); + } + return 1; + default: + break; + } + return 0; +} + + int my_waddstr(WINDOW *w, const char *text, int color) { @@ -61,3 +129,4 @@ my_mvwaddstr(WINDOW *w, int x, int y, const char *text, int color) return ret; } + diff --git a/screen_utils.h b/screen_utils.h index a03c36d47..87cb6e04c 100644 --- a/screen_utils.h +++ b/screen_utils.h @@ -1,5 +1,15 @@ +/* read a string from the status window */ char *screen_readln(WINDOW *w, char *prompt); +/* query user for a string and find it in a list window */ +int screen_find(screen_t *screen, + mpd_client_t *c, + list_window_t *lw, + int rows, + command_t findcmd, + list_window_callback_fn_t callback_fn); + + int my_waddstr(WINDOW *, const char *, int); int my_mvwaddstr(WINDOW *, int, int, const char *, int); |