diff --git a/src/commands.c b/src/commands.c index 22863455515b3aa4d4ab01b21448c40cd035f017..f3337062feb3b3712edbe6f2a553996ab9c548c5 100644 --- a/src/commands.c +++ b/src/commands.c @@ -271,20 +271,30 @@ command_crop(volatile sqlite3 *db, mpd_idle_flag *watch_mask_ptr) bool command_delid(volatile sqlite3 *db, struct lkt_win *win, char *id_str, mpd_idle_flag *watch_mask_ptr) { - UNUSED(win); long id; - char *endptr = NULL, err = 0; + char *endptr = NULL, err = 0, filepath[PATH_MAX]; int uri = 0; - *watch_mask_ptr |= MPD_IDLE_PLAYLIST; STRTOL(id, id_str, endptr, err); RETURN_IF(err, "STRTOL failed", false); - /* If one day we allow suppression of the current kara, will need the `win` - pointer to reload the kara in the same position (but the kara won't be - the same). */ database_queue_current_kara(db, NULL, &uri); - RETURN_IF(id == (long) uri, "Can't delete current kara", false); + + if (id == (long) uri) { + if (database_queue_skip_current(db, filepath)) { + if (!win->load_file(win, filepath)) { + LOG_ERROR_SCT("COMMAND", "Failed to skip current kara to delete id %ld", id); + return false; + } + } + + else { + LOG_WARN_SCT("COMMAND", "Failed to skip current kara to delete id %ld, stop playback", id); + win->close(win); + } + } + + *watch_mask_ptr |= MPD_IDLE_PLAYER; return database_queue_del_id(db, id); }