diff --git a/apps/playlist.c b/apps/playlist.c index f2b0bb197f..c755aca9fd 100644 --- a/apps/playlist.c +++ b/apps/playlist.c @@ -576,20 +576,18 @@ static void empty_playlist_unlocked(struct playlist_info* playlist, bool resume) playlist->utf8 = true; playlist->control_created = false; playlist->in_ram = false; + playlist->modified = false; playlist->fd = -1; playlist->control_fd = -1; - playlist->num_inserted_tracks = 0; playlist->index = 0; playlist->first_index = 0; playlist->amount = 0; playlist->last_insert_pos = -1; - playlist->deleted = false; playlist->started = false; playlist->pending_control_sync = false; - playlist->shuffle_modified = false; if (!resume && playlist == ¤t_playlist) { @@ -810,9 +808,7 @@ static int recreate_control_unlocked(struct playlist_info* playlist) } playlist->seed = 0; - playlist->shuffle_modified = false; - playlist->deleted = false; - playlist->num_inserted_tracks = 0; + playlist->modified = true; for (i=0; iamount; i++) { @@ -841,8 +837,6 @@ static int recreate_control_unlocked(struct playlist_info* playlist) if (result < 0) break; - - playlist->num_inserted_tracks++; } } @@ -1373,18 +1367,11 @@ static int remove_all_tracks_unlocked(struct playlist_info *playlist, bool write #endif /* Update playlist state as if by remove_track_unlocked() */ - bool inserted = playlist->indices[0] & PLAYLIST_INSERT_TYPE_MASK; - playlist->index = 0; + playlist->first_index = 0; playlist->amount = 1; playlist->indices[0] |= PLAYLIST_QUEUED; - - if (inserted) - playlist->num_inserted_tracks = 1; - else - playlist->deleted = true; - - playlist->first_index = 0; + playlist->modified = true; if (playlist->last_insert_pos == 0) playlist->last_insert_pos = -1; @@ -1558,7 +1545,7 @@ static int add_track_to_playlist_unlocked(struct playlist_info* playlist, dc_init_filerefs(playlist, insert_position, 1); playlist->amount++; - playlist->num_inserted_tracks++; + playlist->modified = true; return insert_position; } @@ -1614,13 +1601,10 @@ static int remove_track_unlocked(struct playlist_info* playlist, { int i; int result = 0; - bool inserted; if (playlist->amount <= 0) return -1; - inserted = playlist->indices[position] & PLAYLIST_INSERT_TYPE_MASK; - #ifdef HAVE_DIRCACHE struct dircache_fileref *dcfrefs = NULL; if (playlist->dcfrefs_handle) @@ -1638,11 +1622,7 @@ static int remove_track_unlocked(struct playlist_info* playlist, } playlist->amount--; - - if (inserted) - playlist->num_inserted_tracks--; - else - playlist->deleted = true; + playlist->modified = true; /* update stored indices if needed */ if (position < playlist->index) @@ -1735,8 +1715,7 @@ static int randomise_playlist_unlocked(struct playlist_info* playlist, playlist->last_insert_pos = -1; playlist->seed = seed; - if (playlist->num_inserted_tracks > 0 || playlist->deleted) - playlist->shuffle_modified = true; + playlist->modified = true; if (write) { @@ -1800,9 +1779,8 @@ static int sort_playlist_unlocked(struct playlist_info* playlist, /* indices have been moved so last insert position is no longer valid */ playlist->last_insert_pos = -1; + playlist->modified = true; - if (!playlist->num_inserted_tracks && !playlist->deleted) - playlist->shuffle_modified = false; if (write && playlist->control_fd >= 0) { playlist->first_index = 0; @@ -2905,20 +2883,25 @@ int playlist_insert_track(struct playlist_info* playlist, const char *filename, return result; } -/* returns true if playlist has been modified */ +/* returns true if playlist has been modified by the user */ bool playlist_modified(const struct playlist_info* playlist) { if (!playlist) playlist = ¤t_playlist; - if (playlist->shuffle_modified || - playlist->deleted || - playlist->num_inserted_tracks > 0) - { - return true; - } + return playlist->modified; +} - return false; +/* + * Set the playlist modified status. Useful for clearing the modified status + * after dynamically building a playlist. + */ +void playlist_set_modified(struct playlist_info *playlist, bool modified) +{ + if (!playlist) + playlist = ¤t_playlist; + + playlist->modified = modified; } /* @@ -3938,6 +3921,7 @@ int playlist_save(struct playlist_info* playlist, char *filename, if (fd >= 0) close(fd); + playlist->modified = false; cpu_boost(false); return result; @@ -3996,9 +3980,7 @@ int playlist_set_current(struct playlist_info* playlist) current_playlist.amount = playlist->amount; current_playlist.last_insert_pos = playlist->last_insert_pos; current_playlist.seed = playlist->seed; - current_playlist.shuffle_modified = playlist->shuffle_modified; - current_playlist.deleted = playlist->deleted; - current_playlist.num_inserted_tracks = playlist->num_inserted_tracks; + current_playlist.modified = playlist->modified; memcpy(current_playlist.control_cache, playlist->control_cache, sizeof(current_playlist.control_cache)); diff --git a/apps/playlist.h b/apps/playlist.h index d56a6fd659..cb79eea96c 100644 --- a/apps/playlist.h +++ b/apps/playlist.h @@ -75,11 +75,11 @@ struct playlist_info bool utf8; /* playlist is in .m3u8 format */ bool control_created; /* has control file been created? */ bool in_ram; /* playlist stored in ram (dirplay) */ + bool modified; /* has playlist been modified by the user? */ int fd; /* descriptor of the open playlist file */ int control_fd; /* descriptor of the open control file */ int max_playlist_size; /* Max number of files in playlist. Mirror of global_settings.max_files_in_playlist */ - int num_inserted_tracks; /* number of tracks inserted */ unsigned long *indices; /* array of indices */ struct chunk_alloc_header name_chunk_buffer; /* chunk buffer for @@ -89,11 +89,8 @@ struct playlist_info int first_index; /* index of first song in playlist */ int amount; /* number of tracks in the index */ int last_insert_pos; /* last position we inserted a track */ - bool deleted; /* have any tracks been deleted? */ bool started; /* has playlist been started? */ bool pending_control_sync; /* control file needs to be synced */ - bool shuffle_modified; /* has playlist been shuffled with - inserted tracks? */ int last_shuffled_start; /* number of tracks when insert last shuffled command start */ int seed; /* shuffle seed */ @@ -166,6 +163,7 @@ int playlist_randomise(struct playlist_info* playlist, unsigned int seed, bool start_current); int playlist_sort(struct playlist_info* playlist, bool start_current); bool playlist_modified(const struct playlist_info* playlist); +void playlist_set_modified(struct playlist_info* playlist, bool modified); int playlist_get_first_index(const struct playlist_info* playlist); int playlist_get_seed(const struct playlist_info* playlist); int playlist_amount_ex(const struct playlist_info* playlist); diff --git a/apps/playlist_viewer.c b/apps/playlist_viewer.c index 4328a6de1d..8761f0dbc9 100644 --- a/apps/playlist_viewer.c +++ b/apps/playlist_viewer.c @@ -975,6 +975,7 @@ enum playlist_viewer_result playlist_viewer_ex(const char* filename, if (global_settings.playlist_shuffle) start_index = playlist_shuffle(current_tick, start_index); playlist_start(start_index, 0, 0); + playlist_set_modified(NULL, false); if (viewer.initial_selection) *(viewer.initial_selection) = viewer.selected_track; diff --git a/apps/plugin.c b/apps/plugin.c index 1a0aedf3cc..3db4bb2d80 100644 --- a/apps/plugin.c +++ b/apps/plugin.c @@ -829,6 +829,7 @@ static const struct plugin_api rockbox_api = { tagtree_subentries_do_action, #endif adjust_volume, + playlist_set_modified, }; static int plugin_buffer_handle; diff --git a/apps/plugin.h b/apps/plugin.h index cf6a1bc4e4..c54ef180ec 100644 --- a/apps/plugin.h +++ b/apps/plugin.h @@ -954,6 +954,7 @@ struct plugin_api { bool (*tagtree_subentries_do_action)(bool (*action_cb)(const char *file_name)); #endif void (*adjust_volume)(int steps); + void (*playlist_set_modified)(struct playlist_info *playlist, bool modified); }; /* plugin header */ diff --git a/apps/plugins/pictureflow/pictureflow.c b/apps/plugins/pictureflow/pictureflow.c index 45c4e0fcda..67c26a7dc8 100644 --- a/apps/plugins/pictureflow/pictureflow.c +++ b/apps/plugins/pictureflow/pictureflow.c @@ -4246,7 +4246,7 @@ static bool start_playback(bool return_to_WPS) start_index = rb->playlist_shuffle(*rb->current_tick, pf_tracks.sel); } rb->playlist_start(start_index, 0, 0); - rb->playlist_get_current()->num_inserted_tracks = 0; /* prevent warn_on_pl_erase */ + rb->playlist_set_modified(NULL, false); old_shuffle = shuffle; #ifdef USEGSLIB if (!return_to_WPS) diff --git a/apps/tagtree.c b/apps/tagtree.c index 72eec1494c..e715d4518b 100644 --- a/apps/tagtree.c +++ b/apps/tagtree.c @@ -2359,7 +2359,7 @@ static int tagtree_play_folder(struct tree_context* c) } playlist_start(start_index, 0, 0); - playlist_get_current()->num_inserted_tracks = 0; /* make warn on playlist erase work */ + playlist_set_modified(NULL, false); return 0; }