diff options
author | Kalle Wallin <kaw@linux.se> | 2004-11-15 11:23:11 +0000 |
---|---|---|
committer | Kalle Wallin <kaw@linux.se> | 2004-11-15 11:23:11 +0000 |
commit | e3c905a56bcc1fed3848485201a4a434aa9fc162 (patch) | |
tree | aed87e32dc8c39473fa86b3d11d2048a06ac055f /src | |
parent | 41d25e22f8b3fabc954d5b58db6d1d36706aa418 (diff) | |
download | mpd-e3c905a56bcc1fed3848485201a4a434aa9fc162.tar.gz mpd-e3c905a56bcc1fed3848485201a4a434aa9fc162.tar.xz mpd-e3c905a56bcc1fed3848485201a4a434aa9fc162.zip |
Added a search screen
git-svn-id: https://svn.musicpd.org/ncmpc/trunk@2668 09075e82-0dd4-0310-85a5-a0d7c8717e4f
Diffstat (limited to '')
-rw-r--r-- | src/Makefile.am | 2 | ||||
-rw-r--r-- | src/command.c | 9 | ||||
-rw-r--r-- | src/command.h | 1 | ||||
-rw-r--r-- | src/conf.c | 5 | ||||
-rw-r--r-- | src/mpdclient.c | 34 | ||||
-rw-r--r-- | src/mpdclient.h | 3 | ||||
-rw-r--r-- | src/ncmpc.h | 10 | ||||
-rw-r--r-- | src/options.c | 6 | ||||
-rw-r--r-- | src/options.h | 1 | ||||
-rw-r--r-- | src/screen.c | 17 | ||||
-rw-r--r-- | src/screen_browse.h | 30 | ||||
-rw-r--r-- | src/screen_clock.c | 2 | ||||
-rw-r--r-- | src/screen_file.c | 81 | ||||
-rw-r--r-- | src/screen_help.c | 20 | ||||
-rw-r--r-- | src/screen_keydef.c | 4 | ||||
-rw-r--r-- | src/screen_play.c | 2 | ||||
-rw-r--r-- | src/screen_search.c | 305 | ||||
-rw-r--r-- | src/screen_utils.c | 7 | ||||
-rw-r--r-- | src/screen_utils.h | 3 |
19 files changed, 505 insertions, 37 deletions
diff --git a/src/Makefile.am b/src/Makefile.am index fc81ed9b9..796ac8d9d 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -11,7 +11,7 @@ AM_CPPFLAGS = $(GLIB_CFLAGS) -DLOCALE_DIR=\""$(datadir)/locale"\" -DSYSCONFDIR=\ ncmpc_headers = libmpdclient.h mpdclient.h options.h conf.h command.h \ screen.h screen_utils.h list_window.h colors.h support.h \ - wreadln.h strfsong.h utils.h ncmpc.h + wreadln.h strfsong.h utils.h ncmpc.h screen_browse.h ncmpc_SOURCES = libmpdclient.c main.c mpdclient.c options.c conf.c command.c \ screen.c screen_utils.c screen_play.c screen_file.c \ diff --git a/src/command.c b/src/command.c index aecf31ab7..5b235e678 100644 --- a/src/command.c +++ b/src/command.c @@ -172,8 +172,15 @@ static command_definition_t cmds[] = /* extra screens */ +#ifdef ENABLE_SEARCH_SCREEN + { {'4', F4, 0 }, 0, CMD_SCREEN_SEARCH, "screen-search", + N_("Search screen") }, + { {'m', 0, 0 }, 0, CMD_SEARCH_MODE, "search-mode", + N_("Change search mode") }, +#endif + #ifdef ENABLE_CLOCK_SCREEN - { {'4', F4, 0 }, 0, CMD_SCREEN_CLOCK, "screen-clock", + { {'5', F5, 0 }, 0, CMD_SCREEN_CLOCK, "screen-clock", N_("Clock screen") }, #endif diff --git a/src/command.h b/src/command.h index fc436a443..29e6a0637 100644 --- a/src/command.h +++ b/src/command.h @@ -28,6 +28,7 @@ typedef enum CMD_SAVE_PLAYLIST, CMD_TOGGLE_FIND_WRAP, CMD_TOGGLE_AUTOCENTER, + CMD_SEARCH_MODE, CMD_LIST_PREVIOUS, CMD_LIST_NEXT, CMD_LIST_FIRST, diff --git a/src/conf.c b/src/conf.c index 740939d10..11dba9993 100644 --- a/src/conf.c +++ b/src/conf.c @@ -59,6 +59,7 @@ #define CONF_XTERM_TITLE "set-xterm-title" #define CONF_ENABLE_MOUSE "enable-mouse" #define CONF_CROSSFADE_TIME "crossfade-time" +#define CONF_SEARCH_MODE "search-mode" typedef enum { KEY_PARSER_UNKNOWN, @@ -472,6 +473,10 @@ read_rc_file(char *filename, options_t *options) { options->crossfade_time = atoi(value); } + else if( !strcasecmp(CONF_SEARCH_MODE, name) ) + { + options->search_mode = atoi(value); + } else { match_found = 0; diff --git a/src/mpdclient.c b/src/mpdclient.c index 1f7c73790..7cec3c967 100644 --- a/src/mpdclient.c +++ b/src/mpdclient.c @@ -819,6 +819,8 @@ mpdclient_filelist_free(mpdclient_filelist_t *filelist) GList *list = g_list_first(filelist->list); D("mpdclient_filelist_free()\n"); + if( list == NULL ) + return NULL; while( list!=NULL ) { filelist_entry_t *entry = list->data; @@ -881,6 +883,38 @@ mpdclient_filelist_get(mpdclient_t *c, gchar *path) } mpdclient_filelist_t * +mpdclient_filelist_search(mpdclient_t *c, int table, gchar *filter) +{ + mpdclient_filelist_t *filelist; + mpd_InfoEntity *entity; + gchar *filter_utf8 = locale_to_utf8(filter); + + D("mpdclient_filelist_filter(%s)\n", filter); + mpd_sendSearchCommand(c->connection, table, filter_utf8); + filelist = g_malloc0(sizeof(mpdclient_filelist_t)); + + while( (entity=mpd_getNextInfoEntity(c->connection)) ) + { + filelist_entry_t *entry = g_malloc0(sizeof(filelist_entry_t)); + + entry->entity = entity; + filelist->list = g_list_append(filelist->list, (gpointer) entry); + filelist->length++; + } + + if( mpdclient_finish_command(c) ) + { + g_free(filter_utf8); + return mpdclient_filelist_free(filelist); + } + + g_free(filter_utf8); + filelist->updated = TRUE; + + return filelist; +} + +mpdclient_filelist_t * mpdclient_filelist_update(mpdclient_t *c, mpdclient_filelist_t *filelist) { if( filelist != NULL ) diff --git a/src/mpdclient.h b/src/mpdclient.h index 016d1ba1b..89a2e6327 100644 --- a/src/mpdclient.h +++ b/src/mpdclient.h @@ -158,6 +158,9 @@ void mpdclient_playlist_callback(mpdclient_t *c, int event, gpointer data); /*** filelist functions ***************************************************/ mpdclient_filelist_t *mpdclient_filelist_free(mpdclient_filelist_t *filelist); mpdclient_filelist_t *mpdclient_filelist_get(mpdclient_t *c, gchar *path); +mpdclient_filelist_t *mpdclient_filelist_search(mpdclient_t *c, + int table, + gchar *path); mpdclient_filelist_t *mpdclient_filelist_update(mpdclient_t *c, mpdclient_filelist_t *flist); diff --git a/src/ncmpc.h b/src/ncmpc.h index 75fbf8e4a..0c72a099f 100644 --- a/src/ncmpc.h +++ b/src/ncmpc.h @@ -5,6 +5,16 @@ #include "config.h" #endif +#ifndef DISABLE_SEARCH_SCREEN +#define ENABLE_SEARCH_SCREEN 1 +#endif +#ifndef DISABLE_KEYDEF_SCREEN +#define ENABLE_KEYDEF_SCREEN 1 +#endif +#ifndef DISABLE_CLOCK_SCREEN +#define ENABLE_CLOCK_SCREEN 1 +#endif + #ifdef DEBUG void D(char *format, ...); #else diff --git a/src/options.c b/src/options.c index 4f1100f9d..a5289105b 100644 --- a/src/options.c +++ b/src/options.c @@ -160,6 +160,12 @@ handle_option(int c, char *arg) #ifdef ENABLE_NLS printf(" nls"); #endif +#ifdef HAVE_GETMOUSE + printf(" getmouse"); +#endif +#ifdef ENABLE_SEARCH_SCREEN + printf(" search-screen"); +#endif #ifdef ENABLE_KEYDEF_SCREEN printf(" key-screen"); #endif diff --git a/src/options.h b/src/options.h index e4d61e878..d264dd1fa 100644 --- a/src/options.h +++ b/src/options.h @@ -14,6 +14,7 @@ typedef struct char *xterm_title_format; int port; int crossfade_time; + int search_mode; gboolean reconnect; gboolean debug; gboolean find_wrap; diff --git a/src/screen.c b/src/screen.c index e390720b8..be4865f04 100644 --- a/src/screen.c +++ b/src/screen.c @@ -47,11 +47,14 @@ #define SCREEN_HELP_ID 100 #define SCREEN_KEYDEF_ID 101 #define SCREEN_CLOCK_ID 102 +#define SCREEN_SEARCH_ID 103 + /* screens */ extern screen_functions_t *get_screen_playlist(void); extern screen_functions_t *get_screen_browse(void); extern screen_functions_t *get_screen_help(void); +extern screen_functions_t *get_screen_search(void); extern screen_functions_t *get_screen_keydef(void); extern screen_functions_t *get_screen_clock(void); @@ -69,6 +72,9 @@ static screen_mode_info_t screens[] = { { SCREEN_PLAYLIST_ID, "playlist", get_screen_playlist }, { SCREEN_BROWSE_ID, "browse", get_screen_browse }, { SCREEN_HELP_ID, "help", get_screen_help }, +#ifdef ENABLE_SEARCH_SCREEN + { SCREEN_SEARCH_ID, "search", get_screen_search }, +#endif #ifdef ENABLE_KEYDEF_SCREEN { SCREEN_KEYDEF_ID, "keydef", get_screen_keydef }, #endif @@ -169,7 +175,13 @@ paint_top_window(char *header, mpdclient_t *c, int clear) colors_use(w, COLOR_TITLE_BOLD); waddstr(w, get_key_names(CMD_SCREEN_FILE, FALSE)); colors_use(w, COLOR_TITLE); - waddstr(w, _(":Browse")); + waddstr(w, _(":Browse ")); +#ifdef ENABLE_SEARCH_SCREEN + colors_use(w, COLOR_TITLE_BOLD); + waddstr(w, get_key_names(CMD_SCREEN_SEARCH, FALSE)); + colors_use(w, COLOR_TITLE); + waddstr(w, _(":Search ")); +#endif } if( c->status->volume==MPD_STATUS_NO_VOLUME ) { @@ -873,6 +885,9 @@ screen_cmd(mpdclient_t *c, command_t cmd) case CMD_SCREEN_HELP: switch_screen_mode(SCREEN_HELP_ID, c); break; + case CMD_SCREEN_SEARCH: + switch_screen_mode(SCREEN_SEARCH_ID, c); + break; case CMD_SCREEN_KEYDEF: switch_screen_mode(SCREEN_KEYDEF_ID, c); break; diff --git a/src/screen_browse.h b/src/screen_browse.h new file mode 100644 index 000000000..ddb3f21b0 --- /dev/null +++ b/src/screen_browse.h @@ -0,0 +1,30 @@ + +void clear_highlights(mpdclient_filelist_t *filelist); +void sync_highlights(mpdclient_t *c, mpdclient_filelist_t *filelist); +void set_highlight(mpdclient_filelist_t *filelist, + mpd_Song *song, + int highlight); + + +char *browse_lw_callback(int index, int *highlight, void *filelist); + +int browse_handle_select(screen_t *screen, + mpdclient_t *c, + list_window_t *lw, + mpdclient_filelist_t *filelist); +int browse_handle_enter(screen_t *screen, + mpdclient_t *c, + list_window_t *lw, + mpdclient_filelist_t *filelist); + +#ifdef HAVE_GETMOUSE +int browse_handle_mouse_event(screen_t *screen, + mpdclient_t *c, + list_window_t *lw, + mpdclient_filelist_t *filelist); +#else +#define browse_handle_mouse_event(s,c,lw,filelist) (0) +#endif + + + diff --git a/src/screen_clock.c b/src/screen_clock.c index d3d492559..c996c1924 100644 --- a/src/screen_clock.c +++ b/src/screen_clock.c @@ -13,7 +13,7 @@ #include "config.h" -#ifdef ENABLE_CLOCK_SCREEN +#ifndef DISABLE_CLOCK_SCREEN #include "ncmpc.h" #include "mpdclient.h" #include "options.h" diff --git a/src/screen_file.c b/src/screen_file.c index d25229d1e..75095db9a 100644 --- a/src/screen_file.c +++ b/src/screen_file.c @@ -33,6 +33,7 @@ #include "command.h" #include "screen.h" #include "screen_utils.h" +#include "screen_browse.h" #define USE_OLD_LAYOUT @@ -50,7 +51,7 @@ static mpdclient_filelist_t *filelist = NULL; /* clear the highlight flag for all items in the filelist */ -static void +void clear_highlights(mpdclient_filelist_t *filelist) { GList *list = g_list_first(filelist->list); @@ -65,7 +66,7 @@ clear_highlights(mpdclient_filelist_t *filelist) } /* change the highlight flag for a song */ -static void +void set_highlight(mpdclient_filelist_t *filelist, mpd_Song *song, int highlight) { GList *list = g_list_first(filelist->list); @@ -95,7 +96,7 @@ set_highlight(mpdclient_filelist_t *filelist, mpd_Song *song, int highlight) } /* sync highlight flags with playlist */ -static void +void sync_highlights(mpdclient_t *c, mpdclient_filelist_t *filelist) { GList *list = g_list_first(filelist->list); @@ -178,11 +179,11 @@ pop_lw_state(void) } /* list_window callback */ -static char * -list_callback(int index, int *highlight, void *data) +char * +browse_lw_callback(int index, int *highlight, void *data) { static char buf[BUFSIZE]; - /*mpdclient_t *c = (mpdclient_t *) data;*/ + mpdclient_filelist_t *filelist = (mpdclient_filelist_t *) data; filelist_entry_t *entry; mpd_InfoEntity *entity; @@ -327,9 +328,37 @@ handle_delete(screen_t *screen, mpdclient_t *c) return 0; } - static int -handle_enter(screen_t *screen, mpdclient_t *c) +enqueue_and_play(screen_t *screen, mpdclient_t *c, filelist_entry_t *entry) +{ + mpd_InfoEntity *entity = entry->entity; + mpd_Song *song = entity->info.song; + + if(!( entry->flags & HIGHLIGHT )) + { + if( mpdclient_cmd_add(c, song) == 0 ) + { + char buf[BUFSIZE]; + + entry->flags |= HIGHLIGHT; + strfsong(buf, BUFSIZE, LIST_FORMAT, song); + screen_status_printf(_("Adding \'%s\' to playlist\n"), buf); + mpdclient_update(c); /* get song id */ + } + else + return -1; + } + + int index = playlist_get_index_from_file(c, song->file); + mpdclient_cmd_play(c, index); + return 0; +} + +int +browse_handle_enter(screen_t *screen, + mpdclient_t *c, + list_window_t *lw, + mpdclient_filelist_t *filelist) { filelist_entry_t *entry; mpd_InfoEntity *entity; @@ -343,6 +372,8 @@ handle_enter(screen_t *screen, mpdclient_t *c) return change_directory(screen, c, entry); else if( entity->type==MPD_INFO_ENTITY_TYPE_PLAYLISTFILE ) return load_playlist(screen, c, entry); + else if( entity->type==MPD_INFO_ENTITY_TYPE_SONG ) + return enqueue_and_play(screen, c, entry); return -1; } @@ -403,8 +434,11 @@ add_directory(mpdclient_t *c, char *dir) } #endif -static int -handle_select(screen_t *screen, mpdclient_t *c) +int +browse_handle_select(screen_t *screen, + mpdclient_t *c, + list_window_t *lw, + mpdclient_filelist_t *filelist) { filelist_entry_t *entry; @@ -536,7 +570,7 @@ browse_paint(screen_t *screen, mpdclient_t *c) { lw->clear = 1; - list_window_paint(lw, list_callback, (void *) c); + list_window_paint(lw, browse_lw_callback, (void *) filelist); wnoutrefresh(lw->w); } @@ -549,14 +583,17 @@ browse_update(screen_t *screen, mpdclient_t *c) filelist->updated = FALSE; return; } - list_window_paint(lw, list_callback, (void *) c); + list_window_paint(lw, browse_lw_callback, (void *) filelist); wnoutrefresh(lw->w); } #ifdef HAVE_GETMOUSE -static int -handle_mouse_event(screen_t *screen, mpdclient_t *c) +int +browse_handle_mouse_event(screen_t *screen, + mpdclient_t *c, + list_window_t *lw, + mpdclient_filelist_t *filelist) { int row; int prev_selected = lw->selected; @@ -571,19 +608,17 @@ handle_mouse_event(screen_t *screen, mpdclient_t *c) if( bstate & BUTTON1_CLICKED ) { if( prev_selected == lw->selected ) - handle_enter(screen, c); + browse_handle_enter(screen, c, lw, filelist); } else if( bstate & BUTTON3_CLICKED ) { if( prev_selected == lw->selected ) - handle_select(screen, c); + browse_handle_select(screen, c, lw, filelist); } return 1; } -#else -#define handle_mouse_event(s,c) (0) -#endif +#endif static int browse_cmd(screen_t *screen, mpdclient_t *c, command_t cmd) @@ -591,10 +626,10 @@ browse_cmd(screen_t *screen, mpdclient_t *c, command_t cmd) switch(cmd) { case CMD_PLAY: - handle_enter(screen, c); + browse_handle_enter(screen, c, lw, filelist); return 1; case CMD_SELECT: - if( handle_select(screen, c) == 0 ) + if( browse_handle_select(screen, c, lw, filelist) == 0 ) { /* continue and select next item... */ cmd = CMD_LIST_NEXT; @@ -632,9 +667,9 @@ browse_cmd(screen_t *screen, mpdclient_t *c, command_t cmd) case CMD_LIST_RFIND_NEXT: return screen_find(screen, c, lw, filelist->length, - cmd, list_callback); + cmd, browse_lw_callback, (void *) filelist); case CMD_MOUSE_EVENT: - return handle_mouse_event(screen,c); + return browse_handle_mouse_event(screen,c,lw,filelist); default: break; } diff --git a/src/screen_help.c b/src/screen_help.c index 73ccd6743..66acc3d87 100644 --- a/src/screen_help.c +++ b/src/screen_help.c @@ -53,6 +53,9 @@ static help_text_row_t help_text[] = { 0, CMD_SCREEN_HELP, NULL }, { 0, CMD_SCREEN_PLAY, NULL }, { 0, CMD_SCREEN_FILE, NULL }, +#ifdef ENABLE_SEARCH_SCREEN + { 0, CMD_SCREEN_SEARCH, NULL }, +#endif #ifdef ENABLE_CLOCK_SCREEN { 0, CMD_SCREEN_CLOCK, NULL }, #endif @@ -105,11 +108,22 @@ static help_text_row_t help_text[] = { 0, CMD_NONE, NULL }, { 1, CMD_NONE, N_("Keys - Browse screen") }, { 2, CMD_NONE, NULL }, - { 0, CMD_PLAY, N_("Enter directory") }, + { 0, CMD_PLAY, N_("Enter directory/Select and play song") }, { 0, CMD_SELECT, NULL }, - { 0, CMD_DELETE, NULL }, + { 0, CMD_DELETE, N_("Delete playlist") }, { 0, CMD_SCREEN_UPDATE, NULL }, +#ifdef ENABLE_SEARCH_SCREEN + { 0, CMD_NONE, NULL }, + { 0, CMD_NONE, NULL }, + { 1, CMD_NONE, N_("Keys - Search screen") }, + { 2, CMD_NONE, NULL }, + { 0, CMD_SCREEN_SEARCH, N_("Search") }, + { 0, CMD_PLAY, N_("Select and play") }, + { 0, CMD_SELECT, NULL }, + { 0, CMD_SEARCH_MODE, NULL }, +#endif + { 0, CMD_NONE, NULL }, {-1, CMD_NONE, NULL } }; @@ -255,7 +269,7 @@ help_cmd(screen_t *screen, mpdclient_t *c, command_t cmd) lw->selected = lw->start+lw->rows; if( screen_find(screen, c, lw, help_text_rows, - cmd, list_callback) ) + cmd, list_callback, NULL) ) { /* center the row */ lw->start = lw->selected-(lw->rows/2); diff --git a/src/screen_keydef.c b/src/screen_keydef.c index 3451dd2ed..081b6ec39 100644 --- a/src/screen_keydef.c +++ b/src/screen_keydef.c @@ -26,7 +26,7 @@ #include "config.h" -#ifdef ENABLE_KEYDEF_SCREEN +#ifndef DISABLE_KEYDEF_SCREEN #include "ncmpc.h" #include "mpdclient.h" #include "options.h" @@ -369,7 +369,7 @@ keydef_cmd(screen_t *screen, mpdclient_t *c, command_t cmd) case CMD_LIST_RFIND_NEXT: return screen_find(screen, c, lw, length, - cmd, list_callback); + cmd, list_callback, NULL); default: break; diff --git a/src/screen_play.c b/src/screen_play.c index 307471f2c..a86ab0128 100644 --- a/src/screen_play.c +++ b/src/screen_play.c @@ -444,7 +444,7 @@ play_cmd(screen_t *screen, mpdclient_t *c, command_t cmd) case CMD_LIST_RFIND_NEXT: return screen_find(screen, c, lw, c->playlist.length, - cmd, list_callback); + cmd, list_callback, (void *) c); case CMD_MOUSE_EVENT: return handle_mouse_event(screen,c); default: diff --git a/src/screen_search.c b/src/screen_search.c index d82a049ef..95c3830c1 100644 --- a/src/screen_search.c +++ b/src/screen_search.c @@ -1,10 +1,315 @@ +/* + * $Id$ + * + * (c) 2004 by Kalle Wallin <kaw@linux.se> + * + * 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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + * + */ + +#include <ctype.h> #include <stdlib.h> #include <string.h> #include <glib.h> #include <ncurses.h> #include "config.h" +#ifndef DISABLE_SEARCH_SCREEN +#include "ncmpc.h" +#include "options.h" +#include "support.h" #include "mpdclient.h" +#include "strfsong.h" #include "command.h" #include "screen.h" +#include "screen_utils.h" +#include "screen_browse.h" + +#define SEARCH_TITLE 0 +#define SEARCH_ARTIST 1 +#define SEARCH_ALBUM 2 +#define SEARCH_FILE 3 + +typedef struct { + int table; + char *label; +} search_type_t; + +static search_type_t mode[] = { + { MPD_TABLE_TITLE, N_("Title") }, + { MPD_TABLE_ARTIST, N_("Artist") }, + { MPD_TABLE_ALBUM, N_("Album") }, + { MPD_TABLE_FILENAME, N_("Filename") }, + { 0, NULL } +}; + +static list_window_t *lw = NULL; +static mpdclient_filelist_t *filelist = NULL; +static gchar *pattern = NULL; + +/* the playlist have been updated -> fix highlights */ +static void +playlist_changed_callback(mpdclient_t *c, int event, gpointer data) +{ + if( filelist==NULL ) + return; + D("screen_search.c> playlist_callback() [%d]\n", event); + switch(event) + { + case PLAYLIST_EVENT_CLEAR: + clear_highlights(filelist); + break; + default: + sync_highlights(c, filelist); + break; + } +} + +/* sanity check search mode value */ +static void +search_check_mode(void) +{ + int max = 0; + + while( mode[max].label != NULL ) + max++; + if( options.search_mode<0 ) + options.search_mode = 0; + else if( options.search_mode>=max ) + options.search_mode = max-1; +} + +static void +search_clear(screen_t *screen, mpdclient_t *c, gboolean clear_pattern) +{ + if( filelist ) + { + mpdclient_remove_playlist_callback(c, playlist_changed_callback); + filelist = mpdclient_filelist_free(filelist); + } + if( clear_pattern && pattern ) + { + g_free(pattern); + pattern = NULL; + } +} + +static void +search_new(screen_t *screen, mpdclient_t *c) +{ + search_clear(screen, c, TRUE); + + pattern = screen_readln(screen->status_window.w, + _("Search: "), + NULL, + NULL, + NULL); + + if( pattern && strcmp(pattern,"")==0 ) + { + g_free(pattern); + pattern=NULL; + } + + if( pattern==NULL ) + { + list_window_reset(lw); + return; + } + + filelist = mpdclient_filelist_search(c, + mode[options.search_mode].table, + pattern); + sync_highlights(c, filelist); + mpdclient_install_playlist_callback(c, playlist_changed_callback); + list_window_check_selected(lw, filelist->length); +} + +static void +init(WINDOW *w, int cols, int rows) +{ + lw = list_window_init(w, cols, rows); +} + +static void +quit(void) +{ + if( filelist ) + filelist = mpdclient_filelist_free(filelist); + list_window_free(lw); + if( pattern ) + g_free(pattern); + pattern = NULL; +} + +static void +open(screen_t *screen, mpdclient_t *c) +{ + if( pattern==NULL ) + search_new(screen, c); + else + screen_status_printf(_("Press %s for a new search"), + get_key_names(CMD_SCREEN_SEARCH,0)); + search_check_mode(); +} + +static void +resize(int cols, int rows) +{ + lw->cols = cols; + lw->rows = rows; +} + +static void +close(void) +{ +} + +static void +paint(screen_t *screen, mpdclient_t *c) +{ + lw->clear = 1; + + if( filelist ) + { + list_window_paint(lw, browse_lw_callback, (void *) filelist); + filelist->updated = FALSE; + } + else + { + wmove(lw->w, 0, 0); + wclrtobot(lw->w); + } + wnoutrefresh(lw->w); +} + +void +update(screen_t *screen, mpdclient_t *c) +{ + if( filelist==NULL || filelist->updated ) + { + paint(screen, c); + return; + } + list_window_paint(lw, browse_lw_callback, (void *) filelist); + wnoutrefresh(lw->w); +} + +static char * +get_title(char *str, size_t size) +{ + if( pattern ) + g_snprintf(str, size, + _("Search: Results for %s [%s]"), + pattern, + _(mode[options.search_mode].label)); + else + g_snprintf(str, size, _("Search: Press %s for a new search [%s]"), + get_key_names(CMD_SCREEN_SEARCH,0), + _(mode[options.search_mode].label)); + + return str; +} + +static list_window_t * +get_filelist_window() +{ + return lw; +} + +static int +search_cmd(screen_t *screen, mpdclient_t *c, command_t cmd) +{ + switch(cmd) + { + case CMD_PLAY: + browse_handle_enter(screen, c, lw, filelist); + return 1; + + case CMD_SELECT: + if( browse_handle_select(screen, c, lw, filelist) == 0 ) + { + /* continue and select next item... */ + cmd = CMD_LIST_NEXT; + } + return 1; + + case CMD_SEARCH_MODE: + options.search_mode++; + if( mode[options.search_mode].label == NULL ) + options.search_mode = 0; + screen_status_printf(_("Search mode: %s"), + _(mode[options.search_mode].label)); + /* continue and update... */ + case CMD_SCREEN_UPDATE: + if( pattern ) + { + search_clear(screen, c, FALSE); + filelist = mpdclient_filelist_search(c, + mode[options.search_mode].table, + pattern); + sync_highlights(c, filelist); + } + return 1; + + case CMD_SCREEN_SEARCH: + search_new(screen, c); + return 1; + + case CMD_CLEAR: + search_clear(screen, c, TRUE); + list_window_reset(lw); + return 1; + + case CMD_LIST_FIND: + case CMD_LIST_RFIND: + case CMD_LIST_FIND_NEXT: + case CMD_LIST_RFIND_NEXT: + if( filelist ) + return screen_find(screen, c, + lw, filelist->length, + cmd, browse_lw_callback, (void *) filelist); + case CMD_MOUSE_EVENT: + return browse_handle_mouse_event(screen,c,lw,filelist); + + default: + if( filelist ) + return list_window_cmd(lw, filelist->length, cmd); + } + + return 0; +} + +screen_functions_t * +get_screen_search(void) +{ + static screen_functions_t functions; + + memset(&functions, 0, sizeof(screen_functions_t)); + functions.init = init; + functions.exit = quit; + functions.open = open; + functions.close = close; + functions.resize = resize; + functions.paint = paint; + functions.update = update; + functions.cmd = search_cmd; + functions.get_lw = get_filelist_window; + functions.get_title = get_title; + + return &functions; +} + +#endif /* ENABLE_SEARCH_SCREEN */ diff --git a/src/screen_utils.c b/src/screen_utils.c index baa371be1..09ce85787 100644 --- a/src/screen_utils.c +++ b/src/screen_utils.c @@ -110,7 +110,8 @@ screen_find(screen_t *screen, list_window_t *lw, int rows, command_t findcmd, - list_window_callback_fn_t callback_fn) + list_window_callback_fn_t callback_fn, + void *callback_data) { int reversed = 0; int retval = 0; @@ -145,14 +146,14 @@ screen_find(screen_t *screen, if( reversed ) retval = list_window_rfind(lw, callback_fn, - c, + callback_data, screen->findbuf, options.find_wrap, rows); else retval = list_window_find(lw, callback_fn, - c, + callback_data, screen->findbuf, options.find_wrap); if( retval == 0 ) diff --git a/src/screen_utils.h b/src/screen_utils.h index 56e44d533..d68867a46 100644 --- a/src/screen_utils.h +++ b/src/screen_utils.h @@ -18,7 +18,8 @@ int screen_find(screen_t *screen, list_window_t *lw, int rows, command_t findcmd, - list_window_callback_fn_t callback_fn); + list_window_callback_fn_t callback_fn, + void *callback_data); void screen_display_completion_list(screen_t *screen, GList *list); |