Code

Added delete playlist feature.
authorKalle Wallin <kaw@linux.se>
Sat, 27 Mar 2004 16:36:01 +0000 (16:36 +0000)
committerKalle Wallin <kaw@linux.se>
Sat, 27 Mar 2004 16:36:01 +0000 (16:36 +0000)
git-svn-id: https://svn.musicpd.org/ncmpc/trunk@512 09075e82-0dd4-0310-85a5-a0d7c8717e4f

command.c
command.h
screen_file.c
screen_help.c

index 73623b95534840c46b11e51f9fb498b4a3f59a1a..d254c4e031b840dcd9c5ac6030a85b5560373363 100644 (file)
--- 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" },
index 1672316f7f2d353abb5cd217f2a70aa16c955684..485b7534731c05b14e73c8f2d2709dd5278bf734 100644 (file)
--- 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,
index b792d6ad906e02435caff3344ab5065b069ee021..762752e0acbb7dfd8f5272e734b3ea7bf7460976 100644 (file)
@@ -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:
index 34a007c0af1a53dbce9c36f7238d1e11ae90b53b..de5bfe3e28147c233a385519fab1a67a8cad37a0 100644 (file)
@@ -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 },