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"
|
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>
|
|
|
|
|
2008-10-08 10:49:11 +02:00
|
|
|
static int
|
2009-11-03 21:08:48 +01:00
|
|
|
directoryAddSongToPlaylist(struct song *song, void *data)
|
2006-07-20 18:02:40 +02:00
|
|
|
{
|
2009-11-03 21:08:48 +01:00
|
|
|
struct player_control *pc = data;
|
|
|
|
|
|
|
|
return playlist_append_song(&g_playlist, pc, song, NULL);
|
2004-11-10 22:58:27 +01:00
|
|
|
}
|
|
|
|
|
2008-09-07 13:48:24 +02:00
|
|
|
struct add_data {
|
|
|
|
const char *path;
|
2011-09-11 07:41:25 +02:00
|
|
|
GError **error_r;
|
2008-09-07 13:48:24 +02:00
|
|
|
};
|
|
|
|
|
2008-10-08 10:49:11 +02:00
|
|
|
static int
|
|
|
|
directoryAddSongToStoredPlaylist(struct song *song, void *_data)
|
2006-11-20 16:37:58 +01:00
|
|
|
{
|
2008-09-07 13:48:24 +02:00
|
|
|
struct add_data *data = _data;
|
|
|
|
|
2011-09-11 07:41:25 +02:00
|
|
|
if (!spl_append_song(data->path, song, data->error_r)) {
|
2008-09-07 13:48:24 +02:00
|
|
|
return -1;
|
2011-09-11 07:41:25 +02:00
|
|
|
}
|
|
|
|
|
2008-09-07 13:48:24 +02:00
|
|
|
return 0;
|
2006-11-20 16:37:58 +01:00
|
|
|
}
|
|
|
|
|
2009-11-03 21:08:48 +01:00
|
|
|
int
|
|
|
|
addAllIn(struct player_control *pc, const char *name)
|
2006-07-20 18:02:40 +02:00
|
|
|
{
|
2009-11-03 21:08:48 +01:00
|
|
|
return db_walk(name, directoryAddSongToPlaylist, NULL, pc);
|
2004-11-10 22:58:27 +01:00
|
|
|
}
|
|
|
|
|
2011-09-11 07:41:25 +02:00
|
|
|
bool
|
|
|
|
addAllInToStoredPlaylist(const char *name, const char *utf8file,
|
|
|
|
GError **error_r)
|
2006-11-20 16:37:58 +01:00
|
|
|
{
|
2008-09-07 13:48:24 +02:00
|
|
|
struct add_data data = {
|
|
|
|
.path = utf8file,
|
2011-09-11 07:41:25 +02:00
|
|
|
.error_r = error_r,
|
2008-09-07 13:48:24 +02:00
|
|
|
};
|
|
|
|
|
2011-09-11 07:41:25 +02:00
|
|
|
return db_walk(name, directoryAddSongToStoredPlaylist, NULL, &data) == 0;
|
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;
|
|
|
|
};
|
|
|
|
|
2009-08-25 13:43:22 +02:00
|
|
|
static int
|
|
|
|
findAddInDirectory(struct song *song, void *_data)
|
|
|
|
{
|
2011-09-05 23:12:33 +02:00
|
|
|
struct find_add_data *data = _data;
|
2009-08-25 13:43:22 +02:00
|
|
|
|
|
|
|
if (locate_song_match(song, data->criteria))
|
2009-11-03 21:08:48 +01:00
|
|
|
return playlist_append_song(&g_playlist,
|
2011-09-05 23:12:33 +02:00
|
|
|
data->pc,
|
2009-11-03 21:08:48 +01:00
|
|
|
song, NULL);
|
2009-08-25 13:43:22 +02:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2011-09-05 23:12:33 +02:00
|
|
|
int
|
|
|
|
findAddIn(struct player_control *pc, const char *name,
|
|
|
|
const struct locate_item_list *criteria)
|
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;
|
|
|
|
|
|
|
|
return db_walk(name, findAddInDirectory, NULL, &data);
|
|
|
|
}
|