New command searchadd similar to command findadd.
This commit is contained in:
parent
f2536445f7
commit
16e91baa79
@ -853,6 +853,31 @@ handle_search(struct client *client, int argc, char *argv[])
|
||||
return ret;
|
||||
}
|
||||
|
||||
static enum command_return
|
||||
handle_searchadd(struct client *client, int argc, char *argv[])
|
||||
{
|
||||
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;
|
||||
}
|
||||
|
||||
GError *error = NULL;
|
||||
enum command_return ret = search_add_songs(client->player_control,
|
||||
"", list, &error)
|
||||
? COMMAND_RETURN_OK
|
||||
: print_error(client, error);
|
||||
|
||||
locate_item_list_free(list);
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
static enum command_return
|
||||
handle_count(struct client *client, int argc, char *argv[])
|
||||
{
|
||||
@ -2002,6 +2027,7 @@ static const struct command commands[] = {
|
||||
{ "rm", PERMISSION_CONTROL, 1, 1, handle_rm },
|
||||
{ "save", PERMISSION_CONTROL, 1, 1, handle_save },
|
||||
{ "search", PERMISSION_READ, 2, -1, handle_search },
|
||||
{ "searchadd", PERMISSION_READ, 2, -1, handle_searchadd },
|
||||
{ "seek", PERMISSION_CONTROL, 2, 2, handle_seek },
|
||||
{ "seekcur", PERMISSION_CONTROL, 1, 1, handle_seekcur },
|
||||
{ "seekid", PERMISSION_CONTROL, 2, 2, handle_seekid },
|
||||
|
@ -122,3 +122,45 @@ findAddIn(struct player_control *pc, const char *name,
|
||||
|
||||
return db_walk(name, &find_add_visitor, &data, error_r);
|
||||
}
|
||||
|
||||
static bool
|
||||
searchadd_visitor_song(struct song *song, void *_data, GError **error_r)
|
||||
{
|
||||
struct find_add_data *data = _data;
|
||||
|
||||
if (!locate_song_search(song, data->criteria))
|
||||
return true;
|
||||
|
||||
enum playlist_result result =
|
||||
playlist_append_song(&g_playlist, data->pc, song, NULL);
|
||||
if (result != PLAYLIST_RESULT_SUCCESS) {
|
||||
g_set_error(error_r, playlist_quark(), result,
|
||||
"Playlist error");
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
static const struct db_visitor searchadd_visitor = {
|
||||
.song = searchadd_visitor_song,
|
||||
};
|
||||
|
||||
bool
|
||||
search_add_songs(struct player_control *pc, const char *uri,
|
||||
const struct locate_item_list *criteria,
|
||||
GError **error_r)
|
||||
{
|
||||
struct locate_item_list *new_list =
|
||||
locate_item_list_casefold(criteria);
|
||||
struct find_add_data data = {
|
||||
.pc = pc,
|
||||
.criteria = new_list,
|
||||
};
|
||||
|
||||
bool success = db_walk(uri, &searchadd_visitor, &data, error_r);
|
||||
|
||||
locate_item_list_free(new_list);
|
||||
|
||||
return success;
|
||||
}
|
||||
|
@ -42,4 +42,9 @@ bool
|
||||
findAddIn(struct player_control *pc, const char *name,
|
||||
const struct locate_item_list *criteria, GError **error_r);
|
||||
|
||||
gcc_nonnull(1,2,3)
|
||||
bool
|
||||
search_add_songs(struct player_control *pc, const char *uri,
|
||||
const struct locate_item_list *criteria, GError **error_r);
|
||||
|
||||
#endif
|
||||
|
Loading…
Reference in New Issue
Block a user