diff options
author | Solomon Peachy <pizza@shaftnet.org> | 2018-10-30 09:43:32 -0400 |
---|---|---|
committer | Solomon Peachy <pizza@shaftnet.org> | 2018-12-14 14:03:12 +0100 |
commit | bea9cf7b1ee2eb87f1067e1cfafa3c627a982cf5 (patch) | |
tree | caa6f67f608c86ba9a667218a0a2872f0b3156e3 /apps/bookmark.c | |
parent | 6f020ef155de094fd2cdf30ed8258e7fed07a2e8 (diff) | |
download | rockbox-bea9cf7b1ee2eb87f1067e1cfafa3c627a982cf5.tar.gz 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.c | 61 |
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) | |||
271 | return ret; | 271 | return ret; |
272 | } | 272 | } |
273 | 273 | ||
274 | /* Get the name of the playlist and the name of the track from a bookmark. */ | ||
275 | /* Returns true iff both were extracted. */ | ||
276 | static bool get_playlist_and_track(const char *bookmark, char **pl_start, | ||
277 | char **pl_end, char **track) | ||
278 | { | ||
279 | *pl_start = strchr(bookmark,'/'); | ||
280 | if (!(*pl_start)) | ||
281 | return false; | ||
282 | *pl_end = strrchr(bookmark,';'); | ||
283 | *track = *pl_end + 1; | ||
284 | return true; | ||
285 | } | ||
286 | |||
274 | /* ----------------------------------------------------------------------- */ | 287 | /* ----------------------------------------------------------------------- */ |
275 | /* This function adds a bookmark to a file. */ | 288 | /* This function adds a bookmark to a file. */ |
276 | /* Returns true on successful bookmark add. */ | 289 | /* Returns true on successful bookmark add. */ |
@@ -281,11 +294,13 @@ static bool add_bookmark(const char* bookmark_file_name, const char* bookmark, | |||
281 | int temp_bookmark_file = 0; | 294 | int temp_bookmark_file = 0; |
282 | int bookmark_file = 0; | 295 | int bookmark_file = 0; |
283 | int bookmark_count = 0; | 296 | int bookmark_count = 0; |
284 | char* playlist = NULL; | 297 | char *pl_start = NULL, *bm_pl_start; |
285 | char* cp; | 298 | char *pl_end = NULL, *bm_pl_end; |
286 | char* tmp; | 299 | int pl_len = 0, bm_pl_len; |
287 | int len = 0; | 300 | char *track = NULL, *bm_track; |
288 | bool unique = false; | 301 | bool comp_playlist = false; |
302 | bool comp_track = false; | ||
303 | bool equal; | ||
289 | 304 | ||
290 | /* Opening up a temp bookmark file */ | 305 | /* Opening up a temp bookmark file */ |
291 | snprintf(global_temp_buffer, sizeof(global_temp_buffer), | 306 | snprintf(global_temp_buffer, sizeof(global_temp_buffer), |
@@ -295,12 +310,16 @@ static bool add_bookmark(const char* bookmark_file_name, const char* bookmark, | |||
295 | if (temp_bookmark_file < 0) | 310 | if (temp_bookmark_file < 0) |
296 | return false; /* can't open the temp file */ | 311 | return false; /* can't open the temp file */ |
297 | 312 | ||
298 | if (most_recent && (global_settings.usemrb == BOOKMARK_UNIQUE_ONLY)) | 313 | if (most_recent && ((global_settings.usemrb == BOOKMARK_ONE_PER_PLAYLIST) |
314 | || (global_settings.usemrb == BOOKMARK_ONE_PER_TRACK))) | ||
299 | { | 315 | { |
300 | playlist = strchr(bookmark,'/'); | 316 | if (get_playlist_and_track(bookmark, &pl_start, &pl_end, &track)) |
301 | cp = strrchr(bookmark,';'); | 317 | { |
302 | len = cp - playlist; | 318 | comp_playlist = true; |
303 | unique = true; | 319 | pl_len = pl_end - pl_start; |
320 | if (global_settings.usemrb == BOOKMARK_ONE_PER_TRACK) | ||
321 | comp_track = true; | ||
322 | } | ||
304 | } | 323 | } |
305 | 324 | ||
306 | /* Writing the new bookmark to the begining of the temp file */ | 325 | /* 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, | |||
319 | /* This keeps it from getting too large */ | 338 | /* This keeps it from getting too large */ |
320 | if (most_recent && (bookmark_count >= MAX_BOOKMARKS)) | 339 | if (most_recent && (bookmark_count >= MAX_BOOKMARKS)) |
321 | break; | 340 | break; |
322 | 341 | ||
323 | cp = strchr(global_read_buffer,'/'); | 342 | if (!parse_bookmark(global_read_buffer, false)) |
324 | tmp = strrchr(global_read_buffer,';'); | 343 | break; |
325 | if (parse_bookmark(global_read_buffer, false) && | 344 | |
326 | (!unique || len != tmp -cp || strncmp(playlist,cp,len))) | 345 | equal = false; |
346 | if (comp_playlist) | ||
347 | { | ||
348 | if (get_playlist_and_track(global_read_buffer, &bm_pl_start, | ||
349 | &bm_pl_end, &bm_track)) | ||
350 | { | ||
351 | bm_pl_len = bm_pl_end - bm_pl_start; | ||
352 | equal = (pl_len == bm_pl_len) && !strncmp(pl_start, bm_pl_start, pl_len); | ||
353 | if (equal && comp_track) | ||
354 | equal = !strcmp(track, bm_track); | ||
355 | } | ||
356 | } | ||
357 | if (!equal) | ||
327 | { | 358 | { |
328 | bookmark_count++; | 359 | bookmark_count++; |
329 | write(temp_bookmark_file, global_read_buffer, | 360 | write(temp_bookmark_file, global_read_buffer, |