Code

po: update Chinese translation
[ncmpc.git] / src / screen_help.c
index 81b479fefbce01b26e879b237ae081edcc0202eb..faa9603e7aea0aaf1db978cd930852bc3f546f61 100644 (file)
@@ -1,5 +1,5 @@
 /* ncmpc (Ncurses MPD Client)
- * (c) 2004-2009 The Music Player Daemon Project
+ * (c) 2004-2010 The Music Player Daemon Project
  * Project homepage: http://musicpd.org
 
  * This program is free software; you can redistribute it and/or modify
  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
 */
 
+#include "screen_help.h"
+#include "screen_interface.h"
+#include "screen_find.h"
+#include "paint.h"
+#include "charset.h"
 #include "config.h"
 #include "i18n.h"
-#include "mpdclient.h"
-#include "command.h"
-#include "screen.h"
-#include "screen_utils.h"
 
-#include <stdlib.h>
-#include <string.h>
 #include <glib.h>
 
-typedef struct {
+#include <assert.h>
+
+struct help_text_row {
        signed char highlight;
        command_t command;
        const char *text;
-} help_text_row_t;
+};
 
-static help_text_row_t help_text[] = {
+static const struct help_text_row help_text[] = {
        { 1, CMD_NONE, N_("Movement") },
        { 2, CMD_NONE, NULL },
        { 0, CMD_LIST_PREVIOUS, NULL },
@@ -55,7 +56,7 @@ static help_text_row_t help_text[] = {
 
        { 0, CMD_SCREEN_PREVIOUS,NULL },
        { 0, CMD_SCREEN_NEXT, NULL },
-    { 0, CMD_SCREEN_SWAP, NULL },
+       { 0, CMD_SCREEN_SWAP, NULL },
        { 0, CMD_SCREEN_HELP, NULL },
        { 0, CMD_SCREEN_PLAY, NULL },
        { 0, CMD_SCREEN_FILE, NULL },
@@ -104,7 +105,9 @@ static help_text_row_t help_text[] = {
        { 0, CMD_LIST_JUMP, NULL },
        { 0, CMD_TOGGLE_FIND_WRAP, NULL },
        { 0, CMD_LOCATE, NULL },
+#ifdef ENABLE_SONG_SCREEN
        { 0, CMD_SCREEN_SONG, NULL },
+#endif
        { 0, CMD_NONE, NULL },
        { 0, CMD_QUIT, NULL },
 
@@ -160,6 +163,7 @@ static help_text_row_t help_text[] = {
        { 0, CMD_INTERRUPT, N_("Interrupt retrieval") },
        { 0, CMD_LYRICS_UPDATE, N_("Download lyrics for currently playing song") },
        { 0, CMD_SAVE_PLAYLIST, N_("Save lyrics") },
+       { 0, CMD_DELETE, N_("Delete saved lyrics") },
 #endif
 #ifdef ENABLE_OUTPUTS_SCREEN
        { 0, CMD_NONE, NULL },
@@ -180,66 +184,42 @@ static help_text_row_t help_text[] = {
 #endif
 };
 
-#define help_text_rows (sizeof(help_text) / sizeof(help_text[0]))
-
-static list_window_t *lw;
+static struct list_window *lw;
 
 static const char *
-list_callback(unsigned idx, bool *highlight, G_GNUC_UNUSED char** second_column, G_GNUC_UNUSED void *data)
+list_callback(unsigned i, G_GNUC_UNUSED void *data)
 {
-       static char buf[512];
-
-       if (idx >= help_text_rows)
-               return NULL;
-
-       if (help_text[idx].highlight)
-               *highlight = true;
-
-       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;
-       }
+       const struct help_text_row *row = &help_text[i];
 
-       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;
+       assert(i < G_N_ELEMENTS(help_text));
+
+       if (row->text != NULL)
+               return _(row->text);
+
+       if (row->command != CMD_NONE)
+               return get_key_description(row->command);
+
+       return "";
 }
 
 static void
 help_init(WINDOW *w, int cols, int rows)
 {
-  lw = list_window_init(w, cols, rows);
+       lw = list_window_init(w, cols, rows);
        lw->hide_cursor = true;
+       list_window_set_length(lw, G_N_ELEMENTS(help_text));
 }
 
 static void
 help_resize(int cols, int rows)
 {
-  lw->cols = cols;
-  lw->rows = rows;
+       list_window_resize(lw, cols, rows);
 }
 
 static void
 help_exit(void)
 {
-  list_window_free(lw);
+       list_window_free(lw);
 }
 
 
@@ -249,27 +229,59 @@ help_title(G_GNUC_UNUSED char *str, G_GNUC_UNUSED size_t size)
        return _("Help");
 }
 
+static void
+screen_help_paint_callback(WINDOW *w, unsigned i,
+                          unsigned y, unsigned width,
+                          G_GNUC_UNUSED bool selected,
+                          G_GNUC_UNUSED void *data)
+{
+       const struct help_text_row *row = &help_text[i];
+
+       assert(i < G_N_ELEMENTS(help_text));
+
+       row_color(w, row->highlight ? COLOR_LIST_BOLD : COLOR_LIST, false);
+
+       wclrtoeol(w);
+
+       if (row->command == CMD_NONE) {
+               if (row->text != NULL)
+                       mvwaddstr(w, y, 6, _(row->text));
+               else if (row->highlight == 2)
+                       mvwhline(w, y, 3, '-', width - 6);
+       } else {
+               const char *key = get_key_names(row->command, true);
+
+               if (utf8_width(key) < 20)
+                       wmove(w, y, 20 - utf8_width(key));
+               waddstr(w, key);
+               mvwaddch(w, y, 21, ':');
+               mvwaddstr(w, y, 23,
+                         row->text != NULL
+                         ? _(row->text)
+                         : get_key_description(row->command));
+       }
+}
+
 static void
 help_paint(void)
 {
-       list_window_paint(lw, list_callback, NULL);
+       list_window_paint2(lw, screen_help_paint_callback, NULL);
 }
 
 static bool
-help_cmd(G_GNUC_UNUSED mpdclient_t *c, command_t cmd)
+help_cmd(G_GNUC_UNUSED struct mpdclient *c, command_t cmd)
 {
-       if (list_window_scroll_cmd(lw, help_text_rows, cmd)) {
-               list_window_paint(lw, list_callback, NULL);
+       if (list_window_scroll_cmd(lw, cmd)) {
+               help_paint();
                wrefresh(lw->w);
                return true;
        }
 
-       lw->selected = lw->start;
-       if (screen_find(lw,  help_text_rows,
-                       cmd, list_callback, NULL)) {
+       list_window_set_cursor(lw, lw->start);
+       if (screen_find(lw,  cmd, list_callback, NULL)) {
                /* center the row */
-               list_window_center(lw, help_text_rows, lw->selected);
-               list_window_paint(lw, list_callback, NULL);
+               list_window_center(lw, lw->selected);
+               help_paint();
                wrefresh(lw->w);
                return true;
        }