summary | shortlog | log | commit | commitdiff | tree
raw | patch | inline | side by side (parent: f8da667)
raw | patch | inline | side by side (parent: f8da667)
author | Max Kellermann <max@duempel.org> | |
Fri, 2 Oct 2009 17:49:30 +0000 (19:49 +0200) | ||
committer | Max 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.
before, and this patch merges those.
src/filelist.c | patch | blob | history | |
src/filelist.h | patch | blob | history | |
src/mpdclient.c | patch | blob | history | |
src/screen_search.c | patch | blob | history |
diff --git a/src/filelist.c b/src/filelist.c
index 575d4071831c19ab6882ff3f93933ac1dbc67567..2ce928cd4f73d7388bfb675a42d90b2896d41d3c 100644 (file)
--- a/src/filelist.c
+++ b/src/filelist.c
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;
+}
diff --git a/src/filelist.h b/src/filelist.h
index 0f1f0c09d30cb77cc3f001234352f91d3f4496d0..ee6e60610fa7fc01803a52b3252f5f1b792b6793 100644 (file)
--- a/src/filelist.h
+++ b/src/filelist.h
#include <glib.h>
+struct mpd_connection;
struct mpd_song;
struct filelist_entry {
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
diff --git a/src/mpdclient.c b/src/mpdclient.c
index 9a9154caafb4f57de45d462dc7db54218a140af2..1c21785e2054807c6876bac310906f313663a064 100644 (file)
--- a/src/mpdclient.c
+++ b/src/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);
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);
diff --git a/src/screen_search.c b/src/screen_search.c
index 03399443756ee1ad817d47c997611b0fb7863c9f..8dfec1ff920c1bce707bfec565b7afbacb67cfc4 100644 (file)
--- a/src/screen_search.c
+++ b/src/screen_search.c
int table[10];
char *arg[10];
struct filelist *fl = NULL;
- struct mpd_entity *entity;
advanced_search_mode = FALSE;
if (strchr(query, ':') == NULL)
}
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;