diff options
author | Kalle Wallin <kaw@linux.se> | 2004-06-19 19:33:46 +0000 |
---|---|---|
committer | Kalle Wallin <kaw@linux.se> | 2004-06-19 19:33:46 +0000 |
commit | 7534ac103fd0499f7359304f8cb81a3f250968bb (patch) | |
tree | effe54670895e7a3cd1049d9a8b0fe281c1946d0 | |
parent | 96ba600d2385d910d02339c257154e3da4f1aa13 (diff) | |
download | mpd-7534ac103fd0499f7359304f8cb81a3f250968bb.tar.gz mpd-7534ac103fd0499f7359304f8cb81a3f250968bb.tar.xz mpd-7534ac103fd0499f7359304f8cb81a3f250968bb.zip |
added type argument to gcmp_list_from_path()
git-svn-id: https://svn.musicpd.org/ncmpc/trunk@1567 09075e82-0dd4-0310-85a5-a0d7c8717e4f
-rw-r--r-- | ChangeLog | 20 | ||||
-rw-r--r-- | src/screen_play.c | 54 | ||||
-rw-r--r-- | src/utils.c | 15 | ||||
-rw-r--r-- | src/utils.h | 12 |
4 files changed, 89 insertions, 12 deletions
@@ -1,3 +1,21 @@ +2004-06-17 Kalle Wallin <kaw@linux.se> + * screen_utils.c: fixed the display of completion lists + * wreadln.c: try to complete even if the line is empty + * utils.c: added type argument to gcmp_list_from_path() + * screen_play.c: added completion support to handle_save_playlist() + * command.[c|h]: check_key_bindings() can now write an error messages + to a buffer instead of stderr + * main.c: display errors without exiting when key bindings are broken + +2004-06-17 Kalle Wallin <kaw@linux.se> + * Added a add command, used to add urls or files to the playlist, with + file completion. + + +2004-06-16 Kalle Wallin <kaw@linux.se> + * mpdclient.c: enabled plchanges, make shure the playlist length is + updated when removing songs + 2004-06-16 Kalle Wallin <kaw@linux.se> * libmpdclient updated (r1507) * mpdclient: add path to mpdclient_cmd_db_update() @@ -8,7 +26,7 @@ * conf.c: Added support for cusomized format strings with list-format and status-format * options.c: Added status_format, list_format fields - * mpdclient.c: Sort playlist if needed after plchanges, + * mpdclient.c: disable plchanges (needs more work), update the song position fields in mpdclient_cmd_move, use song id's by default (define ENABLE_SONG_ID), disable plchanges * screen_play.c: Offer to overwrite when saving playlists 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 |