aboutsummaryrefslogtreecommitdiff
path: root/nncmpp.c
diff options
context:
space:
mode:
authorPřemysl Eric Janouch <p@janouch.name>2024-08-07 22:12:43 +0200
committerPřemysl Eric Janouch <p@janouch.name>2024-08-07 22:12:43 +0200
commit24449fe721dfa6cf2bd1fe41ea0f0106efef0d91 (patch)
tree331fb740cc14dbaf7633a06f1bcf700783fa78b4 /nncmpp.c
parent60171cc5a3a2be8834aa263211a6cd9e0eb7f8fe (diff)
downloadnncmpp-24449fe721dfa6cf2bd1fe41ea0f0106efef0d91.tar.gz
nncmpp-24449fe721dfa6cf2bd1fe41ea0f0106efef0d91.tar.xz
nncmpp-24449fe721dfa6cf2bd1fe41ea0f0106efef0d91.zip
Make global search match on filenames
Diffstat (limited to 'nncmpp.c')
-rw-r--r--nncmpp.c32
1 files changed, 32 insertions, 0 deletions
diff --git a/nncmpp.c b/nncmpp.c
index deee323..3c983d0 100644
--- a/nncmpp.c
+++ b/nncmpp.c
@@ -3616,6 +3616,21 @@ out:
free (filter);
}
+static char *
+mpd_quoted_filter_string (const char *value)
+{
+ struct str quoted = str_make ();
+ str_append_c (&quoted, '\'');
+ for (const char *p = value; *p; p++)
+ {
+ if (mpd_client_must_escape_in_quote (*p))
+ str_append_c (&quoted, '\\');
+ str_append_c (&quoted, *p);
+ }
+ str_append_c (&quoted, '\'');
+ return str_steal (&quoted);
+}
+
static void
search_on_changed (void)
{
@@ -3623,8 +3638,25 @@ search_on_changed (void)
size_t len;
char *u8 = (char *) u32_to_u8 (g.editor.line, g.editor.len + 1, NULL, &len);
+ mpd_client_list_begin (c);
mpd_client_send_command (c, "search", "any", u8, NULL);
+ // Just tag search doesn't consider filenames.
+ // Older MPD can do `search any X file X` but without the negation,
+ // which is necessary to avoid duplicates. Neither syntax supports OR.
+ // XXX: We should parse this, but it's probably not going to reach 100 soon,
+ // and it is not really documented what this should even look like.
+ if (strcmp (c->got_hello, "0.21.") > 1)
+ {
+ char *quoted = mpd_quoted_filter_string (u8);
+ char *expression = xstrdup_printf ("((!(any contains %s)) AND "
+ "(file contains %s))", quoted, quoted);
+ mpd_client_send_command (c, "search", expression, NULL);
+ free (expression);
+ free (quoted);
+ }
+
+ mpd_client_list_end (c);
mpd_client_add_task (c, library_tab_on_search_data, u8);
mpd_client_idle (c, 0);
}