Code

screen_utils: moved screen_find() to screen_find.c
authorMax Kellermann <max@duempel.org>
Thu, 1 Oct 2009 22:10:23 +0000 (00:10 +0200)
committerMax Kellermann <max@duempel.org>
Thu, 1 Oct 2009 22:10:23 +0000 (00:10 +0200)
12 files changed:
Makefile.am
src/screen_artist.c
src/screen_browser.c
src/screen_find.c [new file with mode: 0644]
src/screen_find.h [new file with mode: 0644]
src/screen_help.c
src/screen_keydef.c
src/screen_play.c
src/screen_song.c
src/screen_text.c
src/screen_utils.c
src/screen_utils.h

index 52b5953f34897ed1fa8b25f8e6a32e104d789217..fc47485661ad2224378bcf5c3d9ca24957b2f548 100644 (file)
@@ -29,6 +29,7 @@ ncmpc_headers = \
        src/screen_message.h \
        src/screen_interface.h \
        src/screen_list.h \
+       src/screen_find.h \
        src/screen_utils.h \
        src/screen_client.h \
        src/list_window.h \
@@ -82,6 +83,7 @@ src_ncmpc_SOURCES = \
        src/screen.c \
        src/screen_message.c \
        src/screen_list.c \
+       src/screen_find.c \
        src/screen_utils.c \
        src/screen_client.c \
        src/screen_play.c \
index 89fc55e31d0ea3b6a1c06a63dfbe3e7c6301cbb3..bda897081d4ff556870b1f7e9135fa8831b519ef 100644 (file)
 #include "screen_artist.h"
 #include "screen_interface.h"
 #include "screen_message.h"
+#include "screen_find.h"
 #include "screen.h"
 #include "i18n.h"
 #include "charset.h"
 #include "mpdclient.h"
-#include "screen_utils.h"
 #include "screen_browser.h"
 #include "filelist.h"
 
index 638803df58433a0bb41d167155e33c9e59d8f859..851f18cad6189812ed08cd09af43c72cf2297c55 100644 (file)
 #include "screen_song.h"
 #include "screen_lyrics.h"
 #include "screen_message.h"
+#include "screen_find.h"
 #include "screen.h"
 #include "i18n.h"
 #include "options.h"
 #include "charset.h"
 #include "strfsong.h"
-#include "screen_utils.h"
 #include "mpdclient.h"
 #include "filelist.h"
 
