2
* Copyright (C) 2003-2011 The Music Player Daemon Project
3
* http://www.musicpd.org
5
* This program is free software; you can redistribute it and/or modify
6
* it under the terms of the GNU General Public License as published by
7
* the Free Software Foundation; either version 2 of the License, or
8
* (at your option) any later version.
10
* This program is distributed in the hope that it will be useful,
11
* but WITHOUT ANY WARRANTY; without even the implied warranty of
12
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13
* GNU General Public License for more details.
15
* You should have received a copy of the GNU General Public License along
16
* with this program; if not, write to the Free Software Foundation, Inc.,
17
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
24
#include "db_visitor.h"
26
#include "stored_playlist.h"
31
add_to_queue_song(struct song *song, void *ctx, GError **error_r)
33
struct player_control *pc = ctx;
35
enum playlist_result result =
36
playlist_append_song(&g_playlist, pc, song, NULL);
37
if (result != PLAYLIST_RESULT_SUCCESS) {
38
g_set_error(error_r, playlist_quark(), result,
46
static const struct db_visitor add_to_queue_visitor = {
47
.song = add_to_queue_song,
51
addAllIn(struct player_control *pc, const char *uri, GError **error_r)
53
return db_walk(uri, &add_to_queue_visitor, pc, error_r);
61
add_to_spl_song(struct song *song, void *ctx, GError **error_r)
63
struct add_data *data = ctx;
65
if (!spl_append_song(data->path, song, error_r))
71
static const struct db_visitor add_to_spl_visitor = {
72
.song = add_to_spl_song,
76
addAllInToStoredPlaylist(const char *uri_utf8, const char *path_utf8,
79
struct add_data data = {
83
return db_walk(uri_utf8, &add_to_spl_visitor, &data, error_r);
86
struct find_add_data {
87
struct player_control *pc;
88
const struct locate_item_list *criteria;
92
find_add_song(struct song *song, void *ctx, GError **error_r)
94
struct find_add_data *data = ctx;
96
if (!locate_song_match(song, data->criteria))
99
enum playlist_result result =
100
playlist_append_song(&g_playlist, data->pc,
102
if (result != PLAYLIST_RESULT_SUCCESS) {
103
g_set_error(error_r, playlist_quark(), result,
111
static const struct db_visitor find_add_visitor = {
112
.song = find_add_song,
116
findAddIn(struct player_control *pc, const char *name,
117
const struct locate_item_list *criteria, GError **error_r)
119
struct find_add_data data;
121
data.criteria = criteria;
123
return db_walk(name, &find_add_visitor, &data, error_r);
127
searchadd_visitor_song(struct song *song, void *_data, GError **error_r)
129
struct find_add_data *data = _data;
131
if (!locate_song_search(song, data->criteria))
134
enum playlist_result result =
135
playlist_append_song(&g_playlist, data->pc, song, NULL);
136
if (result != PLAYLIST_RESULT_SUCCESS) {
137
g_set_error(error_r, playlist_quark(), result,
145
static const struct db_visitor searchadd_visitor = {
146
.song = searchadd_visitor_song,
150
search_add_songs(struct player_control *pc, const char *uri,
151
const struct locate_item_list *criteria,
154
struct locate_item_list *new_list =
155
locate_item_list_casefold(criteria);
156
struct find_add_data data = {
158
.criteria = new_list,
161
bool success = db_walk(uri, &searchadd_visitor, &data, error_r);
163
locate_item_list_free(new_list);
168
struct search_add_playlist_data {
169
const char *playlist;
170
const struct locate_item_list *criteria;
174
searchaddpl_visitor_song(struct song *song, void *_data,
175
G_GNUC_UNUSED GError **error_r)
177
struct search_add_playlist_data *data = _data;
179
if (!locate_song_search(song, data->criteria))
182
if (!spl_append_song(data->playlist, song, error_r))
188
static const struct db_visitor searchaddpl_visitor = {
189
.song = searchaddpl_visitor_song,
193
search_add_to_playlist(const char *uri, const char *path_utf8,
194
const struct locate_item_list *criteria,
197
struct locate_item_list *new_list
198
= locate_item_list_casefold(criteria);
199
struct search_add_playlist_data data = {
200
.playlist = path_utf8,
201
.criteria = new_list,
204
bool success = db_walk(uri, &searchaddpl_visitor, &data, error_r);
206
locate_item_list_free(new_list);