diff --git a/src/screen_search.c b/src/screen_search.c
index e41e3b09c00542f2bc776bb6674bd50b75d5840b..3abda9d9c574e116c5e417043f100f866250a1ef 100644 (file)
--- a/src/screen_search.c
+++ b/src/screen_search.c
/* ncmpc (Ncurses MPD Client)
- * (c) 2004-2009 The Music Player Daemon Project
+ * (c) 2004-2010 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_search.h"
#include "screen_interface.h"
-#include "screen_message.h"
+#include "screen_status.h"
#include "screen.h"
#include "i18n.h"
#include "options.h"
enum {
SEARCH_URI = MPD_TAG_COUNT + 100,
+ SEARCH_ARTIST_TITLE
};
static const struct {
return -1;
}
-#define SEARCH_ARTIST_TITLE 999
-
typedef struct {
enum mpd_tag_type table;
const char *label;
{ MPD_TAG_TITLE, N_("Title") },
{ MPD_TAG_ARTIST, N_("Artist") },
{ MPD_TAG_ALBUM, N_("Album") },
- { SEARCH_URI, N_("file") },
+ { SEARCH_URI, N_("Filename") },
{ SEARCH_ARTIST_TITLE, N_("Artist + Title") },
{ 0, NULL }
};
static struct screen_browser browser;
+static const char *const help_text[] = {
+ "Quick - Enter a string and ncmpc will search according",
+ " to the current search mode (displayed above).",
+ "",
+ "Advanced - <tag>:<search term> [<tag>:<search term>...]",
+ " Example: artist:radiohead album:pablo honey",
+ "",
+ " Available tags: artist, album, title, track,",
+ " name, genre, date composer, performer, comment, file",
+ "",
+};
/* search info */
static const char *
-lw_search_help_callback(unsigned idx, G_GNUC_UNUSED bool *highlight,
- G_GNUC_UNUSED char** sc, G_GNUC_UNUSED void *data)
+lw_search_help_callback(unsigned idx, G_GNUC_UNUSED void *data)
{
- unsigned text_rows;
- static const char *text[] = {
- "Quick - Enter a string and ncmpc will search according",
- " to the current search mode (displayed above).",
- "",
- "Advanced - <tag>:<search term> [<tag>:<search term>...]",
- " Example: artist:radiohead album:pablo honey",
- "",
- " Available tags: artist, album, title, track,",
- " name, genre, date composer, performer, comment, file",
- "",
- NULL
- };
-
- text_rows=0;
- while (text[text_rows])
- text_rows++;
-
- if (idx < text_rows)
- return text[idx];
- return NULL;
+ assert(idx < G_N_ELEMENTS(help_text));
+
+ return help_text[idx];
}
static void
if (browser.filelist) {
filelist_free(browser.filelist);
browser.filelist = filelist_new();
+ list_window_set_length(browser.lw, 0);
}
if (clear_pattern && pattern) {
g_free(pattern);
mpd_command_list_end(connection);
list = filelist_new_recv(connection);
+ filelist_no_duplicates(list);
+ } else if (table == SEARCH_URI) {
+ mpd_search_db_songs(connection, exact_match);
+ mpd_search_add_uri_constraint(connection, MPD_OPERATOR_DEFAULT,
+ filter_utf8);
+ mpd_search_commit(connection);
- if (list != NULL)
- filelist_sort_all(list, compare_filelistentry_format);
+ list = filelist_new_recv(connection);
} else {
mpd_search_db_songs(connection, exact_match);
mpd_search_add_tag_constraint(connection, MPD_OPERATOR_DEFAULT,
static struct filelist *
do_search(struct mpdclient *c, char *query)
{
- struct filelist *fl;
+ struct mpd_connection *connection = mpdclient_get_connection(c);
+ if (connection == NULL)
+ return NULL;
- fl = search_advanced_query(c->connection, query);
+ struct filelist *fl = search_advanced_query(connection, query);
if (fl != NULL)
return fl;
- if (mpd_connection_get_error(c->connection) != MPD_ERROR_SUCCESS) {
+ if (mpd_connection_get_error(connection) != MPD_ERROR_SUCCESS) {
mpdclient_handle_error(c);
return NULL;
}
- fl = search_simple_query(c->connection, FALSE,
+ fl = search_simple_query(connection, FALSE,
mode[options.search_mode].table,
query);
if (fl == NULL)
return fl;
}
+static void
+screen_search_reload(struct mpdclient *c)
+{
+ if (pattern == NULL)
+ return;
+
+ if (browser.filelist != NULL) {
+ filelist_free(browser.filelist);
+ browser.filelist = NULL;
+ }
+
+ browser.filelist = do_search(c, pattern);
+ if (browser.filelist == NULL)
+ browser.filelist = filelist_new();
+ list_window_set_length(browser.lw, filelist_length(browser.filelist));
+
+ screen_browser_sync_highlights(browser.filelist, &c->playlist);
+}
+
static void
search_new(struct mpdclient *c)
{
return;
}
- if (browser.filelist != NULL) {
- filelist_free(browser.filelist);
- browser.filelist = NULL;
- }
-
- browser.filelist = do_search(c, pattern);
- if (browser.filelist == NULL)
- browser.filelist = filelist_new();
-
- screen_browser_sync_highlights(browser.filelist, &c->playlist);
- list_window_check_selected(browser.lw, filelist_length(browser.filelist));
+ screen_search_reload(c);
}
static void
screen_search_init(WINDOW *w, int cols, int rows)
{
browser.lw = list_window_init(w, cols, rows);
+ list_window_set_length(browser.lw, G_N_ELEMENTS(help_text));
}
static void
// search_new(screen, c);
// else
screen_status_printf(_("Press %s for a new search"),
- get_key_names(CMD_SCREEN_SEARCH,0));
+ get_key_names(CMD_SCREEN_SEARCH, false));
search_check_mode();
}
static void
screen_search_resize(int cols, int rows)
{
- browser.lw->cols = cols;
- browser.lw->rows = rows;
+ list_window_resize(browser.lw, cols, rows);
}
static void
{
if (browser.filelist) {
browser.lw->hide_cursor = false;
- list_window_paint(browser.lw, browser_lw_callback, browser.filelist);
+ screen_browser_paint(&browser);
} else {
browser.lw->hide_cursor = true;
list_window_paint(browser.lw, lw_search_help_callback, NULL);
_(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),
+ get_key_names(CMD_SCREEN_SEARCH, false),
_(mode[options.search_mode].label));
return str;
static void
screen_search_update(struct mpdclient *c)
{
- if (browser.filelist != NULL && c->events & MPD_IDLE_PLAYLIST) {
+ if (browser.filelist != NULL && c->events & MPD_IDLE_QUEUE) {
screen_browser_sync_highlights(browser.filelist, &c->playlist);
search_repaint();
}
_(mode[options.search_mode].label));
/* continue and update... */
case CMD_SCREEN_UPDATE:
- if (pattern) {
- search_clear(false);
- browser.filelist = do_search(c, pattern);
- screen_browser_sync_highlights(browser.filelist,
- &c->playlist);
- }
+ screen_search_reload(c);
search_repaint();
return true;