diff --git a/src/screen_find.c b/src/screen_find.c
new file mode 100644 (file)
index 0000000..f779961
--- /dev/null
@@ -0,0 +1,145 @@
+/* ncmpc (Ncurses MPD Client)
+ * (c) 2004-2009 The Music Player Daemon Project
+ * Project homepage: http://musicpd.org
+ *
+ * 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
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License along
+ * with this program; if not, write to the Free Software Foundation, Inc.,
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+ */
+
+#include "screen_find.h"
+#include "screen_utils.h"
+#include "screen_message.h"
+#include "screen.h"
+#include "i18n.h"
+#include "options.h"
+#include "ncmpc.h"
+
+#define FIND_PROMPT  _("Find")
+#define RFIND_PROMPT _("Find backward")
+#define JUMP_PROMPT _("Jump")
+
+/* query user for a string and find it in a list window */
+int
+screen_find(list_window_t *lw,
+           int rows,
+           command_t findcmd,
+           list_window_callback_fn_t callback_fn,
+           void *callback_data)
+{
+       int reversed = 0;
+       bool found;
+       const char *prompt = FIND_PROMPT;
+       char *value = options.find_show_last_pattern ? (char *) -1 : NULL;
+
+       if (findcmd == CMD_LIST_RFIND || findcmd == CMD_LIST_RFIND_NEXT) {
+               prompt = RFIND_PROMPT;
+               reversed = 1;
+       }
+
+       switch (findcmd) {
+       case CMD_LIST_FIND:
+       case CMD_LIST_RFIND:
+               if (screen.findbuf) {
+                       g_free(screen.findbuf);
+                       screen.findbuf=NULL;
+               }
+               /* continue... */
+
+       case CMD_LIST_FIND_NEXT:
+       case CMD_LIST_RFIND_NEXT:
+               if (!screen.findbuf)
+                       screen.findbuf=screen_readln(prompt,
+                                                    value,
+                                                    &screen.find_history,
+                                                    NULL);
+
+               if (screen.findbuf == NULL)
+                       return 1;
+
+               found = reversed
+                       ? list_window_rfind(lw,
+                                           callback_fn, callback_data,
+                                           screen.findbuf,
+                                           options.find_wrap,
+                                           options.bell_on_wrap,
+                                           rows)
+                       : list_window_find(lw,
+                                          callback_fn, callback_data,
+                                          screen.findbuf,
+                                          options.find_wrap,
+                                          options.bell_on_wrap);
+               if (!found) {
+                       screen_status_printf(_("Unable to find \'%s\'"),
+                                            screen.findbuf);
+                       screen_bell();
+               }
+               return 1;
+       default:
+               break;
+       }
+       return 0;
+}
+
+/* query user for a string and jump to the entry
+ * which begins with this string while the users types */
+void
+screen_jump(struct list_window *lw,
+               list_window_callback_fn_t callback_fn,
+               void *callback_data)
+{
+       char *search_str, *iter;
+       const int WRLN_MAX_LINE_SIZE = 1024;
+       int key = 65;
+       command_t cmd;
+
+       if (screen.findbuf) {
+               g_free(screen.findbuf);
+               screen.findbuf = NULL;
+       }
+       screen.findbuf = g_malloc0(WRLN_MAX_LINE_SIZE);
+       /* In screen.findbuf is the whole string which is displayed in the status_window
+        * and search_str is the string the user entered (without the prompt) */
+       search_str = screen.findbuf + g_snprintf(screen.findbuf, WRLN_MAX_LINE_SIZE, "%s: ", JUMP_PROMPT);
+       iter = search_str;
+
+       /* 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.findbuf);
+               /* if backspace or delete was pressed */
+               if (key == KEY_BACKSPACE || key == 330) {
+                       int i;
+                       /* don't end the loop */
+                       key = 65;
+                       if (search_str <= g_utf8_find_prev_char(screen.findbuf, iter))
+                               iter = g_utf8_find_prev_char(screen.findbuf, iter);
+                       for (i = 0; *(iter + i) != '\0'; i++)
+                               *(iter + i) = '\0';
+                       continue;
+               }
+               else {
+                       *iter = key;
+                       if (iter < screen.findbuf + WRLN_MAX_LINE_SIZE - 3)
+                               ++iter;
+               }
+               list_window_jump(lw, callback_fn, callback_data, search_str);
+               /* repaint the list_window */
+               list_window_paint(lw, callback_fn, callback_data);
+               wrefresh(lw->w);
+       }
+
+       /* ncmpc should get the command */
+       ungetch(key);
+       if ((cmd=get_keyboard_command()) != CMD_NONE)
+               do_input_event(cmd);
+}
diff --git a/src/screen_find.h b/src/screen_find.h
new file mode 100644 (file)
index 0000000..5148bd4
--- /dev/null
@@ -0,0 +1,39 @@
+/* ncmpc (Ncurses MPD Client)
+ * (c) 2004-2009 The Music Player Daemon Project
+ * Project homepage: http://musicpd.org
+ *
+ * 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
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License along
+ * with this program; if not, write to the Free Software Foundation, Inc.,
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+ */
+
+#ifndef NCMPC_SCREEN_FIND_H
+#define NCMPC_SCREEN_FIND_H
+
+#include "command.h"
+#include "list_window.h"
+
+/* query user for a string and find it in a list window */
+int screen_find(struct list_window *lw,
+               int rows,
+               command_t findcmd,
+               list_window_callback_fn_t callback_fn,
+               void *callback_data);
+
+/* query user for a string and jump to the entry
+ * which begins with this string while the users types */
+void screen_jump(struct list_window *lw,
+               list_window_callback_fn_t callback_fn,
+               void *callback_data);
+
+#endif
index 042478a0617287d6ed4f50edc72df3ba2acd99d0..6f4850b60f0978c78e71a3eecdbea2cbb054c475 100644 (file)
@@ -19,9 +19,9 @@
 
 #include "screen_help.h"
 #include "screen_interface.h"
