aboutsummaryrefslogtreecommitdiffstats
path: root/src/screen_play.c
diff options
context:
space:
mode:
authorKalle Wallin <kaw@linux.se>2004-06-15 13:17:22 +0000
committerKalle Wallin <kaw@linux.se>2004-06-15 13:17:22 +0000
commitddd7adff6d0e02c31b371559cd822f3b5feba345 (patch)
treef7c0703e7ee740ce2454cdff6f0249c8d862decd /src/screen_play.c
parenta8baf3be0cbdb33d48df4e704ca2f1cb0b77f93b (diff)
downloadmpd-ddd7adff6d0e02c31b371559cd822f3b5feba345.tar.gz
mpd-ddd7adff6d0e02c31b371559cd822f3b5feba345.tar.xz
mpd-ddd7adff6d0e02c31b371559cd822f3b5feba345.zip
git-svn-id: https://svn.musicpd.org/ncmpc/trunk@1497 09075e82-0dd4-0310-85a5-a0d7c8717e4f
Diffstat (limited to '')
-rw-r--r--src/screen_play.c56
1 files changed, 46 insertions, 10 deletions
diff --git a/src/screen_play.c b/src/screen_play.c
index 73c0bc679..9d3cef8be 100644
--- a/src/screen_play.c
+++ b/src/screen_play.c
@@ -18,6 +18,7 @@
*
*/
+#include <ctype.h>
#include <stdlib.h>
#include <string.h>
#include <glib.h>
@@ -108,18 +109,53 @@ center_playing_item(screen_t *screen, mpdclient_t *c)
}
static int
-handle_save_playlist(screen_t *screen, mpdclient_t *c)
+handle_save_playlist(screen_t *screen, mpdclient_t *c, char *name)
{
- char *filename;
+ gchar *filename;
+ gint error;
- filename=screen_getstr(screen->status_window.w, _("Save playlist as: "));
- filename=trim(filename);
+ if( name==NULL )
+ {
+ /* query the user for a filename */
+ filename=screen_getstr(screen->status_window.w, _("Save playlist as: "));
+ filename=trim(filename);
+ }
+ else
+ {
+ filename=g_strdup(name);
+ }
if( filename==NULL || filename[0]=='\0' )
return -1;
/* send save command to mpd */
- if( mpdclient_cmd_save_playlist(c, filename) )
+ D("Saving playlist as \'%s \'...\n", filename);
+ if( (error=mpdclient_cmd_save_playlist(c, filename)) )
{
- beep();
+ gint code = GET_ACK_ERROR_CODE(error);
+
+ if( code == MPD_ACK_ERROR_EXIST )
+ {
+ char buf[256];
+ int key;
+
+ snprintf(buf, 256, _("Replace %s [%s/%s] ? "), filename, YES, NO);
+ key = tolower(screen_getch(screen->status_window.w, buf));
+ if( key == YES[0] )
+ {
+ char *filename_utf8 = locale_to_utf8(filename);
+
+ if( mpdclient_cmd_delete_playlist(c, filename_utf8) )
+ {
+ g_free(filename);
+ g_free(filename_utf8);
+ return -1;
+ }
+ g_free(filename_utf8);
+ error = handle_save_playlist(screen, c, filename);
+ g_free(filename);
+ return error;
+ }
+ }
+ g_free(filename);
return -1;
}
/* success */
@@ -219,22 +255,22 @@ play_cmd(screen_t *screen, mpdclient_t *c, command_t cmd)
{
case CMD_PLAY:
mpdclient_cmd_play(c, lw->selected);
- break;
+ return 1;
case CMD_DELETE:
mpdclient_cmd_delete(c, lw->selected);
return 1;
case CMD_SAVE_PLAYLIST:
- handle_save_playlist(screen, c);
+ handle_save_playlist(screen, c, NULL);
return 1;
case CMD_SCREEN_UPDATE:
center_playing_item(screen, c);
return 1;
case CMD_LIST_MOVE_UP:
mpdclient_cmd_move(c, lw->selected, lw->selected-1);
- break;
+ return 1;
case CMD_LIST_MOVE_DOWN:
mpdclient_cmd_move(c, lw->selected, lw->selected+1);
- break;
+ return 1;
case CMD_LIST_FIND:
case CMD_LIST_RFIND:
case CMD_LIST_FIND_NEXT: