Code

screen_utils: don't pass WINDOW to screen_readln()
authorMax Kellermann <max@duempel.org>
Wed, 30 Sep 2009 14:30:18 +0000 (16:30 +0200)
committerMax Kellermann <max@duempel.org>
Wed, 30 Sep 2009 14:30:18 +0000 (16:30 +0200)
Callers shouldn't care which window will be used; we're going to use
the global variable screen.status_window.

src/screen_client.c
src/screen_file.c
src/screen_keydef.c
src/screen_play.c
src/screen_search.c
src/screen_utils.c
src/screen_utils.h

index 51b10df9c7661795ad46590f5bab0d5cbca0e746..3916304801d8f00cb700ff878866468d20b4cf21 100644 (file)
@@ -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;
 
index a9d5e6a7ad3346e6939c3aae61345a1b2efc1237..78052100c9aeede306e7ad290a63b857c1de8970 100644 (file)
@@ -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 */
index 16cc95710585982a1cc6636b01da382e9069e47b..b92ebe39d584453f7fa6d61d3a3bdc6f96ad230c 100644 (file)
@@ -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;
index 3e4f05ada50ec563d0d993c1f32496d237930b96..f3a0804903155f4906a5a0928bebdfb20958bb9c 100644 (file)
@@ -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
index 11ffd619f134bcbe50b3ef16ad3fcd6c6d0a52ec..5c7cdeafd0edd2668ed3bd15b5ea2b23889372a4 100644 (file)
@@ -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);
index 3c9ccfe9cbe6e6b800c07cb93261f22d9918b42d..7a3f04b78bdd154d77b507cc3c79b3586cb80e44 100644 (file)
@@ -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;
index 5b133fcec5387986a803169d90e4bef185aadb31..bbcdbf282238b51a5a01a0725dc47362c8a07202 100644 (file)
 #include "list_window.h"
 #include "command.h"
 
-#ifdef HAVE_NCURSESW_NCURSES_H
-#include <ncursesw/ncurses.h>
-#else
-#include <ncurses.h>
-#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 */