FS#13287 - Load a newly saved playlist and resume where it was

Works from any playlist saving operation accessed from the
While Playing Screen, all other playlist saving operations
are unchanged.

Now a user-selectable setting! Located in
General Settings -> Playlists -> Current Playlist ->
Reload After Saving (Yes/No)

Change-Id: I5085c3f4c56c518a812d5ee015d15cc4dca19a28
This commit is contained in:
Dana Conrad 2021-04-18 13:00:41 -05:00 committed by Solomon Peachy
parent 49edfc237b
commit 4f83e66cd4
9 changed files with 102 additions and 12 deletions

View file

@ -38,9 +38,19 @@
#include "talk.h"
#include "playlist_catalog.h"
#include "splash.h"
#include "filetree.h"
/* load a screen to save the playlist passed in (or current playlist if NULL is passed) */
int save_playlist_screen(struct playlist_info* playlist)
{
char directoryonly[MAX_PATH+3];
char *filename;
int resume_index;
uint32_t resume_elapsed;
uint32_t resume_offset;
char temp[MAX_PATH+1], *dot;
int len;
@ -71,6 +81,55 @@ int save_playlist_screen(struct playlist_info* playlist)
/* reload in case playlist was saved to cwd */
reload_directory();
/* only reload newly saved playlist if:
* playlist is null AND setting is turned on
*
* if playlist is null, we should be dealing with the current playlist,
* and thus we got here from the wps screen. That means we want to reload
* the current playlist so the user can make bookmarks. */
if ((global_settings.playlist_reload_after_save == true) &&
(playlist == NULL))
{
/* at least one slash exists in temp */
if (strrchr(temp, '/') != NULL)
{
filename = strrchr(temp, '/') + 1;
if (temp[0] == '/') /* most common situation - first char is a slash */
{
strcpy(directoryonly, temp);
directoryonly[filename - temp] = '\0';
} else /* there is a slash, but not at the beginning of temp - prepend one */
{
directoryonly[0] = '/';
strcpy(directoryonly+1, temp);
directoryonly[filename - temp + 1] = '\0';
}
} else /* temp doesn't contain any slashes, uncommon? */
{
directoryonly[0] = '/';
directoryonly[1] = '\0';
filename = temp;
}
/* can't trust index from id3 (don't know why), get it from playlist */
resume_index = playlist_get_current()->index;
struct mp3entry* id3 = audio_current_track();
/* record elapsed and offset so they don't change when we load new playlist */
resume_elapsed = id3->elapsed;
resume_offset = id3->offset;
ft_play_playlist(temp, directoryonly, filename, true);
playlist_start(resume_index, resume_elapsed, resume_offset);
}
/* cancelled out of name selection */
} else {
return 1;
}
return 0;
@ -112,9 +171,10 @@ MAKE_MENU(viewer_settings_menu, ID2P(LANG_PLAYLISTVIEWER_SETTINGS),
MENUITEM_SETTING(warn_on_erase, &global_settings.warnon_erase_dynplaylist, NULL);
MENUITEM_SETTING(show_shuffled_adding_options, &global_settings.show_shuffled_adding_options, NULL);
MENUITEM_SETTING(show_queue_options, &global_settings.show_queue_options, NULL);
MENUITEM_SETTING(playlist_reload_after_save, &global_settings.playlist_reload_after_save, NULL);
MAKE_MENU(currentplaylist_settings_menu, ID2P(LANG_CURRENT_PLAYLIST),
NULL, Icon_Playlist,
&warn_on_erase, &show_shuffled_adding_options, &show_queue_options);
&warn_on_erase, &show_shuffled_adding_options, &show_queue_options, &playlist_reload_after_save);
MAKE_MENU(playlist_settings, ID2P(LANG_PLAYLISTS), NULL,
Icon_Playlist,