Code

Adding crop feature in ncmpc
[ncmpc.git] / src / screen_help.c
index ced66064a7f42fafec73cb6d0ac81aaedef301f4..79b8fa722ef146a9e638be46515285f42644da07 100644 (file)
@@ -1,5 +1,7 @@
 /* 
- * (c) 2004 by Kalle Wallin (kaw@linux.se)
+ * $Id$
+ *
+ * (c) 2004 by Kalle Wallin <kaw@linux.se>
  *
  * This program is free software; you can redistribute it and/or modify
  * it under the terms of the GNU General Public License as published by
  *
  */
 
-#include <stdlib.h>
-#include <string.h>
-#include <glib.h>
-#include <ncurses.h>
-
 #include "config.h"
 #include "ncmpc.h"
-#include "libmpdclient.h"
-#include "mpc.h"
+#include "mpdclient.h"
 #include "command.h"
 #include "screen.h"
 #include "screen_utils.h"
-#include "screen_help.h"
+#include "gcc.h"
 
+#include <stdlib.h>
+#include <string.h>
+#include <glib.h>
+#include <ncurses.h>
 
-typedef struct
-{
-  signed char highlight;
-  command_t command;
-  char *text;
+
+typedef struct {
+       signed char highlight;
+       command_t command;
+       const char *text;
 } help_text_row_t;
 
 static help_text_row_t help_text[] = 
@@ -49,10 +49,14 @@ static help_text_row_t help_text[] =
   { 0, CMD_LIST_FIRST,     NULL },
   { 0, CMD_LIST_LAST,      NULL },
   { 0, CMD_NONE,           NULL },
+  { 0, CMD_SCREEN_PREVIOUS,NULL },
   { 0, CMD_SCREEN_NEXT,    NULL },
   { 0, CMD_SCREEN_HELP,    NULL },
   { 0, CMD_SCREEN_PLAY,    NULL },
   { 0, CMD_SCREEN_FILE,    NULL },
+#ifdef ENABLE_SEARCH_SCREEN
+  { 0, CMD_SCREEN_SEARCH,  NULL },
+#endif
 #ifdef ENABLE_KEYDEF_SCREEN
   { 0, CMD_SCREEN_KEYDEF,  NULL },
 #endif
@@ -63,6 +67,7 @@ static help_text_row_t help_text[] =
   { 2, CMD_NONE,           NULL },
   { 0, CMD_STOP,           NULL },
   { 0, CMD_PAUSE,          NULL },
+  { 0, CMD_CROP, NULL },
   { 0, CMD_TRACK_NEXT,     NULL },
   { 0, CMD_TRACK_PREVIOUS, NULL },
   { 0, CMD_SEEK_FORWARD,   NULL },
@@ -91,8 +96,9 @@ static help_text_row_t help_text[] =
   { 0, CMD_PLAY,           N_("Play") },
   { 0, CMD_DELETE,         NULL },
   { 0, CMD_CLEAR,          NULL },
-  { 0, CMD_LIST_MOVE_UP,   N_("Move song up") },
+  { 1, CMD_LIST_MOVE_UP,   N_("Move song up") },
   { 0, CMD_LIST_MOVE_DOWN, N_("Move song down") },
+  { 0, CMD_ADD,            NULL },
   { 0, CMD_SAVE_PLAYLIST,  NULL },
   { 0, CMD_SCREEN_UPDATE,  N_("Center") },
   { 0, CMD_TOGGLE_AUTOCENTER, NULL },
@@ -101,89 +107,86 @@ static help_text_row_t help_text[] =
   { 0, CMD_NONE,           NULL },
   { 1, CMD_NONE,           N_("Keys - Browse screen") },
   { 2, CMD_NONE,           NULL },
-  { 0, CMD_PLAY,           N_("Enter directory") },
+  { 0, CMD_PLAY,           N_("Enter directory/Select and play song") },
   { 0, CMD_SELECT,         NULL },
-  { 0, CMD_DELETE,         NULL },
+  { 0, CMD_SAVE_PLAYLIST,  NULL },
+  { 0, CMD_DELETE,         N_("Delete playlist") },
+  { 0, CMD_GO_PARENT_DIRECTORY, NULL },
+  { 0, CMD_GO_ROOT_DIRECTORY, NULL },
   { 0, CMD_SCREEN_UPDATE,  NULL },
 
-  { 0, CMD_NONE, NULL },
-  { 0, CMD_NONE, NULL },
-  { 1, CMD_NONE, "ncmpc build information" },
-  { 2, CMD_NONE, NULL },
-  { 0, CMD_NONE, "             Version : " VERSION },
-  { 0, CMD_NONE, "  Configuration dirs : ~/.ncmpc, " SYSCONFDIR "/" PACKAGE },
-#ifdef ENABLE_NLS
-  { 0, CMD_NONE, "NLS support : yes" },
-#else
-  { 0, CMD_NONE, "NLS support : no" },
+#ifdef ENABLE_SEARCH_SCREEN
+  { 0, CMD_NONE,           NULL },
+  { 0, CMD_NONE,           NULL },
+  { 1, CMD_NONE,           N_("Keys - Search screen") },
+  { 2, CMD_NONE,           NULL },
+  { 0, CMD_SCREEN_SEARCH,  N_("Search") },
+  { 0, CMD_PLAY,           N_("Select and play") },
+  { 0, CMD_SELECT,         NULL },
+  { 0, CMD_SELECT_ALL,    NULL },
+  { 0, CMD_SEARCH_MODE,    NULL },
 #endif
-#ifdef ENABLE_KEYDEF_SCREEN
-  { 0, CMD_NONE, "Key Editor : yes" },
-#else
-  { 0, CMD_NONE, "Key Editor : no" },
+#ifdef ENABLE_LYRICS_SCREEN
+  { 0, CMD_NONE,           NULL },
+  { 0, CMD_NONE,           NULL },
+  { 1, CMD_NONE,           N_("Keys - Lyrics screen") },
+  { 2, CMD_NONE,           NULL },
+  { 0, CMD_SCREEN_LYRICS,  N_("View Lyrics") },
+  { 0, CMD_SELECT,         N_("(Re)load lyrics") },
+  { 0, CMD_INTERRUPT,         N_("Interrupt retrieval") },
+  { 0, CMD_LYRICS_UPDATE,         N_("Explicitly download lyrics") },
+  { 0, CMD_ADD,         N_("Save lyrics") }, 
 #endif
-
-  { 0, CMD_NONE, NULL },
-  {-1, CMD_NONE, NULL }
 };
 
