2009-03-13 18:43:16 +01:00
|
|
|
/*
|
2011-01-29 10:13:54 +01:00
|
|
|
* Copyright (C) 2003-2011 The Music Player Daemon Project
|
2009-03-13 18:43:16 +01:00
|
|
|
* http://www.musicpd.org
|
2006-07-13 21:20:34 +02:00
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation; either version 2 of the License, or
|
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
2009-03-13 18:43:16 +01:00
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License along
|
|
|
|
* with this program; if not, write to the Free Software Foundation, Inc.,
|
|
|
|
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
2006-07-13 21:20:34 +02:00
|
|
|
*/
|
|
|
|
|
2009-11-12 09:12:38 +01:00
|
|
|
#include "config.h"
|
2004-11-10 22:58:27 +01:00
|
|
|
#include "dbUtils.h"
|
2009-01-24 14:52:05 +01:00
|
|
|
#include "locate.h"
|
2008-10-08 11:07:35 +02:00
|
|
|
#include "database.h"
|
2011-09-10 19:24:30 +02:00
|
|
|
#include "db_visitor.h"
|
2004-11-10 22:58:27 +01:00
|
|
|
#include "playlist.h"
|
2008-10-22 17:21:57 +02:00
|
|
|
#include "stored_playlist.h"
|
2004-11-10 22:58:27 +01:00
|
|
|
|
2008-10-15 19:36:37 +02:00
|
|
|
#include <glib.h>
|
|
|
|
|
2011-09-10 19:24:30 +02:00
|
|
|
static bool
|
|
|
|
add_to_queue_song(struct song *song, void *ctx, GError **error_r)
|
2006-07-20 18:02:40 +02:00
|
|
|
{
|
2011-09-10 19:24:30 +02:00
|
|
|
struct player_control *pc = ctx;
|
|
|
|
|
|
|
|
enum playlist_result result =
|
|
|
|
playlist_append_song(&g_playlist, 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 add_to_queue_visitor = {
|
|
|
|
.song = add_to_queue_song,
|
|
|
|
};
|
2009-11-03 21:08:48 +01:00
|
|
|
|
2011-09-10 19:24:30 +02:00
|
|
|
bool
|
|
|
|
addAllIn(struct player_control *pc, const char *uri, GError **error_r)
|
|
|
|
{
|
|
|
|
return db_walk(uri, &add_to_queue_visitor, pc, error_r);
|
2004-11-10 22:58:27 +01:00
|
|
|
}
|
|
|
|
|
2008-09-07 13:48:24 +02:00
|
|
|
struct add_data {
|
|
|
|
const char *path;
|
|
|
|
};
|
|
|
|
|
2011-09-10 19:24:30 +02:00
|
|
|
static bool
|
|
|
|
add_to_spl_song(struct song *song, void *ctx, GError **error_r)
|
2006-11-20 16:37:58 +01:00
|
|
|
{
|
2011-09-10 19:24:30 +02:00
|
|
|
struct add_data *data = ctx;
|
2008-09-07 13:48:24 +02:00
|
|
|
|
2011-09-10 19:24:30 +02:00
|
|
|
if (!spl_append_song(data->path, song, error_r))
|
|
|
|
return false;
|
2011-09-11 07:41:25 +02:00
|
|
|
|
2011-09-10 19:24:30 +02:00
|
|
|
return true;
|
2006-11-20 16:37:58 +01:00
|
|
|
}
|
|
|
|
|
2011-09-10 19:24:30 +02:00
|
|
|
static const struct db_visitor add_to_spl_visitor = {
|
|
|
|
.song = add_to_spl_song,
|
|
|
|
};
|
2004-11-10 22:58:27 +01:00
|
|
|
|
2011-09-11 07:41:25 +02:00
|
|
|
bool
|
2011-09-10 19:24:30 +02:00
|
|
|
addAllInToStoredPlaylist(const char *uri_utf8, const char *path_utf8,
|
2011-09-11 07:41:25 +02:00
|
|
|
GError **error_r)
|
2006-11-20 16:37:58 +01:00
|
|
|
{
|
2008-09-07 13:48:24 +02:00
|
|
|
struct add_data data = {
|
2011-09-10 19:24:30 +02:00
|
|
|
.path = path_utf8,
|
2008-09-07 13:48:24 +02:00
|
|
|
};
|
|
|
|
|
2011-09-10 19:24:30 +02:00
|
|
|
return db_walk(uri_utf8, &add_to_spl_visitor, &data, error_r);
|
2006-11-20 16:37:58 +01:00
|
|
|
}
|
|
|
|
|
2011-09-05 23:12:33 +02:00
|
|
|
struct find_add_data {
|
|
|
|
struct player_control *pc;
|
|
|
|
const struct locate_item_list *criteria;
|
|
|
|
};
|
|
|
|
|
2011-09-10 19:24:30 +02:00
|
|
|
static bool
|
|
|
|
find_add_song(struct song *song, void *ctx, GError **error_r)
|
2009-08-25 13:43:22 +02:00
|
|
|
{
|
2011-09-10 19:24:30 +02:00
|
|
|
struct find_add_data *data = ctx;
|
|
|
|
|
|
|
|
if (!locate_song_match(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;
|
|
|
|
}
|
2009-08-25 13:43:22 +02:00
|
|
|
|
2011-09-10 19:24:30 +02:00
|
|
|
return true;
|
2009-08-25 13:43:22 +02:00
|
|
|
}
|
|
|
|
|
2011-09-10 19:24:30 +02:00
|
|
|
static const struct db_visitor find_add_visitor = {
|
|
|
|
.song = find_add_song,
|
|
|
|
};
|
|
|
|
|
|
|
|
bool
|
2011-09-05 23:12:33 +02:00
|
|
|
findAddIn(struct player_control *pc, const char *name,
|
2011-09-10 19:24:30 +02:00
|
|
|
const struct locate_item_list *criteria, GError **error_r)
|
2009-08-25 13:43:22 +02:00
|
|
|
{
|
2011-09-05 23:12:33 +02:00
|
|
|
struct find_add_data data;
|
|
|
|
data.pc = pc;
|
2009-08-25 13:43:22 +02:00
|
|
|
data.criteria = criteria;
|
|
|
|
|
2011-09-10 19:24:30 +02:00
|
|
|
return db_walk(name, &find_add_visitor, &data, error_r);
|
2009-08-25 13:43:22 +02:00
|
|
|
}
|