From 3f6b5f829a903e2a5bd3dfa8031c90cc122db958 Mon Sep 17 00:00:00 2001 From: Kalle Wallin Date: Sat, 27 Mar 2004 20:55:26 +0000 Subject: Include "config.h" before "support.h" git-svn-id: https://svn.musicpd.org/ncmpc/trunk@517 09075e82-0dd4-0310-85a5-a0d7c8717e4f --- list_window.c | 1 + screen_play.c | 46 +++++++++++++++++++++++++++++++++++++++++++++- 2 files changed, 46 insertions(+), 1 deletion(-) diff --git a/list_window.c b/list_window.c index fa1f94921..d976ce05c 100644 --- a/list_window.c +++ b/list_window.c @@ -4,6 +4,7 @@ #include #include +#include "config.h" #include "support.h" #include "command.h" #include "list_window.h" diff --git a/screen_play.c b/screen_play.c index 7c5cab1ff..5f93ad093 100644 --- a/screen_play.c +++ b/screen_play.c @@ -3,6 +3,8 @@ #include #include +#include "config.h" +#include "support.h" #include "libmpdclient.h" #include "mpc.h" #include "command.h" @@ -34,6 +36,48 @@ list_callback(int index, int *highlight, void *data) return mpc_get_song_name(song); } +static int +handle_save_playlist(screen_t *screen, mpd_client_t *c) +{ + char *filename, *filename_utf8; + + filename=screen_getstr(screen->status_window.w, "Save playlist as: "); + filename=trim(filename); + if( filename==NULL || filename[0]=='\0' ) + return -1; + /* convert filename to utf-8 */ + filename_utf8 = locale_to_utf8(filename); + /* send save command to mpd */ + mpd_sendSaveCommand(c->connection, filename_utf8); + mpd_finishCommand(c->connection); + free(filename_utf8); + /* handle errors */ + if( mpc_error(c)) + { + if( mpc_error_str(c) ) + { + char *str = utf8_to_locale(mpc_error_str(c)); + screen_status_message(str); + free(str); + } + else + screen_status_printf("Error: Unable to save playlist as %s", filename); + mpd_clearError(c->connection); + beep(); + return -1; + } + /* success */ + screen_status_printf("Saved %s", filename); + free(filename); + /* update the file list if it has been initalized */ + if( c->filelist ) + { + mpc_update_filelist(c); + list_window_check_selected(screen->filelist, c->filelist_length); + } + return 0; +} + void play_open(screen_t *screen, mpd_client_t *c) { @@ -93,7 +137,7 @@ play_cmd(screen_t *screen, mpd_client_t *c, command_t cmd) mpc_get_song_name(song)); return 1; case CMD_SAVE_PLAYLIST: - screen_status_printf("Sorry, playlist saving not implemented yet!"); + handle_save_playlist(screen, c); return 1; case CMD_LIST_FIND: case CMD_LIST_RFIND: -- cgit v1.2.3