Code

screen_search: eliminate duplicate results
authorMax Kellermann <max@duempel.org>
Sat, 3 Oct 2009 18:18:50 +0000 (20:18 +0200)
committerMax Kellermann <max@duempel.org>
Sat, 3 Oct 2009 18:18:50 +0000 (20:18 +0200)
NEWS
src/filelist.c
src/filelist.h
src/screen_search.c

diff --git a/NEWS b/NEWS
index bbbe18f9686ece24dcff691f97af5c79d84cd042..1019253de2797b11ecbd57d4cdc546d43fcf710d 100644 (file)
--- 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
index 063acbbc8cf1deb8e0f50604e2abe8ef7ca33fa7..46b9a1c8d82820d263be67aaee84a119d4b7a0fd 100644 (file)
@@ -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)
 {
index bbae9d67209ebaae0aa6c5592fd0bde33eedbc03..a54e2aef993e5e0db8b180d3c356650041b81030 100644 (file)
@@ -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);
 
index 9742410d9b610277a2b0a6c97a64694f46b53a81..85f817964008ebe0b7f93050c4d3c6c31d42bee3 100644 (file)
@@ -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,