command: add "findadd" command.

This commit is contained in:
Anton Khirnov
2009-08-25 13:43:22 +02:00
committed by Max Kellermann
parent 1e56c7b862
commit df0c26a394
5 changed files with 69 additions and 0 deletions

View File

@@ -869,6 +869,30 @@ handle_find(struct client *client, int argc, char *argv[])
return ret;
}
static enum command_return
handle_findadd(struct client *client, int argc, char *argv[])
{
int ret;
struct locate_item_list *list =
locate_item_list_parse(argv + 1, argc - 1);
if (list == NULL || list->length == 0) {
if (list != NULL)
locate_item_list_free(list);
command_error(client, ACK_ERROR_ARG, "incorrect arguments");
return COMMAND_RETURN_ERROR;
}
ret = findAddIn(client, NULL, list);
if (ret == -1)
command_error(client, ACK_ERROR_NO_EXIST,
"directory or file not found");
locate_item_list_free(list);
return ret;
}
static enum command_return
handle_search(struct client *client, int argc, char *argv[])
{
@@ -1671,6 +1695,7 @@ static const struct command commands[] = {
{ "disableoutput", PERMISSION_ADMIN, 1, 1, handle_disableoutput },
{ "enableoutput", PERMISSION_ADMIN, 1, 1, handle_enableoutput },
{ "find", PERMISSION_READ, 2, -1, handle_find },
{ "findadd", PERMISSION_READ, 2, -1, handle_findadd},
{ "idle", PERMISSION_READ, 0, -1, handle_idle },
{ "kill", PERMISSION_ADMIN, -1, -1, handle_kill },
{ "list", PERMISSION_READ, 1, -1, handle_list },

View File

@@ -199,6 +199,28 @@ int addAllInToStoredPlaylist(const char *name, const char *utf8file)
return db_walk(name, directoryAddSongToStoredPlaylist, NULL, &data);
}
static int
findAddInDirectory(struct song *song, void *_data)
{
struct search_data *data = _data;
if (locate_song_match(song, data->criteria))
return directoryAddSongToPlaylist(song, data);
return 0;
}
int findAddIn(struct client *client, const char *name,
const struct locate_item_list *criteria)
{
struct search_data data;
data.client = client;
data.criteria = criteria;
return db_walk(name, findAddInDirectory, NULL, &data);
}
static int
directoryPrintSongInfo(struct song *song, void *data)
{

View File

@@ -39,6 +39,10 @@ int
findSongsIn(struct client *client, const char *name,
const struct locate_item_list *criteria);
int
findAddIn(struct client *client, const char *name,
const struct locate_item_list *criteria);
int
searchStatsForSongsIn(struct client *client, const char *name,
const struct locate_item_list *criteria);