void clients_playlist_changed(player_t *player, size_t nlist,playlist_t *lists) { context_t *ctx; playlist_t *list, *active; size_t i, idx_of_active_list; if (!player || !(ctx = player->ctx)) return; idx_of_active_list = 0; if ((active = player->active_list)) { for (i = 0; i < nlist; i++) { list = lists + i; if (!strcmp(active->id, list->id)) { idx_of_active_list = i; break; } } } playlist_free(player->nlist, player->lists); player->nlist = nlist; player->lists = playlist_dup(nlist, lists); player->active_list = player->lists + idx_of_active_list; }
int cmd_write(int argc, char *argv[]) { playlist *dup; char *filename; bool forced; bool will_clobber; int i, clobber_index; if (argc > 2) { paint_error("usage: w[!] [name]"); return 1; } forced = (strcmp(argv[0], "w!") == 0); if (argc == 1) { /* "save" */ /* can't save library or filter results */ if (viewing_playlist == mdb.library || viewing_playlist == mdb.filter_results) { paint_error("use \"w name\" when saving psuedo-playlists like library/filter"); return 2; } /* can't save a new playlist that has no name */ if (viewing_playlist->filename == NULL) { paint_error("use \"w name\" for new playlists"); return 3; } /* do the save... */ playlist_save(viewing_playlist); viewing_playlist->needs_saving = false; paint_library(); paint_message("\"%s\" %d songs written", viewing_playlist->filename, viewing_playlist->nfiles); } else { /* "save as" */ /* build filename for playlist */ asprintf(&filename, "%s/%s.playlist", mdb.playlist_dir, argv[1]); if (filename == NULL) err(1, "cmd_write: asprintf(3) failed"); /* check to see if playlist with that name already exists */ will_clobber = false; clobber_index = -1; for (i = 0; i < mdb.nplaylists; i++) { if (mdb.playlists[i]->filename != NULL && strcmp(mdb.playlists[i]->filename, filename) == 0) { will_clobber = true; clobber_index = i; } } if (will_clobber && !forced) { paint_error("playlist with that name exists (use \"w!\" to overwrite)"); free(filename); return 4; } /* if reached here, we're going to do the save-as... */ /* duplicate playlist */ dup = playlist_dup(viewing_playlist, filename, argv[1]); if (will_clobber) medialib_playlist_remove(clobber_index); else ui.library->nrows++; /* * TODO If the original playlist was a new one, with no name (i.e. if * name == NULL) then we should remove that playlist from the medialib * and display here. */ /* do the save-as... */ playlist_save(dup); medialib_playlist_add(dup); dup->needs_saving = false; viewing_playlist->needs_saving = false; paint_library(); paint_message("\"%s\" %d songs written", filename, viewing_playlist->nfiles); } return 0; }