From 2079b3df712c6cd8f1f953b77261024432daf7c0 Mon Sep 17 00:00:00 2001 From: Max Kellermann Date: Wed, 30 Sep 2009 16:30:18 +0200 Subject: [PATCH] screen_utils: don't pass WINDOW to screen_readln() Callers shouldn't care which window will be used; we're going to use the global variable screen.status_window. --- src/screen_client.c | 2 +- src/screen_file.c | 2 +- src/screen_keydef.c | 7 +++---- src/screen_play.c | 9 +++------ src/screen_search.c | 3 +-- src/screen_utils.c | 32 +++++++++++++------------------- src/screen_utils.h | 12 +++--------- 7 files changed, 25 insertions(+), 42 deletions(-) diff --git a/src/screen_client.c b/src/screen_client.c index 51b10df..3916304 100644 --- a/src/screen_client.c +++ b/src/screen_client.c @@ -33,7 +33,7 @@ _screen_auth(struct mpdclient *c, gint recursion) if (recursion > 2) return false; - password = screen_read_password(NULL, NULL); + password = screen_read_password(NULL); if (password == NULL) return false; diff --git a/src/screen_file.c b/src/screen_file.c index a9d5e6a..7805210 100644 --- a/src/screen_file.c +++ b/src/screen_file.c @@ -242,7 +242,7 @@ handle_delete(struct mpdclient *c) str = utf8_to_locale(g_basename(mpd_playlist_get_path(playlist))); buf = g_strdup_printf(_("Delete playlist %s [%s/%s] ? "), str, YES, NO); g_free(str); - key = tolower(screen_getch(screen.status_window.w, buf)); + key = tolower(screen_getch(buf)); g_free(buf); if( key != YES[0] ) { /* translators: a dialog was aborted by the user */ diff --git a/src/screen_keydef.c b/src/screen_keydef.c index 16cc957..b92ebe3 100644 --- a/src/screen_keydef.c +++ b/src/screen_keydef.c @@ -149,14 +149,14 @@ delete_key(int cmd_index, int key_index) } static void -assign_new_key(WINDOW *w, int cmd_index, int key_index) +assign_new_key(int cmd_index, int key_index) { int key; char *buf; command_t cmd; buf = g_strdup_printf(_("Enter new key for %s: "), cmds[cmd_index].name); - key = screen_getch(w, buf); + key = screen_getch(buf); g_free(buf); if (key==ERR) { @@ -334,8 +334,7 @@ keydef_cmd(G_GNUC_UNUSED struct mpdclient *c, command_t cmd) keydef_repaint(); } else - assign_new_key(screen.status_window.w, - subcmd, + assign_new_key(subcmd, lw->selected - STATIC_SUB_ITEMS); } return true; diff --git a/src/screen_play.c b/src/screen_play.c index 3e4f05a..f3a0804 100644 --- a/src/screen_play.c +++ b/src/screen_play.c @@ -279,8 +279,7 @@ playlist_save(struct mpdclient *c, char *name, char *defaultname) /* query the user for a filename */ - filename = screen_readln(screen.status_window.w, - _("Save playlist as"), + filename = screen_readln(_("Save playlist as"), defaultname, NULL, gcmp); @@ -314,8 +313,7 @@ playlist_save(struct mpdclient *c, char *name, char *defaultname) buf = g_strdup_printf(_("Replace %s [%s/%s] ? "), filename, YES, NO); - key = tolower(screen_getch(screen.status_window.w, - buf)); + key = tolower(screen_getch(buf)); g_free(buf); if (key != YES[0]) { @@ -423,8 +421,7 @@ handle_add_to_playlist(struct mpdclient *c) #endif /* get path */ - path = screen_readln(screen.status_window.w, - _("Add"), + path = screen_readln(_("Add"), NULL, NULL, #ifdef NCMPC_MINI diff --git a/src/screen_search.c b/src/screen_search.c index 11ffd61..5c7cdea 100644 --- a/src/screen_search.c +++ b/src/screen_search.c @@ -323,8 +323,7 @@ search_new(struct mpdclient *c) search_clear(c, TRUE); g_free(pattern); - pattern = screen_readln(screen.status_window.w, - _("Search"), + pattern = screen_readln(_("Search"), NULL, &search_history, NULL); diff --git a/src/screen_utils.c b/src/screen_utils.c index 3c9ccfe..7a3f04b 100644 --- a/src/screen_utils.c +++ b/src/screen_utils.c @@ -48,8 +48,9 @@ screen_bell(void) } int -screen_getch(WINDOW *w, const char *prompt) +screen_getch(const char *prompt) { + WINDOW *w = screen.status_window.w; int key = -1; colors_use(w, COLOR_STATUS_ALERT); @@ -66,7 +67,7 @@ screen_getch(WINDOW *w, const char *prompt) #ifdef HAVE_GETMOUSE /* ignore mouse events */ if (key == KEY_MOUSE) - return screen_getch(w, prompt); + return screen_getch(prompt); #endif noecho(); @@ -76,43 +77,37 @@ screen_getch(WINDOW *w, const char *prompt) } char * -screen_readln(WINDOW *w, - const char *prompt, +screen_readln(const char *prompt, const char *value, GList **history, GCompletion *gcmp) { + struct window *window = &screen.status_window; + WINDOW *w = window->w; char *line = NULL; wmove(w, 0,0); curs_set(1); colors_use(w, COLOR_STATUS_ALERT); - line = wreadln(w, prompt, value, COLS, history, gcmp); + line = wreadln(w, prompt, value, window->cols, history, gcmp); curs_set(0); return line; } char * -screen_read_password(WINDOW *w, const char *prompt) +screen_read_password(const char *prompt) { + struct window *window = &screen.status_window; + WINDOW *w = window->w; char *ret; - if (w == NULL) { - int rows, cols; - getmaxyx(stdscr, rows, cols); - /* create window for input */ - w = newwin(1, cols, rows-1, 0); - leaveok(w, FALSE); - keypad(w, TRUE); - } - wmove(w, 0,0); curs_set(1); colors_use(w, COLOR_STATUS_ALERT); if (prompt == NULL) prompt = _("Password"); - ret = wreadln_masked(w, prompt, NULL, COLS, NULL, NULL); + ret = wreadln_masked(w, prompt, NULL, window->cols, NULL, NULL); curs_set(0); return ret; @@ -148,8 +143,7 @@ screen_find(list_window_t *lw, case CMD_LIST_FIND_NEXT: case CMD_LIST_RFIND_NEXT: if (!screen.findbuf) - screen.findbuf=screen_readln(screen.status_window.w, - prompt, + screen.findbuf=screen_readln(prompt, value, &screen.find_history, NULL); @@ -205,7 +199,7 @@ screen_jump(struct list_window *lw, /* unfortunately wgetch returns "next/previous-page" not as an ascii-char */ while(!g_ascii_iscntrl(key) && key != KEY_NPAGE && key != KEY_PPAGE) { - key = screen_getch(screen.status_window.w, screen.findbuf); + key = screen_getch(screen.findbuf); /* if backspace or delete was pressed */ if (key == KEY_BACKSPACE || key == 330) { int i; diff --git a/src/screen_utils.h b/src/screen_utils.h index 5b133fc..bbcdbf2 100644 --- a/src/screen_utils.h +++ b/src/screen_utils.h @@ -24,24 +24,18 @@ #include "list_window.h" #include "command.h" -#ifdef HAVE_NCURSESW_NCURSES_H -#include -#else -#include -#endif - struct mpdclient; /* sound an audible and/or visible bell */ void screen_bell(void); /* read a character from the status window */ -int screen_getch(WINDOW *w, const char *prompt); +int screen_getch(const char *prompt); char * -screen_read_password(WINDOW *w, const char *prompt); +screen_read_password(const char *prompt); -char *screen_readln(WINDOW *w, const char *prompt, const char *value, +char *screen_readln(const char *prompt, const char *value, GList **history, GCompletion *gcmp); /* query user for a string and find it in a list window */ -- 2.30.2