diff options
author | Kalle Wallin <kaw@linux.se> | 2004-06-18 14:20:19 +0000 |
---|---|---|
committer | Kalle Wallin <kaw@linux.se> | 2004-06-18 14:20:19 +0000 |
commit | ddf5964927e5fac05139e9345714f39e4cd686b6 (patch) | |
tree | 5a5508d35d60844212095f12d2ee273bcfc0250b | |
parent | 49d3277a7345108f10322712852f3f1f1df92eb6 (diff) | |
download | mpd-ddf5964927e5fac05139e9345714f39e4cd686b6.tar.gz mpd-ddf5964927e5fac05139e9345714f39e4cd686b6.tar.xz mpd-ddf5964927e5fac05139e9345714f39e4cd686b6.zip |
Added a add command (for adding files or urls to the playlist)
git-svn-id: https://svn.musicpd.org/ncmpc/trunk@1554 09075e82-0dd4-0310-85a5-a0d7c8717e4f
-rw-r--r-- | src/command.c | 4 | ||||
-rw-r--r-- | src/command.h | 1 | ||||
-rw-r--r-- | src/screen_play.c | 78 |
3 files changed, 82 insertions, 1 deletions
diff --git a/src/command.c b/src/command.c index 81eec77f7..57f90d437 100644 --- a/src/command.c +++ b/src/command.c @@ -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") }, diff --git a/src/command.h b/src/command.h index 9fd6ab37b..e96940a1a 100644 --- a/src/command.h +++ b/src/command.h @@ -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, diff --git a/src/screen_play.c b/src/screen_play.c index 8c38c5b1a..3bb16ee63 100644 --- a/src/screen_play.c +++ b/src/screen_play.c @@ -23,14 +23,18 @@ #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; |