FS11473: Add bookmarking option: one per track.

Modified version from ticket, taken from Igor Poretsky's tree, and
further modified to incorporate feedback.

Change-Id: I9284497d53a0247a51739d29fdc1db5fbbebfadc
This commit is contained in:
Solomon Peachy 2018-10-30 09:43:32 -04:00
parent 6f020ef155
commit bea9cf7b1e
6 changed files with 108 additions and 30 deletions

View File

@ -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,

View File

@ -4737,16 +4737,16 @@
</phrase>
<phrase>
id: LANG_BOOKMARK_SETTINGS_UNIQUE_ONLY
desc: Save only on bookmark for each playlist in recent bookmarks
desc: deprecated
user: core
<source>
*: "Unique only"
*: ""
</source>
<dest>
*: "Unique only"
*: ""
</dest>
<voice>
*: "Unique only"
*: ""
</voice>
</phrase>
<phrase>
@ -13689,3 +13689,31 @@
*: "gibibyte"
</voice>
</phrase>
<phrase>
id: LANG_BOOKMARK_SETTINGS_ONE_PER_PLAYLIST
desc: Save only one bookmark for a playlist in recent bookmarks
user: core
<source>
*: "One per playlist"
</source>
<dest>
*: "One per playlist"
</dest>
<voice>
*: "One per playlist"
</voice>
</phrase>
<phrase>
id: LANG_BOOKMARK_SETTINGS_ONE_PER_TRACK
desc: Save only one bookmark for a combination (playlist,track) in recent bookmarks
user: core
<source>
*: "One per track"
</source>
<dest>
*: "One per track"
</dest>
<voice>
*: "One per track"
</voice>
</phrase>

View File

@ -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 */

View File

@ -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,

View File

@ -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\\

View File

@ -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}