int mpd_playlist_queue_commit(MpdObj *mi) { if(mi->queue == NULL) { debug_printf(DEBUG_WARNING,"mi->queue is empty"); return MPD_PLAYLIST_QUEUE_EMPTY; } if(!mpd_check_connected(mi)) { debug_printf(DEBUG_WARNING,"not connected\n"); return MPD_NOT_CONNECTED; } if(mpd_lock_conn(mi)) { debug_printf(DEBUG_WARNING,"lock failed\n"); return MPD_LOCK_FAILED; } mpd_sendCommandListBegin(mi->connection); /* get first item */ mi->queue = mi->queue->first; while(mi->queue != NULL) { if(mi->queue->type == MPD_QUEUE_ADD) { if(mi->queue->path != NULL) { mpd_sendAddCommand(mi->connection, mi->queue->path); } } else if(mi->queue->type == MPD_QUEUE_LOAD) { if(mi->queue->path != NULL) { mpd_sendLoadCommand(mi->connection, mi->queue->path); } } else if (mi->queue->type == MPD_QUEUE_DELETE_ID) { if(mi->queue->id >= 0) { mpd_sendDeleteIdCommand(mi->connection, mi->queue->id); } } else if (mi->queue->type == MPD_QUEUE_DELETE_POS) { if(mi->queue->id >= 0) { mpd_sendDeleteCommand(mi->connection, mi->queue->id); } } mpd_queue_get_next(mi); } mpd_sendCommandListEnd(mi->connection); mpd_finishCommand(mi->connection); mpd_unlock_conn(mi); mpd_status_update(mi); return MPD_OK; }
int mpd_playlist_load(MpdObj *mi, const char *path) { int retv = MPD_OK; if(!mpd_check_connected(mi)) { debug_printf(DEBUG_WARNING,"mpd_playlist_load: not connected\n"); return MPD_NOT_CONNECTED; } if(mpd_lock_conn(mi)) { debug_printf(DEBUG_ERROR,"lock failed\n"); return MPD_LOCK_FAILED; } mpd_sendLoadCommand(mi->connection,path); mpd_finishCommand(mi->connection); if(mi->connection->errorCode == MPD_ACK_ERROR_NO_EXIST) { debug_printf(DEBUG_WARNING, "mpd_playlist_load: failed to load playlist\n"); mpd_clearError(mi->connection); retv = MPD_PLAYLIST_LOAD_FAILED; } if(mpd_unlock_conn(mi)) { debug_printf(DEBUG_ERROR, "Failed to unlock connection"); return MPD_LOCK_FAILED; } return retv; }
static TWindow *open_playlist(ttk_menu_item *item) { if (mpdc_tickle() < 0) return TTK_MENU_DONOTHING; mpd_sendClearCommand(mpdz); mpd_finishCommand(mpdz); mpd_sendLoadCommand(mpdz, (char *)item->name); mpd_finishCommand(mpdz); if (mpdz->error) { mpdc_tickle(); return TTK_MENU_DONOTHING; } mpd_sendPlayCommand(mpdz, -1); mpd_finishCommand(mpdz); return mpd_currently_playing(); }
int cmd_load ( int argc, char ** argv, mpd_Connection * conn ) { int i; char * sp; char * dp; mpd_InfoEntity * entity; mpd_PlaylistFile * pl; for(i=0;i<argc;i++) { sp = argv[i]; while((sp = strchr(sp,' '))) *sp = '_'; } mpd_sendLsInfoCommand(conn,""); printErrorAndExit(conn); while((entity = mpd_getNextInfoEntity(conn))) { if(entity->type==MPD_INFO_ENTITY_TYPE_PLAYLISTFILE) { pl = entity->info.playlistFile; dp = sp = strdup(charset_from_utf8(pl->path)); while((sp = strchr(sp,' '))) *sp = '_'; for(i=0;i<argc;i++) { if(strcmp(dp,argv[i])==0) strcpy(argv[i], charset_from_utf8(pl->path)); } free(dp); mpd_freeInfoEntity(entity); } } my_finishCommand(conn); mpd_sendCommandListBegin(conn); printErrorAndExit(conn); for(i=0;i<argc;i++) { printf("loading: %s\n",argv[i]); mpd_sendLoadCommand(conn,charset_to_utf8(argv[i])); printErrorAndExit(conn); } mpd_sendCommandListEnd(conn); my_finishCommand(conn); return 0; }