addToPlaylist/addSongToPlaylist: printId argument changed to added_id
Instead of printing out the Id from playlist.c, instead set the integer that added_id poitns to if added_id is non-NULL. This makes the API cleaner and will allow us to use additional commands to manipulate the newly-added song_id. Callers (handleAddId) that relied on printId to print it to the given fd have now been modified to print the ID at a higher-level; making playlist.c less-dependent on protocol details. git-svn-id: https://svn.musicpd.org/mpd/trunk@7149 09075e82-0dd4-0310-85a5-a0d7c8717e4f
This commit is contained in:
parent
2dafd9cd56
commit
2f0e5bfd85
@ -330,14 +330,19 @@ static int handleAdd(int fd, int *permission, int argc, char *argv[])
|
|||||||
char *path = argv[1];
|
char *path = argv[1];
|
||||||
|
|
||||||
if (isRemoteUrl(path))
|
if (isRemoteUrl(path))
|
||||||
return addToPlaylist(fd, path, 0);
|
return addToPlaylist(fd, path, NULL);
|
||||||
|
|
||||||
return addAllIn(fd, path);
|
return addAllIn(fd, path);
|
||||||
}
|
}
|
||||||
|
|
||||||
static int handleAddId(int fd, int *permission, int argc, char *argv[])
|
static int handleAddId(int fd, int *permission, int argc, char *argv[])
|
||||||
{
|
{
|
||||||
return addToPlaylist(fd, argv[1], 1);
|
int added_id;
|
||||||
|
int ret = addToPlaylist(fd, argv[1], &added_id);
|
||||||
|
|
||||||
|
if (!ret)
|
||||||
|
fdprintf(fd, "Id: %d\n", added_id);
|
||||||
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int handleDelete(int fd, int *permission, int argc, char *argv[])
|
static int handleDelete(int fd, int *permission, int argc, char *argv[])
|
||||||
|
@ -173,7 +173,7 @@ int printAllIn(int fd, char *name)
|
|||||||
|
|
||||||
static int directoryAddSongToPlaylist(int fd, Song * song, void *data)
|
static int directoryAddSongToPlaylist(int fd, Song * song, void *data)
|
||||||
{
|
{
|
||||||
return addSongToPlaylist(fd, song, 0);
|
return addSongToPlaylist(fd, song, NULL);
|
||||||
}
|
}
|
||||||
|
|
||||||
static int directoryAddSongToStoredPlaylist(int fd, Song *song, void *data)
|
static int directoryAddSongToStoredPlaylist(int fd, Song *song, void *data)
|
||||||
|
@ -290,7 +290,8 @@ static void loadPlaylistFromStateFile(FILE *fp, char *buffer,
|
|||||||
song = atoi(strtok(buffer, ":"));
|
song = atoi(strtok(buffer, ":"));
|
||||||
if (!(temp = strtok(NULL, "")))
|
if (!(temp = strtok(NULL, "")))
|
||||||
state_file_fatal();
|
state_file_fatal();
|
||||||
if (!addToPlaylist(STDERR_FILENO, temp, 0) && current == song) {
|
if (!addToPlaylist(STDERR_FILENO, temp, NULL)
|
||||||
|
&& current == song) {
|
||||||
if (state != PLAYER_STATE_STOP) {
|
if (state != PLAYER_STATE_STOP) {
|
||||||
playPlaylist(STDERR_FILENO,
|
playPlaylist(STDERR_FILENO,
|
||||||
playlist.length - 1, 0);
|
playlist.length - 1, 0);
|
||||||
@ -603,7 +604,7 @@ static void clearPlayerQueue(void)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
int addToPlaylist(int fd, char *url, int printId)
|
int addToPlaylist(int fd, char *url, int *added_id)
|
||||||
{
|
{
|
||||||
Song *song;
|
Song *song;
|
||||||
|
|
||||||
@ -618,7 +619,7 @@ int addToPlaylist(int fd, char *url, int printId)
|
|||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
return addSongToPlaylist(fd, song, printId);
|
return addSongToPlaylist(fd, song, added_id);
|
||||||
}
|
}
|
||||||
|
|
||||||
int addToStoredPlaylist(int fd, char *url, char *utf8file)
|
int addToStoredPlaylist(int fd, char *url, char *utf8file)
|
||||||
@ -649,7 +650,7 @@ fail:
|
|||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
int addSongToPlaylist(int fd, Song * song, int printId)
|
int addSongToPlaylist(int fd, Song * song, int *added_id)
|
||||||
{
|
{
|
||||||
int id;
|
int id;
|
||||||
|
|
||||||
@ -695,8 +696,8 @@ int addSongToPlaylist(int fd, Song * song, int printId)
|
|||||||
|
|
||||||
incrPlaylistVersion();
|
incrPlaylistVersion();
|
||||||
|
|
||||||
if (printId)
|
if (added_id)
|
||||||
fdprintf(fd, "Id: %i\n", id);
|
*added_id = id;
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
@ -1550,7 +1551,7 @@ int loadPlaylist(int fd, char *utf8file)
|
|||||||
node = list->firstNode;
|
node = list->firstNode;
|
||||||
while (node != NULL) {
|
while (node != NULL) {
|
||||||
char *temp = node->data;
|
char *temp = node->data;
|
||||||
if ((addToPlaylist(STDERR_FILENO, temp, 0)) < 0) {
|
if ((addToPlaylist(STDERR_FILENO, temp, NULL)) < 0) {
|
||||||
/* for windows compatibility, convert slashes */
|
/* for windows compatibility, convert slashes */
|
||||||
char *temp2 = xstrdup(temp);
|
char *temp2 = xstrdup(temp);
|
||||||
char *p = temp2;
|
char *p = temp2;
|
||||||
@ -1559,7 +1560,7 @@ int loadPlaylist(int fd, char *utf8file)
|
|||||||
*p = '/';
|
*p = '/';
|
||||||
p++;
|
p++;
|
||||||
}
|
}
|
||||||
if ((addToPlaylist(STDERR_FILENO, temp2, 0)) < 0) {
|
if ((addToPlaylist(STDERR_FILENO, temp2, NULL)) < 0) {
|
||||||
commandError(fd, ACK_ERROR_PLAYLIST_LOAD,
|
commandError(fd, ACK_ERROR_PLAYLIST_LOAD,
|
||||||
"can't add file \"%s\"", temp2);
|
"can't add file \"%s\"", temp2);
|
||||||
}
|
}
|
||||||
|
@ -57,11 +57,11 @@ int clearPlaylist(int fd);
|
|||||||
|
|
||||||
int clearStoredPlaylist(int fd, char *utf8file);
|
int clearStoredPlaylist(int fd, char *utf8file);
|
||||||
|
|
||||||
int addToPlaylist(int fd, char *file, int printId);
|
int addToPlaylist(int fd, char *file, int *added_id);
|
||||||
|
|
||||||
int addToStoredPlaylist(int fd, char *file, char *utf8file);
|
int addToStoredPlaylist(int fd, char *file, char *utf8file);
|
||||||
|
|
||||||
int addSongToPlaylist(int fd, Song * song, int printId);
|
int addSongToPlaylist(int fd, Song * song, int *added_id);
|
||||||
|
|
||||||
int showPlaylist(int fd);
|
int showPlaylist(int fd);
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user