1 /***************************************************************************
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
9 * Copyright (C)2003 by Benjamin Metzler
11 * All files in this archive are subject to the GNU General Public License.
12 * See the file COPYING in the source tree root for full license agreement.
14 * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
15 * KIND, either express or implied.
17 ****************************************************************************/
25 #include "applimits.h"
58 #define MAX_BOOKMARKS 10
59 #define MAX_BOOKMARK_SIZE 350
60 #define RECENT_BOOKMARK_FILE ROCKBOX_DIR "/most-recent.bmark"
62 static bool add_bookmark(const char* bookmark_file_name
, const char* bookmark
);
63 static bool check_bookmark(const char* bookmark
);
64 static char* create_bookmark(void);
65 static bool delete_bookmark(const char* bookmark_file_name
, int bookmark_id
);
66 static void display_bookmark(const char* bookmark
,
69 static void say_bookmark(const char* bookmark
,
71 static bool generate_bookmark_file_name(const char *in
);
72 static char* get_bookmark(const char* bookmark_file
, int bookmark_count
);
73 static bool parse_bookmark(const char *bookmark
,
77 int *resume_first_index
,
79 unsigned int resume_file_size
,
84 static char* select_bookmark(const char* bookmark_file_name
);
85 static bool system_check(void);
86 static bool write_bookmark(bool create_bookmark_file
);
87 static int get_bookmark_count(const char* bookmark_file_name
);
89 static char global_temp_buffer
[MAX_PATH
+1];
90 static char global_bookmark_file_name
[MAX_PATH
];
91 static char global_read_buffer
[MAX_BOOKMARK_SIZE
];
92 static char global_bookmark
[MAX_BOOKMARK_SIZE
];
93 static char global_filename
[MAX_PATH
];
95 /* ----------------------------------------------------------------------- */
96 /* This is the interface function from the main menu. */
97 /* ----------------------------------------------------------------------- */
98 bool bookmark_create_menu(void)
100 write_bookmark(true);
104 /* ----------------------------------------------------------------------- */
105 /* This function acts as the load interface from the main menu */
106 /* This function determines the bookmark file name and then loads that file*/
107 /* for the user. The user can then select a bookmark to load. */
108 /* If no file/directory is currently playing, the menu item does not work. */
109 /* ----------------------------------------------------------------------- */
110 bool bookmark_load_menu(void)
122 char* name
= playlist_get_name(NULL
, global_temp_buffer
,
123 sizeof(global_temp_buffer
));
124 if (generate_bookmark_file_name(name
))
126 bookmark
= select_bookmark(global_bookmark_file_name
);
128 return false; /* User exited without selecting a bookmark */
130 success
= parse_bookmark(bookmark
,
136 sizeof(global_temp_buffer
),
138 &global_settings
.repeat_mode
,
139 &global_settings
.playlist_shuffle
,
144 /* something bad happened while creating bookmark name*/
149 bookmark_play(global_temp_buffer
, index
, offset
, seed
,
156 /* ----------------------------------------------------------------------- */
157 /* Gives the user a list of the Most Recent Bookmarks. This is an */
158 /* interface function */
159 /* ----------------------------------------------------------------------- */
160 bool bookmark_mrb_load()
168 bookmark
= select_bookmark(RECENT_BOOKMARK_FILE
);
170 return false; /* User exited without selecting a bookmark */
172 success
= parse_bookmark(bookmark
,
178 sizeof(global_temp_buffer
),
180 &global_settings
.repeat_mode
,
181 &global_settings
.playlist_shuffle
,
185 bookmark_play(global_temp_buffer
, index
, offset
, seed
,
192 /* ----------------------------------------------------------------------- */
193 /* This function handles an autobookmark creation. This is an interface */
195 /* ----------------------------------------------------------------------- */
196 bool bookmark_autobookmark(void)
201 audio_pause(); /* first pause playback */
202 switch (global_settings
.autocreatebookmark
)
205 return write_bookmark(true);
210 case BOOKMARK_RECENT_ONLY_YES
:
211 return write_bookmark(false);
213 #ifdef HAVE_LCD_BITMAP
214 unsigned char *lines
[]={str(LANG_AUTO_BOOKMARK_QUERY
)};
215 struct text_message message
={(char **)lines
, 1};
217 unsigned char *lines
[]={str(LANG_AUTO_BOOKMARK_QUERY
),
218 str(LANG_RESUME_CONFIRM_PLAYER
)};
219 struct text_message message
={(char **)lines
, 2};
221 #ifdef HAVE_LCD_COLOR
222 show_main_backdrop(); /* switch to main backdrop as we may come from wps */
224 gui_syncstatusbar_draw(&statusbars
, false);
225 if(gui_syncyesno_run(&message
, NULL
, NULL
)==YESNO_YES
)
227 if (global_settings
.autocreatebookmark
== BOOKMARK_RECENT_ONLY_ASK
)
228 return write_bookmark(false);
230 return write_bookmark(true);
235 /* ----------------------------------------------------------------------- */
236 /* This function takes the current current resume information and writes */
237 /* that to the beginning of the bookmark file. */
238 /* This file will contain N number of bookmarks in the following format: */
239 /* resume_index*resume_offset*resume_seed*resume_first_index* */
240 /* resume_file*milliseconds*MP3 Title* */
241 /* ------------------------------------------------------------------------*/
242 static bool write_bookmark(bool create_bookmark_file
)
248 return false; /* something didn't happen correctly, do nothing */
250 bookmark
= create_bookmark();
252 return false; /* something didn't happen correctly, do nothing */
254 if (global_settings
.usemrb
)
255 success
= add_bookmark(RECENT_BOOKMARK_FILE
, bookmark
);
258 /* writing the bookmark */
259 if (create_bookmark_file
)
261 char* name
= playlist_get_name(NULL
, global_temp_buffer
,
262 sizeof(global_temp_buffer
));
263 if (generate_bookmark_file_name(name
))
265 success
= add_bookmark(global_bookmark_file_name
, bookmark
);
270 gui_syncsplash(HZ
, true, str(LANG_BOOKMARK_CREATE_SUCCESS
));
272 gui_syncsplash(HZ
, true, str(LANG_BOOKMARK_CREATE_FAILURE
));
277 /* ----------------------------------------------------------------------- */
278 /* This function adds a bookmark to a file. */
279 /* ------------------------------------------------------------------------*/
280 static bool add_bookmark(const char* bookmark_file_name
, const char* bookmark
)
282 int temp_bookmark_file
= 0;
283 int bookmark_file
= 0;
284 int bookmark_count
= 0;
285 char* playlist
= NULL
;
291 /* Opening up a temp bookmark file */
292 snprintf(global_temp_buffer
, sizeof(global_temp_buffer
),
293 "%s.tmp", bookmark_file_name
);
294 temp_bookmark_file
= open(global_temp_buffer
,
295 O_WRONLY
| O_CREAT
| O_TRUNC
);
296 if (temp_bookmark_file
< 0)
297 return false; /* can't open the temp file */
299 if (!strcmp(bookmark_file_name
,RECENT_BOOKMARK_FILE
) &&
300 (global_settings
.usemrb
== BOOKMARK_UNIQUE_ONLY
))
302 playlist
= strchr(bookmark
,'/');
303 cp
= strrchr(bookmark
,';');
308 /* Writing the new bookmark to the begining of the temp file */
309 write(temp_bookmark_file
, bookmark
, strlen(bookmark
));
310 write(temp_bookmark_file
, "\n", 1);
313 /* Reading in the previous bookmarks and writing them to the temp file */
314 bookmark_file
= open(bookmark_file_name
, O_RDONLY
);
315 if (bookmark_file
>= 0)
317 while (read_line(bookmark_file
, global_read_buffer
,
318 sizeof(global_read_buffer
)))
320 /* The MRB has a max of MAX_BOOKMARKS in it */
321 /* This keeps it from getting too large */
322 if ((strcmp(bookmark_file_name
,RECENT_BOOKMARK_FILE
)==0))
324 if(bookmark_count
>= MAX_BOOKMARKS
)
328 cp
= strchr(global_read_buffer
,'/');
329 tmp
= strrchr(global_read_buffer
,';');
330 if (check_bookmark(global_read_buffer
) &&
331 (!unique
|| len
!= tmp
-cp
|| strncmp(playlist
,cp
,len
)))
334 write(temp_bookmark_file
, global_read_buffer
,
335 strlen(global_read_buffer
));
336 write(temp_bookmark_file
, "\n", 1);
339 close(bookmark_file
);
341 close(temp_bookmark_file
);
343 remove(bookmark_file_name
);
344 rename(global_temp_buffer
, bookmark_file_name
);
350 /* ----------------------------------------------------------------------- */
351 /* This function takes the system resume data and formats it into a valid */
353 /* ----------------------------------------------------------------------- */
354 static char* create_bookmark()
356 int resume_index
= 0;
359 /* grab the currently playing track */
360 struct mp3entry
*id3
= audio_current_track();
364 /* Get some basic resume information */
365 /* queue_resume and queue_resume_index are not used and can be ignored.*/
366 playlist_get_resume_info(&resume_index
);
368 /* Get the currently playing file minus the path */
369 /* This is used when displaying the available bookmarks */
370 file
= strrchr(id3
->path
,'/');
374 /* create the bookmark */
375 snprintf(global_bookmark
, sizeof(global_bookmark
),
376 "%d;%ld;%d;%d;%ld;%d;%d;%s;%s",
379 playlist_get_seed(NULL
),
382 global_settings
.repeat_mode
,
383 global_settings
.playlist_shuffle
,
384 playlist_get_name(NULL
, global_temp_buffer
,
385 sizeof(global_temp_buffer
)),
388 /* checking to see if the bookmark is valid */
389 if (check_bookmark(global_bookmark
))
390 return global_bookmark
;
395 static bool check_bookmark(const char* bookmark
)
397 return parse_bookmark(bookmark
,
398 NULL
,NULL
,NULL
, NULL
,
403 /* ----------------------------------------------------------------------- */
404 /* This function will determine if an autoload is necessary. This is an */
405 /* interface function. */
406 /* ------------------------------------------------------------------------*/
407 bool bookmark_autoload(const char* file
)
413 if(global_settings
.autoloadbookmark
== BOOKMARK_NO
)
416 /*Checking to see if a bookmark file exists.*/
417 if(!generate_bookmark_file_name(file
))
421 fd
= open(global_bookmark_file_name
, O_RDONLY
);
424 if(-1 == lseek(fd
, 0, SEEK_END
))
430 if(global_settings
.autoloadbookmark
== BOOKMARK_YES
)
432 return bookmark_load(global_bookmark_file_name
, true);
436 /* Prompting user to confirm bookmark load */
438 screens
[i
].clear_display();
440 gui_syncstatusbar_draw(&statusbars
, false);
444 #ifdef HAVE_LCD_BITMAP
445 screens
[i
].setmargins(0, STATUSBAR_HEIGHT
);
446 screens
[i
].puts_scroll(0,0, str(LANG_BOOKMARK_AUTOLOAD_QUERY
));
447 screens
[i
].puts(0,1, str(LANG_CONFIRM_WITH_PLAY_RECORDER
));
448 screens
[i
].puts(0,2, str(LANG_BOOKMARK_SELECT_LIST_BOOKMARKS
));
449 screens
[i
].puts(0,3, str(LANG_CANCEL_WITH_ANY_RECORDER
));
452 screens
[i
].puts_scroll(0,0, str(LANG_BOOKMARK_AUTOLOAD_QUERY
));
453 screens
[i
].puts(0,1,str(LANG_RESUME_CONFIRM_PLAYER
));
457 /* Wait for a key to be pushed */
458 key
= get_action(CONTEXT_BOOKMARKSCREEN
,TIMEOUT_BLOCK
);
461 #ifdef HAVE_LCD_BITMAP
462 case ACTION_STD_NEXT
:
463 action_signalscreenchange();
464 return bookmark_load(global_bookmark_file_name
, false);
466 case ACTION_BMS_SELECT
:
467 action_signalscreenchange();
468 return bookmark_load(global_bookmark_file_name
, true);
474 action_signalscreenchange();
479 /* ----------------------------------------------------------------------- */
480 /* This function loads the bookmark information into the resume memory. */
481 /* This is an interface function. */
482 /* ------------------------------------------------------------------------*/
483 bool bookmark_load(const char* file
, bool autoload
)
490 char* bookmark
= NULL
;;
494 fd
= open(file
, O_RDONLY
);
497 if(read_line(fd
, global_read_buffer
, sizeof(global_read_buffer
)))
498 bookmark
=global_read_buffer
;
504 /* This is not an auto-load, so list the bookmarks */
505 bookmark
=select_bookmark(file
);
507 return true; /* User exited without selecting a bookmark */
512 success
= parse_bookmark(bookmark
,
518 sizeof(global_temp_buffer
),
520 &global_settings
.repeat_mode
,
521 &global_settings
.playlist_shuffle
,
527 bookmark_play(global_temp_buffer
, index
, offset
, seed
,
534 static int get_bookmark_count(const char* bookmark_file_name
)
537 int file
= open(bookmark_file_name
, O_RDONLY
);
542 /* Get the requested bookmark */
543 while(read_line(file
, global_read_buffer
, sizeof(global_read_buffer
)))
545 if(check_bookmark(global_read_buffer
))
555 /* ----------------------------------------------------------------------- */
556 /* This displays a the bookmarks in a file and allows the user to */
557 /* select one to play. */
558 /* ------------------------------------------------------------------------*/
559 static char* select_bookmark(const char* bookmark_file_name
)
562 int bookmark_id_prev
= -1;
564 char* bookmark
= NULL
;
565 int bookmark_count
= 0;
567 #ifdef HAVE_LCD_BITMAP
569 int x
= lcd_getxmargin();
570 int y
= lcd_getymargin();
572 screens
[i
].setmargins(0, 0);
575 bookmark_count
= get_bookmark_count(bookmark_file_name
);
576 action_signalscreenchange();
580 bookmark_id
= bookmark_count
-1;
581 if(bookmark_id
>= bookmark_count
)
584 if (bookmark_id
!= bookmark_id_prev
)
586 bookmark
= get_bookmark(bookmark_file_name
, bookmark_id
);
587 bookmark_id_prev
= bookmark_id
;
592 /* if there were no bookmarks in the file, delete the file and exit. */
595 gui_syncsplash(HZ
, true, str(LANG_BOOKMARK_LOAD_EMPTY
));
596 remove(bookmark_file_name
);
597 action_signalscreenchange();
602 bookmark_id_prev
= bookmark_id
;
608 display_bookmark(bookmark
, bookmark_id
, bookmark_count
);
609 if (global_settings
.talk_menu
) /* for voice UI */
610 say_bookmark(bookmark
, bookmark_id
);
613 /* waiting for the user to click a button */
614 key
= get_action(CONTEXT_BOOKMARKSCREEN
,TIMEOUT_BLOCK
);
617 case ACTION_BMS_SELECT
:
618 /* User wants to use this bookmark */
619 #ifdef HAVE_LCD_BITMAP
620 if (global_settings
.statusbar
)
623 screens
[i
].setmargins(0, STATUSBAR_HEIGHT
);
628 screens
[i
].setmargins(0, 0);
631 action_signalscreenchange();
634 case ACTION_BMS_DELETE
:
635 /* User wants to delete this bookmark */
636 delete_bookmark(bookmark_file_name
, bookmark_id
);
639 if(bookmark_id
>= bookmark_count
)
640 bookmark_id
= bookmark_count
-1;
643 case ACTION_STD_PREV
:
644 case ACTION_STD_PREVREPEAT
:
648 case ACTION_STD_NEXT
:
649 case ACTION_STD_NEXTREPEAT
:
653 case ACTION_BMS_EXIT
:
654 #ifdef HAVE_LCD_BITMAP
656 screens
[i
].setmargins(x
, y
);
658 action_signalscreenchange();
662 if(default_event_handler(key
) == SYS_USB_CONNECTED
)
664 action_signalscreenchange();
670 action_signalscreenchange();
675 /* ----------------------------------------------------------------------- */
676 /* This function takes a location in a bookmark file and deletes that */
678 /* ------------------------------------------------------------------------*/
679 static bool delete_bookmark(const char* bookmark_file_name
, int bookmark_id
)
681 int temp_bookmark_file
= 0;
682 int bookmark_file
= 0;
683 int bookmark_count
= 0;
685 /* Opening up a temp bookmark file */
686 snprintf(global_temp_buffer
, sizeof(global_temp_buffer
),
687 "%s.tmp", bookmark_file_name
);
688 temp_bookmark_file
= open(global_temp_buffer
,
689 O_WRONLY
| O_CREAT
| O_TRUNC
);
690 bookmark_file
= open(bookmark_file_name
, O_RDONLY
);
692 if (temp_bookmark_file
< 0 || bookmark_file
< 0)
693 return false; /* can't open one of the files */
695 /* Reading in the previous bookmarks and writing them to the temp file */
696 while (read_line(bookmark_file
, global_read_buffer
,
697 sizeof(global_read_buffer
)))
699 /* The MRB has a max of MAX_BOOKMARKS in it */
700 /* This keeps it from getting too large */
701 if ((strcmp(bookmark_file_name
,RECENT_BOOKMARK_FILE
)==0))
703 if(bookmark_count
>= MAX_BOOKMARKS
)
707 if (check_bookmark(global_read_buffer
))
709 if (bookmark_id
!= bookmark_count
)
711 write(temp_bookmark_file
, global_read_buffer
,
712 strlen(global_read_buffer
));
713 write(temp_bookmark_file
, "\n", 1);
719 close(bookmark_file
);
720 close(temp_bookmark_file
);
722 remove(bookmark_file_name
);
723 rename(global_temp_buffer
, bookmark_file_name
);
728 /* ----------------------------------------------------------------------- */
729 /* This function parses a bookmark and displays it for the user. */
730 /* ------------------------------------------------------------------------*/
731 static void display_bookmark(const char* bookmark
,
735 int resume_index
= 0;
738 bool playlist_shuffle
= false;
743 /* getting the index and the time into the file */
744 parse_bookmark(bookmark
,
745 &resume_index
, NULL
, NULL
, NULL
, NULL
, 0,
746 &ms
, &repeat_mode
, &playlist_shuffle
,
751 screens
[i
].clear_display();
752 screens
[i
].stop_scroll();
755 #ifdef HAVE_LCD_BITMAP
756 /* bookmark shuffle and repeat states*/
759 #if (AB_REPEAT_ENABLE == 1)
761 statusbar_icon_play_mode(Icon_RepeatAB
);
766 statusbar_icon_play_mode(Icon_RepeatOne
);
770 statusbar_icon_play_mode(Icon_Repeat
);
774 statusbar_icon_shuffle();
777 len
=strlen(global_filename
);
779 dot
=strrchr(global_filename
+ len
- 4, '.');
785 screens
[i
].puts_scroll(0, 0, (unsigned char *)global_filename
);
789 /* bookmark number */
790 snprintf(global_temp_buffer
, sizeof(global_temp_buffer
), "%s: %2d/%2d",
791 str(LANG_BOOKMARK_SELECT_BOOKMARK_TEXT
),
792 bookmark_id
+ 1, bookmark_count
);
794 screens
[i
].puts_scroll(0, 1, (unsigned char *)global_temp_buffer
);
796 /* bookmark resume index */
797 snprintf(global_temp_buffer
, sizeof(global_temp_buffer
), "%s: %2d",
798 str(LANG_BOOKMARK_SELECT_INDEX_TEXT
), resume_index
+1);
800 screens
[i
].puts_scroll(0, 2, (unsigned char *)global_temp_buffer
);
805 snprintf(global_temp_buffer
, sizeof(global_temp_buffer
), "%s: %ld:%02d",
806 str(LANG_BOOKMARK_SELECT_TIME_TEXT
),
808 (unsigned int)(ms
% 60000) / 1000);
809 /* unsigned int: hinting for 16bits archs */
813 snprintf(global_temp_buffer
, sizeof(global_temp_buffer
),
814 "%s: %ld:%02ld:%02d",
815 str(LANG_BOOKMARK_SELECT_TIME_TEXT
),
817 ms
% 3600000 / 60000,
818 (unsigned int)(ms
% 60000) / 1000);
821 screens
[i
].puts_scroll(0, 3, (unsigned char *)global_temp_buffer
);
826 screens
[i
].puts_scroll(0, 4, str(LANG_BOOKMARK_SELECT_PLAY
));
827 screens
[i
].puts_scroll(0, 5, str(LANG_BOOKMARK_SELECT_EXIT
));
828 screens
[i
].puts_scroll(0, 6, str(LANG_BOOKMARK_SELECT_DELETE
));
832 len
=strlen(global_filename
);
834 dot
=strrchr(global_filename
+len
-4,'.');
841 snprintf(global_temp_buffer
, sizeof(global_temp_buffer
),
842 "%2d, %ld:%02ld, %s,",
850 snprintf(global_temp_buffer
, sizeof(global_temp_buffer
),
851 "%2d, %ld:%02ld:%02ld, %s,",
854 ms
% 3600000 / 60000,
859 gui_syncstatusbar_draw(&statusbars
, false);
863 screens
[i
].puts_scroll(0,0,global_temp_buffer
);
864 screens
[i
].puts(0,1,str(LANG_RESUME_CONFIRM_PLAYER
));
870 #ifdef HAVE_LCD_BITMAP
877 /* ----------------------------------------------------------------------- */
878 /* This function parses a bookmark, says the voice UI part of it. */
879 /* ------------------------------------------------------------------------*/
880 static void say_bookmark(const char* bookmark
,
886 bool enqueue
= false; /* only the first voice is not queued */
888 parse_bookmark(bookmark
,
894 /* disabled, because transition between talkbox and voice UI clip is not nice */
896 if (global_settings
.talk_dir
>= 3)
897 { /* "talkbox" enabled */
898 char* last
= strrchr(dir
, '/');
900 { /* compose filename for talkbox */
901 strncpy(last
+ 1, dir_thumbnail_name
, sizeof(dir
)-(last
-dir
)-1);
902 talk_file(dir
, enqueue
);
907 talk_id(VOICE_EXT_BMARK
, enqueue
);
908 talk_number(bookmark_id
+ 1, true);
909 talk_id(LANG_BOOKMARK_SELECT_INDEX_TEXT
, true);
910 talk_number(resume_index
+ 1, true);
911 talk_id(LANG_BOOKMARK_SELECT_TIME_TEXT
, true);
913 talk_value(ms
/ 60000, UNIT_MIN
, true);
914 talk_value((ms
% 60000) / 1000, UNIT_SEC
, true);
918 /* ----------------------------------------------------------------------- */
919 /* This function retrieves a given bookmark from a file. */
920 /* If the bookmark requested is beyond the number of bookmarks available */
921 /* in the file, it will return the last one. */
922 /* It also returns the index number of the bookmark in the file */
923 /* ------------------------------------------------------------------------*/
924 static char* get_bookmark(const char* bookmark_file
, int bookmark_count
)
928 int file
= open(bookmark_file
, O_RDONLY
);
933 if (bookmark_count
< 0)
936 /* Get the requested bookmark */
937 while (read_count
< bookmark_count
)
939 /*Reading in a single bookmark */
940 result
= read_line(file
,
942 sizeof(global_read_buffer
));
944 /* Reading past the last bookmark in the file
945 causes the loop to stop */
953 if (read_count
== bookmark_count
)
954 return global_read_buffer
;
959 /* ----------------------------------------------------------------------- */
960 /* This function takes a bookmark and parses it. This function also */
961 /* validates the bookmark. Passing in NULL for an output variable */
962 /* indicates that value is not requested. */
963 /* ----------------------------------------------------------------------- */
964 static bool parse_bookmark(const char *bookmark
,
968 int *resume_first_index
,
970 unsigned int resume_file_size
,
972 int * repeat_mode
, bool *shuffle
,
975 /* First check to see if a valid line was passed in. */
976 int bookmark_len
= strlen(bookmark
);
977 int local_resume_index
= 0;
978 int local_resume_offset
= 0;
979 int local_resume_seed
= 0;
980 int local_resume_first_index
= 0;
982 int local_shuffle
= 0;
983 int local_repeat_mode
= 0;
984 char* local_resume_file
= NULL
;
985 char* local_file_name
= NULL
;
988 static char bookmarkcopy
[MAX_BOOKMARK_SIZE
];
990 /* Don't do anything if the bookmark length is 0 */
991 if (bookmark_len
<= 0)
994 /* Making a dup of the bookmark to use with strtok_r */
995 strncpy(bookmarkcopy
, bookmark
, sizeof(bookmarkcopy
));
996 bookmarkcopy
[sizeof(bookmarkcopy
) - 1] = 0;
999 if ((field
= strtok_r(bookmarkcopy
, ";", &end
)))
1000 local_resume_index
= atoi(field
);
1005 if ((field
= strtok_r(NULL
, ";", &end
)))
1006 local_resume_offset
= atoi(field
);
1011 if ((field
= strtok_r(NULL
, ";", &end
)))
1012 local_resume_seed
= atoi(field
);
1016 /* resume_first_index */
1017 if ((field
= strtok_r(NULL
, ";", &end
)))
1018 local_resume_first_index
= atoi(field
);
1022 /* Milliseconds into MP3. Used for the bookmark select menu */
1023 if ((field
= strtok_r(NULL
, ";", &end
)))
1024 local_mS
= atoi(field
);
1029 if ((field
= strtok_r(NULL
, ";", &end
)))
1030 local_repeat_mode
= atoi(field
);
1035 if ((field
= strtok_r(NULL
, ";", &end
)))
1036 local_shuffle
= atoi(field
);
1040 /* resume_file & file_name (for the bookmark select menu)*/
1043 local_resume_file
= strtok_r(NULL
, ";", &end
);
1046 local_file_name
= strtok_r(NULL
, ";", &end
);
1051 /* Only return the values the calling function wants */
1053 *resume_index
= local_resume_index
;
1056 *resume_offset
= local_resume_offset
;
1059 *resume_seed
= local_resume_seed
;
1061 if (resume_first_index
)
1062 *resume_first_index
= local_resume_first_index
;
1064 if (resume_file
&& local_resume_file
)
1066 strncpy(resume_file
, local_resume_file
,
1067 MIN(strlen(local_resume_file
), resume_file_size
-1));
1068 resume_file
[MIN(strlen(local_resume_file
), resume_file_size
-1)]=0;
1075 *shuffle
= local_shuffle
;
1078 *repeat_mode
= local_repeat_mode
;
1080 if (file_name
&& local_file_name
)
1082 strncpy(file_name
, local_file_name
,MAX_PATH
-1);
1083 file_name
[MAX_PATH
-1] = 0;
1089 /* ----------------------------------------------------------------------- */
1090 /* This function is used by multiple functions and is used to generate a */
1091 /* bookmark named based off of the input. */
1092 /* Changing this function could result in how the bookmarks are stored. */
1093 /* it would be here that the centralized/decentralized bookmark code */
1094 /* could be placed. */
1095 /* ----------------------------------------------------------------------- */
1096 static bool generate_bookmark_file_name(const char *in
)
1098 int len
= strlen(in
);
1100 /* if this is a root dir MP3, rename the bookmark file root_dir.bmark */
1101 /* otherwise, name it based on the in variable */
1102 if (!strcmp("/", in
))
1103 strcpy(global_bookmark_file_name
, "/root_dir.bmark");
1106 strcpy(global_bookmark_file_name
, in
);
1107 if(global_bookmark_file_name
[len
-1] == '/')
1109 strcpy(&global_bookmark_file_name
[len
], ".bmark");
1115 /* ----------------------------------------------------------------------- */
1116 /* Returns the bookmark name for the current playlist */
1117 /* ----------------------------------------------------------------------- */
1118 bool bookmark_exist(void)
1124 char* name
= playlist_get_name(NULL
, global_temp_buffer
,
1125 sizeof(global_temp_buffer
));
1126 if (generate_bookmark_file_name(name
))
1128 int fd
=open(global_bookmark_file_name
, O_RDONLY
);
1140 /* ----------------------------------------------------------------------- */
1141 /* Checks the current state of the system and returns if it is in a */
1142 /* bookmarkable state. */
1143 /* ----------------------------------------------------------------------- */
1145 /* ----------------------------------------------------------------------- */
1147 /* return bool: Indicates if the system was in a bookmarkable state */
1148 /* ----------------------------------------------------------------------- */
1149 static bool system_check(void)
1151 int resume_index
= 0;
1152 struct mp3entry
*id3
= audio_current_track();
1156 /* no track playing */
1160 /* Checking to see if playing a queued track */
1161 if (playlist_get_resume_info(&resume_index
) == -1)
1163 /* something bad happened while getting the queue information */
1166 else if (playlist_modified(NULL
))
1168 /* can't bookmark while in the queue */