Code

due to bensonk's demand i added a splash screen.
[ncmpc.git] / src / screen.c
index 0c56a7420433f5567473624e40909f2ce5efbb98..7f21ec934a39fc667f666e44269e28d82dbf0d05 100644 (file)
 #include "screen.h"
 #include "screen_utils.h"
 
-#define MAX_SONGNAME_LENGTH   512
 
 #define SCREEN_PLAYLIST_ID     0
 #define SCREEN_BROWSE_ID       1
+#define SCREEN_ARTIST_ID       2
 #define SCREEN_HELP_ID         100
 #define SCREEN_KEYDEF_ID       101
 #define SCREEN_CLOCK_ID        102
 #define SCREEN_SEARCH_ID       103
+#define SCREEN_LYRICS_ID          104  
+
 
 
 /* screens */
@@ -55,8 +57,10 @@ extern screen_functions_t *get_screen_playlist(void);
 extern screen_functions_t *get_screen_browse(void);
 extern screen_functions_t *get_screen_help(void);
 extern screen_functions_t *get_screen_search(void);
+extern screen_functions_t *get_screen_artist(void);
 extern screen_functions_t *get_screen_keydef(void);
 extern screen_functions_t *get_screen_clock(void);
+extern screen_functions_t *get_screen_lyrics(void);
 
 typedef screen_functions_t * (*screen_get_mode_functions_fn_t) (void);
 
@@ -71,6 +75,9 @@ typedef struct
 static screen_mode_info_t screens[] = {
   { SCREEN_PLAYLIST_ID, "playlist", get_screen_playlist },
   { SCREEN_BROWSE_ID,   "browse",   get_screen_browse },
+#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 },
@@ -80,6 +87,9 @@ static screen_mode_info_t screens[] = {
 #endif
 #ifdef ENABLE_CLOCK_SCREEN
   { SCREEN_CLOCK_ID,    "clock",    get_screen_clock },
+#endif
+  #ifdef ENABLE_LYRICS_SCREEN
+  { SCREEN_LYRICS_ID,    "lyrics",    get_screen_lyrics },
 #endif
   { G_MAXINT, NULL,      NULL }
 };
@@ -90,6 +100,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)
 {
@@ -104,6 +128,10 @@ lookup_mode(gint id)
   return -1;
 }
 
+gint get_cur_mode_id()
+{
+       return screens[screen->mode].id;
+}
 static void
 switch_screen_mode(gint id, mpdclient_t *c)
 {
@@ -133,6 +161,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)
 {
@@ -141,9 +195,9 @@ paint_top_window(char *header, mpdclient_t *c, int clear)
   static int prev_header_len = -1;
   WINDOW *w = screen->top_window.w;
 
-  if(prev_header_len!=strlen(header))
+  if(prev_header_len!=my_strlen(header))
     {
-      prev_header_len = strlen(header);
+      prev_header_len = my_strlen(header);
       clear = 1;
     }
 
@@ -176,11 +230,23 @@ paint_top_window(char *header, mpdclient_t *c, int clear)
          waddstr(w, get_key_names(CMD_SCREEN_FILE, FALSE));
          colors_use(w, COLOR_TITLE);
          waddstr(w, _(":Browse  "));
+#ifdef ENABLE_ARTIST_SCREEN
+         colors_use(w, COLOR_TITLE_BOLD);
+         waddstr(w, get_key_names(CMD_SCREEN_ARTIST, FALSE));
+         colors_use(w, COLOR_TITLE);
+         waddstr(w, _(":Artist  "));
+#endif
 #ifdef ENABLE_SEARCH_SCREEN
          colors_use(w, COLOR_TITLE_BOLD);
          waddstr(w, get_key_names(CMD_SCREEN_SEARCH, FALSE));
          colors_use(w, COLOR_TITLE);
          waddstr(w, _(":Search  "));
+#endif
+#ifdef ENABLE_LYRICS_SCREEN
+         colors_use(w, COLOR_TITLE_BOLD);
+         waddstr(w, get_key_names(CMD_SCREEN_LYRICS, FALSE));
+         colors_use(w, COLOR_TITLE);
+         waddstr(w, _(":Lyrics  "));
 #endif
        }
       if( c->status->volume==MPD_STATUS_NO_VOLUME )
@@ -192,7 +258,7 @@ paint_top_window(char *header, mpdclient_t *c, int clear)
          g_snprintf(buf, 32, _(" Volume %d%%"), c->status->volume); 
        }
       colors_use(w, COLOR_TITLE);
-      mvwaddstr(w, 0, screen->top_window.cols-strlen(buf), buf);
+      mvwaddstr(w, 0, screen->top_window.cols-my_strlen(buf), buf);
 
       flags[0] = 0;
       if( c->status->repeat )
@@ -254,8 +320,9 @@ paint_status_window(mpdclient_t *c)
   WINDOW *w = screen->status_window.w;
   mpd_Status *status = c->status;
   mpd_Song *song   = c->song;
-  int elapsedTime = c->status->elapsedTime;
+  int elapsedTime = 0;
   char *str = NULL;
