Code

screen_search: pass libmpdclient object to search_simple_query()
authorMax Kellermann <max@duempel.org>
Fri, 2 Oct 2009 17:54:50 +0000 (19:54 +0200)
committerMax Kellermann <max@duempel.org>
Fri, 2 Oct 2009 17:54:50 +0000 (19:54 +0200)
Pass mpd_connection instead of mpdclient.  Let the caller handle
errors.

src/screen_search.c

index 8dfec1ff920c1bce707bfec565b7afbacb67cfc4..e41e3b09c00542f2bc776bb6674bd50b75d5840b 100644 (file)
@@ -161,30 +161,38 @@ search_clear(bool clear_pattern)
 }
 
 static struct filelist *
-search_simple_query(struct mpdclient *c, G_GNUC_UNUSED int exact_match,
+search_simple_query(struct mpd_connection *connection, bool exact_match,
                    int table, gchar *local_pattern)
 {
-       struct filelist *list, *list2;
+       struct filelist *list;
        gchar *filter_utf8 = locale_to_utf8(local_pattern);
 
        if (table == SEARCH_ARTIST_TITLE) {
-               list = mpdclient_filelist_search(c, FALSE, MPD_TAG_ARTIST,
-                                                filter_utf8);
-               if (list == NULL)
-                       list = filelist_new();
-
-               list2 = mpdclient_filelist_search(c, FALSE, MPD_TAG_TITLE,
-                                                 filter_utf8);
-               if (list2 != NULL) {
-                       filelist_move(list, list2);
-                       filelist_free(list2);
-               }
+               mpd_command_list_begin(connection, false);
+
+               mpd_search_db_songs(connection, exact_match);
+               mpd_search_add_tag_constraint(connection, MPD_OPERATOR_DEFAULT,
+                                             MPD_TAG_ARTIST, filter_utf8);
+               mpd_search_commit(connection);
+
+               mpd_search_db_songs(connection, exact_match);
+               mpd_search_add_tag_constraint(connection, MPD_OPERATOR_DEFAULT,
+                                             MPD_TAG_TITLE, filter_utf8);
+               mpd_search_commit(connection);
+
+               mpd_command_list_end(connection);
 
-               filelist_sort_all(list, compare_filelistentry_format);
+               list = filelist_new_recv(connection);
+
+               if (list != NULL)
+                       filelist_sort_all(list, compare_filelistentry_format);
        } else {
-               list = mpdclient_filelist_search(c, FALSE, table, filter_utf8);
-               if (list == NULL)
-                       list = filelist_new();
+               mpd_search_db_songs(connection, exact_match);
+               mpd_search_add_tag_constraint(connection, MPD_OPERATOR_DEFAULT,
+                                             table, filter_utf8);
+               mpd_search_commit(connection);
+
+               list = filelist_new_recv(connection);
        }
 
        g_free(filter_utf8);
@@ -298,9 +306,12 @@ do_search(struct mpdclient *c, char *query)
                return NULL;
        }
 
-       return search_simple_query(c, FALSE,
-                                  mode[options.search_mode].table,
-                                  query);
+       fl = search_simple_query(c->connection, FALSE,
+                                mode[options.search_mode].table,
+                                query);
+       if (fl == NULL)
+               mpdclient_handle_error(c);
+       return fl;
 }
 
 static void