1
0
Fork 0
forked from len0rd/rockbox

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; 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. */ /* This function adds a bookmark to a file. */
/* Returns true on successful bookmark add. */ /* 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 temp_bookmark_file = 0;
int bookmark_file = 0; int bookmark_file = 0;
int bookmark_count = 0; int bookmark_count = 0;
char* playlist = NULL; char *pl_start = NULL, *bm_pl_start;
char* cp; char *pl_end = NULL, *bm_pl_end;
char* tmp; int pl_len = 0, bm_pl_len;
int len = 0; char *track = NULL, *bm_track;
bool unique = false; bool comp_playlist = false;
bool comp_track = false;
bool equal;
/* Opening up a temp bookmark file */ /* Opening up a temp bookmark file */
snprintf(global_temp_buffer, sizeof(global_temp_buffer), 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) if (temp_bookmark_file < 0)
return false; /* can't open the temp file */ 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,'/'); if (get_playlist_and_track(bookmark, &pl_start, &pl_end, &track))
cp = strrchr(bookmark,';'); {
len = cp - playlist; comp_playlist = true;
unique = 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 */ /* Writing the new bookmark to the begining of the temp file */
@ -320,10 +339,22 @@ static bool add_bookmark(const char* bookmark_file_name, const char* bookmark,
if (most_recent && (bookmark_count >= MAX_BOOKMARKS)) if (most_recent && (bookmark_count >= MAX_BOOKMARKS))
break; break;
cp = strchr(global_read_buffer,'/'); if (!parse_bookmark(global_read_buffer, false))
tmp = strrchr(global_read_buffer,';'); break;
if (parse_bookmark(global_read_buffer, false) &&
(!unique || len != tmp -cp || strncmp(playlist,cp,len))) 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++; bookmark_count++;
write(temp_bookmark_file, global_read_buffer, write(temp_bookmark_file, global_read_buffer,

View file

@ -4737,16 +4737,16 @@
</phrase> </phrase>
<phrase> <phrase>
id: LANG_BOOKMARK_SETTINGS_UNIQUE_ONLY id: LANG_BOOKMARK_SETTINGS_UNIQUE_ONLY
desc: Save only on bookmark for each playlist in recent bookmarks desc: deprecated
user: core user: core
<source> <source>
*: "Unique only" *: ""
</source> </source>
<dest> <dest>
*: "Unique only" *: ""
</dest> </dest>
<voice> <voice>
*: "Unique only" *: ""
</voice> </voice>
</phrase> </phrase>
<phrase> <phrase>
@ -13689,3 +13689,31 @@
*: "gibibyte" *: "gibibyte"
</voice> </voice>
</phrase> </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_FILENAME 32
#define MAX_PATHNAME 80 #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 { enum {
BOOKMARK_NO = 0, BOOKMARK_NO = 0,
BOOKMARK_YES, BOOKMARK_YES = 1,
BOOKMARK_ASK, };
BOOKMARK_UNIQUE_ONLY = 2,
BOOKMARK_RECENT_ONLY_YES, /* Auto create bookmark */
BOOKMARK_RECENT_ONLY_ASK, 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 enum
@ -557,7 +569,8 @@ struct user_settings
int autoloadbookmark; /* auto load option: 0=off, 1=ask, 2=on */ int autoloadbookmark; /* auto load option: 0=off, 1=ask, 2=on */
int autocreatebookmark; /* auto create option: 0=off, 1=ask, 2=on */ int autocreatebookmark; /* auto create option: 0=off, 1=ask, 2=on */
bool autoupdatebookmark;/* auto update option */ 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 #ifdef HAVE_DIRCACHE
bool dircache; /* enable directory cache */ bool dircache; /* enable directory cache */

View file

@ -1246,9 +1246,10 @@ const struct settings_list settings[] = {
ID2P(LANG_ASK)), ID2P(LANG_ASK)),
CHOICE_SETTING(0, usemrb, LANG_BOOKMARK_SETTINGS_MAINTAIN_RECENT_BOOKMARKS, CHOICE_SETTING(0, usemrb, LANG_BOOKMARK_SETTINGS_MAINTAIN_RECENT_BOOKMARKS,
BOOKMARK_NO, "use most-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_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 #ifdef HAVE_LCD_BITMAP
/* peak meter */ /* peak meter */
STRINGCHOICE_SETTING(0, peak_meter_clip_hold, LANG_PM_CLIP_HOLD, 16, STRINGCHOICE_SETTING(0, peak_meter_clip_hold, LANG_PM_CLIP_HOLD, 16,

View file

@ -126,7 +126,7 @@
autoload bookmarks autoload bookmarks
& off, on & N/A\\ & off, on & N/A\\
use most-recent-bookmarks 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\\ pause on headphone unplug & off, pause, pause and resume & N/A\\
rewind duration on pause & 0 to 15 & s\\ rewind duration on pause & 0 to 15 & s\\
disable autoresume if phones not present & off, on & N/A\\ disable autoresume if phones not present & off, on & N/A\\

View file

@ -81,10 +81,15 @@
\item[Yes] \item[Yes]
Keep a list of recently used bookmarks. Each new bookmark is added Keep a list of recently used bookmarks. Each new bookmark is added
to the list of recent bookmarks. 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 Add each new bookmark to the list of recently used bookmarks, but
only keep one bookmark from the current directory or playlist; any 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}
\end{description} \end{description}