aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--command.c1
-rw-r--r--command.h1
-rw-r--r--screen_file.c60
-rw-r--r--screen_help.c2
4 files changed, 57 insertions, 7 deletions
diff --git a/command.c b/command.c
index 73623b955..d254c4e03 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 1672316f7..485b75347 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 b792d6ad9..762752e0a 100644
--- a/screen_file.c
+++ b/screen_file.c
@@ -1,3 +1,4 @@
+#include <ctype.h>
#include <stdlib.h>
#include <string.h>
#include <glib.h>
@@ -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 34a007c0a..de5bfe3e2 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 },