Code

Added a add command (for adding files or urls to the playlist)
authorKalle Wallin <kaw@linux.se>
Fri, 18 Jun 2004 14:20:19 +0000 (14:20 +0000)
committerKalle Wallin <kaw@linux.se>
Fri, 18 Jun 2004 14:20:19 +0000 (14:20 +0000)
git-svn-id: https://svn.musicpd.org/ncmpc/trunk@1554 09075e82-0dd4-0310-85a5-a0d7c8717e4f

src/command.c
src/command.h
src/screen_play.c

index 81eec77f7c36f07e8fea50e928da0a1f77d2b9fa..57f90d437d2b80f722c214c6931ef13cfe73b76f 100644 (file)
@@ -88,7 +88,7 @@ static command_definition_t cmds[] =
   { { 'U',   0,   0 }, CMD_TOGGLE_AUTOCENTER, "autocenter-mode", 
     N_("Toggle auto center mode") },
 
-  { { ' ',  'a',   0 }, CMD_SELECT, "select", 
+  { { ' ',   0,   0 }, CMD_SELECT, "select", 
     N_("Select/deselect song in playlist") },
   { { DEL,  'd',  0 }, CMD_DELETE, "delete",
     N_("Delete song from playlist") },
@@ -107,6 +107,8 @@ static command_definition_t cmds[] =
 
   { { 'S',   0,   0 }, CMD_SAVE_PLAYLIST, "save",
     N_("Save playlist") },
+  { { 'a',   0,   0 }, CMD_ADD, "add",
+    N_("Add url/file to playlist") },
 
   { { 0,  0,   0 }, CMD_LIST_MOVE_UP,     "move-up", 
     N_("Move item up") },
index 9fd6ab37b853751a73fb561114ffdf2b8472851d..e96940a1a9ad537e8c78a7d00120ba3d05486f05 100644 (file)
@@ -23,6 +23,7 @@ typedef enum
   CMD_DB_UPDATE,
   CMD_VOLUME_UP,
   CMD_VOLUME_DOWN,
+  CMD_ADD,
   CMD_SAVE_PLAYLIST,
   CMD_TOGGLE_FIND_WRAP,
   CMD_TOGGLE_AUTOCENTER,
index 8c38c5b1a6a86b0bd2d0ef0b7c56acbcf6a577ea..3bb16ee638d49fa20e3a7102960468c25d981dce 100644 (file)
 #include <string.h>
 #include <glib.h>
 #include <ncurses.h>
+#include <panel.h>
 
 #include "config.h"
 #include "ncmpc.h"
 #include "options.h"
 #include "support.h"
 #include "mpdclient.h"
+#include "utils.h"
 #include "strfsong.h"
+#include "wreadln.h"
 #include "command.h"
+#include "colors.h"
 #include "screen.h"
 #include "screen_utils.h"
 
@@ -165,6 +169,77 @@ handle_save_playlist(screen_t *screen, mpdclient_t *c, char *name)
   return 0;
 }
 
+static int
+handle_add_to_playlist(screen_t *screen, mpdclient_t *c)
+{
+  gchar *path;
+  GCompletion *gcmp;
+  GList *list = NULL;
+  GList *dir_list = NULL;
+
+  void add_dir(gchar *dir)
+    {
+      g_completion_remove_items(gcmp, list);
+      list = string_list_remove(list, dir);
+      list = gcmp_list_from_path(c, dir, list);
+      g_completion_add_items(gcmp, list);
+      dir_list = g_list_append(dir_list, g_strdup(dir));
+    }
+
+  void pre_completion_cb(GCompletion *gcmp, gchar *line)       
+    {
+      if( list == NULL )
+       {
+         /* create initial list */
+         list = gcmp_list_from_path(c, "", NULL);
+         g_completion_add_items(gcmp, list);
+       }
+      else if( line && line[0] && line[strlen(line)-1]=='/' &&
+              string_list_find(dir_list, line) == NULL )
+       {         
+         /* add directory content to list */
+         add_dir(line);
+       }
+    }
+
+  void post_completion_cb(GCompletion *gcmp, gchar *line, GList *items)
+    {
+      if( g_list_length(items)>1 )
+       screen_display_completion_list(screen, items);
+
+      if( line && line[0] && line[strlen(line)-1]=='/' &&
+         string_list_find(dir_list, line) == NULL )
+       {         
+         /* add directory content to list */
+         add_dir(line);
+       }
+    }
+    
+
+  gcmp = g_completion_new(NULL);
+  g_completion_set_compare(gcmp, strncmp);
+
+  wrln_pre_completion_callback = pre_completion_cb;
+  wrln_post_completion_callback = post_completion_cb;
+  path = screen_readln(screen->status_window.w, 
+                      _("Add: "),
+                      NULL, 
+                      NULL, 
+                      gcmp);
+  wrln_pre_completion_callback = NULL;
+  wrln_post_completion_callback = NULL;
+  
+  g_completion_free(gcmp);
+
+  string_list_free(list);
+  string_list_free(dir_list);
+
+  if( path && path[0] )
+    mpdclient_cmd_add_path(c, path);
+
+  return 0;
+}
+
 static void
 play_init(WINDOW *w, int cols, int rows)
 {
@@ -263,6 +338,9 @@ play_cmd(screen_t *screen, mpdclient_t *c, command_t cmd)
     case CMD_SAVE_PLAYLIST:
       handle_save_playlist(screen, c, NULL);
       return 1;
+    case CMD_ADD:
+      handle_add_to_playlist(screen, c);
+      return 1;
     case CMD_SCREEN_UPDATE:
       center_playing_item(screen, c);
       return 1;