diff --git a/apps/bookmark.c b/apps/bookmark.c index 567f98ac29..f783c83992 100644 --- a/apps/bookmark.c +++ b/apps/bookmark.c @@ -271,6 +271,19 @@ static bool write_bookmark(bool create_bookmark_file, const char *bookmark) return ret; } +/* Get the name of the playlist and the name of the track from a bookmark. */ +/* Returns true iff both were extracted. */ +static bool get_playlist_and_track(const char *bookmark, char **pl_start, + char **pl_end, char **track) +{ + *pl_start = strchr(bookmark,'/'); + if (!(*pl_start)) + return false; + *pl_end = strrchr(bookmark,';'); + *track = *pl_end + 1; + return true; +} + /* ----------------------------------------------------------------------- */ /* This function adds a bookmark to a file. */ /* Returns true on successful bookmark add. */ @@ -281,11 +294,13 @@ static bool add_bookmark(const char* bookmark_file_name, const char* bookmark, int temp_bookmark_file = 0; int bookmark_file = 0; int bookmark_count = 0; - char* playlist = NULL; - char* cp; - char* tmp; - int len = 0; - bool unique = false; + char *pl_start = NULL, *bm_pl_start; + char *pl_end = NULL, *bm_pl_end; + int pl_len = 0, bm_pl_len; + char *track = NULL, *bm_track; + bool comp_playlist = false; + bool comp_track = false; + bool equal; /* Opening up a temp bookmark file */ snprintf(global_temp_buffer, sizeof(global_temp_buffer), @@ -295,12 +310,16 @@ static bool add_bookmark(const char* bookmark_file_name, const char* bookmark, if (temp_bookmark_file < 0) return false; /* can't open the temp file */ - if (most_recent && (global_settings.usemrb == BOOKMARK_UNIQUE_ONLY)) + if (most_recent && ((global_settings.usemrb == BOOKMARK_ONE_PER_PLAYLIST) + || (global_settings.usemrb == BOOKMARK_ONE_PER_TRACK))) { - playlist = strchr(bookmark,'/'); - cp = strrchr(bookmark,';'); - len = cp - playlist; - unique = true; + if (get_playlist_and_track(bookmark, &pl_start, &pl_end, &track)) + { + comp_playlist = true; + pl_len = pl_end - pl_start; + if (global_settings.usemrb == BOOKMARK_ONE_PER_TRACK) + comp_track = true; + } } /* Writing the new bookmark to the begining of the temp file */ @@ -319,11 +338,23 @@ static bool add_bookmark(const char* bookmark_file_name, const char* bookmark, /* This keeps it from getting too large */ if (most_recent && (bookmark_count >= MAX_BOOKMARKS)) break; - - cp = strchr(global_read_buffer,'/'); - tmp = strrchr(global_read_buffer,';'); - if (parse_bookmark(global_read_buffer, false) && - (!unique || len != tmp -cp || strncmp(playlist,cp,len))) + + if (!parse_bookmark(global_read_buffer, false)) + break; + + equal = false; + if (comp_playlist) + { + if (get_playlist_and_track(global_read_buffer, &bm_pl_start, + &bm_pl_end, &bm_track)) + { + bm_pl_len = bm_pl_end - bm_pl_start; + equal = (pl_len == bm_pl_len) && !strncmp(pl_start, bm_pl_start, pl_len); + if (equal && comp_track) + equal = !strcmp(track, bm_track); + } + } + if (!equal) { bookmark_count++; write(temp_bookmark_file, global_read_buffer, diff --git a/apps/lang/english.lang b/apps/lang/english.lang index f4f1b12032..02482d08af 100644 --- a/apps/lang/english.lang +++ b/apps/lang/english.lang @@ -4737,16 +4737,16 @@ id: LANG_BOOKMARK_SETTINGS_UNIQUE_ONLY - desc: Save only on bookmark for each playlist in recent bookmarks + desc: deprecated user: core - *: "Unique only" + *: "" - *: "Unique only" + *: "" - *: "Unique only" + *: "" @@ -13689,3 +13689,31 @@ *: "gibibyte" + + id: LANG_BOOKMARK_SETTINGS_ONE_PER_PLAYLIST + desc: Save only one bookmark for a playlist in recent bookmarks + user: core + + *: "One per playlist" + + + *: "One per playlist" + + + *: "One per playlist" + + + + id: LANG_BOOKMARK_SETTINGS_ONE_PER_TRACK + desc: Save only one bookmark for a combination (playlist,track) in recent bookmarks + user: core + + *: "One per track" + + + *: "One per track" + + + *: "One per track" + + diff --git a/apps/settings.h b/apps/settings.h index cbe12d70b7..db16e717e6 100644 --- a/apps/settings.h +++ b/apps/settings.h @@ -45,14 +45,26 @@ struct opt_items { #define MAX_FILENAME 32 #define MAX_PATHNAME 80 +/* The values are assigned to the enums so that they correspond to */ +/* setting values in settings_list.c */ +/* Shared by all bookmark parameters */ enum { BOOKMARK_NO = 0, - BOOKMARK_YES, - BOOKMARK_ASK, - BOOKMARK_UNIQUE_ONLY = 2, - BOOKMARK_RECENT_ONLY_YES, - BOOKMARK_RECENT_ONLY_ASK, + BOOKMARK_YES = 1, +}; + +/* Auto create bookmark */ +enum { + BOOKMARK_ASK = 2, + BOOKMARK_RECENT_ONLY_YES = 3, + BOOKMARK_RECENT_ONLY_ASK = 4, +}; + +/* Most recent bookmark */ +enum { + BOOKMARK_ONE_PER_PLAYLIST = 2, + BOOKMARK_ONE_PER_TRACK = 3, }; enum @@ -557,7 +569,8 @@ struct user_settings int autoloadbookmark; /* auto load option: 0=off, 1=ask, 2=on */ int autocreatebookmark; /* auto create option: 0=off, 1=ask, 2=on */ bool autoupdatebookmark;/* auto update option */ - int usemrb; /* use MRB list: 0=No, 1=Yes, 2=One per playlist */ + int usemrb; /* use MRB list: 0=No, 1=Yes, 2=One per playlist, + 3=One per playlist and track */ #ifdef HAVE_DIRCACHE bool dircache; /* enable directory cache */ diff --git a/apps/settings_list.c b/apps/settings_list.c index 57763d345a..d4ad6f64dc 100644 --- a/apps/settings_list.c +++ b/apps/settings_list.c @@ -1246,9 +1246,10 @@ const struct settings_list settings[] = { ID2P(LANG_ASK)), CHOICE_SETTING(0, usemrb, LANG_BOOKMARK_SETTINGS_MAINTAIN_RECENT_BOOKMARKS, BOOKMARK_NO, "use most-recent-bookmarks", - "off,on,unique only", NULL, 3, ID2P(LANG_SET_BOOL_NO), + "off,on,unique only,one per track", NULL, 4, ID2P(LANG_SET_BOOL_NO), ID2P(LANG_SET_BOOL_YES), - ID2P(LANG_BOOKMARK_SETTINGS_UNIQUE_ONLY)), + ID2P(LANG_BOOKMARK_SETTINGS_ONE_PER_PLAYLIST), + ID2P(LANG_BOOKMARK_SETTINGS_ONE_PER_TRACK)), #ifdef HAVE_LCD_BITMAP /* peak meter */ STRINGCHOICE_SETTING(0, peak_meter_clip_hold, LANG_PM_CLIP_HOLD, 16, diff --git a/manual/appendix/config_file_options.tex b/manual/appendix/config_file_options.tex index f3db4e5b96..ddd41e105d 100644 --- a/manual/appendix/config_file_options.tex +++ b/manual/appendix/config_file_options.tex @@ -126,7 +126,7 @@ autoload bookmarks & off, on & N/A\\ use most-recent-bookmarks - & off, on & N/A\\ + & off, on, unique only, one per track & N/A\\ pause on headphone unplug & off, pause, pause and resume & N/A\\ rewind duration on pause & 0 to 15 & s\\ disable autoresume if phones not present & off, on & N/A\\ diff --git a/manual/configure_rockbox/bookmarking.tex b/manual/configure_rockbox/bookmarking.tex index 68dad4b33c..8147715ace 100644 --- a/manual/configure_rockbox/bookmarking.tex +++ b/manual/configure_rockbox/bookmarking.tex @@ -81,10 +81,15 @@ \item[Yes] Keep a list of recently used bookmarks. Each new bookmark is added to the list of recent bookmarks. - \item[Unique Only] + \item[One per playlist] Add each new bookmark to the list of recently used bookmarks, but only keep one bookmark from the current directory or playlist; any - previous entries are removed. + previous entries for the playlist are removed. + \item[One per track] + Add each new bookmark to the list of recently used bookmarks, but + only keep one bookmark from the current directory or playlist and + the current track; any previous entries for the track within the + playlist are removed. \end{description} \end{description}