summaryrefslogtreecommitdiff
path: root/apps/bookmark.c
diff options
context:
space:
mode:
Diffstat (limited to 'apps/bookmark.c')
-rw-r--r--apps/bookmark.c86
1 files changed, 43 insertions, 43 deletions
diff --git a/apps/bookmark.c b/apps/bookmark.c
index dece69dce6..70dbd8075d 100644
--- a/apps/bookmark.c
+++ b/apps/bookmark.c
@@ -75,10 +75,10 @@ static struct {
75 bool shuffle; 75 bool shuffle;
76 /* optional values */ 76 /* optional values */
77 int pitch; 77 int pitch;
78 int speed; 78 int speed;
79} bm; 79} bm;
80 80
81static bool add_bookmark(const char* bookmark_file_name, const char* bookmark, 81static bool add_bookmark(const char* bookmark_file_name, const char* bookmark,
82 bool most_recent); 82 bool most_recent);
83static char* create_bookmark(void); 83static char* create_bookmark(void);
84static bool delete_bookmark(const char* bookmark_file_name, int bookmark_id); 84static bool delete_bookmark(const char* bookmark_file_name, int bookmark_id);
@@ -275,7 +275,7 @@ static bool get_playlist_and_track(const char *bookmark, char **pl_start,
275/* This function adds a bookmark to a file. */ 275/* This function adds a bookmark to a file. */
276/* Returns true on successful bookmark add. */ 276/* Returns true on successful bookmark add. */
277/* ------------------------------------------------------------------------*/ 277/* ------------------------------------------------------------------------*/
278static bool add_bookmark(const char* bookmark_file_name, const char* bookmark, 278static bool add_bookmark(const char* bookmark_file_name, const char* bookmark,
279 bool most_recent) 279 bool most_recent)
280{ 280{
281 int temp_bookmark_file = 0; 281 int temp_bookmark_file = 0;
@@ -466,7 +466,7 @@ bool bookmark_autoload(const char* file)
466 else 466 else
467 { 467 {
468 int ret = select_bookmark(global_bookmark_file_name, true, &bookmark); 468 int ret = select_bookmark(global_bookmark_file_name, true, &bookmark);
469 469
470 if (bookmark != NULL) 470 if (bookmark != NULL)
471 { 471 {
472 if (!play_bookmark(bookmark)) 472 if (!play_bookmark(bookmark))
@@ -475,7 +475,7 @@ bool bookmark_autoload(const char* file)
475 splash(HZ*2, ID2P(LANG_NOTHING_TO_RESUME)); 475 splash(HZ*2, ID2P(LANG_NOTHING_TO_RESUME));
476 } 476 }
477 477
478 /* Act as if autoload was done even if it failed, since the 478 /* Act as if autoload was done even if it failed, since the
479 * user did make an active selection. 479 * user did make an active selection.
480 */ 480 */
481 return true; 481 return true;
@@ -520,7 +520,7 @@ bool bookmark_load(const char* file, bool autoload)
520 { 520 {
521 splash(HZ*2, ID2P(LANG_NOTHING_TO_RESUME)); 521 splash(HZ*2, ID2P(LANG_NOTHING_TO_RESUME));
522 } 522 }
523 523
524 return false; 524 return false;
525 } 525 }
526 } 526 }
@@ -541,7 +541,7 @@ static int get_bookmark_count(const char* bookmark_file_name)
541 { 541 {
542 read_count++; 542 read_count++;
543 } 543 }
544 544
545 close(file); 545 close(file);
546 return read_count; 546 return read_count;
547} 547}
@@ -563,25 +563,25 @@ static int buffer_bookmarks(struct bookmark_list* bookmarks, int first_line)
563 /* Entire file fits in buffer */ 563 /* Entire file fits in buffer */
564 first_line = 0; 564 first_line = 0;
565 } 565 }
566 566
567 bookmarks->start = first_line; 567 bookmarks->start = first_line;
568 bookmarks->count = 0; 568 bookmarks->count = 0;
569 bookmarks->reload = false; 569 bookmarks->reload = false;
570 570
571 while(read_line(file, global_read_buffer, sizeof(global_read_buffer)) > 0) 571 while(read_line(file, global_read_buffer, sizeof(global_read_buffer)) > 0)
572 { 572 {
573 read_count++; 573 read_count++;
574 574
575 if (read_count >= first_line) 575 if (read_count >= first_line)
576 { 576 {
577 dest -= strlen(global_read_buffer) + 1; 577 dest -= strlen(global_read_buffer) + 1;
578 578
579 if (dest < ((char*) bookmarks) + sizeof(*bookmarks) 579 if (dest < ((char*) bookmarks) + sizeof(*bookmarks)
580 + (sizeof(char*) * (bookmarks->count + 1))) 580 + (sizeof(char*) * (bookmarks->count + 1)))
581 { 581 {
582 break; 582 break;
583 } 583 }
584 584
585 strcpy(dest, global_read_buffer); 585 strcpy(dest, global_read_buffer);
586 bookmarks->items[bookmarks->count] = dest; 586 bookmarks->items[bookmarks->count] = dest;
587 bookmarks->count++; 587 bookmarks->count++;
@@ -604,22 +604,22 @@ static const char* get_bookmark_info(int list_index,
604 { 604 {
605 if (index == 0) 605 if (index == 0)
606 { 606 {
607 return list_index % 2 == 0 607 return list_index % 2 == 0
608 ? (char*) str(LANG_BOOKMARK_DONT_RESUME) : " "; 608 ? (char*) str(LANG_BOOKMARK_DONT_RESUME) : " ";
609 } 609 }
610 610
611 index--; 611 index--;
612 } 612 }
613 613
614 if (bookmarks->reload || (index >= bookmarks->start + bookmarks->count) 614 if (bookmarks->reload || (index >= bookmarks->start + bookmarks->count)
615 || (index < bookmarks->start)) 615 || (index < bookmarks->start))
616 { 616 {
617 int read_index = index; 617 int read_index = index;
618 618
619 /* Using count as a guide on how far to move could possibly fail 619 /* Using count as a guide on how far to move could possibly fail
620 * sometimes. Use byte count if that is a problem? 620 * sometimes. Use byte count if that is a problem?
621 */ 621 */
622 622
623 if (read_index != 0) 623 if (read_index != 0)
624 { 624 {
625 /* Move count * 3 / 4 items in the direction the user is moving, 625 /* Move count * 3 / 4 items in the direction the user is moving,
@@ -627,31 +627,31 @@ static const char* get_bookmark_info(int list_index,
627 */ 627 */
628 int offset = bookmarks->count; 628 int offset = bookmarks->count;
629 int max = bookmarks->total_count - (bookmarks->count / 2); 629 int max = bookmarks->total_count - (bookmarks->count / 2);
630 630
631 if (read_index < bookmarks->start) 631 if (read_index < bookmarks->start)
632 { 632 {
633 offset *= 3; 633 offset *= 3;
634 } 634 }
635 635
636 read_index = index - offset / 4; 636 read_index = index - offset / 4;
637 637
638 if (read_index > max) 638 if (read_index > max)
639 { 639 {
640 read_index = max; 640 read_index = max;
641 } 641 }
642 642
643 if (read_index < 0) 643 if (read_index < 0)
644 { 644 {
645 read_index = 0; 645 read_index = 0;
646 } 646 }
647 } 647 }
648 648
649 if (buffer_bookmarks(bookmarks, read_index) <= index) 649 if (buffer_bookmarks(bookmarks, read_index) <= index)
650 { 650 {
651 return ""; 651 return "";
652 } 652 }
653 } 653 }
654 654
655 if (!parse_bookmark(bookmarks->items[index - bookmarks->start], true, true)) 655 if (!parse_bookmark(bookmarks->items[index - bookmarks->start], true, true))
656 { 656 {
657 return list_index % 2 == 0 ? (char*) str(LANG_BOOKMARK_INVALID) : " "; 657 return list_index % 2 == 0 ? (char*) str(LANG_BOOKMARK_INVALID) : " ";
@@ -662,12 +662,12 @@ static const char* get_bookmark_info(int list_index,
662 char *name; 662 char *name;
663 char *format; 663 char *format;
664 int len = strlen(global_temp_buffer); 664 int len = strlen(global_temp_buffer);
665 665
666 if (bookmarks->show_playlist_name && len > 0) 666 if (bookmarks->show_playlist_name && len > 0)
667 { 667 {
668 name = global_temp_buffer; 668 name = global_temp_buffer;
669 len--; 669 len--;
670 670
671 if (name[len] != '/') 671 if (name[len] != '/')
672 { 672 {
673 strrsplt(name, '.'); 673 strrsplt(name, '.');
@@ -689,7 +689,7 @@ static const char* get_bookmark_info(int list_index,
689 name = global_filename; 689 name = global_filename;
690 format = "%s"; 690 format = "%s";
691 } 691 }
692 692
693 strrsplt(global_filename, '.'); 693 strrsplt(global_filename, '.');
694 snprintf(buffer, buffer_len, format, name, global_filename); 694 snprintf(buffer, buffer_len, format, name, global_filename);
695 return buffer; 695 return buffer;
@@ -751,12 +751,12 @@ static int select_bookmark(const char* bookmark_file_name, bool show_dont_resume
751 gui_synclist_init(&list, &get_bookmark_info, (void*) bookmarks, false, 2, NULL); 751 gui_synclist_init(&list, &get_bookmark_info, (void*) bookmarks, false, 2, NULL);
752 if(global_settings.talk_menu) 752 if(global_settings.talk_menu)
753 gui_synclist_set_voice_callback(&list, bookmark_list_voice_cb); 753 gui_synclist_set_voice_callback(&list, bookmark_list_voice_cb);
754 gui_synclist_set_title(&list, str(LANG_BOOKMARK_SELECT_BOOKMARK), 754 gui_synclist_set_title(&list, str(LANG_BOOKMARK_SELECT_BOOKMARK),
755 Icon_Bookmark); 755 Icon_Bookmark);
756 756
757 while (!exit) 757 while (!exit)
758 { 758 {
759 759
760 if (refresh) 760 if (refresh)
761 { 761 {
762 int count = get_bookmark_count(bookmark_file_name); 762 int count = get_bookmark_count(bookmark_file_name);
@@ -805,17 +805,17 @@ static int select_bookmark(const char* bookmark_file_name, bool show_dont_resume
805 if (action == ACTION_STD_CONTEXT) 805 if (action == ACTION_STD_CONTEXT)
806 { 806 {
807 MENUITEM_STRINGLIST(menu_items, ID2P(LANG_BOOKMARK_CONTEXT_MENU), 807 MENUITEM_STRINGLIST(menu_items, ID2P(LANG_BOOKMARK_CONTEXT_MENU),
808 NULL, ID2P(LANG_BOOKMARK_CONTEXT_RESUME), 808 NULL, ID2P(LANG_BOOKMARK_CONTEXT_RESUME),
809 ID2P(LANG_BOOKMARK_CONTEXT_DELETE)); 809 ID2P(LANG_BOOKMARK_CONTEXT_DELETE));
810 static const int menu_actions[] = 810 static const int menu_actions[] =
811 { 811 {
812 ACTION_STD_OK, ACTION_BMS_DELETE 812 ACTION_STD_OK, ACTION_BMS_DELETE
813 }; 813 };
814 int selection = do_menu(&menu_items, NULL, NULL, false); 814 int selection = do_menu(&menu_items, NULL, NULL, false);
815 815
816 refresh = true; 816 refresh = true;
817 817
818 if (selection >= 0 && selection <= 818 if (selection >= 0 && selection <=
819 (int) (sizeof(menu_actions) / sizeof(menu_actions[0]))) 819 (int) (sizeof(menu_actions) / sizeof(menu_actions[0])))
820 { 820 {
821 action = menu_actions[selection]; 821 action = menu_actions[selection];
@@ -842,7 +842,7 @@ static int select_bookmark(const char* bookmark_file_name, bool show_dont_resume
842 842
843 case ACTION_BMS_DELETE: 843 case ACTION_BMS_DELETE:
844 if (item >= 0) 844 if (item >= 0)
845 { 845 {
846 const char *lines[]={ 846 const char *lines[]={
847 ID2P(LANG_REALLY_DELETE) 847 ID2P(LANG_REALLY_DELETE)
848 }; 848 };
@@ -854,7 +854,7 @@ static int select_bookmark(const char* bookmark_file_name, bool show_dont_resume
854 const struct text_message yes_message={yes_lines, 1}; 854 const struct text_message yes_message={yes_lines, 1};
855 855
856 if(gui_syncyesno_run(&message, &yes_message, NULL)==YESNO_YES) 856 if(gui_syncyesno_run(&message, &yes_message, NULL)==YESNO_YES)
857 { 857 {
858 delete_bookmark(bookmark_file_name, item); 858 delete_bookmark(bookmark_file_name, item);
859 bookmarks->reload = true; 859 bookmarks->reload = true;
860 } 860 }
@@ -1002,12 +1002,12 @@ static const char* skip_token(const char* s)
1002 { 1002 {
1003 s++; 1003 s++;
1004 } 1004 }
1005 1005
1006 if (*s) 1006 if (*s)
1007 { 1007 {
1008 s++; 1008 s++;
1009 } 1009 }
1010 1010
1011 return s; 1011 return s;
1012} 1012}
1013 1013
@@ -1033,11 +1033,11 @@ static bool parse_bookmark(const char *bookmark, const bool parse_filenames, con
1033{ 1033{
1034 const char* s = bookmark; 1034 const char* s = bookmark;
1035 const char* end; 1035 const char* end;
1036 1036
1037#define GET_INT_TOKEN(var) s = int_token(s, &var) 1037#define GET_INT_TOKEN(var) s = int_token(s, &var)
1038#define GET_LONG_TOKEN(var) s = long_token(s, &var) 1038#define GET_LONG_TOKEN(var) s = long_token(s, &var)
1039#define GET_BOOL_TOKEN(var) var = (atoi(s)!=0); s = skip_token(s) 1039#define GET_BOOL_TOKEN(var) var = (atoi(s)!=0); s = skip_token(s)
1040 1040
1041 /* if new format bookmark, extract the optional content flags, 1041 /* if new format bookmark, extract the optional content flags,
1042 otherwise treat as an original format bookmark */ 1042 otherwise treat as an original format bookmark */
1043 int opt_flags = 0; 1043 int opt_flags = 0;
@@ -1047,7 +1047,7 @@ static bool parse_bookmark(const char *bookmark, const bool parse_filenames, con
1047 s++; 1047 s++;
1048 GET_INT_TOKEN(opt_flags); 1048 GET_INT_TOKEN(opt_flags);
1049 } 1049 }
1050 1050
1051 /* extract all original bookmark tokens */ 1051 /* extract all original bookmark tokens */
1052 GET_INT_TOKEN(bm.resume_index); 1052 GET_INT_TOKEN(bm.resume_index);
1053 GET_LONG_TOKEN(bm.resume_offset); 1053 GET_LONG_TOKEN(bm.resume_offset);
@@ -1057,18 +1057,18 @@ static bool parse_bookmark(const char *bookmark, const bool parse_filenames, con
1057 GET_LONG_TOKEN(bm.resume_time); 1057 GET_LONG_TOKEN(bm.resume_time);
1058 GET_INT_TOKEN(bm.repeat_mode); 1058 GET_INT_TOKEN(bm.repeat_mode);
1059 GET_BOOL_TOKEN(bm.shuffle); 1059 GET_BOOL_TOKEN(bm.shuffle);
1060 1060
1061 /* extract all optional bookmark tokens */ 1061 /* extract all optional bookmark tokens */
1062 if (opt_flags & BM_PITCH) 1062 if (opt_flags & BM_PITCH)
1063 GET_INT_TOKEN(bm.pitch); 1063 GET_INT_TOKEN(bm.pitch);
1064 if (opt_flags & BM_SPEED) 1064 if (opt_flags & BM_SPEED)
1065 GET_INT_TOKEN(bm.speed); 1065 GET_INT_TOKEN(bm.speed);
1066 1066
1067 if (*s == 0) 1067 if (*s == 0)
1068 { 1068 {
1069 return false; 1069 return false;
1070 } 1070 }
1071 1071
1072 end = strchr(s, ';'); 1072 end = strchr(s, ';');
1073 1073
1074 /* extract file names */ 1074 /* extract file names */
@@ -1077,7 +1077,7 @@ static bool parse_bookmark(const char *bookmark, const bool parse_filenames, con
1077 size_t len = (end == NULL) ? strlen(s) : (size_t) (end - s); 1077 size_t len = (end == NULL) ? strlen(s) : (size_t) (end - s);
1078 len = MIN(TEMP_BUF_SIZE - 1, len); 1078 len = MIN(TEMP_BUF_SIZE - 1, len);
1079 strlcpy(global_temp_buffer, s, len + 1); 1079 strlcpy(global_temp_buffer, s, len + 1);
1080 1080
1081 if (end != NULL) 1081 if (end != NULL)
1082 { 1082 {
1083 end++; 1083 end++;
@@ -1093,7 +1093,7 @@ static bool parse_bookmark(const char *bookmark, const bool parse_filenames, con
1093 strlcpy(global_filename, end, MAX_PATH); 1093 strlcpy(global_filename, end, MAX_PATH);
1094 } 1094 }
1095 } 1095 }
1096 1096
1097 return true; 1097 return true;
1098} 1098}
1099 1099