From 759aaecdffc3302cf965ade7aef9c2742a9270f3 Mon Sep 17 00:00:00 2001 From: Christian Soffke Date: Fri, 13 Oct 2023 17:49:28 +0200 Subject: Playlist Viewer: Eliminate 'dirty' flag A playlist's explicit 'modified' flag is now used for keeping track of whether it's been modified in the Playlist Viewer, not just in case of the currently playing list, but for other playlists as well. When you start playback of a track from the Playlist Viewer, a playlist's 'modified' status is now carried over to the current playlist, so as to produce a warning when there is an attempt to replace the list at a later point. This also prevents (auto) bookmarking of the playlist if it had been modified in the Playlist Viewer prior to becoming the current playlist. (Bugfix) Change-Id: Ibc391fd69285f8a67d6ffb6d8c274df3d223974c --- apps/playlist_viewer.c | 24 +++++++++++------------- 1 file changed, 11 insertions(+), 13 deletions(-) (limited to 'apps/playlist_viewer.c') diff --git a/apps/playlist_viewer.c b/apps/playlist_viewer.c index d12aa26de4..d780bfb7e9 100644 --- a/apps/playlist_viewer.c +++ b/apps/playlist_viewer.c @@ -121,8 +121,6 @@ static struct playlist_viewer viewer; static struct playlist_info temp_playlist; static bool temp_playlist_init = false; -static bool dirty = false; - static void playlist_buffer_init(struct playlist_buffer *pb, char *names_buffer, int names_buffer_size); static void playlist_buffer_load_entries(struct playlist_buffer * pb, int index, @@ -661,8 +659,14 @@ static enum pv_onplay_result onplay_menu(int index) break; case 6: /* save playlist */ - if (!save_playlist_screen(viewer.playlist)) - dirty = false; + if (!save_playlist_screen(viewer.playlist) && viewer.playlist) + /* + * Set unmodified unless it's the current playlist, which may + * contain queued songs that aren't saved to the playlist file + * TODO: This can be removed once g5192 is merged, + * "playlist: Rewrite playlist_save(), optimization & fixes" + */ + playlist_set_modified(viewer.playlist, false); ret = PV_ONPLAY_UNCHANGED; break; case 7: @@ -802,8 +806,7 @@ static bool update_viewer_with_changes(struct gui_synclist *playlist_lists, enum if (res == PV_ONPLAY_CHANGED || res == PV_ONPLAY_ITEM_REMOVED) { - if (!viewer.playlist) - playlist_set_modified(NULL, true); + playlist_set_modified(viewer.playlist, true); if (res == PV_ONPLAY_ITEM_REMOVED) gui_synclist_del_item(playlist_lists); @@ -815,8 +818,6 @@ static bool update_viewer_with_changes(struct gui_synclist *playlist_lists, enum if (viewer.selected_track >= viewer.num_tracks) viewer.selected_track = viewer.num_tracks-1; - - dirty = true; } /* the show_icons option in the playlist viewer settings @@ -956,13 +957,11 @@ enum playlist_viewer_result playlist_viewer_ex(const char* filename, str(LANG_FAILED)); } - if (!viewer.playlist) - playlist_set_modified(NULL, true); + playlist_set_modified(viewer.playlist, true); update_playlist(true); viewer.moving_track = -1; viewer.moving_playlist_index = -1; - dirty = true; } else if (!viewer.playlist) { @@ -1128,11 +1127,10 @@ static void close_playlist_viewer(void) if (viewer.initial_selection) *(viewer.initial_selection) = viewer.selected_track; - if(dirty && yesno_pop(ID2P(LANG_SAVE_CHANGES))) + if(playlist_modified(viewer.playlist) && yesno_pop(ID2P(LANG_SAVE_CHANGES))) save_playlist_screen(viewer.playlist); playlist_close(viewer.playlist); } - dirty = false; } static const char* playlist_search_callback_name(int selected_item, void * data, -- cgit v1.2.3