diff options
Diffstat (limited to 'apps/playlist_viewer.c')
-rw-r--r-- | apps/playlist_viewer.c | 35 |
1 files changed, 23 insertions, 12 deletions
diff --git a/apps/playlist_viewer.c b/apps/playlist_viewer.c index 7f98ccd8e3..8f1c5d961d 100644 --- a/apps/playlist_viewer.c +++ b/apps/playlist_viewer.c | |||
@@ -105,6 +105,7 @@ struct playlist_viewer { | |||
105 | const char *title; /* Playlist Viewer list title */ | 105 | const char *title; /* Playlist Viewer list title */ |
106 | struct playlist_info* playlist; /* Playlist being viewed */ | 106 | struct playlist_info* playlist; /* Playlist being viewed */ |
107 | int num_tracks; /* Number of tracks in playlist */ | 107 | int num_tracks; /* Number of tracks in playlist */ |
108 | int *initial_selection; /* The initially selected track */ | ||
108 | int current_playing_track; /* Index of current playing track */ | 109 | int current_playing_track; /* Index of current playing track */ |
109 | int selected_track; /* The selected track, relative (first is 0) */ | 110 | int selected_track; /* The selected track, relative (first is 0) */ |
110 | int moving_track; /* The track to move, relative (first is 0) | 111 | 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 | |||
132 | int index); | 133 | int index); |
133 | 134 | ||
134 | static bool playlist_viewer_init(struct playlist_viewer * viewer, | 135 | static bool playlist_viewer_init(struct playlist_viewer * viewer, |
135 | const char* filename, bool reload); | 136 | const char* filename, bool reload, |
137 | int *most_recent_selection); | ||
136 | 138 | ||
137 | static void format_name(char* dest, const char* src); | 139 | static void format_name(char* dest, const char* src); |
138 | static void format_line(const struct playlist_entry* track, char* str, | 140 | 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 | |||
321 | 323 | ||
322 | /* Initialize the playlist viewer. */ | 324 | /* Initialize the playlist viewer. */ |
323 | static bool playlist_viewer_init(struct playlist_viewer * viewer, | 325 | static bool playlist_viewer_init(struct playlist_viewer * viewer, |
324 | const char* filename, bool reload) | 326 | const char* filename, bool reload, |
327 | int *most_recent_selection) | ||
325 | { | 328 | { |
326 | char* buffer; | 329 | char* buffer; |
327 | size_t buffer_size; | 330 | size_t buffer_size; |
@@ -406,11 +409,12 @@ static bool playlist_viewer_init(struct playlist_viewer * viewer, | |||
406 | 409 | ||
407 | viewer->moving_track = -1; | 410 | viewer->moving_track = -1; |
408 | viewer->moving_playlist_index = -1; | 411 | viewer->moving_playlist_index = -1; |
412 | viewer->initial_selection = most_recent_selection; | ||
409 | 413 | ||
410 | if (!reload) | 414 | if (!reload) |
411 | { | 415 | { |
412 | if (viewer->playlist) | 416 | if (viewer->playlist) |
413 | viewer->selected_track = 0; | 417 | viewer->selected_track = most_recent_selection ? *most_recent_selection : 0; |
414 | else | 418 | else |
415 | viewer->selected_track = playlist_get_display_index() - 1; | 419 | viewer->selected_track = playlist_get_display_index() - 1; |
416 | } | 420 | } |
@@ -668,7 +672,7 @@ static enum pv_onplay_result onplay_menu(int index) | |||
668 | /* View current playlist */ | 672 | /* View current playlist */ |
669 | enum playlist_viewer_result playlist_viewer(void) | 673 | enum playlist_viewer_result playlist_viewer(void) |
670 | { | 674 | { |
671 | return playlist_viewer_ex(NULL); | 675 | return playlist_viewer_ex(NULL, NULL); |
672 | } | 676 | } |
673 | 677 | ||
674 | static int get_track_num(struct playlist_viewer *local_viewer, | 678 | static int get_track_num(struct playlist_viewer *local_viewer, |
@@ -821,11 +825,11 @@ static void prepare_lists(struct gui_synclist * playlist_lists) | |||
821 | 825 | ||
822 | static bool open_playlist_viewer(const char* filename, | 826 | static bool open_playlist_viewer(const char* filename, |
823 | struct gui_synclist *playlist_lists, | 827 | struct gui_synclist *playlist_lists, |
824 | bool reload) | 828 | bool reload, int *most_recent_selection) |
825 | { | 829 | { |
826 | push_current_activity(ACTIVITY_PLAYLISTVIEWER); | 830 | push_current_activity(ACTIVITY_PLAYLISTVIEWER); |
827 | 831 | ||
828 | if (!playlist_viewer_init(&viewer, filename, reload)) | 832 | if (!playlist_viewer_init(&viewer, filename, reload, most_recent_selection)) |
829 | return false; | 833 | return false; |
830 | 834 | ||
831 | prepare_lists(playlist_lists); | 835 | prepare_lists(playlist_lists); |
@@ -835,14 +839,15 @@ static bool open_playlist_viewer(const char* filename, | |||
835 | 839 | ||
836 | /* Main viewer function. Filename identifies playlist to be viewed. If NULL, | 840 | /* Main viewer function. Filename identifies playlist to be viewed. If NULL, |
837 | view current playlist. */ | 841 | view current playlist. */ |
838 | enum playlist_viewer_result playlist_viewer_ex(const char* filename) | 842 | enum playlist_viewer_result playlist_viewer_ex(const char* filename, |
843 | int* most_recent_selection) | ||
839 | { | 844 | { |
840 | enum playlist_viewer_result ret = PLAYLIST_VIEWER_OK; | 845 | enum playlist_viewer_result ret = PLAYLIST_VIEWER_OK; |
841 | bool exit = false; /* exit viewer */ | 846 | bool exit = false; /* exit viewer */ |
842 | int button; | 847 | int button; |
843 | struct gui_synclist playlist_lists; | 848 | struct gui_synclist playlist_lists; |
844 | 849 | ||
845 | if (!open_playlist_viewer(filename, &playlist_lists, false)) | 850 | if (!open_playlist_viewer(filename, &playlist_lists, false, most_recent_selection)) |
846 | { | 851 | { |
847 | ret = PLAYLIST_VIEWER_CANCEL; | 852 | ret = PLAYLIST_VIEWER_CANCEL; |
848 | goto exit; | 853 | goto exit; |
@@ -961,8 +966,11 @@ enum playlist_viewer_result playlist_viewer_ex(const char* filename) | |||
961 | start_index = playlist_shuffle(current_tick, start_index); | 966 | start_index = playlist_shuffle(current_tick, start_index); |
962 | playlist_start(start_index, 0, 0); | 967 | playlist_start(start_index, 0, 0); |
963 | 968 | ||
969 | if (viewer.initial_selection) | ||
970 | *(viewer.initial_selection) = viewer.selected_track; | ||
971 | |||
964 | /* Our playlist is now the current list */ | 972 | /* Our playlist is now the current list */ |
965 | if (!playlist_viewer_init(&viewer, NULL, true)) | 973 | if (!playlist_viewer_init(&viewer, NULL, true, NULL)) |
966 | goto exit; | 974 | goto exit; |
967 | exit = true; | 975 | exit = true; |
968 | } | 976 | } |
@@ -986,7 +994,7 @@ enum playlist_viewer_result playlist_viewer_ex(const char* filename) | |||
986 | return PLAYLIST_VIEWER_OK; | 994 | return PLAYLIST_VIEWER_OK; |
987 | else if (pv_onplay_result == PV_ONPLAY_CLOSED) | 995 | else if (pv_onplay_result == PV_ONPLAY_CLOSED) |
988 | { | 996 | { |
989 | if (!open_playlist_viewer(filename, &playlist_lists, true)) | 997 | if (!open_playlist_viewer(filename, &playlist_lists, true, NULL)) |
990 | { | 998 | { |
991 | ret = PLAYLIST_VIEWER_CANCEL; | 999 | ret = PLAYLIST_VIEWER_CANCEL; |
992 | goto exit; | 1000 | goto exit; |
@@ -1035,7 +1043,7 @@ enum playlist_viewer_result playlist_viewer_ex(const char* filename) | |||
1035 | return PLAYLIST_VIEWER_USB; | 1043 | return PLAYLIST_VIEWER_USB; |
1036 | else if (plugin_result == PV_ONPLAY_WPS_CLOSED) | 1044 | else if (plugin_result == PV_ONPLAY_WPS_CLOSED) |
1037 | return PLAYLIST_VIEWER_OK; | 1045 | return PLAYLIST_VIEWER_OK; |
1038 | else if (!open_playlist_viewer(filename, &playlist_lists, true)) | 1046 | else if (!open_playlist_viewer(filename, &playlist_lists, true, NULL)) |
1039 | { | 1047 | { |
1040 | ret = PLAYLIST_VIEWER_CANCEL; | 1048 | ret = PLAYLIST_VIEWER_CANCEL; |
1041 | goto exit; | 1049 | goto exit; |
@@ -1087,6 +1095,9 @@ static void close_playlist_viewer(void) | |||
1087 | pop_current_activity(); | 1095 | pop_current_activity(); |
1088 | if (viewer.playlist) | 1096 | if (viewer.playlist) |
1089 | { | 1097 | { |
1098 | if (viewer.initial_selection) | ||
1099 | *(viewer.initial_selection) = viewer.selected_track; | ||
1100 | |||
1090 | if(dirty && yesno_pop(ID2P(LANG_SAVE_CHANGES))) | 1101 | if(dirty && yesno_pop(ID2P(LANG_SAVE_CHANGES))) |
1091 | save_playlist_screen(viewer.playlist); | 1102 | save_playlist_screen(viewer.playlist); |
1092 | playlist_close(viewer.playlist); | 1103 | playlist_close(viewer.playlist); |
@@ -1127,7 +1138,7 @@ bool search_playlist(void) | |||
1127 | struct gui_synclist playlist_lists; | 1138 | struct gui_synclist playlist_lists; |
1128 | struct playlist_track_info track; | 1139 | struct playlist_track_info track; |
1129 | 1140 | ||
1130 | if (!playlist_viewer_init(&viewer, 0, false)) | 1141 | if (!playlist_viewer_init(&viewer, 0, false, NULL)) |
1131 | return ret; | 1142 | return ret; |
1132 | if (kbd_input(search_str, sizeof(search_str), NULL) < 0) | 1143 | if (kbd_input(search_str, sizeof(search_str), NULL) < 0) |
1133 | return ret; | 1144 | return ret; |