+#include "screen_find.h"
 #include "config.h"
 #include "i18n.h"
-#include "screen_utils.h"
 
 #include <glib.h>
 
index d93757a9c67bd5ca64f744dc2b8c79cd395727af..28822e58f5e56ed3d1f1f385935ab27c733ac19a 100644 (file)
@@ -20,6 +20,7 @@
 #include "screen_keydef.h"
 #include "screen_interface.h"
 #include "screen_message.h"
+#include "screen_find.h"
 #include "i18n.h"
 #include "conf.h"
 #include "screen.h"
index 3adcb6dfd9b6ba2b55da8445fc4f10acc9fba342..f481d5b4f4dfbba78c8e38e7b9880f4b6c1361bd 100644 (file)
@@ -21,6 +21,7 @@
 #include "screen_interface.h"
 #include "screen_file.h"
 #include "screen_message.h"
+#include "screen_find.h"
 #include "config.h"
 #include "i18n.h"
 #include "charset.h"
index eeb2f1129cf8b2a3019fe577a4927646f7f3b4a4..d0ad9f9c96f6322c0a759556a2cd7f1ff92d18de 100644 (file)
@@ -21,9 +21,9 @@
 #include "screen_interface.h"
 #include "screen_file.h"
 #include "screen_lyrics.h"
+#include "screen_find.h"
 #include "i18n.h"
 #include "screen.h"
-#include "screen_utils.h"
 #include "charset.h"
 #include "utils.h"
 #include "mpdclient.h"
index 6f642e8498bb570c356df2bb855fd03d48291e28..faee9cb76aee4c20461d7db3c31ddc5592f0ed1f 100644 (file)
@@ -18,7 +18,7 @@
 */
 
 #include "screen_text.h"
-#include "screen_utils.h"
+#include "screen_find.h"
 #include "charset.h"
 
 #include <assert.h>
index 6cd72324140675cf9f409d9eedb950fa851401dd..39b11622aeba0a35848f4b17981200204a89d0aa 100644 (file)
@@ -18,7 +18,6 @@
 */
 
 #include "screen_utils.h"
-#include "screen_message.h"
 #include "screen.h"
 #include "mpdclient.h"
 #include "config.h"
 #include "options.h"
 #include "colors.h"
 #include "wreadln.h"
-#ifndef NCMPC_H
-#include "ncmpc.h"
-#endif /* NCMPC_H */
 
 #include <mpd/client.h>
 
-#include <stdlib.h>
-#include <unistd.h>
-
-#define FIND_PROMPT  _("Find")
-#define RFIND_PROMPT _("Find backward")
-#define JUMP_PROMPT _("Jump")
-
 void
 screen_bell(void)
 {
@@ -114,121 +103,6 @@ screen_read_password(const char *prompt)
        return ret;
 }
 