-static int help_text_rows = -1;
+#define help_text_rows (sizeof(help_text) / sizeof(help_text[0]))
+
 static list_window_t *lw = NULL;
 
 
-static char *
-list_callback(int index, int *highlight, void *data)
+static const char *
+list_callback(unsigned idx, int *highlight, mpd_unused void *data)
 {
-  static char buf[256];
-
-  if( help_text_rows<0 )
-    {
-      help_text_rows = 0;
-      while( help_text[help_text_rows].highlight != -1 )
-       help_text_rows++;
-    }
-
-  *highlight = 0;
-  if( index<help_text_rows )
-    {
-      *highlight = help_text[index].highlight > 0;
-      if( help_text[index].command == CMD_NONE )
-       {
-         if( help_text[index].text )
-           snprintf(buf, 256, "%28s", _(help_text[index].text));
-         else 
-           if( help_text[index].highlight == 2 )
-             {
-               int i;
-
-               for(i=3; i<COLS-3 && i<256; i++)
-                 buf[i]='-';
-               buf[i] = '\0';
-             }
-           else
-             strcpy(buf, " ");
-         return buf;
+       static char buf[512];
+
+       if (idx >= help_text_rows)
+               return NULL;
+
+       if (help_text[idx].highlight)
+               *highlight = 1;
+
+       if (help_text[idx].command == CMD_NONE) {
+               if (help_text[idx].text)
+                       g_snprintf(buf, sizeof(buf), "      %s", _(help_text[idx].text));
+               else if (help_text[idx].highlight == 2) {
+                       int i;
+
+                       for (i = 3; i < COLS - 3 && i < (int)sizeof(buf); i++)
+                               buf[i] = '-';
+                       buf[i] = '\0';
+               } else
+                       g_strlcpy(buf, " ", sizeof(buf));
+               return buf;
        }
-      if( help_text[index].text )
-       snprintf(buf, 256, 
-                "%20s : %s   ", 
-                get_key_names(help_text[index].command, TRUE),
-                _(help_text[index].text));
-      else
-       snprintf(buf, 256, 
-                "%20s : %s   ", 
-                get_key_names(help_text[index].command, TRUE),
-                get_key_description(help_text[index].command));
-      return buf;
-    }
 
-  return NULL;
+       if (help_text[idx].text)
+               g_snprintf(buf, sizeof(buf),
+                          "%20s : %s   ",
+                          get_key_names(help_text[idx].command, TRUE),
+                          _(help_text[idx].text));
+       else
+               g_snprintf(buf, sizeof(buf),
+                          "%20s : %s   ",
+                          get_key_names(help_text[idx].command, TRUE),
+                          get_key_description(help_text[idx].command));
+       return buf;
 }
 
 static void
 help_init(WINDOW *w, int cols, int rows)
 {
   lw = list_window_init(w, cols, rows);
+  lw->flags = LW_HIDE_CURSOR;
 }
 
 static void
@@ -200,68 +203,48 @@ help_exit(void)
 }
 
 
