Rockbox open source high quality audio player as a Music Player Daemon
mpris rockbox mpd libadwaita audio rust zig deno
2
fork

Configure Feed

Select the types of activity you want to include in your feed.

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

+36 -19
+1 -1
apps/menus/playlist_menu.c
··· 137 137 138 138 static int playlist_view_(void) 139 139 { 140 - playlist_viewer_ex(NULL); 140 + playlist_viewer_ex(NULL, NULL); 141 141 return 0; 142 142 } 143 143 MENUITEM_FUNCTION(create_playlist_item, 0, ID2P(LANG_CREATE_PLAYLIST),
+1 -1
apps/onplay.c
··· 591 591 { 592 592 bool result; 593 593 594 - result = playlist_viewer_ex(selected_file); 594 + result = playlist_viewer_ex(selected_file, NULL); 595 595 596 596 if (result == PLAYLIST_VIEWER_OK && 597 597 onplay_result == ONPLAY_OK)
+9 -4
apps/playlist_catalog.c
··· 147 147 If "view" mode is set then we're not adding anything into playlist. */ 148 148 static int display_playlists(char* playlist, bool view) 149 149 { 150 + static int most_recent_selection = 0; 150 151 struct browse_context browse; 151 152 char selected_playlist[MAX_PATH]; 152 153 int result = -1; ··· 154 155 browse_context_init(&browse, SHOW_M3U, 155 156 BROWSE_SELECTONLY|(view? 0: BROWSE_NO_CONTEXT_MENU), 156 157 str(LANG_CATALOG), NOICON, 157 - playlist_dir, most_recent_playlist); 158 + playlist_dir, playlist_dir_length + 1 + most_recent_playlist); 158 159 159 160 browse.buf = selected_playlist; 160 161 browse.bufsize = sizeof(selected_playlist); ··· 168 169 169 170 if (browse.flags & BROWSE_SELECTED) 170 171 { 171 - strmemccpy(most_recent_playlist, selected_playlist+playlist_dir_length+1, 172 - sizeof(most_recent_playlist)); 172 + if (strcmp(most_recent_playlist, selected_playlist)) /* isn't most recent one */ 173 + { 174 + strmemccpy(most_recent_playlist, selected_playlist, 175 + sizeof(most_recent_playlist)); 176 + most_recent_selection = 0; 177 + } 173 178 174 179 if (view) 175 180 { ··· 179 184 result = 0; 180 185 else 181 186 { 182 - switch (playlist_viewer_ex(selected_playlist)) { 187 + switch (playlist_viewer_ex(selected_playlist, &most_recent_selection)) { 183 188 case PLAYLIST_VIEWER_OK: 184 189 result = 0; 185 190 break;
+23 -12
apps/playlist_viewer.c
··· 105 105 const char *title; /* Playlist Viewer list title */ 106 106 struct playlist_info* playlist; /* Playlist being viewed */ 107 107 int num_tracks; /* Number of tracks in playlist */ 108 + int *initial_selection; /* The initially selected track */ 108 109 int current_playing_track; /* Index of current playing track */ 109 110 int selected_track; /* The selected track, relative (first is 0) */ 110 111 int moving_track; /* The track to move, relative (first is 0) ··· 132 133 int index); 133 134 134 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 139 static void format_name(char* dest, const char* src); 138 140 static void format_line(const struct playlist_entry* track, char* str, ··· 321 323 322 324 /* Initialize the playlist viewer. */ 323 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 329 char* buffer; 327 330 size_t buffer_size; ··· 406 409 407 410 viewer->moving_track = -1; 408 411 viewer->moving_playlist_index = -1; 412 + viewer->initial_selection = most_recent_selection; 409 413 410 414 if (!reload) 411 415 { 412 416 if (viewer->playlist) 413 - viewer->selected_track = 0; 417 + viewer->selected_track = most_recent_selection ? *most_recent_selection : 0; 414 418 else 415 419 viewer->selected_track = playlist_get_display_index() - 1; 416 420 } ··· 668 672 /* View current playlist */ 669 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 678 static int get_track_num(struct playlist_viewer *local_viewer, ··· 821 825 822 826 static bool open_playlist_viewer(const char* filename, 823 827 struct gui_synclist *playlist_lists, 824 - bool reload) 828 + bool reload, int *most_recent_selection) 825 829 { 826 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 833 return false; 830 834 831 835 prepare_lists(playlist_lists); ··· 835 839 836 840 /* Main viewer function. Filename identifies playlist to be viewed. If NULL, 837 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 845 enum playlist_viewer_result ret = PLAYLIST_VIEWER_OK; 841 846 bool exit = false; /* exit viewer */ 842 847 int button; 843 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 852 ret = PLAYLIST_VIEWER_CANCEL; 848 853 goto exit; ··· 961 966 start_index = playlist_shuffle(current_tick, start_index); 962 967 playlist_start(start_index, 0, 0); 963 968 969 + if (viewer.initial_selection) 970 + *(viewer.initial_selection) = viewer.selected_track; 971 + 964 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 974 goto exit; 967 975 exit = true; 968 976 } ··· 986 994 return PLAYLIST_VIEWER_OK; 987 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 999 ret = PLAYLIST_VIEWER_CANCEL; 992 1000 goto exit; ··· 1035 1043 return PLAYLIST_VIEWER_USB; 1036 1044 else if (plugin_result == PV_ONPLAY_WPS_CLOSED) 1037 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 1048 ret = PLAYLIST_VIEWER_CANCEL; 1041 1049 goto exit; ··· 1087 1095 pop_current_activity(); 1088 1096 if (viewer.playlist) 1089 1097 { 1098 + if (viewer.initial_selection) 1099 + *(viewer.initial_selection) = viewer.selected_track; 1100 + 1090 1101 if(dirty && yesno_pop(ID2P(LANG_SAVE_CHANGES))) 1091 1102 save_playlist_screen(viewer.playlist); 1092 1103 playlist_close(viewer.playlist); ··· 1127 1138 struct gui_synclist playlist_lists; 1128 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 1142 return ret; 1132 1143 if (kbd_input(search_str, sizeof(search_str), NULL) < 0) 1133 1144 return ret;
+2 -1
apps/playlist_viewer.h
··· 24 24 #define _PLAYLIST_VIEWER_H_ 25 25 26 26 enum playlist_viewer_result playlist_viewer(void); 27 - enum playlist_viewer_result playlist_viewer_ex(const char* filename); 27 + enum playlist_viewer_result playlist_viewer_ex(const char* filename, 28 + int* most_recent_selection); 28 29 bool search_playlist(void); 29 30 30 31 enum playlist_viewer_result {