1 /***************************************************************************
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
9 * Copyright (C)2003 by Benjamin Metzler
11 * This program is free software; you can redistribute it and/or
12 * modify it under the terms of the GNU General Public License
13 * as published by the Free Software Foundation; either version 2
14 * of the License, or (at your option) any later version.
16 * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
17 * KIND, either express or implied.
19 ****************************************************************************/
44 #include "filefuncs.h"
46 #define MAX_BOOKMARKS 10
47 #define MAX_BOOKMARK_SIZE 350
48 #define RECENT_BOOKMARK_FILE ROCKBOX_DIR "/most-recent.bmark"
50 /* Used to buffer bookmarks while displaying the bookmark list. */
58 bool show_dont_resume
;
60 bool show_playlist_name
;
65 #define F_BMFILES 0x01
70 unsigned long resume_offset
;
77 static bool add_bookmark(const char* bookmark_file_name
, const char* bookmark
,
79 static char* create_bookmark(void);
80 static bool delete_bookmark(const char* bookmark_file_name
, int bookmark_id
);
81 static void say_bookmark(const char* bookmark
,
82 int bookmark_id
, bool show_playlist_name
);
83 static bool play_bookmark(const char* bookmark
);
84 static bool generate_bookmark_file_name(const char *in
);
85 static bool parse_bookmark(const char *bookmark
, const int flags
);
86 static int buffer_bookmarks(struct bookmark_list
* bookmarks
, int first_line
);
87 static const char* get_bookmark_info(int list_index
,
91 static char* select_bookmark(const char* bookmark_file_name
, bool show_dont_resume
);
92 static bool system_check(void);
93 static bool write_bookmark(bool create_bookmark_file
, const char *bookmark
);
94 static int get_bookmark_count(const char* bookmark_file_name
);
96 #define TEMP_BUF_SIZE (MAX_PATH + 1)
97 static char global_temp_buffer
[TEMP_BUF_SIZE
];
98 /* File name created by generate_bookmark_file_name */
99 static char global_bookmark_file_name
[MAX_PATH
];
100 static char global_read_buffer
[MAX_BOOKMARK_SIZE
];
101 /* Bookmark created by create_bookmark*/
102 static char global_bookmark
[MAX_BOOKMARK_SIZE
];
103 /* Filename from parsed bookmark (can be made local where needed) */
104 static char global_filename
[MAX_PATH
];
106 /* ----------------------------------------------------------------------- */
107 /* This is the interface function from the main menu. */
108 /* ----------------------------------------------------------------------- */
109 bool bookmark_create_menu(void)
111 write_bookmark(true, create_bookmark());
115 /* ----------------------------------------------------------------------- */
116 /* This function acts as the load interface from the main menu */
117 /* This function determines the bookmark file name and then loads that file*/
118 /* for the user. The user can then select a bookmark to load. */
119 /* If no file/directory is currently playing, the menu item does not work. */
120 /* ----------------------------------------------------------------------- */
121 bool bookmark_load_menu(void)
125 char* name
= playlist_get_name(NULL
, global_temp_buffer
,
126 sizeof(global_temp_buffer
));
127 if (generate_bookmark_file_name(name
))
129 char* bookmark
= select_bookmark(global_bookmark_file_name
, false);
131 if (bookmark
!= NULL
)
133 return play_bookmark(bookmark
);
141 /* ----------------------------------------------------------------------- */
142 /* Gives the user a list of the Most Recent Bookmarks. This is an */
143 /* interface function */
144 /* ----------------------------------------------------------------------- */
145 bool bookmark_mrb_load()
147 char* bookmark
= select_bookmark(RECENT_BOOKMARK_FILE
, false);
149 if (bookmark
!= NULL
)
151 return play_bookmark(bookmark
);
157 /* ----------------------------------------------------------------------- */
158 /* This function handles an autobookmark creation. This is an interface */
160 /* ----------------------------------------------------------------------- */
161 bool bookmark_autobookmark(bool prompt_ok
)
167 audio_pause(); /* first pause playback */
168 bookmark
= create_bookmark();
169 /* Workaround for inability to speak when paused: all callers will
170 just do audio_stop() when we return, so we can do it right
171 away. This makes it possible to speak the "Create a Bookmark?"
172 prompt and the "Bookmark Created" splash. */
174 switch (global_settings
.autocreatebookmark
)
177 return write_bookmark(true, bookmark
);
182 case BOOKMARK_RECENT_ONLY_YES
:
183 return write_bookmark(false, bookmark
);
185 #ifdef HAVE_LCD_BITMAP
186 const char *lines
[]={ID2P(LANG_AUTO_BOOKMARK_QUERY
)};
187 const struct text_message message
={lines
, 1};
189 const char *lines
[]={ID2P(LANG_AUTO_BOOKMARK_QUERY
),
190 str(LANG_CONFIRM_WITH_BUTTON
)};
191 const struct text_message message
={lines
, 2};
194 if(prompt_ok
&& gui_syncyesno_run(&message
, NULL
, NULL
)==YESNO_YES
)
196 if (global_settings
.autocreatebookmark
== BOOKMARK_RECENT_ONLY_ASK
)
197 return write_bookmark(false, bookmark
);
199 return write_bookmark(true, bookmark
);
204 /* ----------------------------------------------------------------------- */
205 /* This function takes the current current resume information and writes */
206 /* that to the beginning of the bookmark file. */
207 /* This file will contain N number of bookmarks in the following format: */
208 /* resume_index*resume_offset*resume_seed*resume_first_index* */
209 /* resume_file*milliseconds*MP3 Title* */
210 /* ------------------------------------------------------------------------*/
211 static bool write_bookmark(bool create_bookmark_file
, const char *bookmark
)
215 return false; /* something didn't happen correctly, do nothing */
217 if (global_settings
.usemrb
)
218 success
= add_bookmark(RECENT_BOOKMARK_FILE
, bookmark
, true);
221 /* writing the bookmark */
222 if (create_bookmark_file
)
224 char* name
= playlist_get_name(NULL
, global_temp_buffer
,
225 sizeof(global_temp_buffer
));
226 if (generate_bookmark_file_name(name
))
228 success
= add_bookmark(global_bookmark_file_name
, bookmark
, false);
232 splash(HZ
, success
? ID2P(LANG_BOOKMARK_CREATE_SUCCESS
)
233 : ID2P(LANG_BOOKMARK_CREATE_FAILURE
));
238 /* ----------------------------------------------------------------------- */
239 /* This function adds a bookmark to a file. */
240 /* ------------------------------------------------------------------------*/
241 static bool add_bookmark(const char* bookmark_file_name
, const char* bookmark
,
244 int temp_bookmark_file
= 0;
245 int bookmark_file
= 0;
246 int bookmark_count
= 0;
247 char* playlist
= NULL
;
253 /* Opening up a temp bookmark file */
254 snprintf(global_temp_buffer
, sizeof(global_temp_buffer
),
255 "%s.tmp", bookmark_file_name
);
256 temp_bookmark_file
= open(global_temp_buffer
,
257 O_WRONLY
| O_CREAT
| O_TRUNC
);
258 if (temp_bookmark_file
< 0)
259 return false; /* can't open the temp file */
261 if (most_recent
&& (global_settings
.usemrb
== BOOKMARK_UNIQUE_ONLY
))
263 playlist
= strchr(bookmark
,'/');
264 cp
= strrchr(bookmark
,';');
269 /* Writing the new bookmark to the begining of the temp file */
270 write(temp_bookmark_file
, bookmark
, strlen(bookmark
));
271 write(temp_bookmark_file
, "\n", 1);
274 /* Reading in the previous bookmarks and writing them to the temp file */
275 bookmark_file
= open(bookmark_file_name
, O_RDONLY
);
276 if (bookmark_file
>= 0)
278 while (read_line(bookmark_file
, global_read_buffer
,
279 sizeof(global_read_buffer
)) > 0)
281 /* The MRB has a max of MAX_BOOKMARKS in it */
282 /* This keeps it from getting too large */
283 if (most_recent
&& (bookmark_count
>= MAX_BOOKMARKS
))
286 cp
= strchr(global_read_buffer
,'/');
287 tmp
= strrchr(global_read_buffer
,';');
288 if (parse_bookmark(global_read_buffer
, 0) &&
289 (!unique
|| len
!= tmp
-cp
|| strncmp(playlist
,cp
,len
)))
292 write(temp_bookmark_file
, global_read_buffer
,
293 strlen(global_read_buffer
));
294 write(temp_bookmark_file
, "\n", 1);
297 close(bookmark_file
);
299 close(temp_bookmark_file
);
301 remove(bookmark_file_name
);
302 rename(global_temp_buffer
, bookmark_file_name
);
308 /* ----------------------------------------------------------------------- */
309 /* This function takes the system resume data and formats it into a valid */
311 /* ----------------------------------------------------------------------- */
312 static char* create_bookmark()
314 int resume_index
= 0;
318 return NULL
; /* something didn't happen correctly, do nothing */
320 /* grab the currently playing track */
321 struct mp3entry
*id3
= audio_current_track();
325 /* Get some basic resume information */
326 /* queue_resume and queue_resume_index are not used and can be ignored.*/
327 playlist_get_resume_info(&resume_index
);
329 /* Get the currently playing file minus the path */
330 /* This is used when displaying the available bookmarks */
331 file
= strrchr(id3
->path
,'/');
335 /* create the bookmark */
336 snprintf(global_bookmark
, sizeof(global_bookmark
),
337 "%d;%ld;%d;%d;%ld;%d;%d;%s;%s",
340 playlist_get_seed(NULL
),
343 global_settings
.repeat_mode
,
344 global_settings
.playlist_shuffle
,
345 playlist_get_name(NULL
, global_temp_buffer
,
346 sizeof(global_temp_buffer
)),
349 /* checking to see if the bookmark is valid */
350 if (parse_bookmark(global_bookmark
, 0))
351 return global_bookmark
;
356 /* ----------------------------------------------------------------------- */
357 /* This function will determine if an autoload is necessary. This is an */
358 /* interface function. */
359 /* ------------------------------------------------------------------------*/
360 bool bookmark_autoload(const char* file
)
362 if(global_settings
.autoloadbookmark
== BOOKMARK_NO
)
365 /*Checking to see if a bookmark file exists.*/
366 if(!generate_bookmark_file_name(file
))
371 if(!file_exists(global_bookmark_file_name
))
374 if(global_settings
.autoloadbookmark
== BOOKMARK_YES
)
376 return bookmark_load(global_bookmark_file_name
, true);
380 char* bookmark
= select_bookmark(global_bookmark_file_name
, true);
382 if (bookmark
!= NULL
)
384 if (!play_bookmark(bookmark
))
386 /* Selected bookmark not found. */
387 splash(HZ
*2, ID2P(LANG_NOTHING_TO_RESUME
));
390 /* Act as if autoload was done even if it failed, since the
391 * user did make an active selection.
400 /* ----------------------------------------------------------------------- */
401 /* This function loads the bookmark information into the resume memory. */
402 /* This is an interface function. */
403 /* ------------------------------------------------------------------------*/
404 bool bookmark_load(const char* file
, bool autoload
)
407 char* bookmark
= NULL
;
411 fd
= open(file
, O_RDONLY
);
414 if(read_line(fd
, global_read_buffer
, sizeof(global_read_buffer
)) > 0)
415 bookmark
=global_read_buffer
;
421 /* This is not an auto-load, so list the bookmarks */
422 bookmark
= select_bookmark(file
, false);
425 if (bookmark
!= NULL
)
427 if (!play_bookmark(bookmark
))
429 /* Selected bookmark not found. */
432 splash(HZ
*2, ID2P(LANG_NOTHING_TO_RESUME
));
443 static int get_bookmark_count(const char* bookmark_file_name
)
446 int file
= open(bookmark_file_name
, O_RDONLY
);
451 while(read_line(file
, global_read_buffer
, sizeof(global_read_buffer
)) > 0)
460 static int buffer_bookmarks(struct bookmark_list
* bookmarks
, int first_line
)
462 char* dest
= ((char*) bookmarks
) + bookmarks
->buffer_size
- 1;
464 int file
= open(bookmarks
->filename
, O_RDONLY
);
471 if ((first_line
!= 0) && ((size_t) filesize(file
) < bookmarks
->buffer_size
472 - sizeof(*bookmarks
) - (sizeof(char*) * bookmarks
->total_count
)))
474 /* Entire file fits in buffer */
478 bookmarks
->start
= first_line
;
479 bookmarks
->count
= 0;
480 bookmarks
->reload
= false;
482 while(read_line(file
, global_read_buffer
, sizeof(global_read_buffer
)) > 0)
486 if (read_count
>= first_line
)
488 dest
-= strlen(global_read_buffer
) + 1;
490 if (dest
< ((char*) bookmarks
) + sizeof(*bookmarks
)
491 + (sizeof(char*) * (bookmarks
->count
+ 1)))
496 strcpy(dest
, global_read_buffer
);
497 bookmarks
->items
[bookmarks
->count
] = dest
;
503 return bookmarks
->start
+ bookmarks
->count
;
506 static const char* get_bookmark_info(int list_index
,
511 struct bookmark_list
* bookmarks
= (struct bookmark_list
*) data
;
512 int index
= list_index
/ 2;
514 if (bookmarks
->show_dont_resume
)
518 return list_index
% 2 == 0
519 ? (char*) str(LANG_BOOKMARK_DONT_RESUME
) : " ";
525 if (bookmarks
->reload
|| (index
>= bookmarks
->start
+ bookmarks
->count
)
526 || (index
< bookmarks
->start
))
528 int read_index
= index
;
530 /* Using count as a guide on how far to move could possibly fail
531 * sometimes. Use byte count if that is a problem?
536 /* Move count * 3 / 4 items in the direction the user is moving,
537 * but don't go too close to the end.
539 int offset
= bookmarks
->count
;
540 int max
= bookmarks
->total_count
- (bookmarks
->count
/ 2);
542 if (read_index
< bookmarks
->start
)
547 read_index
= index
- offset
/ 4;
549 if (read_index
> max
)
560 if (buffer_bookmarks(bookmarks
, read_index
) <= index
)
566 const int flags
= F_BMFILES
;
568 if (!parse_bookmark(bookmarks
->items
[index
- bookmarks
->start
], flags
))
570 return list_index
% 2 == 0 ? (char*) str(LANG_BOOKMARK_INVALID
) : " ";
573 if (list_index
% 2 == 0)
577 int len
= strlen(global_temp_buffer
);
579 if (bookmarks
->show_playlist_name
&& len
> 0)
581 name
= global_temp_buffer
;
584 if (name
[len
] != '/')
595 name
= strrsplt(name
, '/');
602 name
= global_filename
;
606 strrsplt(global_filename
, '.');
607 snprintf(buffer
, buffer_len
, format
, name
, global_filename
);
614 format_time(time_buf
, sizeof(time_buf
), bm
.resume_time
);
615 snprintf(buffer
, buffer_len
, "%s, %d%s", time_buf
, bm
.resume_index
+ 1,
616 bm
.shuffle
? (char*) str(LANG_BOOKMARK_SHUFFLE
) : "");
621 static int bookmark_list_voice_cb(int list_index
, void* data
)
623 struct bookmark_list
* bookmarks
= (struct bookmark_list
*) data
;
624 int index
= list_index
/ 2;
626 if (bookmarks
->show_dont_resume
)
629 return talk_id(LANG_BOOKMARK_DONT_RESUME
, false);
632 say_bookmark(bookmarks
->items
[index
- bookmarks
->start
], index
,
633 bookmarks
->show_playlist_name
);
637 /* ----------------------------------------------------------------------- */
638 /* This displays a the bookmarks in a file and allows the user to */
639 /* select one to play. */
640 /* ------------------------------------------------------------------------*/
641 static char* select_bookmark(const char* bookmark_file_name
, bool show_dont_resume
)
643 struct bookmark_list
* bookmarks
;
644 struct gui_synclist list
;
651 bookmarks
= plugin_get_buffer(&size
);
652 bookmarks
->buffer_size
= size
;
653 bookmarks
->show_dont_resume
= show_dont_resume
;
654 bookmarks
->filename
= bookmark_file_name
;
655 bookmarks
->start
= 0;
656 bookmarks
->show_playlist_name
657 = strcmp(bookmark_file_name
, RECENT_BOOKMARK_FILE
) == 0;
658 gui_synclist_init(&list
, &get_bookmark_info
, (void*) bookmarks
, false, 2, NULL
);
659 if(global_settings
.talk_menu
)
660 gui_synclist_set_voice_callback(&list
, bookmark_list_voice_cb
);
661 gui_synclist_set_title(&list
, str(LANG_BOOKMARK_SELECT_BOOKMARK
),
669 int count
= get_bookmark_count(bookmark_file_name
);
670 bookmarks
->total_count
= count
;
672 if (bookmarks
->total_count
< 1)
674 /* No more bookmarks, delete file and exit */
675 splash(HZ
, ID2P(LANG_BOOKMARK_LOAD_EMPTY
));
676 remove(bookmark_file_name
);
680 if (bookmarks
->show_dont_resume
)
686 gui_synclist_set_nb_items(&list
, count
* 2);
690 /* Selected item has been deleted */
692 gui_synclist_select_item(&list
, item
* 2);
695 buffer_bookmarks(bookmarks
, bookmarks
->start
);
696 gui_synclist_draw(&list
);
697 cond_talk_ids_fq(VOICE_EXT_BMARK
);
698 gui_synclist_speak_item(&list
);
702 list_do_action(CONTEXT_BOOKMARKSCREEN
, HZ
/ 2,
703 &list
, &action
, LIST_WRAP_UNLESS_HELD
);
704 item
= gui_synclist_get_sel_pos(&list
) / 2;
706 if (bookmarks
->show_dont_resume
)
711 if (action
== ACTION_STD_CONTEXT
)
713 MENUITEM_STRINGLIST(menu_items
, ID2P(LANG_BOOKMARK_CONTEXT_MENU
),
714 NULL
, ID2P(LANG_BOOKMARK_CONTEXT_RESUME
),
715 ID2P(LANG_BOOKMARK_CONTEXT_DELETE
));
716 static const int menu_actions
[] =
718 ACTION_STD_OK
, ACTION_BMS_DELETE
720 int selection
= do_menu(&menu_items
, NULL
, NULL
, false);
724 if (selection
>= 0 && selection
<=
725 (int) (sizeof(menu_actions
) / sizeof(menu_actions
[0])))
727 action
= menu_actions
[selection
];
737 return bookmarks
->items
[item
- bookmarks
->start
];
740 /* Else fall through */
742 case ACTION_TREE_WPS
:
743 case ACTION_STD_CANCEL
:
747 case ACTION_BMS_DELETE
:
750 const char *lines
[]={
751 ID2P(LANG_REALLY_DELETE
)
753 const char *yes_lines
[]={
757 const struct text_message message
={lines
, 1};
758 const struct text_message yes_message
={yes_lines
, 1};
760 if(gui_syncyesno_run(&message
, &yes_message
, NULL
)==YESNO_YES
)
762 delete_bookmark(bookmark_file_name
, item
);
763 bookmarks
->reload
= true;
770 if (default_event_handler(action
) == SYS_USB_CONNECTED
)
783 /* ----------------------------------------------------------------------- */
784 /* This function takes a location in a bookmark file and deletes that */
786 /* ------------------------------------------------------------------------*/
787 static bool delete_bookmark(const char* bookmark_file_name
, int bookmark_id
)
789 int temp_bookmark_file
= 0;
790 int bookmark_file
= 0;
791 int bookmark_count
= 0;
793 /* Opening up a temp bookmark file */
794 snprintf(global_temp_buffer
, sizeof(global_temp_buffer
),
795 "%s.tmp", bookmark_file_name
);
796 temp_bookmark_file
= open(global_temp_buffer
,
797 O_WRONLY
| O_CREAT
| O_TRUNC
);
799 if (temp_bookmark_file
< 0)
800 return false; /* can't open the temp file */
802 /* Reading in the previous bookmarks and writing them to the temp file */
803 bookmark_file
= open(bookmark_file_name
, O_RDONLY
);
804 if (bookmark_file
>= 0)
806 while (read_line(bookmark_file
, global_read_buffer
,
807 sizeof(global_read_buffer
)) > 0)
809 if (bookmark_id
!= bookmark_count
)
811 write(temp_bookmark_file
, global_read_buffer
,
812 strlen(global_read_buffer
));
813 write(temp_bookmark_file
, "\n", 1);
817 close(bookmark_file
);
819 close(temp_bookmark_file
);
821 remove(bookmark_file_name
);
822 rename(global_temp_buffer
, bookmark_file_name
);
827 /* ----------------------------------------------------------------------- */
828 /* This function parses a bookmark, says the voice UI part of it. */
829 /* ------------------------------------------------------------------------*/
830 static void say_bookmark(const char* bookmark
,
831 int bookmark_id
, bool show_playlist_name
)
835 const int flags
= F_BMFILES
;
837 if (!parse_bookmark(bookmark
, flags
))
839 talk_id(LANG_BOOKMARK_INVALID
, false);
843 talk_number(bookmark_id
+ 1, false);
845 is_dir
= (global_temp_buffer
[0]
846 && global_temp_buffer
[strlen(global_temp_buffer
)-1] == '/');
847 #if CONFIG_CODEC == SWCODEC
848 /* HWCODEC cannot enqueue voice file entries and .talk thumbnails
849 together, because there is no guarantee that the same mp3
850 parameters are used. */
851 if(show_playlist_name
)
852 { /* It's useful to know which playlist this is */
854 talk_dir_or_spell(global_temp_buffer
,
855 TALK_IDARRAY(VOICE_DIR
), true);
856 else talk_file_or_spell(NULL
, global_temp_buffer
,
857 TALK_IDARRAY(LANG_PLAYLIST
), true);
860 (void)show_playlist_name
;
864 talk_id(LANG_SHUFFLE
, true);
866 talk_id(VOICE_BOOKMARK_SELECT_INDEX_TEXT
, true);
867 talk_number(bm
.resume_index
+ 1, true);
868 talk_id(LANG_TIME
, true);
869 talk_value(bm
.resume_time
/ 1000, UNIT_TIME
, true);
871 #if CONFIG_CODEC == SWCODEC
874 talk_file_or_spell(global_temp_buffer
, global_filename
,
875 TALK_IDARRAY(VOICE_FILE
), true);
877 { /* Unfortunately if this is a playlist, we do not know in which
878 directory the file is and therefore cannot find the track's
880 talk_id(VOICE_FILE
, true);
881 talk_spell(global_filename
, true);
886 /* ----------------------------------------------------------------------- */
887 /* This function parses a bookmark and then plays it. */
888 /* ------------------------------------------------------------------------*/
889 static bool play_bookmark(const char* bookmark
)
891 const int flags
= F_BMFILES
;
893 if (parse_bookmark(bookmark
, flags
))
895 global_settings
.repeat_mode
= bm
.repeat_mode
;
896 global_settings
.playlist_shuffle
= bm
.shuffle
;
897 return bookmark_play(global_temp_buffer
, bm
.resume_index
,
898 bm
.resume_offset
, bm
.resume_seed
, global_filename
);
904 static const char* skip_token(const char* s
)
906 while (*s
&& *s
!= ';')
919 static const char* long_token(const char* s
, long* dest
)
921 *dest
= atoi(s
); /* Should be atol, but we don't have it. */
922 return skip_token(s
);
925 /* ----------------------------------------------------------------------- */
926 /* This function takes a bookmark and parses it. This function also */
927 /* validates the bookmark. Flags are set to indicate which bookmark */
928 /* tokens are to be processed. */
929 /* ----------------------------------------------------------------------- */
930 static bool parse_bookmark(const char *bookmark
, const int flags
)
932 const char* s
= bookmark
;
935 #define FLAG(a) (flags & a)
936 #define GET_INT_TOKEN(var) s = long_token(s, (long *)&var)
937 #define GET_BOOL_TOKEN(var) var = (atoi(s)!=0); s = skip_token(s)
939 GET_INT_TOKEN(bm
.resume_index
);
940 GET_INT_TOKEN(bm
.resume_offset
);
941 GET_INT_TOKEN(bm
.resume_seed
);
942 /* skip deprecated token */
944 GET_INT_TOKEN(bm
.resume_time
);
945 GET_INT_TOKEN(bm
.repeat_mode
);
946 GET_BOOL_TOKEN(bm
.shuffle
);
953 end
= strchr(s
, ';');
955 /* extract file names */
958 size_t len
= (end
== NULL
) ? strlen(s
) : (size_t) (end
- s
);
959 len
= MIN(TEMP_BUF_SIZE
- 1, len
);
960 strlcpy(global_temp_buffer
, s
, len
+ 1);
965 strlcpy(global_filename
, end
, MAX_PATH
);
972 /* ----------------------------------------------------------------------- */
973 /* This function is used by multiple functions and is used to generate a */
974 /* bookmark named based off of the input. */
975 /* Changing this function could result in how the bookmarks are stored. */
976 /* it would be here that the centralized/decentralized bookmark code */
977 /* could be placed. */
978 /* ----------------------------------------------------------------------- */
979 static bool generate_bookmark_file_name(const char *in
)
981 int len
= strlen(in
);
983 /* if this is a root dir MP3, rename the bookmark file root_dir.bmark */
984 /* otherwise, name it based on the in variable */
985 if (!strcmp("/", in
))
986 strcpy(global_bookmark_file_name
, "/root_dir.bmark");
989 #ifdef HAVE_MULTIVOLUME
990 /* The "root" of an extra volume need special handling too. */
991 bool volume_root
= (strip_volume(in
, global_bookmark_file_name
) &&
992 !strcmp("/", global_bookmark_file_name
));
995 strcpy(global_bookmark_file_name
, in
);
996 if(global_bookmark_file_name
[len
-1] == '/')
998 #ifdef HAVE_MULTIVOLUME
1000 strcpy(&global_bookmark_file_name
[len
], "/volume_dir.bmark");
1003 strcpy(&global_bookmark_file_name
[len
], ".bmark");
1009 /* ----------------------------------------------------------------------- */
1010 /* Returns true if a bookmark file exists for the current playlist */
1011 /* ----------------------------------------------------------------------- */
1012 bool bookmark_exist(void)
1018 char* name
= playlist_get_name(NULL
, global_temp_buffer
,
1019 sizeof(global_temp_buffer
));
1020 if (generate_bookmark_file_name(name
))
1022 exist
= file_exists(global_bookmark_file_name
);
1029 /* ----------------------------------------------------------------------- */
1030 /* Checks the current state of the system and returns true if it is in a */
1031 /* bookmarkable state. */
1032 /* ----------------------------------------------------------------------- */
1033 static bool system_check(void)
1035 int resume_index
= 0;
1037 if (!(audio_status() && audio_current_track()) ||
1038 /* no track playing */
1039 (playlist_get_resume_info(&resume_index
) == -1) ||
1040 /* invalid queue info */
1041 (playlist_modified(NULL
)))
1042 /* can't bookmark while in the queue */