diff options
-rw-r--r-- | apps/menus/playlist_menu.c | 2 | ||||
-rw-r--r-- | apps/onplay.c | 2 | ||||
-rw-r--r-- | apps/playlist_catalog.c | 13 | ||||
-rw-r--r-- | apps/playlist_viewer.c | 35 | ||||
-rw-r--r-- | apps/playlist_viewer.h | 3 |
5 files changed, 36 insertions, 19 deletions
diff --git a/apps/menus/playlist_menu.c b/apps/menus/playlist_menu.c index e1e83d4311..357efe6b29 100644 --- a/apps/menus/playlist_menu.c +++ b/apps/menus/playlist_menu.c | |||
@@ -137,7 +137,7 @@ int save_playlist_screen(struct playlist_info* playlist) | |||
137 | 137 | ||
138 | static int playlist_view_(void) | 138 | static int playlist_view_(void) |
139 | { | 139 | { |
140 | playlist_viewer_ex(NULL); | 140 | playlist_viewer_ex(NULL, NULL); |
141 | return 0; | 141 | return 0; |
142 | } | 142 | } |
143 | MENUITEM_FUNCTION(create_playlist_item, 0, ID2P(LANG_CREATE_PLAYLIST), | 143 | MENUITEM_FUNCTION(create_playlist_item, 0, ID2P(LANG_CREATE_PLAYLIST), |
diff --git a/apps/onplay.c b/apps/onplay.c index 7cc52fca46..f2dbf8b3bf 100644 --- a/apps/onplay.c +++ b/apps/onplay.c | |||
@@ -591,7 +591,7 @@ static bool view_playlist(void) | |||
591 | { | 591 | { |
592 | bool result; | 592 | bool result; |
593 | 593 | ||
594 | result = playlist_viewer_ex(selected_file); | 594 | result = playlist_viewer_ex(selected_file, NULL); |
595 | 595 | ||
596 | if (result == PLAYLIST_VIEWER_OK && | 596 | if (result == PLAYLIST_VIEWER_OK && |
597 | onplay_result == ONPLAY_OK) | 597 | onplay_result == ONPLAY_OK) |
diff --git a/apps/playlist_catalog.c b/apps/playlist_catalog.c index 01cbc31600..a20600b268 100644 --- a/apps/playlist_catalog.c +++ b/apps/playlist_catalog.c | |||
@@ -147,6 +147,7 @@ const char* catalog_get_directory(void) | |||
147 | If "view" mode is set then we're not adding anything into playlist. */ | 147 | If "view" mode is set then we're not adding anything into playlist. */ |
148 | static int display_playlists(char* playlist, bool view) | 148 | static int display_playlists(char* playlist, bool view) |
149 | { | 149 | { |
150 | static int most_recent_selection = 0; | ||
150 | struct browse_context browse; | 151 | struct browse_context browse; |
151 | char selected_playlist[MAX_PATH]; | 152 | char selected_playlist[MAX_PATH]; |
152 | int result = -1; | 153 | int result = -1; |
@@ -154,7 +155,7 @@ static int display_playlists(char* playlist, bool view) | |||
154 | browse_context_init(&browse, SHOW_M3U, | 155 | browse_context_init(&browse, SHOW_M3U, |
155 | BROWSE_SELECTONLY|(view? 0: BROWSE_NO_CONTEXT_MENU), | 156 | BROWSE_SELECTONLY|(view? 0: BROWSE_NO_CONTEXT_MENU), |
156 | str(LANG_CATALOG), NOICON, | 157 | str(LANG_CATALOG), NOICON, |
157 | playlist_dir, most_recent_playlist); | 158 | playlist_dir, playlist_dir_length + 1 + most_recent_playlist); |
158 | 159 | ||
159 | browse.buf = selected_playlist; | 160 | browse.buf = selected_playlist; |
160 | browse.bufsize = sizeof(selected_playlist); | 161 | browse.bufsize = sizeof(selected_playlist); |
@@ -168,8 +169,12 @@ restart: | |||
168 | 169 | ||
169 | if (browse.flags & BROWSE_SELECTED) | 170 | if (browse.flags & BROWSE_SELECTED) |
170 | { | 171 | { |
171 | strmemccpy(most_recent_playlist, selected_playlist+playlist_dir_length+1, | 172 | if (strcmp(most_recent_playlist, selected_playlist)) /* isn't most recent one */ |
172 | sizeof(most_recent_playlist)); | 173 | { |
174 | strmemccpy(most_recent_playlist, selected_playlist, | ||
175 | sizeof(most_recent_playlist)); | ||
176 | most_recent_selection = 0; | ||
177 | } | ||
173 | 178 | ||
174 | if (view) | 179 | if (view) |
175 | { | 180 | { |
@@ -179,7 +184,7 @@ restart: | |||
179 | result = 0; | 184 | result = 0; |
180 | else | 185 | else |
181 | { | 186 | { |
182 | switch (playlist_viewer_ex(selected_playlist)) { | 187 | switch (playlist_viewer_ex(selected_playlist, &most_recent_selection)) { |
183 | case PLAYLIST_VIEWER_OK: | 188 | case PLAYLIST_VIEWER_OK: |
184 | result = 0; | 189 | result = 0; |
185 | break; | 190 | break; |
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; |
diff --git a/apps/playlist_viewer.h b/apps/playlist_viewer.h index 0a54c1b2cd..2bb1336f4f 100644 --- a/apps/playlist_viewer.h +++ b/apps/playlist_viewer.h | |||
@@ -24,7 +24,8 @@ | |||
24 | #define _PLAYLIST_VIEWER_H_ | 24 | #define _PLAYLIST_VIEWER_H_ |
25 | 25 | ||
26 | enum playlist_viewer_result playlist_viewer(void); | 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 | bool search_playlist(void); | 29 | bool search_playlist(void); |
29 | 30 | ||
30 | enum playlist_viewer_result { | 31 | enum playlist_viewer_result { |