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 ****************************************************************************/
24 #include "applimits.h"
55 #if (LCD_DEPTH > 1) || (defined(HAVE_LCD_REMOTE) && (LCD_REMOTE_DEPTH > 1))
59 #define MAX_BOOKMARKS 10
60 #define MAX_BOOKMARK_SIZE 350
61 #define RECENT_BOOKMARK_FILE ROCKBOX_DIR "/most-recent.bmark"
63 /* Used to buffer bookmarks while displaying the bookmark list. */
71 bool show_dont_resume
;
73 bool show_playlist_name
;
77 static bool add_bookmark(const char* bookmark_file_name
, const char* bookmark
,
79 static bool check_bookmark(const char* bookmark
);
80 static char* create_bookmark(void);
81 static bool delete_bookmark(const char* bookmark_file_name
, int bookmark_id
);
82 static void say_bookmark(const char* bookmark
,
84 static bool play_bookmark(const char* bookmark
);
85 static bool generate_bookmark_file_name(const char *in
);
86 static const char* skip_token(const char* s
);
87 static const char* int_token(const char* s
, int* dest
);
88 static const char* long_token(const char* s
, long* dest
);
89 static const char* bool_token(const char* s
, bool* dest
);
90 static bool parse_bookmark(const char *bookmark
,
94 int *resume_first_index
,
96 unsigned int resume_file_size
,
101 static int buffer_bookmarks(struct bookmark_list
* bookmarks
, int first_line
);
102 static char* get_bookmark_info(int list_index
, void* data
, char *buffer
);
103 static char* select_bookmark(const char* bookmark_file_name
, bool show_dont_resume
);
104 static bool system_check(void);
105 static bool write_bookmark(bool create_bookmark_file
);
106 static int get_bookmark_count(const char* bookmark_file_name
);
108 static char global_temp_buffer
[MAX_PATH
+1];
109 /* File name created by generate_bookmark_file_name */
110 static char global_bookmark_file_name
[MAX_PATH
];
111 static char global_read_buffer
[MAX_BOOKMARK_SIZE
];
112 /* Bookmark created by create_bookmark*/
113 static char global_bookmark
[MAX_BOOKMARK_SIZE
];
114 /* Filename from parsed bookmark (can be made local where needed) */
115 static char global_filename
[MAX_PATH
];
117 /* ----------------------------------------------------------------------- */
118 /* This is the interface function from the main menu. */
119 /* ----------------------------------------------------------------------- */
120 bool bookmark_create_menu(void)
122 write_bookmark(true);
126 /* ----------------------------------------------------------------------- */
127 /* This function acts as the load interface from the main menu */
128 /* This function determines the bookmark file name and then loads that file*/
129 /* for the user. The user can then select a bookmark to load. */
130 /* If no file/directory is currently playing, the menu item does not work. */
131 /* ----------------------------------------------------------------------- */
132 bool bookmark_load_menu(void)
136 char* name
= playlist_get_name(NULL
, global_temp_buffer
,
137 sizeof(global_temp_buffer
));
138 if (generate_bookmark_file_name(name
))
140 char* bookmark
= select_bookmark(global_bookmark_file_name
, false);
142 if (bookmark
!= NULL
)
144 return play_bookmark(bookmark
);
152 /* ----------------------------------------------------------------------- */
153 /* Gives the user a list of the Most Recent Bookmarks. This is an */
154 /* interface function */
155 /* ----------------------------------------------------------------------- */
156 bool bookmark_mrb_load()
158 char* bookmark
= select_bookmark(RECENT_BOOKMARK_FILE
, false);
160 if (bookmark
!= NULL
)
162 return play_bookmark(bookmark
);
168 /* ----------------------------------------------------------------------- */
169 /* This function handles an autobookmark creation. This is an interface */
171 /* ----------------------------------------------------------------------- */
172 bool bookmark_autobookmark(void)
177 audio_pause(); /* first pause playback */
178 switch (global_settings
.autocreatebookmark
)
181 return write_bookmark(true);
186 case BOOKMARK_RECENT_ONLY_YES
:
187 return write_bookmark(false);
189 #ifdef HAVE_LCD_BITMAP
190 unsigned char *lines
[]={ID2P(LANG_AUTO_BOOKMARK_QUERY
)};
191 struct text_message message
={(char **)lines
, 1};
193 unsigned char *lines
[]={ID2P(LANG_AUTO_BOOKMARK_QUERY
),
194 str(LANG_CONFIRM_WITH_BUTTON
)};
195 struct text_message message
={(char **)lines
, 2};
198 show_main_backdrop(); /* switch to main backdrop as we may come from wps */
200 #if defined(HAVE_REMOTE_LCD) && LCD_REMOTE_DEPTH > 1
201 show_remote_main_backdrop();
203 gui_syncstatusbar_draw(&statusbars
, false);
204 if(gui_syncyesno_run(&message
, NULL
, NULL
)==YESNO_YES
)
206 if (global_settings
.autocreatebookmark
== BOOKMARK_RECENT_ONLY_ASK
)
207 return write_bookmark(false);
209 return write_bookmark(true);
214 /* ----------------------------------------------------------------------- */
215 /* This function takes the current current resume information and writes */
216 /* that to the beginning of the bookmark file. */
217 /* This file will contain N number of bookmarks in the following format: */
218 /* resume_index*resume_offset*resume_seed*resume_first_index* */
219 /* resume_file*milliseconds*MP3 Title* */
220 /* ------------------------------------------------------------------------*/
221 static bool write_bookmark(bool create_bookmark_file
)
227 return false; /* something didn't happen correctly, do nothing */
229 bookmark
= create_bookmark();
231 return false; /* something didn't happen correctly, do nothing */
233 if (global_settings
.usemrb
)
234 success
= add_bookmark(RECENT_BOOKMARK_FILE
, bookmark
, true);
237 /* writing the bookmark */
238 if (create_bookmark_file
)
240 char* name
= playlist_get_name(NULL
, global_temp_buffer
,
241 sizeof(global_temp_buffer
));
242 if (generate_bookmark_file_name(name
))
244 success
= add_bookmark(global_bookmark_file_name
, bookmark
, false);
248 gui_syncsplash(HZ
, success
? ID2P(LANG_BOOKMARK_CREATE_SUCCESS
)
249 : ID2P(LANG_BOOKMARK_CREATE_FAILURE
));
254 /* ----------------------------------------------------------------------- */
255 /* This function adds a bookmark to a file. */
256 /* ------------------------------------------------------------------------*/
257 static bool add_bookmark(const char* bookmark_file_name
, const char* bookmark
,
260 int temp_bookmark_file
= 0;
261 int bookmark_file
= 0;
262 int bookmark_count
= 0;
263 char* playlist
= NULL
;
269 /* Opening up a temp bookmark file */
270 snprintf(global_temp_buffer
, sizeof(global_temp_buffer
),
271 "%s.tmp", bookmark_file_name
);
272 temp_bookmark_file
= open(global_temp_buffer
,
273 O_WRONLY
| O_CREAT
| O_TRUNC
);
274 if (temp_bookmark_file
< 0)
275 return false; /* can't open the temp file */
277 if (most_recent
&& (global_settings
.usemrb
== BOOKMARK_UNIQUE_ONLY
))
279 playlist
= strchr(bookmark
,'/');
280 cp
= strrchr(bookmark
,';');
285 /* Writing the new bookmark to the begining of the temp file */
286 write(temp_bookmark_file
, bookmark
, strlen(bookmark
));
287 write(temp_bookmark_file
, "\n", 1);
290 /* Reading in the previous bookmarks and writing them to the temp file */
291 bookmark_file
= open(bookmark_file_name
, O_RDONLY
);
292 if (bookmark_file
>= 0)
294 while (read_line(bookmark_file
, global_read_buffer
,
295 sizeof(global_read_buffer
)) > 0)
297 /* The MRB has a max of MAX_BOOKMARKS in it */
298 /* This keeps it from getting too large */
299 if (most_recent
&& (bookmark_count
>= MAX_BOOKMARKS
))
302 cp
= strchr(global_read_buffer
,'/');
303 tmp
= strrchr(global_read_buffer
,';');
304 if (check_bookmark(global_read_buffer
) &&
305 (!unique
|| len
!= tmp
-cp
|| strncmp(playlist
,cp
,len
)))
308 write(temp_bookmark_file
, global_read_buffer
,
309 strlen(global_read_buffer
));
310 write(temp_bookmark_file
, "\n", 1);
313 close(bookmark_file
);
315 close(temp_bookmark_file
);
317 remove(bookmark_file_name
);
318 rename(global_temp_buffer
, bookmark_file_name
);
324 /* ----------------------------------------------------------------------- */
325 /* This function takes the system resume data and formats it into a valid */
327 /* ----------------------------------------------------------------------- */
328 static char* create_bookmark()
330 int resume_index
= 0;
333 /* grab the currently playing track */
334 struct mp3entry
*id3
= audio_current_track();
338 /* Get some basic resume information */
339 /* queue_resume and queue_resume_index are not used and can be ignored.*/
340 playlist_get_resume_info(&resume_index
);
342 /* Get the currently playing file minus the path */
343 /* This is used when displaying the available bookmarks */
344 file
= strrchr(id3
->path
,'/');
348 /* create the bookmark */
349 snprintf(global_bookmark
, sizeof(global_bookmark
),
350 "%d;%ld;%d;%d;%ld;%d;%d;%s;%s",
353 playlist_get_seed(NULL
),
356 global_settings
.repeat_mode
,
357 global_settings
.playlist_shuffle
,
358 playlist_get_name(NULL
, global_temp_buffer
,
359 sizeof(global_temp_buffer
)),
362 /* checking to see if the bookmark is valid */
363 if (check_bookmark(global_bookmark
))
364 return global_bookmark
;
369 static bool check_bookmark(const char* bookmark
)
371 return parse_bookmark(bookmark
,
372 NULL
,NULL
,NULL
, NULL
,
377 /* ----------------------------------------------------------------------- */
378 /* This function will determine if an autoload is necessary. This is an */
379 /* interface function. */
380 /* ------------------------------------------------------------------------*/
381 bool bookmark_autoload(const char* file
)
385 if(global_settings
.autoloadbookmark
== BOOKMARK_NO
)
388 /*Checking to see if a bookmark file exists.*/
389 if(!generate_bookmark_file_name(file
))
393 fd
= open(global_bookmark_file_name
, O_RDONLY
);
397 if(global_settings
.autoloadbookmark
== BOOKMARK_YES
)
399 return bookmark_load(global_bookmark_file_name
, true);
403 char* bookmark
= select_bookmark(global_bookmark_file_name
, true);
405 if (bookmark
!= NULL
)
407 if (!play_bookmark(bookmark
))
409 /* Selected bookmark not found. */
410 gui_syncsplash(HZ
*2, ID2P(LANG_NOTHING_TO_RESUME
));
413 /* Act as if autoload was done even if it failed, since the
414 * user did make an active selection.
423 /* ----------------------------------------------------------------------- */
424 /* This function loads the bookmark information into the resume memory. */
425 /* This is an interface function. */
426 /* ------------------------------------------------------------------------*/
427 bool bookmark_load(const char* file
, bool autoload
)
430 char* bookmark
= NULL
;
434 fd
= open(file
, O_RDONLY
);
437 if(read_line(fd
, global_read_buffer
, sizeof(global_read_buffer
)) > 0)
438 bookmark
=global_read_buffer
;
444 /* This is not an auto-load, so list the bookmarks */
445 bookmark
= select_bookmark(file
, false);
448 if (bookmark
!= NULL
)
450 if (!play_bookmark(bookmark
))
452 /* Selected bookmark not found. */
455 gui_syncsplash(HZ
*2, ID2P(LANG_NOTHING_TO_RESUME
));
466 static int get_bookmark_count(const char* bookmark_file_name
)
469 int file
= open(bookmark_file_name
, O_RDONLY
);
474 while(read_line(file
, global_read_buffer
, sizeof(global_read_buffer
)) > 0)
483 static int buffer_bookmarks(struct bookmark_list
* bookmarks
, int first_line
)
485 char* dest
= ((char*) bookmarks
) + bookmarks
->buffer_size
- 1;
487 int file
= open(bookmarks
->filename
, O_RDONLY
);
494 if ((first_line
!= 0) && ((size_t) filesize(file
) < bookmarks
->buffer_size
495 - sizeof(*bookmarks
) - (sizeof(char*) * bookmarks
->total_count
)))
497 /* Entire file fits in buffer */
501 bookmarks
->start
= first_line
;
502 bookmarks
->count
= 0;
503 bookmarks
->reload
= false;
505 while(read_line(file
, global_read_buffer
, sizeof(global_read_buffer
)) > 0)
509 if (read_count
>= first_line
)
511 dest
-= strlen(global_read_buffer
) + 1;
513 if (dest
< ((char*) bookmarks
) + sizeof(*bookmarks
)
514 + (sizeof(char*) * (bookmarks
->count
+ 1)))
519 strcpy(dest
, global_read_buffer
);
520 bookmarks
->items
[bookmarks
->count
] = dest
;
526 return bookmarks
->start
+ bookmarks
->count
;
529 static char* get_bookmark_info(int list_index
, void* data
, char *buffer
)
531 struct bookmark_list
* bookmarks
= (struct bookmark_list
*) data
;
532 int index
= list_index
/ 2;
533 int resume_index
= 0;
534 long resume_time
= 0;
535 bool shuffle
= false;
537 if (bookmarks
->show_dont_resume
)
541 return list_index
% 2 == 0
542 ? (char*) str(LANG_BOOKMARK_DONT_RESUME
) : " ";
548 if (bookmarks
->reload
|| (index
>= bookmarks
->start
+ bookmarks
->count
)
549 || (index
< bookmarks
->start
))
551 int read_index
= index
;
553 /* Using count as a guide on how far to move could possibly fail
554 * sometimes. Use byte count if that is a problem?
559 /* Move count * 3 / 4 items in the direction the user is moving,
560 * but don't go too close to the end.
562 int offset
= bookmarks
->count
;
563 int max
= bookmarks
->total_count
- (bookmarks
->count
/ 2);
565 if (read_index
< bookmarks
->start
)
570 read_index
= index
- offset
/ 4;
572 if (read_index
> max
)
583 if (buffer_bookmarks(bookmarks
, read_index
) <= index
)
589 if (!parse_bookmark(bookmarks
->items
[index
- bookmarks
->start
],
590 &resume_index
, NULL
, NULL
, NULL
, global_temp_buffer
,
591 sizeof(global_temp_buffer
), &resume_time
, NULL
, &shuffle
,
594 return list_index
% 2 == 0 ? (char*) str(LANG_BOOKMARK_INVALID
) : " ";
597 if (list_index
% 2 == 0)
601 int len
= strlen(global_temp_buffer
);
603 if (bookmarks
->show_playlist_name
&& len
> 0)
605 name
= global_temp_buffer
;
608 if (name
[len
] != '/')
619 name
= strrsplt(name
, '/');
626 name
= global_filename
;
630 strrsplt(global_filename
, '.');
631 snprintf(buffer
, MAX_PATH
, format
, name
, global_filename
);
638 format_time(time_buf
, sizeof(time_buf
), resume_time
);
639 snprintf(buffer
, MAX_PATH
, "%s, %d%s", time_buf
, resume_index
+ 1,
640 shuffle
? (char*) str(LANG_BOOKMARK_SHUFFLE
) : "");
645 /* ----------------------------------------------------------------------- */
646 /* This displays a the bookmarks in a file and allows the user to */
647 /* select one to play. */
648 /* ------------------------------------------------------------------------*/
649 static char* select_bookmark(const char* bookmark_file_name
, bool show_dont_resume
)
651 struct bookmark_list
* bookmarks
;
652 struct gui_synclist list
;
660 bookmarks
= plugin_get_buffer(&size
);
661 bookmarks
->buffer_size
= size
;
662 bookmarks
->show_dont_resume
= show_dont_resume
;
663 bookmarks
->filename
= bookmark_file_name
;
664 bookmarks
->start
= 0;
665 bookmarks
->show_playlist_name
666 = strcmp(bookmark_file_name
, RECENT_BOOKMARK_FILE
) == 0;
667 gui_synclist_init(&list
, &get_bookmark_info
, (void*) bookmarks
, false, 2);
668 gui_synclist_set_title(&list
, str(LANG_BOOKMARK_SELECT_BOOKMARK
),
670 gui_syncstatusbar_draw(&statusbars
, true);
674 gui_syncstatusbar_draw(&statusbars
, false);
678 int count
= get_bookmark_count(bookmark_file_name
);
679 bookmarks
->total_count
= count
;
681 if (bookmarks
->total_count
< 1)
683 /* No more bookmarks, delete file and exit */
684 gui_syncsplash(HZ
, ID2P(LANG_BOOKMARK_LOAD_EMPTY
));
685 remove(bookmark_file_name
);
689 if (bookmarks
->show_dont_resume
)
695 gui_synclist_set_nb_items(&list
, count
* 2);
699 /* Selected item has been deleted */
701 gui_synclist_select_item(&list
, item
* 2);
704 buffer_bookmarks(bookmarks
, bookmarks
->start
);
705 gui_synclist_draw(&list
);
709 action
= get_action(CONTEXT_BOOKMARKSCREEN
, HZ
/ 2);
710 gui_synclist_do_button(&list
, &action
, LIST_WRAP_UNLESS_HELD
);
711 item
= gui_synclist_get_sel_pos(&list
) / 2;
713 if (bookmarks
->show_dont_resume
)
718 if (item
!= last_item
&& global_settings
.talk_menu
)
724 talk_id(LANG_BOOKMARK_DONT_RESUME
, true);
728 say_bookmark(bookmarks
->items
[item
- bookmarks
->start
], item
);
732 if (action
== ACTION_STD_CONTEXT
)
734 MENUITEM_STRINGLIST(menu_items
, ID2P(LANG_BOOKMARK_CONTEXT_MENU
),
735 NULL
, ID2P(LANG_BOOKMARK_CONTEXT_RESUME
),
736 ID2P(LANG_BOOKMARK_CONTEXT_DELETE
));
737 static const int menu_actions
[] =
739 ACTION_STD_OK
, ACTION_BMS_DELETE
741 int selection
= do_menu(&menu_items
, NULL
);
745 if (selection
>= 0 && selection
<=
746 (int) (sizeof(menu_actions
) / sizeof(menu_actions
[0])))
748 action
= menu_actions
[selection
];
757 return bookmarks
->items
[item
- bookmarks
->start
];
760 /* Else fall through */
762 case ACTION_TREE_WPS
:
763 case ACTION_STD_CANCEL
:
767 case ACTION_BMS_DELETE
:
770 delete_bookmark(bookmark_file_name
, item
);
771 bookmarks
->reload
= true;
778 if (default_event_handler(action
) == SYS_USB_CONNECTED
)
790 /* ----------------------------------------------------------------------- */
791 /* This function takes a location in a bookmark file and deletes that */
793 /* ------------------------------------------------------------------------*/
794 static bool delete_bookmark(const char* bookmark_file_name
, int bookmark_id
)
796 int temp_bookmark_file
= 0;
797 int bookmark_file
= 0;
798 int bookmark_count
= 0;
800 /* Opening up a temp bookmark file */
801 snprintf(global_temp_buffer
, sizeof(global_temp_buffer
),
802 "%s.tmp", bookmark_file_name
);
803 temp_bookmark_file
= open(global_temp_buffer
,
804 O_WRONLY
| O_CREAT
| O_TRUNC
);
806 if (temp_bookmark_file
< 0)
807 return false; /* can't open the temp file */
809 /* Reading in the previous bookmarks and writing them to the temp file */
810 bookmark_file
= open(bookmark_file_name
, O_RDONLY
);
811 if (bookmark_file
>= 0)
813 while (read_line(bookmark_file
, global_read_buffer
,
814 sizeof(global_read_buffer
)) > 0)
816 if (bookmark_id
!= bookmark_count
)
818 write(temp_bookmark_file
, global_read_buffer
,
819 strlen(global_read_buffer
));
820 write(temp_bookmark_file
, "\n", 1);
824 close(bookmark_file
);
826 close(temp_bookmark_file
);
828 remove(bookmark_file_name
);
829 rename(global_temp_buffer
, bookmark_file_name
);
834 /* ----------------------------------------------------------------------- */
835 /* This function parses a bookmark, says the voice UI part of it. */
836 /* ------------------------------------------------------------------------*/
837 static void say_bookmark(const char* bookmark
,
842 bool enqueue
= false; /* only the first voice is not queued */
844 if (!parse_bookmark(bookmark
, &resume_index
, NULL
, NULL
, NULL
,
845 global_temp_buffer
, sizeof(global_temp_buffer
), &ms
, NULL
, NULL
, NULL
))
847 talk_id(LANG_BOOKMARK_INVALID
, true);
851 /* disabled, because transition between talkbox and voice UI clip is not nice */
853 if (global_settings
.talk_dir
>= 3)
854 { /* "talkbox" enabled */
855 char* last
= strrchr(global_temp_buffer
, '/');
857 { /* compose filename for talkbox */
858 strncpy(last
+ 1, dir_thumbnail_name
,
859 sizeof(global_temp_buffer
) - (last
- global_temp_buffer
) - 1);
860 talk_file(global_temp_buffer
, enqueue
);
865 talk_id(VOICE_EXT_BMARK
, enqueue
);
866 talk_number(bookmark_id
+ 1, true);
867 talk_id(VOICE_BOOKMARK_SELECT_INDEX_TEXT
, true);
868 talk_number(resume_index
+ 1, true);
869 talk_id(LANG_TIME
, true);
871 talk_value(ms
/ 60000, UNIT_MIN
, true);
872 talk_value((ms
% 60000) / 1000, UNIT_SEC
, true);
875 /* ----------------------------------------------------------------------- */
876 /* This function parses a bookmark and then plays it. */
877 /* ------------------------------------------------------------------------*/
878 static bool play_bookmark(const char* bookmark
)
884 if (parse_bookmark(bookmark
,
890 sizeof(global_temp_buffer
),
892 &global_settings
.repeat_mode
,
893 &global_settings
.playlist_shuffle
,
896 return bookmark_play(global_temp_buffer
, index
, offset
, seed
,
903 static const char* skip_token(const char* s
)
905 while (*s
&& *s
!= ';')
918 static const char* int_token(const char* s
, int* dest
)
925 return skip_token(s
);
928 static const char* long_token(const char* s
, long* dest
)
932 *dest
= atoi(s
); /* Should be atol, but we don't have it. */
935 return skip_token(s
);
938 static const char* bool_token(const char* s
, bool* dest
)
942 *dest
= atoi(s
) != 0;
945 return skip_token(s
);
948 /* ----------------------------------------------------------------------- */
949 /* This function takes a bookmark and parses it. This function also */
950 /* validates the bookmark. Passing in NULL for an output variable */
951 /* indicates that value is not requested. */
952 /* ----------------------------------------------------------------------- */
953 static bool parse_bookmark(const char *bookmark
,
957 int *resume_first_index
,
959 unsigned int resume_file_size
,
961 int * repeat_mode
, bool *shuffle
,
964 const char* s
= bookmark
;
967 s
= int_token(s
, resume_index
);
968 s
= int_token(s
, resume_offset
);
969 s
= int_token(s
, resume_seed
);
970 s
= int_token(s
, resume_first_index
);
971 s
= long_token(s
, ms
);
972 s
= int_token(s
, repeat_mode
);
973 s
= bool_token(s
, shuffle
);
980 end
= strchr(s
, ';');
982 if (resume_file
!= NULL
)
984 size_t len
= (end
== NULL
) ? strlen(s
) : (size_t) (end
- s
);
986 len
= MIN(resume_file_size
- 1, len
);
987 strncpy(resume_file
, s
, len
);
988 resume_file
[len
] = 0;
991 if (end
!= NULL
&& file_name
!= NULL
)
994 strncpy(file_name
, end
, MAX_PATH
- 1);
995 file_name
[MAX_PATH
- 1] = 0;
1001 /* ----------------------------------------------------------------------- */
1002 /* This function is used by multiple functions and is used to generate a */
1003 /* bookmark named based off of the input. */
1004 /* Changing this function could result in how the bookmarks are stored. */
1005 /* it would be here that the centralized/decentralized bookmark code */
1006 /* could be placed. */
1007 /* ----------------------------------------------------------------------- */
1008 static bool generate_bookmark_file_name(const char *in
)
1010 int len
= strlen(in
);
1012 /* if this is a root dir MP3, rename the bookmark file root_dir.bmark */
1013 /* otherwise, name it based on the in variable */
1014 if (!strcmp("/", in
))
1015 strcpy(global_bookmark_file_name
, "/root_dir.bmark");
1018 strcpy(global_bookmark_file_name
, in
);
1019 if(global_bookmark_file_name
[len
-1] == '/')
1021 strcpy(&global_bookmark_file_name
[len
], ".bmark");
1027 /* ----------------------------------------------------------------------- */
1028 /* Returns true if a bookmark file exists for the current playlist */
1029 /* ----------------------------------------------------------------------- */
1030 bool bookmark_exist(void)
1036 char* name
= playlist_get_name(NULL
, global_temp_buffer
,
1037 sizeof(global_temp_buffer
));
1038 if (generate_bookmark_file_name(name
))
1040 int fd
=open(global_bookmark_file_name
, O_RDONLY
);
1052 /* ----------------------------------------------------------------------- */
1053 /* Checks the current state of the system and returns if it is in a */
1054 /* bookmarkable state. */
1055 /* ----------------------------------------------------------------------- */
1057 /* ----------------------------------------------------------------------- */
1059 /* return bool: Indicates if the system was in a bookmarkable state */
1060 /* ----------------------------------------------------------------------- */
1061 static bool system_check(void)
1063 int resume_index
= 0;
1065 if (!(audio_status() && audio_current_track()))
1067 /* no track playing */
1071 /* Checking to see if playing a queued track */
1072 if (playlist_get_resume_info(&resume_index
) == -1)
1074 /* something bad happened while getting the queue information */
1077 else if (playlist_modified(NULL
))
1079 /* can't bookmark while in the queue */