diff options
author | Kalle Wallin <kaw@linux.se> | 2005-06-15 13:04:22 +0000 |
---|---|---|
committer | Kalle Wallin <kaw@linux.se> | 2005-06-15 13:04:22 +0000 |
commit | c94d06df7370bfe88f6a42f22142f05927c5c44b (patch) | |
tree | a1be838de371da566b4acb6b52e68b08fcb0dcef | |
parent | 7c9aa09019ac6ab2cdf847d785c2dc127a46ac94 (diff) | |
download | mpd-c94d06df7370bfe88f6a42f22142f05927c5c44b.tar.gz mpd-c94d06df7370bfe88f6a42f22142f05927c5c44b.tar.xz mpd-c94d06df7370bfe88f6a42f22142f05927c5c44b.zip |
New configuraton option: screen-list
git-svn-id: https://svn.musicpd.org/ncmpc/trunk@3358 09075e82-0dd4-0310-85a5-a0d7c8717e4f
-rw-r--r-- | ChangeLog | 6 | ||||
-rw-r--r-- | doc/config.sample | 5 | ||||
-rw-r--r-- | src/conf.c | 49 | ||||
-rw-r--r-- | src/ncmpc.h | 3 | ||||
-rw-r--r-- | src/options.c | 1 | ||||
-rw-r--r-- | src/options.h | 1 | ||||
-rw-r--r-- | src/screen.c | 59 |
7 files changed, 114 insertions, 10 deletions
@@ -1,5 +1,11 @@ +2005-06-15: Kalle Wallin <kaw@linux.se> + * Added configuraton option screen-list + 2005-06-14: Kalle Wallin <kaw@linux.se> * Moved list window state code to list_window.c + * mpdclient.c: added exact_match parameter to + mpdclient_filelist_search() + * screen_artist.c: support adding of artists and albums (all songs) 2005-06-11: Kalle Wallin <kaw@linux.se> * configure.ac: support wide-char ncurses library (--with-ncursesw) diff --git a/doc/config.sample b/doc/config.sample index f3bcab541..7be4181c6 100644 --- a/doc/config.sample +++ b/doc/config.sample @@ -2,6 +2,11 @@ ## Configuration file for ncmpc (~/.ncmpc/config) ## +## screen list - used when navigating with next-screen (tab) and +## previous-screen (shift+tab) +## names: playlist browse help artist clock +#screen-list = playlist artist + ## auto center (center the playing track in the playlist) #auto-center = no diff --git a/src/conf.c b/src/conf.c index 7e4b4e1ae..73135b8f6 100644 --- a/src/conf.c +++ b/src/conf.c @@ -62,6 +62,7 @@ #define CONF_SEARCH_MODE "search-mode" #define CONF_HIDE_CURSOR "hide-cursor" #define CONF_SEEK_TIME "seek-time" +#define CONF_SCREEN_LIST "screen-list" typedef enum { KEY_PARSER_UNKNOWN, @@ -71,6 +72,10 @@ typedef enum { KEY_PARSER_DONE } key_parser_state_t; + +extern gint screen_get_id(char *name); + + static gboolean str2bool(char *str) { @@ -314,6 +319,36 @@ get_format(char *str) return g_strdup(str); } +static char ** +check_screen_list(char *value) +{ + char **tmp = g_strsplit_set(value, " \t,", 100); + char **screen = NULL; + int i,j; + + i=0; + j=0; + while( tmp && tmp[i] ) + { + tmp[i] = lowerstr(tmp[i]); + if( screen_get_id(tmp[i]) == -1 ) + fprintf(stderr, + _("Error: Unsupported screen \"%s\"\n"), + tmp[i]); + else + { + screen = g_realloc(screen, (j+2)*sizeof(char *)); + screen[j++] = g_strdup(tmp[i]); + screen[j] = NULL; + } + i++; + } + g_strfreev(tmp); + if( screen == NULL ) + return g_strsplit_set(DEFAULT_SCREEN_LIST, " ", 0); + + return screen; +} static int read_rc_file(char *filename, options_t *options) @@ -487,11 +522,23 @@ read_rc_file(char *filename, options_t *options) { options->seek_time = atoi(value); } + else if( !strcasecmp(CONF_SCREEN_LIST, name) ) + { + g_strfreev(options->screen_list); + options->screen_list = check_screen_list(value); + +#ifdef DEBUG + D("screen-list:"); + j=0; + while(options->screen_list[j]) + D(" %s", options->screen_list[j++]); + D("\n"); +#endif + } else { match_found = 0; } - if( !match_found ) fprintf(stderr, diff --git a/src/ncmpc.h b/src/ncmpc.h index 194d7ac5c..4d3b840a5 100644 --- a/src/ncmpc.h +++ b/src/ncmpc.h @@ -45,6 +45,9 @@ void D(char *format, ...); /* welcome message time [s] */ #define SCREEN_WELCOME_TIME 10 +/* screen list */ +#define DEFAULT_SCREEN_LIST "playlist browse" + /* status message time [s] */ #define SCREEN_STATUS_MESSAGE_TIME 3 diff --git a/src/options.c b/src/options.c index e1ed99e63..dd31203b6 100644 --- a/src/options.c +++ b/src/options.c @@ -367,6 +367,7 @@ options_init( void ) options.audible_bell = TRUE; options.crossfade_time = DEFAULT_CROSSFADE_TIME; options.seek_time = 1; + options.screen_list = g_strsplit_set(DEFAULT_SCREEN_LIST, " ", 0); return &options; } diff --git a/src/options.h b/src/options.h index 3f203b09c..6acf88b09 100644 --- a/src/options.h +++ b/src/options.h @@ -12,6 +12,7 @@ typedef struct char *list_format; char *status_format; char *xterm_title_format; + char **screen_list; int port; int crossfade_time; int search_mode; diff --git a/src/screen.c b/src/screen.c index b5a1d473a..b94719001 100644 --- a/src/screen.c +++ b/src/screen.c @@ -74,10 +74,10 @@ typedef struct static screen_mode_info_t screens[] = { { SCREEN_PLAYLIST_ID, "playlist", get_screen_playlist }, { SCREEN_BROWSE_ID, "browse", get_screen_browse }, - { SCREEN_HELP_ID, "help", get_screen_help }, #ifdef ENABLE_ARTIST_SCREEN { SCREEN_ARTIST_ID, "artist", get_screen_artist }, #endif + { SCREEN_HELP_ID, "help", get_screen_help }, #ifdef ENABLE_SEARCH_SCREEN { SCREEN_SEARCH_ID, "search", get_screen_search }, #endif @@ -96,6 +96,20 @@ static screen_functions_t *mode_fn = NULL; static int seek_id = -1; static int seek_target_time = 0; +gint +screen_get_id(char *name) +{ + gint i=0; + + while( screens[i].name ) + { + if( strcmp(name, screens[i].name) == 0 ) + return screens[i].id; + i++; + } + return -1; +} + static gint lookup_mode(gint id) { @@ -140,6 +154,32 @@ switch_screen_mode(gint id, mpdclient_t *c) } static void +screen_next_mode(mpdclient_t *c, int offset) +{ + int max = g_strv_length(options.screen_list); + int current, next; + int i; + + /* find current screen */ + current = -1; + i = 0; + while( options.screen_list[i] ) + { + if( strcmp(options.screen_list[i], screens[screen->mode].name) == 0 ) + current = i; + i++; + } + next = current + offset; + if( next<0 ) + next = max-1; + else if( next>=max ) + next = 0; + + D("current mode: %d:%d next:%d\n", current, max, next); + switch_screen_mode(screen_get_id(options.screen_list[next]), c); +} + +static void paint_top_window(char *header, mpdclient_t *c, int clear) { char flags[5]; @@ -590,7 +630,14 @@ screen_init(mpdclient_t *c) i++; } +#if 0 + /* broken */ + mode_fn = NULL; + switch_screen_mode(screen_get_id(options.screen_list[0]), c); +#else mode_fn = get_screen_playlist(); +#endif + if( mode_fn && mode_fn->open ) mode_fn->open(screen, c); @@ -877,16 +924,10 @@ screen_cmd(mpdclient_t *c, command_t cmd) screen->painted = 0; break; case CMD_SCREEN_PREVIOUS: - if( screen->mode > 0 ) - switch_screen_mode(screens[screen->mode-1].id, c); - else - switch_screen_mode(lookup_mode(SCREEN_HELP_ID)-1, c); + screen_next_mode(c, -1); break; case CMD_SCREEN_NEXT: - if( screens[screen->mode+1].id < SCREEN_HELP_ID ) - switch_screen_mode(screens[screen->mode+1].id, c); - else - switch_screen_mode(screens[0].id, c); + screen_next_mode(c, 1); break; case CMD_SCREEN_PLAY: switch_screen_mode(SCREEN_PLAYLIST_ID, c); |