-/* query user for a string and find it in a list window */
-int
-screen_find(list_window_t *lw,
-           int rows,
-           command_t findcmd,
-           list_window_callback_fn_t callback_fn,
-           void *callback_data)
-{
-       int reversed = 0;
-       bool found;
-       const char *prompt = FIND_PROMPT;
-       char *value = options.find_show_last_pattern ? (char *) -1 : NULL;
-
-       if (findcmd == CMD_LIST_RFIND || findcmd == CMD_LIST_RFIND_NEXT) {
-               prompt = RFIND_PROMPT;
-               reversed = 1;
-       }
-
-       switch (findcmd) {
-       case CMD_LIST_FIND:
-       case CMD_LIST_RFIND:
-               if (screen.findbuf) {
-                       g_free(screen.findbuf);
-                       screen.findbuf=NULL;
-               }
-               /* continue... */
-
-       case CMD_LIST_FIND_NEXT:
-       case CMD_LIST_RFIND_NEXT:
-               if (!screen.findbuf)
-                       screen.findbuf=screen_readln(prompt,
-                                                    value,
-                                                    &screen.find_history,
-                                                    NULL);
-
-               if (screen.findbuf == NULL)
-                       return 1;
-
-               found = reversed
-                       ? list_window_rfind(lw,
-                                           callback_fn, callback_data,
-                                           screen.findbuf,
-                                           options.find_wrap,
-                                           options.bell_on_wrap,
-                                           rows)
-                       : list_window_find(lw,
-                                          callback_fn, callback_data,
-                                          screen.findbuf,
-                                          options.find_wrap,
-                                          options.bell_on_wrap);
-               if (!found) {
-                       screen_status_printf(_("Unable to find \'%s\'"),
-                                            screen.findbuf);
-                       screen_bell();
-               }
-               return 1;
-       default:
-               break;
-       }
-       return 0;
-}
-
-/* query user for a string and jump to the entry
- * which begins with this string while the users types */
-void
-screen_jump(struct list_window *lw,
-               list_window_callback_fn_t callback_fn,
-               void *callback_data)
-{
-       char *search_str, *iter;
-       const int WRLN_MAX_LINE_SIZE = 1024;
-       int key = 65;
-       command_t cmd;
-
-       if (screen.findbuf) {
-               g_free(screen.findbuf);
-               screen.findbuf = NULL;
-       }
-       screen.findbuf = g_malloc0(WRLN_MAX_LINE_SIZE);
-       /* In screen.findbuf is the whole string which is displayed in the status_window
-        * and search_str is the string the user entered (without the prompt) */
-       search_str = screen.findbuf + g_snprintf(screen.findbuf, WRLN_MAX_LINE_SIZE, "%s: ", JUMP_PROMPT);
-       iter = search_str;
-
-       /* 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.findbuf);
-               /* if backspace or delete was pressed */
-               if (key == KEY_BACKSPACE || key == 330) {
-                       int i;
-                       /* don't end the loop */
-                       key = 65;
-                       if (search_str <= g_utf8_find_prev_char(screen.findbuf, iter))
-                               iter = g_utf8_find_prev_char(screen.findbuf, iter);
-                       for (i = 0; *(iter + i) != '\0'; i++)
-                               *(iter + i) = '\0';
-                       continue;
-               }
-               else {
-                       *iter = key;
-                       if (iter < screen.findbuf + WRLN_MAX_LINE_SIZE - 3)
-                               ++iter;
-               }
-               list_window_jump(lw, callback_fn, callback_data, search_str);
-               /* repaint the list_window */
-               list_window_paint(lw, callback_fn, callback_data);
-               wrefresh(lw->w);
-       }
-
-       /* ncmpc should get the command */
-       ungetch(key);
-       if ((cmd=get_keyboard_command()) != CMD_NONE)
-               do_input_event(cmd);
-}
-
 void
 screen_display_completion_list(GList *list)
 {
index bbcdbf282238b51a5a01a0725dc47362c8a07202..288535d2f8ff8146309413637f7a82d95ff9387e 100644 (file)
@@ -38,19 +38,6 @@ screen_read_password(const char *prompt);
 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 */
-int screen_find(struct list_window *lw,
-               int rows,
-               command_t findcmd,
-               list_window_callback_fn_t callback_fn,
-               void *callback_data);
-
-/* query user for a string and jump to the entry
- * which begins with this string while the users types */
-void screen_jump(struct list_window *lw,
-               list_window_callback_fn_t callback_fn,
-               void *callback_data);
-
 void screen_display_completion_list(GList *list);
 
 #ifndef NCMPC_MINI