From 1baf411e7d0bd33ce8776d5dc71edac87c3846a0 Mon Sep 17 00:00:00 2001 From: Max Kellermann Date: Sat, 3 Oct 2009 20:18:50 +0200 Subject: [PATCH] screen_search: eliminate duplicate results --- NEWS | 1 + src/filelist.c | 20 ++++++++++++++++++++ src/filelist.h | 6 ++++++ src/screen_search.c | 4 +--- 4 files changed, 28 insertions(+), 3 deletions(-) diff --git a/NEWS b/NEWS index bbbe18f..1019253 100644 --- a/NEWS +++ b/NEWS @@ -5,6 +5,7 @@ ncmpc 0.16 - not yet released * reactivate incremental playlist changes * optimize "add+play song" with addid/playid * handle stderr messages from lyrics plugins +* search: eliminate duplicate results ncmpc 0.15 - 2009-09-24 diff --git a/src/filelist.c b/src/filelist.c index 063acbb..46b9a1c 100644 --- a/src/filelist.c +++ b/src/filelist.c @@ -174,6 +174,26 @@ filelist_sort_dir_play(struct filelist *filelist, GCompareFunc compare_func) filelist_compare_indirect, compare_func); } +void +filelist_no_duplicates(struct filelist *filelist) +{ + for (int i = filelist_length(filelist) - 1; i >= 0; --i) { + struct filelist_entry *entry = filelist_get(filelist, i); + const struct mpd_song *song; + + if (entry->entity == NULL || + mpd_entity_get_type(entry->entity) != MPD_ENTITY_TYPE_SONG) + continue; + + song = mpd_entity_get_song(entry->entity); + if (filelist_find_song(filelist, song) < i) { + g_ptr_array_remove_index(filelist->entries, i); + mpd_entity_free(entry->entity); + g_slice_free(struct filelist_entry, entry); + } + } +} + static bool same_song(const struct mpd_song *a, const struct mpd_song *b) { diff --git a/src/filelist.h b/src/filelist.h index bbae9d6..a54e2ae 100644 --- a/src/filelist.h +++ b/src/filelist.h @@ -78,6 +78,12 @@ filelist_sort_all(struct filelist *filelist, GCompareFunc compare_func); void filelist_sort_dir_play(struct filelist *filelist, GCompareFunc compare_func); +/** + * Eliminates duplicate songs from the filelist. + */ +void +filelist_no_duplicates(struct filelist *filelist); + int filelist_find_song(struct filelist *flist, const struct mpd_song *song); diff --git a/src/screen_search.c b/src/screen_search.c index 9742410..85f8179 100644 --- a/src/screen_search.c +++ b/src/screen_search.c @@ -183,9 +183,7 @@ search_simple_query(struct mpd_connection *connection, bool exact_match, mpd_command_list_end(connection); list = filelist_new_recv(connection); - - if (list != NULL) - filelist_sort_all(list, compare_filelistentry_format); + 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, -- 2.30.2