+  char *timestr = NULL;
   int x = 0;
 
   if( time(NULL) - screen->status_timestamp <= SCREEN_STATUS_MESSAGE_TIME )
@@ -281,7 +348,7 @@ paint_status_window(mpdclient_t *c)
   if( str )
     {
       waddstr(w, str);
-      x += strlen(str)+1;
+      x += my_strlen(str)+1;
     }
 
   /* create time string */
@@ -289,11 +356,24 @@ paint_status_window(mpdclient_t *c)
   if( IS_PLAYING(status->state) || IS_PAUSED(status->state) )
     {
       if( status->totalTime > 0 )
-       {
-         if( c->song && seek_id == c->song->id )
+        {
+       
+       /*checks the conf to see whether to display elapsed or remaining time */
+       if(!strcmp(options.timedisplay_type,"elapsed"))
+          {
+             timestr= " [%i:%02i/%i:%02i]";        
+             elapsedTime = c->status->elapsedTime;
+          }
+        else if(!strcmp(options.timedisplay_type,"remaining"))
+          {
+            timestr= " [-%i:%02i/%i:%02i]";        
+            elapsedTime = (c->status->totalTime - c->status->elapsedTime);
+          }  
+       if( c->song && seek_id == c->song->id )
            elapsedTime = seek_target_time;
+       /*write out the time*/
          g_snprintf(screen->buf, screen->buf_size, 
-                  " [%i:%02i/%i:%02i]",
+                  timestr,
                   elapsedTime/60, elapsedTime%60,
                   status->totalTime/60,   status->totalTime%60 );
        }
@@ -315,7 +395,7 @@ paint_status_window(mpdclient_t *c)
   if( (IS_PLAYING(status->state) || IS_PAUSED(status->state)) )
     {
       char songname[MAX_SONGNAME_LENGTH];
-      int width = COLS-x-strlen(screen->buf);
+      int width = COLS-x-my_strlen(screen->buf);
 
       if( song )
        strfsong(songname, MAX_SONGNAME_LENGTH, STATUS_FORMAT, song);
@@ -324,7 +404,7 @@ paint_status_window(mpdclient_t *c)
 
       colors_use(w, COLOR_STATUS);
       /* scroll if the song name is to long */
-      if( strlen(songname) > width )
+      if( my_strlen(songname) > width )
        {
          static  scroll_state_t st = { 0, 0 };
          char *tmp = strscroll(songname, " *** ", width, &st);
@@ -332,7 +412,8 @@ paint_status_window(mpdclient_t *c)
          g_strlcpy(songname, tmp, MAX_SONGNAME_LENGTH);
          g_free(tmp);    
        }
-      mvwaddnstr(w, 0, x, songname, width);
+      //mvwaddnstr(w, 0, x, songname, width);
+      mvwaddstr(w, 0, x, songname);
     } 
 
   /* display time string */
@@ -465,10 +546,9 @@ screen_status_printf(char *format, ...)
   g_free(msg);
 }
 
-int
-screen_init(mpdclient_t *c)
+void
+ncurses_init()
 {
-  gint i;
 
   /* initialize the curses library */
   initscr();
@@ -478,7 +558,7 @@ screen_init(mpdclient_t *c)
   nonl();          
   /*  use raw mode (ignore interrupt,quit,suspend, and flow control ) */
 #ifdef ENABLE_RAW_MODE
-  raw();
+  //  raw();
 #endif
   /* don't echo input */
   noecho();    
@@ -499,12 +579,18 @@ screen_init(mpdclient_t *c)
       fprintf(stderr, _("Error: Screen to small!\n"));
       exit(EXIT_FAILURE);
     }
-
   screen = g_malloc(sizeof(screen_t));
   memset(screen, 0, sizeof(screen_t));
   screen->mode = 0;
   screen->cols = COLS;
   screen->rows = LINES;
+}
+
+int
+screen_init(mpdclient_t *c)
+{
+  gint i;
+
   screen->buf  = g_malloc(screen->cols);
   screen->buf_size = screen->cols;
   screen->findbuf = NULL;
@@ -578,7 +664,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);
 
@@ -865,16 +958,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);
@@ -888,11 +975,17 @@ screen_cmd(mpdclient_t *c, command_t cmd)
     case CMD_SCREEN_SEARCH:
       switch_screen_mode(SCREEN_SEARCH_ID, c);
       break;
+    case CMD_SCREEN_ARTIST:
+      switch_screen_mode(SCREEN_ARTIST_ID, c);
+      break;
     case CMD_SCREEN_KEYDEF:
       switch_screen_mode(SCREEN_KEYDEF_ID, c);
       break;
     case CMD_SCREEN_CLOCK:
       switch_screen_mode(SCREEN_CLOCK_ID, c);
+      break;
+       case CMD_SCREEN_LYRICS:
+      switch_screen_mode(SCREEN_LYRICS_ID, c);
       break;
     case CMD_QUIT:
       exit(EXIT_SUCCESS);
@@ -900,6 +993,3 @@ screen_cmd(mpdclient_t *c, command_t cmd)
       break;
     }
 }
-
-
-