summary | shortlog | log | commit | commitdiff | tree
raw | patch | inline | side by side (parent: d08e14f)
raw | patch | inline | side by side (parent: d08e14f)
author | Max Kellermann <max@duempel.org> | |
Thu, 1 Oct 2009 22:10:23 +0000 (00:10 +0200) | ||
committer | Max Kellermann <max@duempel.org> | |
Thu, 1 Oct 2009 22:10:23 +0000 (00:10 +0200) |
12 files changed:
Makefile.am | patch | blob | history | |
src/screen_artist.c | patch | blob | history | |
src/screen_browser.c | patch | blob | history | |
src/screen_find.c | [new file with mode: 0644] | patch | blob |
src/screen_find.h | [new file with mode: 0644] | patch | blob |
src/screen_help.c | patch | blob | history | |
src/screen_keydef.c | patch | blob | history | |
src/screen_play.c | patch | blob | history | |
src/screen_song.c | patch | blob | history | |
src/screen_text.c | patch | blob | history | |
src/screen_utils.c | patch | blob | history | |
src/screen_utils.h | patch | blob | history |
diff --git a/Makefile.am b/Makefile.am
index 52b5953f34897ed1fa8b25f8e6a32e104d789217..fc47485661ad2224378bcf5c3d9ca24957b2f548 100644 (file)
--- a/Makefile.am
+++ b/Makefile.am
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 \
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 \
diff --git a/src/screen_artist.c b/src/screen_artist.c
index 89fc55e31d0ea3b6a1c06a63dfbe3e7c6301cbb3..bda897081d4ff556870b1f7e9135fa8831b519ef 100644 (file)
--- a/src/screen_artist.c
+++ b/src/screen_artist.c
#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"
diff --git a/src/screen_browser.c b/src/screen_browser.c
index 638803df58433a0bb41d167155e33c9e59d8f859..851f18cad6189812ed08cd09af43c72cf2297c55 100644 (file)
--- a/src/screen_browser.c
+++ b/src/screen_browser.c
#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
--- /dev/null
+++ b/src/screen_find.c
@@ -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
--- /dev/null
+++ b/src/screen_find.h
@@ -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
diff --git a/src/screen_help.c b/src/screen_help.c
index 042478a0617287d6ed4f50edc72df3ba2acd99d0..6f4850b60f0978c78e71a3eecdbea2cbb054c475 100644 (file)
--- a/src/screen_help.c
+++ b/src/screen_help.c
#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>
diff --git a/src/screen_keydef.c b/src/screen_keydef.c
index d93757a9c67bd5ca64f744dc2b8c79cd395727af..28822e58f5e56ed3d1f1f385935ab27c733ac19a 100644 (file)
--- a/src/screen_keydef.c
+++ b/src/screen_keydef.c
#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"
diff --git a/src/screen_play.c b/src/screen_play.c
index 3adcb6dfd9b6ba2b55da8445fc4f10acc9fba342..f481d5b4f4dfbba78c8e38e7b9880f4b6c1361bd 100644 (file)
--- a/src/screen_play.c
+++ b/src/screen_play.c
#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"
diff --git a/src/screen_song.c b/src/screen_song.c
index eeb2f1129cf8b2a3019fe577a4927646f7f3b4a4..d0ad9f9c96f6322c0a759556a2cd7f1ff92d18de 100644 (file)
--- a/src/screen_song.c
+++ b/src/screen_song.c
#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"
diff --git a/src/screen_text.c b/src/screen_text.c
index 6f642e8498bb570c356df2bb855fd03d48291e28..faee9cb76aee4c20461d7db3c31ddc5592f0ed1f 100644 (file)
--- a/src/screen_text.c
+++ b/src/screen_text.c
*/
#include "screen_text.h"
-#include "screen_utils.h"
+#include "screen_find.h"
#include "charset.h"
#include <assert.h>
diff --git a/src/screen_utils.c b/src/screen_utils.c
index 6cd72324140675cf9f409d9eedb950fa851401dd..39b11622aeba0a35848f4b17981200204a89d0aa 100644 (file)
--- a/src/screen_utils.c
+++ b/src/screen_utils.c
*/
#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)
{
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)
{
diff --git a/src/screen_utils.h b/src/screen_utils.h
index bbcdbf282238b51a5a01a0725dc47362c8a07202..288535d2f8ff8146309413637f7a82d95ff9387e 100644 (file)
--- a/src/screen_utils.h
+++ b/src/screen_utils.h
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