From: Kalle Wallin Date: Sat, 27 Mar 2004 16:36:01 +0000 (+0000) Subject: Added delete playlist feature. X-Git-Tag: v0.12_alpha1~642 X-Git-Url: https://git.tokkee.org/?a=commitdiff_plain;h=fe441717ab5bbebbf3bb3d518079636c14ef9357;p=ncmpc.git Added delete playlist feature. git-svn-id: https://svn.musicpd.org/ncmpc/trunk@512 09075e82-0dd4-0310-85a5-a0d7c8717e4f --- diff --git a/command.c b/command.c index 73623b9..d254c4e 100644 --- a/command.c +++ b/command.c @@ -60,7 +60,6 @@ static command_definition_t cmds[] = { { 'r', 0, 0 }, CMD_REPEAT, "Toggle repeat mode" }, { { 'z', 0, 0 }, CMD_RANDOM, "Toggle random mode" }, { { 'S', 0, 0 }, CMD_SAVE_PLAYLIST, "Save playlist" }, - { { 'D', 0, 0 }, CMD_DELETE_PLAYLIST, "Delete playlist" }, { { UP, 0, 0 }, CMD_LIST_PREVIOUS, "Move: Up" }, { { DWN, 0, 0 }, CMD_LIST_NEXT, "Move: Down" }, diff --git a/command.h b/command.h index 1672316..485b753 100644 --- a/command.h +++ b/command.h @@ -16,7 +16,6 @@ typedef enum CMD_VOLUME_UP, CMD_VOLUME_DOWN, CMD_SAVE_PLAYLIST, - CMD_DELETE_PLAYLIST, CMD_TOGGLE_FIND_WRAP, CMD_LIST_PREVIOUS, CMD_LIST_NEXT, diff --git a/screen_file.c b/screen_file.c index b792d6a..762752e 100644 --- a/screen_file.c +++ b/screen_file.c @@ -1,3 +1,4 @@ +#include #include #include #include @@ -108,6 +109,57 @@ load_playlist(screen_t *screen, mpd_client_t *c, filelist_entry_t *entry) return 0; } +static int +handle_delete(screen_t *screen, mpd_client_t *c) +{ + list_window_t *lw = screen->filelist; + filelist_entry_t *entry; + mpd_InfoEntity *entity; + mpd_PlaylistFile *plf; + char *str, buf[BUFSIZE]; + int key; + + entry = ( filelist_entry_t *) g_list_nth_data(c->filelist, lw->selected); + if( entry==NULL || entry->entity==NULL ) + return -1; + + entity = entry->entity; + + if( entity->type!=MPD_INFO_ENTITY_TYPE_PLAYLISTFILE ) + { + screen_status_printf("You can only delete playlists!"); + beep(); + return -1; + } + + plf = entity->info.playlistFile; + str = utf8_to_locale(basename(plf->path)); + snprintf(buf, BUFSIZE, "Delete playlist %s [y/n] ? ", str); + free(str); + key = tolower(screen_getch(screen->status_window.w, buf)); + if( key!='y' ) + { + screen_status_printf("Aborted!"); + return 0; + } + + mpd_sendRmCommand(c->connection, plf->path); + mpd_finishCommand(c->connection); + if( mpc_error(c)) + { + str = utf8_to_locale(mpc_error_str(c)); + screen_status_printf("Error: %s", str); + free(str); + beep(); + return -1; + } + screen_status_printf("Playlist deleted!"); + mpc_update_filelist(c); + list_window_check_selected(lw, c->filelist_length); + return 0; +} + + static int handle_play_cmd(screen_t *screen, mpd_client_t *c) { @@ -177,7 +229,7 @@ add_directory(mpd_client_t *c, char *dir) } static int -select_entry(screen_t *screen, mpd_client_t *c) +handle_select(screen_t *screen, mpd_client_t *c) { list_window_t *w = screen->filelist; filelist_entry_t *entry; @@ -336,14 +388,14 @@ file_cmd(screen_t *screen, mpd_client_t *c, command_t cmd) handle_play_cmd(screen, c); return 1; case CMD_SELECT: - if( select_entry(screen, c) == 0 ) + if( handle_select(screen, c) == 0 ) { /* continue and select next item... */ cmd = CMD_LIST_NEXT; } break; - case CMD_DELETE_PLAYLIST: - screen_status_printf("Sorry, command not implemented yet!"); + case CMD_DELETE: + handle_delete(screen, c); return 1; break; case CMD_LIST_FIND: diff --git a/screen_help.c b/screen_help.c index 34a007c..de5bfe3 100644 --- a/screen_help.c +++ b/screen_help.c @@ -59,7 +59,7 @@ static help_text_row_t help_text[] = { 0, CMD_NONE, " ------------------------" }, { 0, CMD_PLAY, "Enter directory/Load playlist" }, { 0, CMD_SELECT, "Add/remove song from playlist" }, - { 0, CMD_DELETE_PLAYLIST, "Delete playlist" }, + { 0, CMD_DELETE, "Delete playlist" }, { 0, CMD_NONE, " " }, { 0, CMD_NONE, " " }, { 1, CMD_NONE, " " PACKAGE " version " VERSION },