diff options
Diffstat (limited to '')
-rw-r--r-- | src/screen_play.c | 54 | ||||
-rw-r--r-- | src/utils.c | 15 | ||||
-rw-r--r-- | src/utils.h | 12 |
3 files changed, 70 insertions, 11 deletions
diff --git a/src/screen_play.c b/src/screen_play.c index 3bb16ee63..fc130b986 100644 --- a/src/screen_play.c +++ b/src/screen_play.c @@ -117,12 +117,46 @@ handle_save_playlist(screen_t *screen, mpdclient_t *c, char *name) { gchar *filename; gint error; + GCompletion *gcmp; + GList *list = NULL; + + void pre_completion_cb(GCompletion *gcmp, gchar *line) + { + if( list == NULL ) + { + /* create completion list */ + list = gcmp_list_from_path(c, "", NULL, GCMP_TYPE_PLAYLIST); + g_completion_add_items(gcmp, list); + } + } + + void post_completion_cb(GCompletion *gcmp, gchar *line, GList *items) + { + if( g_list_length(items)>=1 ) + screen_display_completion_list(screen, items); + } if( name==NULL ) { + /* initialize completion support */ + 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; + /* query the user for a filename */ - filename=screen_getstr(screen->status_window.w, _("Save playlist as: ")); + filename = screen_readln(screen->status_window.w, + _("Save playlist as: "), + NULL, + NULL, + gcmp); filename=trim(filename); + + /* destroy completion support */ + wrln_pre_completion_callback = NULL; + wrln_post_completion_callback = NULL; + g_completion_free(gcmp); + list = string_list_free(list); } else { @@ -181,17 +215,18 @@ handle_add_to_playlist(screen_t *screen, mpdclient_t *c) { g_completion_remove_items(gcmp, list); list = string_list_remove(list, dir); - list = gcmp_list_from_path(c, dir, list); + list = gcmp_list_from_path(c, dir, list, GCMP_TYPE_RFILE); g_completion_add_items(gcmp, list); dir_list = g_list_append(dir_list, g_strdup(dir)); } void pre_completion_cb(GCompletion *gcmp, gchar *line) { + D("pre_completion()...\n"); if( list == NULL ) { /* create initial list */ - list = gcmp_list_from_path(c, "", NULL); + list = gcmp_list_from_path(c, "", NULL, GCMP_TYPE_RFILE); g_completion_add_items(gcmp, list); } else if( line && line[0] && line[strlen(line)-1]=='/' && @@ -204,6 +239,7 @@ handle_add_to_playlist(screen_t *screen, mpdclient_t *c) void post_completion_cb(GCompletion *gcmp, gchar *line, GList *items) { + D("post_completion()...\n"); if( g_list_length(items)>1 ) screen_display_completion_list(screen, items); @@ -215,28 +251,32 @@ handle_add_to_playlist(screen_t *screen, mpdclient_t *c) } } - + /* initialize completion support */ 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; + /* get path */ path = screen_readln(screen->status_window.w, _("Add: "), NULL, NULL, gcmp); + + /* destroy completion data */ wrln_pre_completion_callback = NULL; wrln_post_completion_callback = NULL; - g_completion_free(gcmp); - string_list_free(list); string_list_free(dir_list); + /* add the path to the playlist */ if( path && path[0] ) mpdclient_cmd_add_path(c, path); + lw->clear = 1; + lw->repaint = 1; + return 0; } diff --git a/src/utils.c b/src/utils.c index 49841a350..58340c42e 100644 --- a/src/utils.c +++ b/src/utils.c @@ -81,7 +81,7 @@ string_list_remove(GList *string_list, gchar *str) /* create a list suiteble for GCompletion from path */ GList * -gcmp_list_from_path(mpdclient_t *c, gchar *path, GList *list) +gcmp_list_from_path(mpdclient_t *c, gchar *path, GList *list, gint types) { GList *flist = NULL; mpdclient_filelist_t *filelist; @@ -96,7 +96,8 @@ gcmp_list_from_path(mpdclient_t *c, gchar *path, GList *list) mpd_InfoEntity *entity = entry ? entry->entity : NULL; char *name = NULL; - if( entity && entity->type==MPD_INFO_ENTITY_TYPE_DIRECTORY ) + if( entity && entity->type==MPD_INFO_ENTITY_TYPE_DIRECTORY && + types & GCMP_TYPE_DIR) { mpd_Directory *dir = entity->info.directory; gchar *tmp = utf8_to_locale(dir->path); @@ -106,11 +107,19 @@ gcmp_list_from_path(mpdclient_t *c, gchar *path, GList *list) strcat(name, "/"); g_free(tmp); } - else if( entity && entity->type==MPD_INFO_ENTITY_TYPE_SONG ) + else if( entity && entity->type==MPD_INFO_ENTITY_TYPE_SONG && + types & GCMP_TYPE_FILE ) { mpd_Song *song = entity->info.song; name = utf8_to_locale(song->file); } + else if( entity && entity->type==MPD_INFO_ENTITY_TYPE_PLAYLISTFILE && + types & GCMP_TYPE_PLAYLIST ) + { + mpd_PlaylistFile *plf = entity->info.playlistFile; + name = utf8_to_locale(plf->path); + } + if( name ) list = g_list_append(list, name); diff --git a/src/utils.h b/src/utils.h index 998a0dece..4446d1cd7 100644 --- a/src/utils.h +++ b/src/utils.h @@ -1,12 +1,22 @@ #ifndef UTILS_H #define UTILS_H + /* functions for lists containing strings */ GList *string_list_free(GList *string_list); GList *string_list_find(GList *string_list, gchar *str); GList *string_list_remove(GList *string_list, gchar *str); /* create a string list from path - used for completion */ -GList *gcmp_list_from_path(mpdclient_t *c, gchar *path, GList *list); +#define GCMP_TYPE_DIR (0x01 << 0) +#define GCMP_TYPE_FILE (0x01 << 1) +#define GCMP_TYPE_PLAYLIST (0x01 << 2) +#define GCMP_TYPE_RFILE (GCMP_TYPE_DIR | GCMP_TYPE_FILE) +#define GCMP_TYPE_RPLAYLIST (GCMP_TYPE_DIR | GCMP_TYPE_PLAYLIST) + +GList *gcmp_list_from_path(mpdclient_t *c, + gchar *path, + GList *list, + gint types); #endif |