Code

New configuraton option: screen-list
authorKalle Wallin <kaw@linux.se>
Wed, 15 Jun 2005 13:04:22 +0000 (13:04 +0000)
committerKalle Wallin <kaw@linux.se>
Wed, 15 Jun 2005 13:04:22 +0000 (13:04 +0000)
git-svn-id: https://svn.musicpd.org/ncmpc/trunk@3358 09075e82-0dd4-0310-85a5-a0d7c8717e4f

ChangeLog
doc/config.sample
src/conf.c
src/ncmpc.h
src/options.c
src/options.h
src/screen.c

index 393bb68094325e890a9eb1395ef5cb7097a6c25d..ed3e6127aea4b8cd9964a50436bb74b18896d746 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -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)
index f3bcab541af3bd872a56735145d5af32f6ef89a5..7be4181c68ccd7054a1725b6eb64f459e1da09ac 100644 (file)
@@ -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
 
index 7e4b4e1aea86da786d83ad57db409c591c3b9f55..73135b8f64ce8875c9e407a9673fc8dbef054bb7 100644 (file)
@@ -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, 
index 194d7ac5cf0f684d72bf13eb4d6c726c91725fcf..4d3b840a524e89df6066c4caeba8e3235c70d021 100644 (file)
@@ -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
 
index e1ed99e632be2a7ccf77248cb48f3fa60fb3b571..dd31203b63bb1210ee77436a4e3d66545f3a45e4 100644 (file)
@@ -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;
 }
index 3f203b09c1793d9dc3046cb03efef8964dbbc644..6acf88b0902ccc03a9754d33fdab619abb61be5e 100644 (file)
@@ -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;
index b5a1d473a4645f303abf67c156c0bf6871d46b0d..b947190011aac6beaf6c1dd71f0390dca3ef5214 100644 (file)
@@ -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)
 {
@@ -139,6 +153,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)
 {
@@ -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);