Warn before overwriting another playlist on disk
When saving a playlist to an existing file on disk, warn user, unless the playlist's file name remains unchanged. Change-Id: I10d82667de5fadb5323be4f981bea9263849f07a
This commit is contained in:
parent
2747e920ba
commit
422ea20cef
6 changed files with 55 additions and 27 deletions
|
@ -65,18 +65,10 @@ int save_playlist_screen(struct playlist_info* playlist)
|
|||
strlcat(temp, DEFAULT_DYNAMIC_PLAYLIST_NAME, sizeof(temp));
|
||||
}
|
||||
|
||||
dot = strrchr(temp, '.');
|
||||
if (dot) /* remove extension */
|
||||
*dot = '\0';
|
||||
|
||||
if (!kbd_input(temp, sizeof(temp), NULL))
|
||||
if (catalog_pick_new_playlist_name(temp, sizeof(temp),
|
||||
playlist ? playlist->filename :
|
||||
playlist_get_current()->filename))
|
||||
{
|
||||
len = strlen(temp);
|
||||
if(len > 4 && !strcasecmp(&temp[len-4], ".m3u"))
|
||||
strlcat(temp, "8", sizeof(temp));
|
||||
else if(len <= 5 || strcasecmp(&temp[len-5], ".m3u8"))
|
||||
strlcat(temp, ".m3u8", sizeof(temp));
|
||||
|
||||
playlist_save(playlist, temp, NULL, 0);
|
||||
|
||||
/* reload in case playlist was saved to cwd */
|
||||
|
|
|
@ -1227,6 +1227,13 @@ int confirm_delete_yesno(const char *name)
|
|||
return gui_syncyesno_run(&message, &yes_message, NULL);
|
||||
}
|
||||
|
||||
int confirm_overwrite_yesno(void)
|
||||
{
|
||||
static const char *lines[] = { ID2P(LANG_REALLY_OVERWRITE) };
|
||||
static const struct text_message message = { lines, 1 };
|
||||
return gui_syncyesno_run(&message, NULL, NULL);
|
||||
}
|
||||
|
||||
/* time_split_units()
|
||||
split time values depending on base unit
|
||||
unit_idx: UNIT_HOUR, UNIT_MIN, UNIT_SEC, UNIT_MS
|
||||
|
|
|
@ -159,6 +159,7 @@ int hex_to_rgb(const char* hex, int* color);
|
|||
#endif
|
||||
|
||||
int confirm_delete_yesno(const char *name);
|
||||
int confirm_overwrite_yesno(void);
|
||||
|
||||
char* strrsplt(char* str, int c);
|
||||
char* skip_whitespace(char* const str);
|
||||
|
|
|
@ -948,13 +948,6 @@ static bool poll_cancel_action(const char *path)
|
|||
return ACTION_STD_CANCEL == get_action(CONTEXT_STD, TIMEOUT_NOBLOCK);
|
||||
}
|
||||
|
||||
static int confirm_overwrite(void)
|
||||
{
|
||||
static const char *lines[] = { ID2P(LANG_REALLY_OVERWRITE) };
|
||||
static const struct text_message message = { lines, 1 };
|
||||
return gui_syncyesno_run(&message, NULL, NULL);
|
||||
}
|
||||
|
||||
static bool check_new_name(const char *basename)
|
||||
{
|
||||
/* at least prevent escapes out of the base directory from keyboard-
|
||||
|
@ -1426,7 +1419,7 @@ static int clipboard_paste(void)
|
|||
case RELATE_DIFFERENT:
|
||||
if (file_exists(target.path)) {
|
||||
/* If user chooses not to overwrite, cancel */
|
||||
if (confirm_overwrite() == YESNO_NO) {
|
||||
if (confirm_overwrite_yesno() == YESNO_NO) {
|
||||
rc = OPRC_NOOVERWRT;
|
||||
break;
|
||||
}
|
||||
|
|
|
@ -389,6 +389,43 @@ bool catalog_view_playlists(void)
|
|||
return (display_playlists(NULL, CATBROWSE_CATVIEW) >= 0);
|
||||
}
|
||||
|
||||
static void apply_playlist_extension(char* buf, size_t buf_size)
|
||||
{
|
||||
size_t len = strlen(buf);
|
||||
if(len > 4 && !strcasecmp(&buf[len-4], ".m3u"))
|
||||
strlcat(buf, "8", buf_size);
|
||||
else if(len <= 5 || strcasecmp(&buf[len-5], ".m3u8"))
|
||||
strlcat(buf, ".m3u8", buf_size);
|
||||
}
|
||||
|
||||
static int remove_extension(char* path)
|
||||
{
|
||||
char *dot = strrchr(path, '.');
|
||||
if (dot)
|
||||
*dot = '\0';
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
bool catalog_pick_new_playlist_name(char *pl_name, size_t buf_size,
|
||||
const char* curr_pl_name)
|
||||
{
|
||||
bool do_save = false;
|
||||
while (!do_save && !remove_extension(pl_name) &&
|
||||
!kbd_input(pl_name, buf_size - 7, NULL))
|
||||
{
|
||||
do_save = true;
|
||||
apply_playlist_extension(pl_name, buf_size);
|
||||
|
||||
/* warn before overwriting existing (different) playlist */
|
||||
if ((!curr_pl_name || strcmp(curr_pl_name, pl_name)) &&
|
||||
file_exists(pl_name))
|
||||
do_save = confirm_overwrite_yesno() == YESNO_YES;
|
||||
}
|
||||
return do_save;
|
||||
}
|
||||
|
||||
static int (*ctx_add_to_playlist)(const char* playlist, bool new_playlist);
|
||||
bool catalog_add_to_a_playlist(const char* sel, int sel_attr,
|
||||
bool new_playlist, char *m3u8name,
|
||||
|
@ -404,7 +441,6 @@ bool catalog_add_to_a_playlist(const char* sel, int sel_attr,
|
|||
|
||||
if (new_playlist)
|
||||
{
|
||||
size_t len;
|
||||
if (m3u8name == NULL)
|
||||
{
|
||||
const char *name;
|
||||
|
@ -425,14 +461,10 @@ bool catalog_add_to_a_playlist(const char* sel, int sel_attr,
|
|||
else
|
||||
strmemccpy(playlist, m3u8name, MAX_PATH);
|
||||
|
||||
if (kbd_input(playlist, MAX_PATH, NULL))
|
||||
apply_playlist_extension(playlist, sizeof(playlist));
|
||||
|
||||
if (!catalog_pick_new_playlist_name(playlist, sizeof(playlist), NULL))
|
||||
return false;
|
||||
|
||||
len = strlen(playlist);
|
||||
if(len > 4 && !strcasecmp(&playlist[len-4], ".m3u"))
|
||||
strlcat(playlist, "8", sizeof(playlist));
|
||||
else if(len <= 5 || strcasecmp(&playlist[len-5], ".m3u8"))
|
||||
strlcat(playlist, ".m3u8", sizeof(playlist));
|
||||
}
|
||||
else
|
||||
{
|
||||
|
|
|
@ -33,6 +33,9 @@ void catalog_set_directory(const char* directory);
|
|||
*/
|
||||
bool catalog_view_playlists(void);
|
||||
|
||||
bool catalog_pick_new_playlist_name(char *pl_name, size_t buf_size,
|
||||
const char* curr_pl_name);
|
||||
|
||||
/*
|
||||
* Add something to a playlist (new or select from list of playlists in
|
||||
* catalog).
|
||||
|
|
Loading…
Reference in a new issue