mirror of
https://github.com/Rockbox/rockbox.git
synced 2025-10-13 10:07:38 -04:00
Playlist Catalogue: Restore selection in playlist
Saves and restores the selected item in your most-recently accessed playlist, similar to Database and File Browser. Change-Id: I00afca41e33470cb458c4b87baccd6fd4016887a
This commit is contained in:
parent
88ecaf2b8c
commit
098a8fd334
5 changed files with 36 additions and 19 deletions
|
@ -137,7 +137,7 @@ int save_playlist_screen(struct playlist_info* playlist)
|
||||||
|
|
||||||
static int playlist_view_(void)
|
static int playlist_view_(void)
|
||||||
{
|
{
|
||||||
playlist_viewer_ex(NULL);
|
playlist_viewer_ex(NULL, NULL);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
MENUITEM_FUNCTION(create_playlist_item, 0, ID2P(LANG_CREATE_PLAYLIST),
|
MENUITEM_FUNCTION(create_playlist_item, 0, ID2P(LANG_CREATE_PLAYLIST),
|
||||||
|
|
|
@ -591,7 +591,7 @@ static bool view_playlist(void)
|
||||||
{
|
{
|
||||||
bool result;
|
bool result;
|
||||||
|
|
||||||
result = playlist_viewer_ex(selected_file);
|
result = playlist_viewer_ex(selected_file, NULL);
|
||||||
|
|
||||||
if (result == PLAYLIST_VIEWER_OK &&
|
if (result == PLAYLIST_VIEWER_OK &&
|
||||||
onplay_result == ONPLAY_OK)
|
onplay_result == ONPLAY_OK)
|
||||||
|
|
|
@ -147,6 +147,7 @@ const char* catalog_get_directory(void)
|
||||||
If "view" mode is set then we're not adding anything into playlist. */
|
If "view" mode is set then we're not adding anything into playlist. */
|
||||||
static int display_playlists(char* playlist, bool view)
|
static int display_playlists(char* playlist, bool view)
|
||||||
{
|
{
|
||||||
|
static int most_recent_selection = 0;
|
||||||
struct browse_context browse;
|
struct browse_context browse;
|
||||||
char selected_playlist[MAX_PATH];
|
char selected_playlist[MAX_PATH];
|
||||||
int result = -1;
|
int result = -1;
|
||||||
|
@ -154,7 +155,7 @@ static int display_playlists(char* playlist, bool view)
|
||||||
browse_context_init(&browse, SHOW_M3U,
|
browse_context_init(&browse, SHOW_M3U,
|
||||||
BROWSE_SELECTONLY|(view? 0: BROWSE_NO_CONTEXT_MENU),
|
BROWSE_SELECTONLY|(view? 0: BROWSE_NO_CONTEXT_MENU),
|
||||||
str(LANG_CATALOG), NOICON,
|
str(LANG_CATALOG), NOICON,
|
||||||
playlist_dir, most_recent_playlist);
|
playlist_dir, playlist_dir_length + 1 + most_recent_playlist);
|
||||||
|
|
||||||
browse.buf = selected_playlist;
|
browse.buf = selected_playlist;
|
||||||
browse.bufsize = sizeof(selected_playlist);
|
browse.bufsize = sizeof(selected_playlist);
|
||||||
|
@ -168,8 +169,12 @@ restart:
|
||||||
|
|
||||||
if (browse.flags & BROWSE_SELECTED)
|
if (browse.flags & BROWSE_SELECTED)
|
||||||
{
|
{
|
||||||
strmemccpy(most_recent_playlist, selected_playlist+playlist_dir_length+1,
|
if (strcmp(most_recent_playlist, selected_playlist)) /* isn't most recent one */
|
||||||
sizeof(most_recent_playlist));
|
{
|
||||||
|
strmemccpy(most_recent_playlist, selected_playlist,
|
||||||
|
sizeof(most_recent_playlist));
|
||||||
|
most_recent_selection = 0;
|
||||||
|
}
|
||||||
|
|
||||||
if (view)
|
if (view)
|
||||||
{
|
{
|
||||||
|
@ -179,7 +184,7 @@ restart:
|
||||||
result = 0;
|
result = 0;
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
switch (playlist_viewer_ex(selected_playlist)) {
|
switch (playlist_viewer_ex(selected_playlist, &most_recent_selection)) {
|
||||||
case PLAYLIST_VIEWER_OK:
|
case PLAYLIST_VIEWER_OK:
|
||||||
result = 0;
|
result = 0;
|
||||||
break;
|
break;
|
||||||
|
|
|
@ -105,6 +105,7 @@ struct playlist_viewer {
|
||||||
const char *title; /* Playlist Viewer list title */
|
const char *title; /* Playlist Viewer list title */
|
||||||
struct playlist_info* playlist; /* Playlist being viewed */
|
struct playlist_info* playlist; /* Playlist being viewed */
|
||||||
int num_tracks; /* Number of tracks in playlist */
|
int num_tracks; /* Number of tracks in playlist */
|
||||||
|
int *initial_selection; /* The initially selected track */
|
||||||
int current_playing_track; /* Index of current playing track */
|
int current_playing_track; /* Index of current playing track */
|
||||||
int selected_track; /* The selected track, relative (first is 0) */
|
int selected_track; /* The selected track, relative (first is 0) */
|
||||||
int moving_track; /* The track to move, relative (first is 0)
|
int moving_track; /* The track to move, relative (first is 0)
|
||||||
|
@ -132,7 +133,8 @@ static struct playlist_entry * playlist_buffer_get_track(struct playlist_buffer
|
||||||
int index);
|
int index);
|
||||||
|
|
||||||
static bool playlist_viewer_init(struct playlist_viewer * viewer,
|
static bool playlist_viewer_init(struct playlist_viewer * viewer,
|
||||||
const char* filename, bool reload);
|
const char* filename, bool reload,
|
||||||
|
int *most_recent_selection);
|
||||||
|
|
||||||
static void format_name(char* dest, const char* src);
|
static void format_name(char* dest, const char* src);
|
||||||
static void format_line(const struct playlist_entry* track, char* str,
|
static void format_line(const struct playlist_entry* track, char* str,
|
||||||
|
@ -321,7 +323,8 @@ static struct playlist_entry * playlist_buffer_get_track(struct playlist_buffer
|
||||||
|
|
||||||
/* Initialize the playlist viewer. */
|
/* Initialize the playlist viewer. */
|
||||||
static bool playlist_viewer_init(struct playlist_viewer * viewer,
|
static bool playlist_viewer_init(struct playlist_viewer * viewer,
|
||||||
const char* filename, bool reload)
|
const char* filename, bool reload,
|
||||||
|
int *most_recent_selection)
|
||||||
{
|
{
|
||||||
char* buffer;
|
char* buffer;
|
||||||
size_t buffer_size;
|
size_t buffer_size;
|
||||||
|
@ -406,11 +409,12 @@ static bool playlist_viewer_init(struct playlist_viewer * viewer,
|
||||||
|
|
||||||
viewer->moving_track = -1;
|
viewer->moving_track = -1;
|
||||||
viewer->moving_playlist_index = -1;
|
viewer->moving_playlist_index = -1;
|
||||||
|
viewer->initial_selection = most_recent_selection;
|
||||||
|
|
||||||
if (!reload)
|
if (!reload)
|
||||||
{
|
{
|
||||||
if (viewer->playlist)
|
if (viewer->playlist)
|
||||||
viewer->selected_track = 0;
|
viewer->selected_track = most_recent_selection ? *most_recent_selection : 0;
|
||||||
else
|
else
|
||||||
viewer->selected_track = playlist_get_display_index() - 1;
|
viewer->selected_track = playlist_get_display_index() - 1;
|
||||||
}
|
}
|
||||||
|
@ -668,7 +672,7 @@ static enum pv_onplay_result onplay_menu(int index)
|
||||||
/* View current playlist */
|
/* View current playlist */
|
||||||
enum playlist_viewer_result playlist_viewer(void)
|
enum playlist_viewer_result playlist_viewer(void)
|
||||||
{
|
{
|
||||||
return playlist_viewer_ex(NULL);
|
return playlist_viewer_ex(NULL, NULL);
|
||||||
}
|
}
|
||||||
|
|
||||||
static int get_track_num(struct playlist_viewer *local_viewer,
|
static int get_track_num(struct playlist_viewer *local_viewer,
|
||||||
|
@ -821,11 +825,11 @@ static void prepare_lists(struct gui_synclist * playlist_lists)
|
||||||
|
|
||||||
static bool open_playlist_viewer(const char* filename,
|
static bool open_playlist_viewer(const char* filename,
|
||||||
struct gui_synclist *playlist_lists,
|
struct gui_synclist *playlist_lists,
|
||||||
bool reload)
|
bool reload, int *most_recent_selection)
|
||||||
{
|
{
|
||||||
push_current_activity(ACTIVITY_PLAYLISTVIEWER);
|
push_current_activity(ACTIVITY_PLAYLISTVIEWER);
|
||||||
|
|
||||||
if (!playlist_viewer_init(&viewer, filename, reload))
|
if (!playlist_viewer_init(&viewer, filename, reload, most_recent_selection))
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
prepare_lists(playlist_lists);
|
prepare_lists(playlist_lists);
|
||||||
|
@ -835,14 +839,15 @@ static bool open_playlist_viewer(const char* filename,
|
||||||
|
|
||||||
/* Main viewer function. Filename identifies playlist to be viewed. If NULL,
|
/* Main viewer function. Filename identifies playlist to be viewed. If NULL,
|
||||||
view current playlist. */
|
view current playlist. */
|
||||||
enum playlist_viewer_result playlist_viewer_ex(const char* filename)
|
enum playlist_viewer_result playlist_viewer_ex(const char* filename,
|
||||||
|
int* most_recent_selection)
|
||||||
{
|
{
|
||||||
enum playlist_viewer_result ret = PLAYLIST_VIEWER_OK;
|
enum playlist_viewer_result ret = PLAYLIST_VIEWER_OK;
|
||||||
bool exit = false; /* exit viewer */
|
bool exit = false; /* exit viewer */
|
||||||
int button;
|
int button;
|
||||||
struct gui_synclist playlist_lists;
|
struct gui_synclist playlist_lists;
|
||||||
|
|
||||||
if (!open_playlist_viewer(filename, &playlist_lists, false))
|
if (!open_playlist_viewer(filename, &playlist_lists, false, most_recent_selection))
|
||||||
{
|
{
|
||||||
ret = PLAYLIST_VIEWER_CANCEL;
|
ret = PLAYLIST_VIEWER_CANCEL;
|
||||||
goto exit;
|
goto exit;
|
||||||
|
@ -961,8 +966,11 @@ enum playlist_viewer_result playlist_viewer_ex(const char* filename)
|
||||||
start_index = playlist_shuffle(current_tick, start_index);
|
start_index = playlist_shuffle(current_tick, start_index);
|
||||||
playlist_start(start_index, 0, 0);
|
playlist_start(start_index, 0, 0);
|
||||||
|
|
||||||
|
if (viewer.initial_selection)
|
||||||
|
*(viewer.initial_selection) = viewer.selected_track;
|
||||||
|
|
||||||
/* Our playlist is now the current list */
|
/* Our playlist is now the current list */
|
||||||
if (!playlist_viewer_init(&viewer, NULL, true))
|
if (!playlist_viewer_init(&viewer, NULL, true, NULL))
|
||||||
goto exit;
|
goto exit;
|
||||||
exit = true;
|
exit = true;
|
||||||
}
|
}
|
||||||
|
@ -986,7 +994,7 @@ enum playlist_viewer_result playlist_viewer_ex(const char* filename)
|
||||||
return PLAYLIST_VIEWER_OK;
|
return PLAYLIST_VIEWER_OK;
|
||||||
else if (pv_onplay_result == PV_ONPLAY_CLOSED)
|
else if (pv_onplay_result == PV_ONPLAY_CLOSED)
|
||||||
{
|
{
|
||||||
if (!open_playlist_viewer(filename, &playlist_lists, true))
|
if (!open_playlist_viewer(filename, &playlist_lists, true, NULL))
|
||||||
{
|
{
|
||||||
ret = PLAYLIST_VIEWER_CANCEL;
|
ret = PLAYLIST_VIEWER_CANCEL;
|
||||||
goto exit;
|
goto exit;
|
||||||
|
@ -1035,7 +1043,7 @@ enum playlist_viewer_result playlist_viewer_ex(const char* filename)
|
||||||
return PLAYLIST_VIEWER_USB;
|
return PLAYLIST_VIEWER_USB;
|
||||||
else if (plugin_result == PV_ONPLAY_WPS_CLOSED)
|
else if (plugin_result == PV_ONPLAY_WPS_CLOSED)
|
||||||
return PLAYLIST_VIEWER_OK;
|
return PLAYLIST_VIEWER_OK;
|
||||||
else if (!open_playlist_viewer(filename, &playlist_lists, true))
|
else if (!open_playlist_viewer(filename, &playlist_lists, true, NULL))
|
||||||
{
|
{
|
||||||
ret = PLAYLIST_VIEWER_CANCEL;
|
ret = PLAYLIST_VIEWER_CANCEL;
|
||||||
goto exit;
|
goto exit;
|
||||||
|
@ -1087,6 +1095,9 @@ static void close_playlist_viewer(void)
|
||||||
pop_current_activity();
|
pop_current_activity();
|
||||||
if (viewer.playlist)
|
if (viewer.playlist)
|
||||||
{
|
{
|
||||||
|
if (viewer.initial_selection)
|
||||||
|
*(viewer.initial_selection) = viewer.selected_track;
|
||||||
|
|
||||||
if(dirty && yesno_pop(ID2P(LANG_SAVE_CHANGES)))
|
if(dirty && yesno_pop(ID2P(LANG_SAVE_CHANGES)))
|
||||||
save_playlist_screen(viewer.playlist);
|
save_playlist_screen(viewer.playlist);
|
||||||
playlist_close(viewer.playlist);
|
playlist_close(viewer.playlist);
|
||||||
|
@ -1127,7 +1138,7 @@ bool search_playlist(void)
|
||||||
struct gui_synclist playlist_lists;
|
struct gui_synclist playlist_lists;
|
||||||
struct playlist_track_info track;
|
struct playlist_track_info track;
|
||||||
|
|
||||||
if (!playlist_viewer_init(&viewer, 0, false))
|
if (!playlist_viewer_init(&viewer, 0, false, NULL))
|
||||||
return ret;
|
return ret;
|
||||||
if (kbd_input(search_str, sizeof(search_str), NULL) < 0)
|
if (kbd_input(search_str, sizeof(search_str), NULL) < 0)
|
||||||
return ret;
|
return ret;
|
||||||
|
|
|
@ -24,7 +24,8 @@
|
||||||
#define _PLAYLIST_VIEWER_H_
|
#define _PLAYLIST_VIEWER_H_
|
||||||
|
|
||||||
enum playlist_viewer_result playlist_viewer(void);
|
enum playlist_viewer_result playlist_viewer(void);
|
||||||
enum playlist_viewer_result playlist_viewer_ex(const char* filename);
|
enum playlist_viewer_result playlist_viewer_ex(const char* filename,
|
||||||
|
int* most_recent_selection);
|
||||||
bool search_playlist(void);
|
bool search_playlist(void);
|
||||||
|
|
||||||
enum playlist_viewer_result {
|
enum playlist_viewer_result {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue