diff options
Diffstat (limited to 'apps')
-rw-r--r-- | apps/bookmark.c | 205 |
1 files changed, 84 insertions, 121 deletions
diff --git a/apps/bookmark.c b/apps/bookmark.c index dd800f75c0..d0cecf0b7a 100644 --- a/apps/bookmark.c +++ b/apps/bookmark.c | |||
@@ -61,31 +61,38 @@ struct bookmark_list | |||
61 | char* items[]; | 61 | char* items[]; |
62 | }; | 62 | }; |
63 | 63 | ||
64 | /* bookmark flags */ | ||
65 | #define F_BMFILES 0x001 | ||
66 | #define F_RES_IND 0x002 | ||
67 | #define F_RES_OFF 0x004 | ||
68 | #define F_RES_SED 0x008 | ||
69 | #define F_RES_1ST 0x010 | ||
70 | #define F_RES_TIM 0x020 | ||
71 | #define F_REP_MOD 0x040 | ||
72 | #define F_SHUFFLE 0x080 | ||
73 | |||
74 | static struct bookmark_values | ||
75 | { | ||
76 | int resume_index; | ||
77 | int resume_offset; | ||
78 | int resume_seed; | ||
79 | int resume_first_index; /* ?? */ | ||
80 | long resume_time; | ||
81 | int repeat_mode; | ||
82 | bool shuffle; | ||
83 | } bm; | ||
84 | |||
85 | #define CHECK_BOOKMARK(bookmark) parse_bookmark(bookmark, 0) | ||
64 | static bool add_bookmark(const char* bookmark_file_name, const char* bookmark, | 86 | static bool add_bookmark(const char* bookmark_file_name, const char* bookmark, |
65 | bool most_recent); | 87 | bool most_recent); |
66 | static bool check_bookmark(const char* bookmark); | ||
67 | static char* create_bookmark(void); | 88 | static char* create_bookmark(void); |
68 | static bool delete_bookmark(const char* bookmark_file_name, int bookmark_id); | 89 | static bool delete_bookmark(const char* bookmark_file_name, int bookmark_id); |
69 | static void say_bookmark(const char* bookmark, | 90 | static void say_bookmark(const char* bookmark, |
70 | int bookmark_id, bool show_playlist_name); | 91 | int bookmark_id, bool show_playlist_name); |
71 | static bool play_bookmark(const char* bookmark); | 92 | static bool play_bookmark(const char* bookmark); |
72 | static bool generate_bookmark_file_name(const char *in); | 93 | static bool generate_bookmark_file_name(const char *in); |
73 | static const char* skip_token(const char* s); | 94 | static bool parse_bookmark(const char *bookmark, const int flags); |
74 | static const char* int_token(const char* s, int* dest); | 95 | static int buffer_bookmarks(struct bookmark_list* bookmarks, int first_line); |
75 | static const char* long_token(const char* s, long* dest); | ||
76 | static const char* bool_token(const char* s, bool* dest); | ||
77 | static bool parse_bookmark(const char *bookmark, | ||
78 | int *resume_index, | ||
79 | int *resume_offset, | ||
80 | int *resume_seed, | ||
81 | int *resume_first_index, | ||
82 | char* resume_file, | ||
83 | unsigned int resume_file_size, | ||
84 | long* ms, | ||
85 | int * repeat_mode, | ||
86 | bool *shuffle, | ||
87 | char* file_name); | ||
88 | static int buffer_bookmarks(struct bookmark_list* bookmarks, int first_line); | ||
89 | static const char* get_bookmark_info(int list_index, | 96 | static const char* get_bookmark_info(int list_index, |
90 | void* data, | 97 | void* data, |
91 | char *buffer, | 98 | char *buffer, |
@@ -95,7 +102,8 @@ static bool system_check(void); | |||
95 | static bool write_bookmark(bool create_bookmark_file, const char *bookmark); | 102 | static bool write_bookmark(bool create_bookmark_file, const char *bookmark); |
96 | static int get_bookmark_count(const char* bookmark_file_name); | 103 | static int get_bookmark_count(const char* bookmark_file_name); |
97 | 104 | ||
98 | static char global_temp_buffer[MAX_PATH+1]; | 105 | #define TEMP_BUF_SIZE (MAX_PATH + 1) |
106 | static char global_temp_buffer[TEMP_BUF_SIZE]; | ||
99 | /* File name created by generate_bookmark_file_name */ | 107 | /* File name created by generate_bookmark_file_name */ |
100 | static char global_bookmark_file_name[MAX_PATH]; | 108 | static char global_bookmark_file_name[MAX_PATH]; |
101 | static char global_read_buffer[MAX_BOOKMARK_SIZE]; | 109 | static char global_read_buffer[MAX_BOOKMARK_SIZE]; |
@@ -286,7 +294,7 @@ static bool add_bookmark(const char* bookmark_file_name, const char* bookmark, | |||
286 | 294 | ||
287 | cp = strchr(global_read_buffer,'/'); | 295 | cp = strchr(global_read_buffer,'/'); |
288 | tmp = strrchr(global_read_buffer,';'); | 296 | tmp = strrchr(global_read_buffer,';'); |
289 | if (check_bookmark(global_read_buffer) && | 297 | if (CHECK_BOOKMARK(global_read_buffer) && |
290 | (!unique || len != tmp -cp || strncmp(playlist,cp,len))) | 298 | (!unique || len != tmp -cp || strncmp(playlist,cp,len))) |
291 | { | 299 | { |
292 | bookmark_count++; | 300 | bookmark_count++; |
@@ -348,20 +356,12 @@ static char* create_bookmark() | |||
348 | file+1); | 356 | file+1); |
349 | 357 | ||
350 | /* checking to see if the bookmark is valid */ | 358 | /* checking to see if the bookmark is valid */ |
351 | if (check_bookmark(global_bookmark)) | 359 | if (CHECK_BOOKMARK(global_bookmark)) |
352 | return global_bookmark; | 360 | return global_bookmark; |
353 | else | 361 | else |
354 | return NULL; | 362 | return NULL; |
355 | } | 363 | } |
356 | 364 | ||
357 | static bool check_bookmark(const char* bookmark) | ||
358 | { | ||
359 | return parse_bookmark(bookmark, | ||
360 | NULL,NULL,NULL, NULL, | ||
361 | NULL,0,NULL,NULL, | ||
362 | NULL, NULL); | ||
363 | } | ||
364 | |||
365 | /* ----------------------------------------------------------------------- */ | 365 | /* ----------------------------------------------------------------------- */ |
366 | /* This function will determine if an autoload is necessary. This is an */ | 366 | /* This function will determine if an autoload is necessary. This is an */ |
367 | /* interface function. */ | 367 | /* interface function. */ |
@@ -519,9 +519,6 @@ static const char* get_bookmark_info(int list_index, | |||
519 | { | 519 | { |
520 | struct bookmark_list* bookmarks = (struct bookmark_list*) data; | 520 | struct bookmark_list* bookmarks = (struct bookmark_list*) data; |
521 | int index = list_index / 2; | 521 | int index = list_index / 2; |
522 | int resume_index = 0; | ||
523 | long resume_time = 0; | ||
524 | bool shuffle = false; | ||
525 | 522 | ||
526 | if (bookmarks->show_dont_resume) | 523 | if (bookmarks->show_dont_resume) |
527 | { | 524 | { |
@@ -575,10 +572,9 @@ static const char* get_bookmark_info(int list_index, | |||
575 | } | 572 | } |
576 | } | 573 | } |
577 | 574 | ||
578 | if (!parse_bookmark(bookmarks->items[index - bookmarks->start], | 575 | const int flags = F_BMFILES | F_RES_IND | F_RES_TIM | F_SHUFFLE; |
579 | &resume_index, NULL, NULL, NULL, global_temp_buffer, | 576 | |
580 | sizeof(global_temp_buffer), &resume_time, NULL, &shuffle, | 577 | if (!parse_bookmark(bookmarks->items[index - bookmarks->start], flags)) |
581 | global_filename)) | ||
582 | { | 578 | { |
583 | return list_index % 2 == 0 ? (char*) str(LANG_BOOKMARK_INVALID) : " "; | 579 | return list_index % 2 == 0 ? (char*) str(LANG_BOOKMARK_INVALID) : " "; |
584 | } | 580 | } |
@@ -624,9 +620,9 @@ static const char* get_bookmark_info(int list_index, | |||
624 | { | 620 | { |
625 | char time_buf[32]; | 621 | char time_buf[32]; |
626 | 622 | ||
627 | format_time(time_buf, sizeof(time_buf), resume_time); | 623 | format_time(time_buf, sizeof(time_buf), bm.resume_time); |
628 | snprintf(buffer, buffer_len, "%s, %d%s", time_buf, resume_index + 1, | 624 | snprintf(buffer, buffer_len, "%s, %d%s", time_buf, bm.resume_index + 1, |
629 | shuffle ? (char*) str(LANG_BOOKMARK_SHUFFLE) : ""); | 625 | bm.shuffle ? (char*) str(LANG_BOOKMARK_SHUFFLE) : ""); |
630 | return buffer; | 626 | return buffer; |
631 | } | 627 | } |
632 | } | 628 | } |
@@ -772,7 +768,6 @@ static char* select_bookmark(const char* bookmark_file_name, bool show_dont_resu | |||
772 | 768 | ||
773 | if(gui_syncyesno_run(&message, &yes_message, NULL)==YESNO_YES) | 769 | if(gui_syncyesno_run(&message, &yes_message, NULL)==YESNO_YES) |
774 | { | 770 | { |
775 | splash(0, str(LANG_DELETING)); | ||
776 | delete_bookmark(bookmark_file_name, item); | 771 | delete_bookmark(bookmark_file_name, item); |
777 | bookmarks->reload = true; | 772 | bookmarks->reload = true; |
778 | } | 773 | } |
@@ -844,15 +839,11 @@ static bool delete_bookmark(const char* bookmark_file_name, int bookmark_id) | |||
844 | static void say_bookmark(const char* bookmark, | 839 | static void say_bookmark(const char* bookmark, |
845 | int bookmark_id, bool show_playlist_name) | 840 | int bookmark_id, bool show_playlist_name) |
846 | { | 841 | { |
847 | int resume_index; | ||
848 | long ms; | ||
849 | bool playlist_shuffle = false; | ||
850 | bool is_dir; | 842 | bool is_dir; |
851 | 843 | ||
852 | if (!parse_bookmark(bookmark, &resume_index, NULL, NULL, NULL, | 844 | const int flags = F_BMFILES | F_RES_IND | F_RES_TIM | F_SHUFFLE; |
853 | global_temp_buffer,sizeof(global_temp_buffer), | 845 | |
854 | &ms, NULL, &playlist_shuffle, | 846 | if (!parse_bookmark(bookmark, flags)) |
855 | global_filename)) | ||
856 | { | 847 | { |
857 | talk_id(LANG_BOOKMARK_INVALID, false); | 848 | talk_id(LANG_BOOKMARK_INVALID, false); |
858 | return; | 849 | return; |
@@ -878,13 +869,13 @@ static void say_bookmark(const char* bookmark, | |||
878 | (void)show_playlist_name; | 869 | (void)show_playlist_name; |
879 | #endif | 870 | #endif |
880 | 871 | ||
881 | if(playlist_shuffle) | 872 | if(bm.shuffle) |
882 | talk_id(LANG_SHUFFLE, true); | 873 | talk_id(LANG_SHUFFLE, true); |
883 | 874 | ||
884 | talk_id(VOICE_BOOKMARK_SELECT_INDEX_TEXT, true); | 875 | talk_id(VOICE_BOOKMARK_SELECT_INDEX_TEXT, true); |
885 | talk_number(resume_index + 1, true); | 876 | talk_number(bm.resume_index + 1, true); |
886 | talk_id(LANG_TIME, true); | 877 | talk_id(LANG_TIME, true); |
887 | talk_value(ms / 1000, UNIT_TIME, true); | 878 | talk_value(bm.resume_time / 1000, UNIT_TIME, true); |
888 | 879 | ||
889 | #if CONFIG_CODEC == SWCODEC | 880 | #if CONFIG_CODEC == SWCODEC |
890 | /* Track filename */ | 881 | /* Track filename */ |
@@ -906,24 +897,15 @@ static void say_bookmark(const char* bookmark, | |||
906 | /* ------------------------------------------------------------------------*/ | 897 | /* ------------------------------------------------------------------------*/ |
907 | static bool play_bookmark(const char* bookmark) | 898 | static bool play_bookmark(const char* bookmark) |
908 | { | 899 | { |
909 | int index; | 900 | const int flags = F_BMFILES | F_RES_IND | F_RES_OFF | F_RES_SED | |
910 | int offset; | 901 | F_REP_MOD | F_SHUFFLE; |
911 | int seed; | 902 | |
912 | 903 | if (parse_bookmark(bookmark, flags)) | |
913 | if (parse_bookmark(bookmark, | ||
914 | &index, | ||
915 | &offset, | ||
916 | &seed, | ||
917 | NULL, | ||
918 | global_temp_buffer, | ||
919 | sizeof(global_temp_buffer), | ||
920 | NULL, | ||
921 | &global_settings.repeat_mode, | ||
922 | &global_settings.playlist_shuffle, | ||
923 | global_filename)) | ||
924 | { | 904 | { |
925 | return bookmark_play(global_temp_buffer, index, offset, seed, | 905 | global_settings.repeat_mode = bm.repeat_mode; |
926 | global_filename); | 906 | global_settings.playlist_shuffle = bm.shuffle; |
907 | return bookmark_play(global_temp_buffer, bm.resume_index, | ||
908 | bm.resume_offset, bm.resume_seed, global_filename); | ||
927 | } | 909 | } |
928 | 910 | ||
929 | return false; | 911 | return false; |
@@ -944,9 +926,9 @@ static const char* skip_token(const char* s) | |||
944 | return s; | 926 | return s; |
945 | } | 927 | } |
946 | 928 | ||
947 | static const char* int_token(const char* s, int* dest) | 929 | static const char* int_token(const char* s, bool parse, int* dest) |
948 | { | 930 | { |
949 | if (dest != NULL) | 931 | if (parse) |
950 | { | 932 | { |
951 | *dest = atoi(s); | 933 | *dest = atoi(s); |
952 | } | 934 | } |
@@ -954,9 +936,9 @@ static const char* int_token(const char* s, int* dest) | |||
954 | return skip_token(s); | 936 | return skip_token(s); |
955 | } | 937 | } |
956 | 938 | ||
957 | static const char* long_token(const char* s, long* dest) | 939 | static const char* long_token(const char* s, bool parse, long* dest) |
958 | { | 940 | { |
959 | if (dest != NULL) | 941 | if (parse) |
960 | { | 942 | { |
961 | *dest = atoi(s); /* Should be atol, but we don't have it. */ | 943 | *dest = atoi(s); /* Should be atol, but we don't have it. */ |
962 | } | 944 | } |
@@ -964,9 +946,9 @@ static const char* long_token(const char* s, long* dest) | |||
964 | return skip_token(s); | 946 | return skip_token(s); |
965 | } | 947 | } |
966 | 948 | ||
967 | static const char* bool_token(const char* s, bool* dest) | 949 | static const char* bool_token(const char* s, bool parse, bool* dest) |
968 | { | 950 | { |
969 | if (dest != NULL) | 951 | if (parse) |
970 | { | 952 | { |
971 | *dest = atoi(s) != 0; | 953 | *dest = atoi(s) != 0; |
972 | } | 954 | } |
@@ -976,30 +958,23 @@ static const char* bool_token(const char* s, bool* dest) | |||
976 | 958 | ||
977 | /* ----------------------------------------------------------------------- */ | 959 | /* ----------------------------------------------------------------------- */ |
978 | /* This function takes a bookmark and parses it. This function also */ | 960 | /* This function takes a bookmark and parses it. This function also */ |
979 | /* validates the bookmark. Passing in NULL for an output variable */ | 961 | /* validates the bookmark. Flags are set to indicate which bookmark */ |
980 | /* indicates that value is not requested. */ | 962 | /* tokens are to be processed. */ |
981 | /* ----------------------------------------------------------------------- */ | 963 | /* ----------------------------------------------------------------------- */ |
982 | static bool parse_bookmark(const char *bookmark, | 964 | static bool parse_bookmark(const char *bookmark, const int flags) |
983 | int *resume_index, | ||
984 | int *resume_offset, | ||
985 | int *resume_seed, | ||
986 | int *resume_first_index, | ||
987 | char* resume_file, | ||
988 | unsigned int resume_file_size, | ||
989 | long* ms, | ||
990 | int * repeat_mode, bool *shuffle, | ||
991 | char* file_name) | ||
992 | { | 965 | { |
993 | const char* s = bookmark; | 966 | const char* s = bookmark; |
994 | const char* end; | 967 | const char* end; |
995 | 968 | ||
996 | s = int_token(s, resume_index); | 969 | #define FLAG(a) (flags & a) |
997 | s = int_token(s, resume_offset); | 970 | |
998 | s = int_token(s, resume_seed); | 971 | s = int_token(s, FLAG(F_RES_IND), &bm.resume_index); |
999 | s = int_token(s, resume_first_index); | 972 | s = int_token(s, FLAG(F_RES_OFF), &bm.resume_offset); |
1000 | s = long_token(s, ms); | 973 | s = int_token(s, FLAG(F_RES_SED), &bm.resume_seed); |
1001 | s = int_token(s, repeat_mode); | 974 | s = int_token(s, FLAG(F_RES_1ST), &bm.resume_first_index); |
1002 | s = bool_token(s, shuffle); | 975 | s = long_token(s, FLAG(F_RES_TIM), &bm.resume_time); |
976 | s = int_token(s, FLAG(F_REP_MOD), &bm.repeat_mode); | ||
977 | s = bool_token(s, FLAG(F_SHUFFLE), &bm.shuffle); | ||
1003 | 978 | ||
1004 | if (*s == 0) | 979 | if (*s == 0) |
1005 | { | 980 | { |
@@ -1008,18 +983,19 @@ static bool parse_bookmark(const char *bookmark, | |||
1008 | 983 | ||
1009 | end = strchr(s, ';'); | 984 | end = strchr(s, ';'); |
1010 | 985 | ||
1011 | if (resume_file != NULL) | 986 | /* extract file names */ |
987 | if (FLAG(F_BMFILES)) | ||
1012 | { | 988 | { |
1013 | size_t len = (end == NULL) ? strlen(s) : (size_t) (end - s); | 989 | size_t len = (end == NULL) ? strlen(s) : (size_t) (end - s); |
1014 | len = MIN(resume_file_size - 1, len); | 990 | len = MIN(TEMP_BUF_SIZE - 1, len); |
1015 | strlcpy(resume_file, s, len + 1); | 991 | strlcpy(global_temp_buffer, s, len + 1); |
1016 | } | 992 | |
1017 | 993 | if (end != NULL) | |
1018 | if (end != NULL && file_name != NULL) | 994 | { |
1019 | { | 995 | end++; |
1020 | end++; | 996 | strlcpy(global_filename, end, MAX_PATH); |
1021 | strlcpy(file_name, end, MAX_PATH); | 997 | } |
1022 | } | 998 | } |
1023 | 999 | ||
1024 | return true; | 1000 | return true; |
1025 | } | 1001 | } |
@@ -1082,33 +1058,20 @@ bool bookmark_exist(void) | |||
1082 | } | 1058 | } |
1083 | 1059 | ||
1084 | /* ----------------------------------------------------------------------- */ | 1060 | /* ----------------------------------------------------------------------- */ |
1085 | /* Checks the current state of the system and returns if it is in a */ | 1061 | /* Checks the current state of the system and returns true if it is in a */ |
1086 | /* bookmarkable state. */ | 1062 | /* bookmarkable state. */ |
1087 | /* ----------------------------------------------------------------------- */ | 1063 | /* ----------------------------------------------------------------------- */ |
1088 | /* Inputs: */ | ||
1089 | /* ----------------------------------------------------------------------- */ | ||
1090 | /* Outputs: */ | ||
1091 | /* return bool: Indicates if the system was in a bookmarkable state */ | ||
1092 | /* ----------------------------------------------------------------------- */ | ||
1093 | static bool system_check(void) | 1064 | static bool system_check(void) |
1094 | { | 1065 | { |
1095 | int resume_index = 0; | 1066 | int resume_index = 0; |
1096 | 1067 | ||
1097 | if (!(audio_status() && audio_current_track())) | 1068 | if (!(audio_status() && audio_current_track()) || |
1098 | { | ||
1099 | /* no track playing */ | 1069 | /* no track playing */ |
1100 | return false; | 1070 | (playlist_get_resume_info(&resume_index) == -1) || |
1101 | } | 1071 | /* invalid queue info */ |
1102 | 1072 | (playlist_modified(NULL))) | |
1103 | /* Checking to see if playing a queued track */ | ||
1104 | if (playlist_get_resume_info(&resume_index) == -1) | ||
1105 | { | ||
1106 | /* something bad happened while getting the queue information */ | ||
1107 | return false; | ||
1108 | } | ||
1109 | else if (playlist_modified(NULL)) | ||
1110 | { | ||
1111 | /* can't bookmark while in the queue */ | 1073 | /* can't bookmark while in the queue */ |
1074 | { | ||
1112 | return false; | 1075 | return false; |
1113 | } | 1076 | } |
1114 | 1077 | ||