Make player_queue_make() generic and introduce player_queue_make_daap()

This commit is contained in:
Kai Elwert 2010-07-31 10:27:33 +02:00 committed by Julien BLACHE
parent 2e6ed82e14
commit 055fe8f442
3 changed files with 40 additions and 32 deletions

View File

@ -716,7 +716,7 @@ dacp_reply_cue_play(struct evhttp_request *req, struct evbuffer *evbuf, char **u
{
sort = evhttp_find_header(query, "sort");
ps = player_queue_make(cuequery, sort);
ps = player_queue_make_daap(cuequery, sort);
if (!ps)
{
DPRINTF(E_LOG, L_DACP, "Could not build song queue\n");

View File

@ -338,10 +338,9 @@ player_laudio_status_cb(enum laudio_state status)
/* Audio sources */
/* Thread: httpd (DACP) */
struct player_source *
player_queue_make(const char *query, const char *sort)
static struct player_source *
player_queue_make(struct query_params *qp, const char *sort)
{
struct query_params qp;
struct db_media_file_info dbmfi;
struct player_source *q_head;
struct player_source *q_tail;
@ -349,46 +348,30 @@ player_queue_make(const char *query, const char *sort)
uint32_t id;
int ret;
memset(&qp, 0, sizeof(struct query_params));
qp.type = Q_ITEMS;
qp.offset = 0;
qp.limit = 0;
qp.idx_type = I_NONE;
qp.sort = S_NONE;
qp.filter = daap_query_parse_sql(query);
if (!qp.filter)
{
DPRINTF(E_LOG, L_PLAYER, "Improper DAAP query!\n");
return NULL;
}
qp->idx_type = I_NONE;
qp->sort = S_NONE;
if (sort)
{
if (strcmp(sort, "name") == 0)
qp.sort = S_NAME;
qp->sort = S_NAME;
else if (strcmp(sort, "album") == 0)
qp.sort = S_ALBUM;
qp->sort = S_ALBUM;
}
ret = db_query_start(&qp);
ret = db_query_start(qp);
if (ret < 0)
{
DPRINTF(E_LOG, L_PLAYER, "Could not start query\n");
if (qp.filter)
free(qp.filter);
return NULL;
}
DPRINTF(E_DBG, L_PLAYER, "Player queue query returned %d items\n", qp.results);
DPRINTF(E_DBG, L_PLAYER, "Player queue query returned %d items\n", qp->results);
q_head = NULL;
q_tail = NULL;
while (((ret = db_query_fetch_file(&qp, &dbmfi)) == 0) && (dbmfi.id))
while (((ret = db_query_fetch_file(qp, &dbmfi)) == 0) && (dbmfi.id))
{
ret = safe_atou32(dbmfi.id, &id);
if (ret < 0)
@ -428,10 +411,7 @@ player_queue_make(const char *query, const char *sort)
DPRINTF(E_DBG, L_PLAYER, "Added song id %d (%s)\n", id, dbmfi.title);
}
if (qp.filter)
free(qp.filter);
db_query_end(&qp);
db_query_end(qp);
if (ret < 0)
{
@ -449,6 +429,34 @@ player_queue_make(const char *query, const char *sort)
return q_head;
}
/* Thread: httpd (DACP) */
struct player_source *
player_queue_make_daap(const char *query, const char *sort)
{
struct query_params qp;
struct player_source *ps;
memset(&qp, 0, sizeof(struct query_params));
qp.type = Q_ITEMS;
qp.offset = 0;
qp.limit = 0;
qp.filter = daap_query_parse_sql(query);
if (!qp.filter)
{
DPRINTF(E_LOG, L_PLAYER, "Improper DAAP query!\n");
return NULL;
}
ps = player_queue_make(&qp, sort);
free(qp.filter);
return ps;
}
static void
source_free(struct player_source *ps)
{

View File

@ -95,7 +95,7 @@ player_shuffle_set(int enable);
struct player_source *
player_queue_make(const char *query, const char *sort);
player_queue_make_daap(const char *query, const char *sort);
int
player_queue_add(struct player_source *ps);