summaryrefslogtreecommitdiffstats
path: root/apps/bookmark.c
diff options
context:
space:
mode:
authorSolomon Peachy <pizza@shaftnet.org>2018-10-30 09:43:32 -0400
committerSolomon Peachy <pizza@shaftnet.org>2018-12-14 14:03:12 +0100
commitbea9cf7b1ee2eb87f1067e1cfafa3c627a982cf5 (patch)
treecaa6f67f608c86ba9a667218a0a2872f0b3156e3 /apps/bookmark.c
parent6f020ef155de094fd2cdf30ed8258e7fed07a2e8 (diff)
downloadrockbox-bea9cf7b1ee2eb87f1067e1cfafa3c627a982cf5.tar.gz
rockbox-bea9cf7b1ee2eb87f1067e1cfafa3c627a982cf5.tar.bz2
rockbox-bea9cf7b1ee2eb87f1067e1cfafa3c627a982cf5.zip
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
Diffstat (limited to 'apps/bookmark.c')
-rw-r--r--apps/bookmark.c61
1 files changed, 46 insertions, 15 deletions
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,