Code

filelist: added constructor filelist_new_recv()
authorMax Kellermann <max@duempel.org>
Fri, 2 Oct 2009 17:49:30 +0000 (19:49 +0200)
committerMax Kellermann <max@duempel.org>
Fri, 2 Oct 2009 17:49:30 +0000 (19:49 +0200)
This receives a filelist from a mpd_connection.  This code has existed
before, and this patch merges those.

src/filelist.c
src/filelist.h
src/mpdclient.c
src/screen_search.c

index 575d4071831c19ab6882ff3f93933ac1dbc67567..2ce928cd4f73d7388bfb675a42d90b2896d41d3c 100644 (file)
@@ -217,3 +217,20 @@ filelist_find_directory(struct filelist *filelist, const char *name)
 
        return -1;
 }
+
+void
+filelist_recv(struct filelist *filelist, struct mpd_connection *connection)
+{
+       struct mpd_entity *entity;
+
+       while ((entity = mpd_recv_entity(connection)) != NULL)
+               filelist_append(filelist, entity);
+}
+
+struct filelist *
+filelist_new_recv(struct mpd_connection *connection)
+{
+       struct filelist *filelist = filelist_new();
+       filelist_recv(filelist, connection);
+       return filelist;
+}
index 0f1f0c09d30cb77cc3f001234352f91d3f4496d0..ee6e60610fa7fc01803a52b3252f5f1b792b6793 100644 (file)
@@ -22,6 +22,7 @@
 
 #include <glib.h>
 
+struct mpd_connection;
 struct mpd_song;
 
 struct filelist_entry {
@@ -82,4 +83,19 @@ filelist_find_song(struct filelist *flist, const struct mpd_song *song);
 int
 filelist_find_directory(struct filelist *filelist, const char *name);
 
+/**
+ * Receives entities from the connection, and appends them to the
+ * specified filelist.  This does not finish the response, and does
+ * not check for errors.
+ */
+void
+filelist_recv(struct filelist *filelist, struct mpd_connection *connection);
+
+/**
+ * Creates a new filelist and receives entities from the connection.
+ * This does not finish the response, and does not check for errors.
+ */
+struct filelist *
+filelist_new_recv(struct mpd_connection *connection);
+
 #endif
index 9a9154caafb4f57de45d462dc7db54218a140af2..1c21785e2054807c6876bac310906f313663a064 100644 (file)
@@ -708,25 +708,21 @@ mpdclient_playlist_update_changes(struct mpdclient *c)
 /*** Filelist functions *****************************************************/
 /****************************************************************************/
 
+static struct filelist *
+mpdclient_recv_filelist_response(struct mpdclient *c);
+
 struct filelist *
 mpdclient_filelist_get(struct mpdclient *c, const gchar *path)
 {
        struct filelist *filelist;
-       struct mpd_entity *entity;
 
        if (MPD_ERROR(c))
                return NULL;
 
        mpd_send_list_meta(c->connection, path);
-       filelist = filelist_new();
-
-       while ((entity = mpd_recv_entity(c->connection)) != NULL)
-               filelist_append(filelist, entity);
-
-       if (!mpdclient_finish_command(c)) {
-               filelist_free(filelist);
+       filelist = mpdclient_recv_filelist_response(c);
+       if (filelist == NULL)
                return NULL;
-       }
 
        filelist_sort_dir_play(filelist, compare_filelistentry);
 
@@ -737,12 +733,8 @@ static struct filelist *
 mpdclient_recv_filelist_response(struct mpdclient *c)
 {
        struct filelist *filelist;
-       struct mpd_entity *entity;
-
-       filelist = filelist_new();
 
-       while ((entity = mpd_recv_entity(c->connection)) != NULL)
-               filelist_append(filelist, entity);
+       filelist = filelist_new_recv(c->connection);
 
        if (!mpdclient_finish_command(c)) {
                filelist_free(filelist);
index 03399443756ee1ad817d47c997611b0fb7863c9f..8dfec1ff920c1bce707bfec565b7afbacb67cfc4 100644 (file)
@@ -204,7 +204,6 @@ search_advanced_query(struct mpd_connection *connection, char *query)
        int table[10];
        char *arg[10];
        struct filelist *fl = NULL;
-       struct mpd_entity *entity;
 
        advanced_search_mode = FALSE;
        if (strchr(query, ':') == NULL)
@@ -273,12 +272,7 @@ search_advanced_query(struct mpd_connection *connection, char *query)
        }
 
        mpd_search_commit(connection);
-
-       fl = filelist_new();
-
-       while ((entity = mpd_recv_entity(connection)) != NULL)
-               filelist_append(fl, entity);
-
+       fl = filelist_new_recv(connection);
        if (!mpd_response_finish(connection)) {
                filelist_free(fl);
                fl = NULL;