allow editing of smart playlists

This commit is contained in:
Ron Pedde 2005-11-03 05:02:17 +00:00
parent 88ab086900
commit f127d8cb58
8 changed files with 815 additions and 721 deletions

View File

@ -53,7 +53,8 @@ function pl_update() {
var url = '/databases/1/containers/add?output=xml&org.mt-daapd.playlist-type=1&dmap.itemname=' + name + '&org.mt-daapd.smart-playlist-spec=' + spec;
result = pl_exec(url,false);
} else {
pl_errormsg("Can't yet update existing playlists.. sorry.");
var url='/databases/1/containers/edit?output=xml&dmap.itemid=' + id + '&dmap.itemname=' + name + '&org.mt-daapd.smart-playlist-spec=' + spec;
result = pl_exec(url,false);
}
init();

View File

@ -50,6 +50,7 @@ typedef struct tag_db_functions {
int(*dbs_add_playlist_item)(int, int);
int(*dbs_delete_playlist)(int);
int(*dbs_delete_playlist_item)(int, int);
int(*dbs_edit_playlist)(int, char*, char*);
int(*dbs_enum_start)(DBQUERYINFO *);
int(*dbs_enum_size)(DBQUERYINFO *, int *);
int(*dbs_enum_fetch)(DBQUERYINFO *, unsigned char **);
@ -79,6 +80,7 @@ DB_FUNCTIONS db_functions[] = {
db_sqlite_add_playlist_item,
db_sqlite_delete_playlist,
db_sqlite_delete_playlist_item,
db_sqlite_edit_playlist,
db_sqlite_enum_start,
db_sqlite_enum_size,
db_sqlite_enum_fetch,
@ -203,6 +205,7 @@ DAAP_ITEMS taglist[] = {
{ 0x0C, "MAPI", "org.mt-daapd.addplaylistitem" },
{ 0x0C, "MDPR", "org.mt-daapd.delplaylist" },
{ 0x0C, "MDPI", "org.mt-daapd.delplaylistitem" },
{ 0x0C, "MEPR", "org.mt-daapd.editplaylist" },
{ 0x00, NULL, NULL }
};
@ -550,6 +553,24 @@ int db_delete_playlist_item(int playlistid, int songid) {
return retval;
}
/**
* edit a playlist
*
* @param id playlist id to edit
* @param name new name of playlist
* @param clause new where clause
*/
int db_edit_playlist(int id, char *name, char *clause) {
int retval;
db_writelock();
retval = db_current->dbs_edit_playlist(id, name, clause);
db_unlock();
return retval;
}
/**
* start a db enumeration, based info in the DBQUERYINFO struct
*

View File

@ -158,6 +158,7 @@ extern int db_scanning(void);
extern int db_add_playlist(char *name, int type, char *clause, char *path, int index, int *playlistid);
extern int db_add_playlist_item(int playlistid, int songid);
extern int db_edit_playlist(int id, char *name, char *clause);
extern int db_delete_playlist(int playlistid);
extern int db_delete_playlist_item(int playlistid, int songid);

View File

@ -304,6 +304,8 @@ int db_sqlite_deinit(void) {
* start a background scan
*/
int db_sqlite_start_scan(void) {
DPRINTF(E_DBG,L_DB,"Starting db scan\n");
if(db_sqlite_reload) {
db_sqlite_exec(E_FATAL,"PRAGMA synchronous = OFF");
db_sqlite_exec(E_FATAL,"BEGIN TRANSACTION");
@ -427,6 +429,24 @@ int db_sqlite_delete_playlist_item(int playlistid, int songid) {
return result;
}
/**
* edit a playlist. The only things worth changing are the name
* and the "where" clause.
*
* @param id id of the playlist to alter
* @param name new name of the playlist
* @param where new where clause
*/
int db_sqlite_edit_playlist(int id, char *name, char *clause) {
int result;
result = db_sqlite_exec(E_LOG,"update playlists set title='%q',query='%q' where id=%d",
name, clause, id);
return result;
}
/**
* add a playlist

View File

@ -42,6 +42,7 @@ extern void db_sqlite_dispose_item(MP3FILE *pmp3);
extern void db_sqlite_dispose_playlist(M3UFILE *pm3u);
extern int db_sqlite_add_playlist(char *name, int type, char *clause, char *path, int index, int *playlistid);
extern int db_sqlite_add_playlist_item(int playlistid, int songid);
extern int db_sqlite_edit_playlist(int id, char *name, char *clause);
extern int db_sqlite_delete_playlist(int playlistid);
extern int db_sqlite_delete_playlist_item(int playlistid, int songid);

View File

@ -55,6 +55,7 @@ static void dispatch_browse(WS_CONNINFO *pwsc, DBQUERYINFO *pqi);
static void dispatch_playlists(WS_CONNINFO *pqsc, DBQUERYINFO *pqi);
static void dispatch_addplaylist(WS_CONNINFO *pwsc, DBQUERYINFO *pqi);
static void dispatch_addplaylistitems(WS_CONNINFO *pwsc, DBQUERYINFO *pqi);
static void dispatch_editplaylist(WS_CONNINFO *pwsc, DBQUERYINFO *pqi);
static void dispatch_deleteplaylist(WS_CONNINFO *pwsc, DBQUERYINFO *pqi);
static void dispatch_deleteplaylistitems(WS_CONNINFO *pwsc, DBQUERYINFO *pqi);
static void dispatch_items(WS_CONNINFO *pwsc, DBQUERYINFO *pqi);
@ -209,7 +210,10 @@ void daap_handler(WS_CONNINFO *pwsc) {
(!strcasecmp(pqi->uri_sections[3],"del")))
/* /databases/id/containers/del */
return dispatch_deleteplaylist(pwsc,pqi);
if((!strcasecmp(pqi->uri_sections[2],"containers")) &&
(!strcasecmp(pqi->uri_sections[3],"edit")))
/* /databases/id/contaienrs/edit */
return dispatch_editplaylist(pwsc,pqi);
pwsc->close=1;
free(pqi);
ws_returnerror(pwsc,404,"Page not found");
@ -951,6 +955,48 @@ void dispatch_addplaylist(WS_CONNINFO *pwsc, DBQUERYINFO *pqi) {
return;
}
/**
* edit an existing playlist (by id)
*/
void dispatch_editplaylist(WS_CONNINFO *pwsc, DBQUERYINFO *pqi) {
unsigned char edit_response[20];
unsigned char *current = edit_response;
char *name, *query;
int id;
int retval;
if((!ws_getvar(pwsc,"dmap.itemname")) ||
(!ws_getvar(pwsc,"dmap.itemid"))) {
DPRINTF(E_LOG,L_DAAP,"Missing name on playlist edit");
ws_returnerror(pwsc,500,"missing playlist name");
return;
}
name=ws_getvar(pwsc,"dmap.itemname");
query=ws_getvar(pwsc,"org.mt-daapd.smart-playlist-spec");
id=atoi(ws_getvar(pwsc,"dmap.itemid"));
retval=db_edit_playlist(id,name,query);
if(retval != DB_E_SUCCESS) {
DPRINTF(E_LOG,L_DAAP,"error editing playlist.");
ws_returnerror(pwsc,500,"Error editing playlist");
return;
}
current += db_dmap_add_container(current,"MEPR",12);
current += db_dmap_add_int(current,"mstt",200); /* 12 */
dispatch_output_start(pwsc,pqi,20);
dispatch_output_write(pwsc,pqi,edit_response,20);
dispatch_output_end(pwsc,pqi);
pwsc->close=1;
return;
}
/**
* enumerate and return playlistitems
*/

View File

@ -493,7 +493,7 @@ int main(int argc, char *argv[]) {
}
if(!skip_initial) {
DPRINTF(E_LOG,L_MAIN|L_SCAN,"Starting mp3 scan\n");
DPRINTF(E_LOG,L_MAIN|L_SCAN,"Starting mp3 scan of %s\n",config.mp3dir);
if(scan_init(config.mp3dir)) {
DPRINTF(E_FATAL,L_MAIN|L_SCAN,"Error scanning MP3 files: %s\n",strerror(errno));
}

View File

@ -227,8 +227,12 @@ void scan_process_playlistlist(void) {
int scan_init(char *path) {
int err=0;
if(db_start_scan())
DPRINTF(E_DBG,L_SCAN,"Starting scan_init\n");
if(db_start_scan()) {
DPRINTF(E_DBG,L_SCAN,"Error in db_start_scan()\n");
return -1;
}
DPRINTF(E_DBG,L_SCAN,"Scanning for MP3s in %s\n",path);