-static char *
-help_title(void)
+static const char *
+help_title(mpd_unused char *str, mpd_unused size_t size)
 {
-  return _("Music Player Client - Help");
+       return _("Help");
 }
 
-static void 
-help_paint(screen_t *screen, mpd_client_t *c)
+static void
+help_paint(mpd_unused screen_t *screen, mpd_unused mpdclient_t *c)
 {
-  lw->clear = 1;
-  list_window_paint(lw, list_callback, NULL);
-  wrefresh(lw->w);
+       lw->clear = 1;
+       list_window_paint(lw, list_callback, NULL);
+       wrefresh(lw->w);
 }
 
-static void 
-help_update(screen_t *screen, mpd_client_t *c)
-{  
-  if( lw->repaint )
-    {
-      list_window_paint(lw, list_callback, NULL);
-      wrefresh(lw->w);
-      lw->repaint = 0;
-    }
-}
-
-
-static int 
-help_cmd(screen_t *screen, mpd_client_t *c, command_t cmd)
+static int
+help_cmd(screen_t *screen, mpd_unused mpdclient_t *c, command_t cmd)
 {
-  int retval;
-
-  retval = list_window_cmd(lw, help_text_rows, cmd);
-  if( !retval )
-    return screen_find(screen, c, 
-                      lw,  help_text_rows,
-                      cmd, list_callback);
+       if (list_window_scroll_cmd(lw, help_text_rows, cmd)) {
+               list_window_paint(lw, list_callback, NULL);
+               wrefresh(lw->w);
+               return 1;
+       }
 
-  return retval;
-}
+       lw->selected = lw->start+lw->rows;
+       if (screen_find(screen,
+                       lw,  help_text_rows,
+                       cmd, list_callback, NULL)) {
+               /* center the row */
+               list_window_center(lw, help_text_rows, lw->selected);
+               list_window_paint(lw, list_callback, NULL);
+               wrefresh(lw->w);
+               return 1;
+       }
 
-static list_window_t *
-help_lw(void)
-{
-  return lw;
+       return 0;
 }
 
-screen_functions_t *
-get_screen_help(void)
-{
-  static screen_functions_t functions;
-
-  memset(&functions, 0, sizeof(screen_functions_t));
-  functions.init   = help_init;
-  functions.exit   = help_exit;
-  functions.open   = NULL;
-  functions.close  = NULL;
-  functions.resize = help_resize;
-  functions.paint  = help_paint;
-  functions.update = help_update;
-  functions.cmd    = help_cmd;
-  functions.get_lw = help_lw;
-  functions.get_title = help_title;
-
-  return &functions;
-}
+const struct screen_functions screen_help = {
+       .init = help_init,
+       .exit = help_exit,
+       .resize = help_resize,
+       .paint = help_paint,
+       .cmd = help_cmd,
+       .get_title = help_title,
+};