1 /***************************************************************************
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
10 * Copyright (C) 2002 Daniel Stenberg
12 * All files in this archive are subject to the GNU General Public License.
13 * See the file COPYING in the source tree root for full license agreement.
15 * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
16 * KIND, either express or implied.
18 ****************************************************************************/
24 #include "applimits.h"
29 #include "backlight.h"
34 #include "main_menu.h"
57 #include "filetypes.h"
62 #include "recorder/recording.h"
70 #include "gwps-common.h"
71 #include "eeprom_settings.h"
72 #include "scrobbler.h"
76 #include "statusbar.h"
78 #include "buttonbar.h"
82 #include "root_menu.h"
88 /* a table for the know file types */
89 const struct filetype filetypes
[] = {
90 { "mp3", TREE_ATTR_MPA
, Icon_Audio
, VOICE_EXT_MPA
},
91 { "mp2", TREE_ATTR_MPA
, Icon_Audio
, VOICE_EXT_MPA
},
92 { "mpa", TREE_ATTR_MPA
, Icon_Audio
, VOICE_EXT_MPA
},
93 #if CONFIG_CODEC == SWCODEC
94 /* Temporary hack to allow playlist creation */
95 { "mp1", TREE_ATTR_MPA
, Icon_Audio
, VOICE_EXT_MPA
},
96 { "ogg", TREE_ATTR_MPA
, Icon_Audio
, VOICE_EXT_MPA
},
97 { "wma", TREE_ATTR_MPA
, Icon_Audio
, VOICE_EXT_MPA
},
98 { "wav", TREE_ATTR_MPA
, Icon_Audio
, VOICE_EXT_MPA
},
99 { "flac",TREE_ATTR_MPA
, Icon_Audio
, VOICE_EXT_MPA
},
100 { "ac3", TREE_ATTR_MPA
, Icon_Audio
, VOICE_EXT_MPA
},
101 { "a52", TREE_ATTR_MPA
, Icon_Audio
, VOICE_EXT_MPA
},
102 { "mpc", TREE_ATTR_MPA
, Icon_Audio
, VOICE_EXT_MPA
},
103 { "wv", TREE_ATTR_MPA
, Icon_Audio
, VOICE_EXT_MPA
},
104 { "m4a", TREE_ATTR_MPA
, Icon_Audio
, VOICE_EXT_MPA
},
105 { "m4b", TREE_ATTR_MPA
, Icon_Audio
, VOICE_EXT_MPA
},
106 { "mp4", TREE_ATTR_MPA
, Icon_Audio
, VOICE_EXT_MPA
},
107 { "shn", TREE_ATTR_MPA
, Icon_Audio
, VOICE_EXT_MPA
},
108 { "aif", TREE_ATTR_MPA
, Icon_Audio
, VOICE_EXT_MPA
},
109 { "aiff",TREE_ATTR_MPA
, Icon_Audio
, VOICE_EXT_MPA
},
110 { "spx" ,TREE_ATTR_MPA
, Icon_Audio
, VOICE_EXT_MPA
},
111 { "sid", TREE_ATTR_MPA
, Icon_Audio
, VOICE_EXT_MPA
},
112 { "adx", TREE_ATTR_MPA
, Icon_Audio
, VOICE_EXT_MPA
},
113 { "nsf", TREE_ATTR_MPA
, Icon_Audio
, VOICE_EXT_MPA
},
114 { "nsfe", TREE_ATTR_MPA
, Icon_Audio
, VOICE_EXT_MPA
},
115 { "spc", TREE_ATTR_MPA
, Icon_Audio
, VOICE_EXT_MPA
},
117 { "m3u", TREE_ATTR_M3U
, Icon_Playlist
, LANG_PLAYLIST
},
118 { "m3u8", TREE_ATTR_M3U
, Icon_Playlist
, LANG_PLAYLIST
},
119 { "cfg", TREE_ATTR_CFG
, Icon_Config
, VOICE_EXT_CFG
},
120 { "wps", TREE_ATTR_WPS
, Icon_Wps
, VOICE_EXT_WPS
},
121 #ifdef HAVE_REMOTE_LCD
122 { "rwps", TREE_ATTR_RWPS
, Icon_Wps
, VOICE_EXT_RWPS
},
125 { "bmp", TREE_ATTR_BMP
, Icon_Wps
, VOICE_EXT_WPS
},
128 { "fmr", TREE_ATTR_FMR
, Icon_Preset
, LANG_FMR
},
130 { "lng", TREE_ATTR_LNG
, Icon_Language
, LANG_LANGUAGE
},
131 { "rock",TREE_ATTR_ROCK
,Icon_Plugin
, VOICE_EXT_ROCK
},
132 #ifdef HAVE_LCD_BITMAP
133 { "fnt", TREE_ATTR_FONT
,Icon_Font
, VOICE_EXT_FONT
},
134 { "kbd", TREE_ATTR_KBD
, Icon_Keyboard
, VOICE_EXT_KBD
},
136 { "bmark",TREE_ATTR_BMARK
, Icon_Bookmark
, VOICE_EXT_BMARK
},
137 { "cue", TREE_ATTR_CUE
, Icon_Bookmark
, LANG_CUESHEET
},
139 { BOOTFILE_EXT
, TREE_ATTR_MOD
, Icon_Firmware
, VOICE_EXT_AJZ
},
140 #endif /* #ifndef SIMULATOR */
143 struct gui_synclist tree_lists
;
145 /* I put it here because other files doesn't use it yet,
146 * but should be elsewhere since it will be used mostly everywhere */
148 struct gui_buttonbar tree_buttonbar
;
150 static struct tree_context tc
;
152 bool boot_changed
= false;
154 char lastfile
[MAX_PATH
];
155 static char lastdir
[MAX_PATH
];
157 static int lasttable
, lastextra
, lastfirstpos
;
159 static int max_files
= 0;
161 static bool reload_dir
= false;
163 static bool start_wps
= false;
164 static int curr_context
= false;/* id3db or tree*/
169 * removes the extension of filename (if it doesn't start with a .)
170 * puts the result in buffer
172 static char * strip_extension(char * filename
, char * buffer
)
175 char * dot
=strrchr(filename
, '.');
176 if(dot
!=0 && filename
[0]!='.')
178 dotpos
= dot
-filename
;
179 strncpy(buffer
, filename
, dotpos
);
187 static char * tree_get_filename(int selected_item
, void * data
, char *buffer
)
189 struct tree_context
* local_tc
=(struct tree_context
*)data
;
193 bool id3db
= *(local_tc
->dirfilter
) == SHOW_ID3DB
;
197 return tagtree_get_entry(&tc
, selected_item
)->name
;
202 struct entry
* dc
= local_tc
->dircache
;
203 struct entry
* e
= &dc
[selected_item
];
207 /* if any file filter is on, and if it's not a directory,
208 * strip the extension */
210 if ( (*(local_tc
->dirfilter
) != SHOW_ID3DB
) && !(attr
& ATTR_DIRECTORY
)
211 && (*(local_tc
->dirfilter
) != SHOW_ALL
) )
213 return(strip_extension(name
, buffer
));
219 static void tree_get_fileicon(int selected_item
, void * data
, ICON
* icon
)
221 struct tree_context
* local_tc
=(struct tree_context
*)data
;
223 bool id3db
= *(local_tc
->dirfilter
) == SHOW_ID3DB
;
225 *icon
= (ICON
)tagtree_get_icon(&tc
);
230 struct entry
* dc
= local_tc
->dircache
;
231 struct entry
* e
= &dc
[selected_item
];
232 *icon
= (ICON
)filetype_get_icon(e
->attr
);
236 bool check_rockboxdir(void)
238 DIR *dir
= opendir(ROCKBOX_DIR
);
240 { /* No need to localise this message.
241 If .rockbox is missing, it wouldn't work anyway */
244 screens
[i
].clear_display();
245 gui_syncsplash(HZ
*2, true, "No .rockbox directory");
247 screens
[i
].clear_display();
248 gui_syncsplash(HZ
*2, true, "Installation incomplete");
255 void browse_root(void)
257 gui_sync_wps_screen_init();
262 strcpy(tc
.currdir
, "/");
264 #ifdef HAVE_LCD_CHARCELLS
267 screens
[i
].double_height(false);
270 gui_buttonbar_init(&tree_buttonbar
);
271 /* since archos only have one screen, no need to create more than that */
272 gui_buttonbar_set_display(&tree_buttonbar
, &(screens
[SCREEN_MAIN
]) );
274 gui_synclist_init(&tree_lists
, &tree_get_filename
, &tc
, false, 1);
275 gui_synclist_set_icon_callback(&tree_lists
, &tree_get_fileicon
);
276 /* not the best place for this call... but... */
280 void tree_get_filetypes(const struct filetype
** types
, int* count
)
283 *count
= sizeof(filetypes
) / sizeof(*filetypes
);
286 struct tree_context
* tree_get_context(void)
291 /* talkbox hovering delay, to avoid immediate disk activity */
292 #define HOVER_DELAY (HZ/2)
294 * Returns the position of a given file in the current directory
295 * returns -1 if not found
297 static int tree_get_file_position(char * filename
)
301 /* use lastfile to determine the selected item (default=0) */
302 for (i
=0; i
< tc
.filesindir
; i
++)
304 struct entry
* dc
= tc
.dircache
;
305 struct entry
* e
= &dc
[i
];
306 if (!strcasecmp(e
->name
, filename
))
309 return(-1);/* no file can match, returns undefined */
313 * Called when a new dir is loaded (for example when returning from other apps ...)
314 * also completely redraws the tree
316 static int update_dir(void)
318 bool changed
= false;
320 bool id3db
= *tc
.dirfilter
== SHOW_ID3DB
;
321 /* Checks for changes */
323 if (tc
.currtable
!= lasttable
||
324 tc
.currextra
!= lastextra
||
325 tc
.firstpos
!= lastfirstpos
||
328 if (tagtree_load(&tc
) < 0)
331 lasttable
= tc
.currtable
;
332 lastextra
= tc
.currextra
;
333 lastfirstpos
= tc
.firstpos
;
340 /* if the tc.currdir has been changed, reload it ...*/
341 if (strncmp(tc
.currdir
, lastdir
, sizeof(lastdir
)) || reload_dir
) {
343 if (ft_load(&tc
, NULL
) < 0)
345 strcpy(lastdir
, tc
.currdir
);
349 /* if selected item is undefined */
350 if (tc
.selected_item
== -1)
352 /* use lastfile to determine the selected item */
353 tc
.selected_item
= tree_get_file_position(lastfile
);
355 /* If the file doesn't exists, select the first one (default) */
356 if(tc
.selected_item
< 0)
357 tc
.selected_item
= 0;
367 tc
.filesindir
== global_settings
.max_files_in_dir
) )
369 gui_syncsplash(HZ
, true, str(LANG_SHOWDIR_BUFFER_FULL
));
375 if (global_settings
.show_path_in_browser
== SHOW_PATH_FULL
376 || global_settings
.show_path_in_browser
== SHOW_PATH_CURRENT
)
378 gui_synclist_set_title(&tree_lists
, tagtree_get_title(&tc
),
379 filetype_get_icon(ATTR_DIRECTORY
));
383 /* Must clear the title as the list is reused */
384 gui_synclist_set_title(&tree_lists
, NULL
, NOICON
);
390 if (global_settings
.show_path_in_browser
== SHOW_PATH_FULL
)
392 gui_synclist_set_title(&tree_lists
, tc
.currdir
,
393 filetype_get_icon(ATTR_DIRECTORY
));
395 else if (global_settings
.show_path_in_browser
== SHOW_PATH_CURRENT
)
397 char *title
= strrchr(tc
.currdir
, '/') + 1;
400 /* Display "Files" for the root dir */
401 gui_synclist_set_title(&tree_lists
, str(LANG_DIR_BROWSER
),
402 filetype_get_icon(ATTR_DIRECTORY
));
405 gui_synclist_set_title(&tree_lists
, title
,
406 filetype_get_icon(ATTR_DIRECTORY
));
410 /* Must clear the title as the list is reused */
411 gui_synclist_set_title(&tree_lists
, NULL
, NOICON
);
415 gui_synclist_set_nb_items(&tree_lists
, tc
.filesindir
);
416 gui_synclist_set_icon_callback(&tree_lists
, tree_get_fileicon
);
417 if( tc
.selected_item
>= tc
.filesindir
)
418 tc
.selected_item
=tc
.filesindir
-1;
420 gui_synclist_select_item(&tree_lists
, tc
.selected_item
);
422 if (global_settings
.buttonbar
) {
423 if (*tc
.dirfilter
< NUM_FILTER_MODES
)
424 gui_buttonbar_set(&tree_buttonbar
, str(LANG_SYSFONT_DIRBROWSE_F1
),
425 str(LANG_SYSFONT_DIRBROWSE_F2
),
426 str(LANG_SYSFONT_DIRBROWSE_F3
));
428 gui_buttonbar_set(&tree_buttonbar
, "<<<", "", "");
429 gui_buttonbar_draw(&tree_buttonbar
);
432 gui_synclist_draw(&tree_lists
);
433 gui_syncstatusbar_draw(&statusbars
, true);
434 return tc
.filesindir
;
437 /* load tracks from specified directory to resume play */
438 void resume_directory(const char *dir
)
441 bool id3db
= *tc
.dirfilter
== SHOW_ID3DB
;
444 if (ft_load(&tc
, dir
) < 0)
448 ft_build_playlist(&tc
, 0);
456 /* Returns the current working directory and also writes cwd to buf if
457 non-NULL. In case of error, returns NULL. */
458 char *getcwd(char *buf
, int size
)
464 strncpy(buf
, tc
.currdir
, size
);
471 /* Force a reload of the directory next time directory browser is called */
472 void reload_directory(void)
477 void get_current_file(char* buffer
, int buffer_len
)
480 /* in ID3DB mode it is a bad idea to call this function */
481 /* (only happens with `follow playlist') */
482 if( *tc
.dirfilter
== SHOW_ID3DB
)
486 struct entry
* dc
= tc
.dircache
;
487 struct entry
* e
= &dc
[tc
.selected_item
];
488 snprintf(buffer
, buffer_len
, "%s/%s", getcwd(NULL
,0),
492 /* Selects a file and update tree context properly */
493 void set_current_file(char *path
)
499 /* in ID3DB mode it is a bad idea to call this function */
500 /* (only happens with `follow playlist') */
501 if( *tc
.dirfilter
== SHOW_ID3DB
)
505 /* separate directory from filename */
506 /* gets the directory's name and put it into tc.currdir */
507 name
= strrchr(path
+1,'/');
511 strcpy(tc
.currdir
, path
);
517 strcpy(tc
.currdir
, "/");
521 strcpy(lastfile
, name
);
524 /* If we changed dir we must recalculate the dirlevel
525 and adjust the selected history properly */
526 if (strncmp(tc
.currdir
,lastdir
,sizeof(lastdir
)))
529 tc
.selected_item_history
[tc
.dirlevel
] = -1;
531 /* use '/' to calculate dirlevel */
532 for (i
= 1; path
[i
] != '\0'; i
++)
537 tc
.selected_item_history
[tc
.dirlevel
] = -1;
541 if (ft_load(&tc
, NULL
) >= 0)
543 tc
.selected_item
= tree_get_file_position(lastfile
);
547 #if defined(HAVE_TAGCACHE) && defined(HAVE_QUICKSCREEN)
548 static bool check_changed_id3mode(bool currmode
)
550 if (currmode
!= (global_settings
.dirfilter
== SHOW_ID3DB
)) {
551 currmode
= global_settings
.dirfilter
== SHOW_ID3DB
;
553 curr_context
=CONTEXT_ID3DB
;
560 curr_context
=CONTEXT_TREE
;
569 /* main loop, handles key events */
575 unsigned button
, returned_button
;
576 bool reload_root
= false;
577 int lastfilter
= *tc
.dirfilter
;
578 bool lastsortcase
= global_settings
.sort_case
;
579 bool need_update
= true;
580 bool exit_func
= false;
581 long thumbnail_time
= -1; /* for delaying a thumbnail */
582 long last_cancel
= 0;
584 char* currdir
= tc
.currdir
; /* just a shortcut */
586 bool id3db
= *tc
.dirfilter
== SHOW_ID3DB
;
589 curr_context
=CONTEXT_ID3DB
;
592 curr_context
=CONTEXT_TREE
;
593 if (tc
.selected_item
< 0)
594 tc
.selected_item
= 0;
603 numentries
= update_dir();
604 if (numentries
== -1)
605 return false; /* currdir is not a directory */
607 if (*tc
.dirfilter
> NUM_FILTER_MODES
&& numentries
==0)
609 gui_syncsplash(HZ
*2, true, str(LANG_NO_FILES
));
610 return false; /* No files found for rockbox_browser() */
614 struct entry
*dircache
= tc
.dircache
;
615 bool restore
= false;
617 tc
.dirlevel
= 0; /* shouldnt be needed.. this code needs work! */
620 char *lines
[]={str(LANG_BOOT_CHANGED
), str(LANG_REBOOT_NOW
)};
621 struct text_message message
={lines
, 2};
622 if(gui_syncyesno_run(&message
, NULL
, NULL
)==YESNO_YES
)
623 rolo_load("/" BOOTFILE
);
625 boot_changed
= false;
628 button
= get_action(CONTEXT_TREE
,HZ
/5);
629 returned_button
= gui_synclist_do_button(&tree_lists
, button
,LIST_WRAP_UNLESS_HELD
);
632 if (returned_button
== ACTION_STD_CANCEL
)
633 button
= ACTION_STD_CANCEL
;
637 /* nothing to do if no files to display */
638 if ( numentries
== 0 )
642 switch (id3db
?tagtree_enter(&tc
):ft_enter(&tc
))
644 switch (ft_enter(&tc
))
647 case 1: reload_dir
= true; break;
648 case 2: start_wps
= true; break;
649 case 3: exit_func
= true; break;
655 case ACTION_STD_CANCEL
:
656 if (*tc
.dirfilter
> NUM_FILTER_MODES
&& tc
.dirlevel
< 1) {
660 if ((*tc
.dirfilter
== SHOW_ID3DB
&& tc
.dirlevel
== 0) ||
661 ((*tc
.dirfilter
!= SHOW_ID3DB
&& !strcmp(currdir
,"/"))))
663 if (last_cancel
&& TIME_BEFORE(current_tick
, last_cancel
+HZ
/2))
666 action_signalscreenchange(); /* eat the cancel presses */
672 last_cancel
= current_tick
;
679 if (ft_exit(&tc
) == 3)
685 case ACTION_TREE_STOP
:
686 if (*tc
.dirfilter
< NUM_FILTER_MODES
)
688 /* Stop the music if it is playing */
690 if (!global_settings
.party_mode
) {
691 if (global_settings
.fade_on_stop
)
693 bookmark_autobookmark();
697 #if CONFIG_CHARGING && \
698 (CONFIG_KEYPAD == RECORDER_PAD) && !defined(HAVE_SW_POWEROFF)
700 if (!charger_inserted()) {
701 if(shutdown_screen())
710 #if CONFIG_CHARGING && !defined(HAVE_POWEROFF_WHILE_CHARGING)
712 static int last_off
= 0;
713 if (current_tick
- last_off
< 50) {
714 if (charger_inserted()) {
719 last_off
= current_tick
;
722 break; /* case ACTION_TREE_STOP: */
723 case ACTION_STD_MENU
:
727 case ACTION_TREE_WPS
:
728 return GO_TO_PREVIOUS_MUSIC
;
730 #ifdef HAVE_QUICKSCREEN
731 case ACTION_STD_QUICKSCREEN
:
732 /* don't enter f2 from plugin browser */
733 if (*tc
.dirfilter
< NUM_FILTER_MODES
)
735 if (quick_screen_quick(button
))
740 id3db
= check_changed_id3mode(id3db
);
748 /* don't enter f3 from plugin browser */
749 if (*tc
.dirfilter
< NUM_FILTER_MODES
)
751 if (quick_screen_f3(BUTTON_F3
))
758 case ACTION_STD_CONTEXT
:
764 onplay_result
= onplay(NULL
, 0, curr_context
);
769 if (tagtree_get_attr(&tc
) == TREE_ATTR_MPA
)
771 attr
= TREE_ATTR_MPA
;
772 tagtree_get_filename(&tc
, buf
, sizeof(buf
));
775 attr
= ATTR_DIRECTORY
;
780 attr
= dircache
[tc
.selected_item
].attr
;
782 if (currdir
[1]) /* Not in / */
783 snprintf(buf
, sizeof buf
, "%s/%s",
785 dircache
[tc
.selected_item
].name
);
787 snprintf(buf
, sizeof buf
, "/%s",
788 dircache
[tc
.selected_item
].name
);
790 onplay_result
= onplay(buf
, attr
, curr_context
);
792 switch (onplay_result
)
794 case ONPLAY_MAINMENU
:
801 case ONPLAY_RELOAD_DIR
:
805 case ONPLAY_START_PLAY
:
813 if (thumbnail_time
!= -1 &&
814 TIME_AFTER(current_tick
, thumbnail_time
))
815 { /* a delayed hovering thumbnail is due now */
823 attr
= tagtree_get_attr(&tc
);
824 name
= tagtree_get_entry(&tc
, lasti
)->name
;
829 attr
= dircache
[lasti
].attr
;
830 name
= dircache
[lasti
].name
;
833 if (attr
& ATTR_DIRECTORY
)
835 DEBUGF("Playing directory thumbnail: %s", currdir
);
836 res
= ft_play_dirname(name
);
837 if (res
< 0) /* failed, not existing */
838 { /* say the number instead, as a fallback */
839 talk_id(VOICE_DIR
, false);
840 talk_number(lasti
+1, true);
845 DEBUGF("Playing file thumbnail: %s/%s%s\n",
848 /* no fallback necessary, we knew in advance
849 that the file exists */
850 ft_play_filename(currdir
, name
);
852 thumbnail_time
= -1; /* job done */
854 gui_syncstatusbar_draw(&statusbars
, false);
863 /* The 'dir no longer valid' situation will be caught later
864 * by checking the showdir() result. */
869 if (default_event_handler(button
) == SYS_USB_CONNECTED
)
871 if(*tc
.dirfilter
> NUM_FILTER_MODES
)
872 /* leave sub-browsers after usb, doing otherwise
873 might be confusing to the user */
889 /* do we need to rescan dir? */
890 if (reload_dir
|| reload_root
||
891 lastfilter
!= *tc
.dirfilter
||
892 lastsortcase
!= global_settings
.sort_case
)
895 strcpy(currdir
, "/");
908 gui_synclist_select_item(&tree_lists
, 0);
909 gui_synclist_draw(&tree_lists
);
910 tc
.selected_item
= 0;
914 lastfilter
= *tc
.dirfilter
;
915 lastsortcase
= global_settings
.sort_case
;
920 return GO_TO_PREVIOUS
;
922 if (restore
|| reload_dir
) {
923 /* restore display */
924 numentries
= update_dir();
925 if (currdir
[1] && (numentries
< 0))
926 { /* not in root and reload failed */
927 reload_root
= true; /* try root */
936 tc
.selected_item
= gui_synclist_get_sel_pos(&tree_lists
);
938 if ( numentries
> 0 ) {
939 /* Voice the file if changed */
940 if(lasti
!= tc
.selected_item
|| restore
) {
944 lasti
= tc
.selected_item
;
945 thumbnail_time
= -1; /* Cancel whatever we were
951 attr
= tagtree_get_attr(&tc
);
952 name
= tagtree_get_entry(&tc
, tc
.selected_item
)->name
;
957 attr
= dircache
[tc
.selected_item
].attr
;
958 name
= dircache
[tc
.selected_item
].name
;
962 if (attr
& ATTR_DIRECTORY
)
964 /* play directory thumbnail */
965 switch (global_settings
.talk_dir
) {
966 case 1: /* dirs as numbers */
967 talk_id(VOICE_DIR
, false);
968 talk_number(tc
.selected_item
+1, true);
971 case 2: /* dirs spelled */
972 talk_spell(name
, false);
975 case 3: /* thumbnail clip */
976 /* "schedule" a thumbnail, to have a little
978 thumbnail_time
= current_tick
+ HOVER_DELAY
;
987 switch (global_settings
.talk_file
) {
988 case 1: /* files as numbers */
990 tc
.selected_item
-tc
.dirsindir
+1,
991 attr
& TREE_ATTR_MASK
);
994 case 2: /* files spelled */
995 talk_spell(name
, false);
998 case 3: /* thumbnail clip */
999 /* "schedule" a thumbnail, to have a little
1001 if (attr
& TREE_ATTR_THUMBNAIL
)
1002 thumbnail_time
= current_tick
+ HOVER_DELAY
;
1004 /* spell the number as fallback */
1005 talk_spell(name
, false);
1016 action_signalscreenchange();
1020 static int plsize
= 0;
1022 static bool add_dir(char* dirname
, int len
, int fd
)
1027 /* check for user abort */
1028 if (action_userabort(TIMEOUT_NOBLOCK
))
1031 dir
= opendir_cached(dirname
);
1036 struct dircache_entry
*entry
;
1038 entry
= readdir_cached(dir
);
1041 if (entry
->attribute
& ATTR_DIRECTORY
) {
1042 int dirlen
= strlen(dirname
);
1045 if (!strcmp((char *)entry
->d_name
, ".") ||
1046 !strcmp((char *)entry
->d_name
, ".."))
1050 snprintf(dirname
+dirlen
, len
-dirlen
, "/%s", entry
->d_name
);
1052 snprintf(dirname
, len
, "/%s", entry
->d_name
);
1054 result
= add_dir(dirname
, len
, fd
);
1055 dirname
[dirlen
] = '\0';
1062 int x
= strlen((char *)entry
->d_name
);
1064 char *cp
= strrchr((char *)entry
->d_name
,'.');
1069 /* add all supported audio files to playlists */
1070 for (i
=0; i
< sizeof(filetypes
)/sizeof(struct filetype
); i
++) {
1071 if (filetypes
[i
].tree_attr
== TREE_ATTR_MPA
) {
1072 if (!strcasecmp(cp
, filetypes
[i
].extension
)) {
1075 write(fd
, dirname
, strlen(dirname
));
1077 write(fd
, entry
->d_name
, x
);
1081 if(TIME_AFTER(current_tick
, pltick
+HZ
/4)) {
1082 pltick
= current_tick
;
1084 snprintf(buf
, sizeof buf
, "%d", plsize
);
1085 #ifdef HAVE_LCD_BITMAP
1088 screens
[i
].puts(0, 4, (unsigned char *)buf
);
1089 gui_textarea_update(&screens
[i
]);
1104 screens
[i
].puts(x
,0,buf
);
1115 closedir_cached(dir
);
1120 bool create_playlist(void)
1124 char filename
[MAX_PATH
];
1126 pltick
= current_tick
;
1128 snprintf(filename
, sizeof filename
, "%s.m3u8",
1129 tc
.currdir
[1] ? tc
.currdir
: "/root");
1132 gui_textarea_clear(&screens
[i
]);
1133 screens
[i
].puts(0, 0, str(LANG_CREATING
));
1134 screens
[i
].puts_scroll(0, 1, (unsigned char *)filename
);
1135 #if defined(HAVE_LCD_BITMAP) || defined(SIMULATOR)
1136 gui_textarea_update(&screens
[i
]);
1139 fd
= creat(filename
);
1143 trigger_cpu_boost();
1145 snprintf(filename
, sizeof(filename
), "%s",
1146 tc
.currdir
[1] ? tc
.currdir
: "/");
1148 add_dir(filename
, sizeof(filename
), fd
);
1156 int rockbox_browse(const char *root
, int dirfilter
)
1159 int *last_filter
= tc
.dirfilter
;
1160 tc
.dirfilter
= &dirfilter
;
1163 if (dirfilter
>= NUM_FILTER_MODES
)
1165 static struct tree_context backup
;
1169 tc
.selected_item
= 0;
1171 memcpy(tc
.currdir
, root
, sizeof(tc
.currdir
));
1173 last_context
= curr_context
;
1175 ret_val
= dirbrowse();
1177 curr_context
= last_context
;
1181 static char buf
[MAX_PATH
];
1182 if (dirfilter
!= SHOW_ID3DB
)
1183 tc
.dirfilter
= &global_settings
.dirfilter
;
1185 set_current_file(buf
);
1186 ret_val
= dirbrowse();
1188 tc
.dirfilter
= last_filter
;
1192 void tree_init(void)
1194 /* We copy the settings value in case it is changed by the user. We can't
1195 use it until the next reboot. */
1196 max_files
= global_settings
.max_files_in_dir
;
1198 /* initialize tree context struct */
1199 memset(&tc
, 0, sizeof(tc
));
1200 tc
.dirfilter
= &global_settings
.dirfilter
;
1202 tc
.name_buffer_size
= AVERAGE_FILENAME_LENGTH
* max_files
;
1203 tc
.name_buffer
= buffer_alloc(tc
.name_buffer_size
);
1205 tc
.dircache_size
= max_files
* sizeof(struct entry
);
1206 tc
.dircache
= buffer_alloc(tc
.dircache_size
);
1209 void bookmark_play(char *resume_file
, int index
, int offset
, int seed
,
1213 char* suffix
= strrchr(resume_file
, '.');
1215 if (suffix
!= NULL
&&
1216 (!strcasecmp(suffix
, ".m3u") || !strcasecmp(suffix
, ".m3u8")))
1218 /* Playlist playback */
1220 /* check that the file exists */
1221 int fd
= open(resume_file
, O_RDONLY
);
1226 slash
= strrchr(resume_file
,'/');
1236 if (playlist_create(cp
, slash
+1) != -1)
1238 if (global_settings
.playlist_shuffle
)
1239 playlist_shuffle(seed
, -1);
1240 playlist_start(index
,offset
);
1247 /* Directory playback */
1249 if (playlist_create(resume_file
, NULL
) != -1)
1251 resume_directory(resume_file
);
1252 if (global_settings
.playlist_shuffle
)
1253 playlist_shuffle(seed
, -1);
1255 /* Check if the file is at the same spot in the directory,
1256 else search for it */
1257 if ((strcmp(strrchr(playlist_peek(index
),'/') + 1,
1260 for ( i
=0; i
< playlist_amount(); i
++ )
1262 if ((strcmp(strrchr(playlist_peek(i
),'/') + 1,
1266 if (i
< playlist_amount())
1271 playlist_start(index
,offset
);
1278 int ft_play_filenumber(int pos
, int attr
)
1280 /* try to find a voice ID for the extension, if known */
1282 int ext_id
= -1; /* default to none */
1283 for (j
=0; j
<sizeof(filetypes
)/sizeof(*filetypes
); j
++)
1285 if (attr
== filetypes
[j
].tree_attr
)
1287 ext_id
= filetypes
[j
].voiceclip
;
1292 talk_id(VOICE_FILE
, false);
1293 talk_number(pos
, true);
1294 talk_id(ext_id
, true);
1298 int ft_play_dirname(char* name
)
1301 char dirname_mp3_filename
[MAX_PATH
+1];
1303 #if CONFIG_CODEC != SWCODEC
1304 if (audio_status() & AUDIO_STATUS_PLAY
)
1308 snprintf(dirname_mp3_filename
, sizeof(dirname_mp3_filename
), "%s/%s/%s",
1309 tc
.currdir
[1] ? tc
.currdir
: "" , name
,
1310 dir_thumbnail_name
);
1312 DEBUGF("Checking for %s\n", dirname_mp3_filename
);
1314 fd
= open(dirname_mp3_filename
, O_RDONLY
);
1317 DEBUGF("Failed to find: %s\n", dirname_mp3_filename
);
1323 DEBUGF("Found: %s\n", dirname_mp3_filename
);
1325 talk_file(dirname_mp3_filename
, false);
1329 void ft_play_filename(char *dir
, char *file
)
1331 char name_mp3_filename
[MAX_PATH
+1];
1333 #if CONFIG_CODEC != SWCODEC
1334 if (audio_status() & AUDIO_STATUS_PLAY
)
1338 if (strcasecmp(&file
[strlen(file
) - strlen(file_thumbnail_ext
)],
1339 file_thumbnail_ext
))
1340 { /* file has no .talk extension */
1341 snprintf(name_mp3_filename
, sizeof(name_mp3_filename
),
1342 "%s/%s%s", dir
, file
, file_thumbnail_ext
);
1344 talk_file(name_mp3_filename
, false);
1347 { /* it already is a .talk file, play this directly */
1348 snprintf(name_mp3_filename
, sizeof(name_mp3_filename
),
1349 "%s/%s", dir
, file
);
1350 talk_id(LANG_VOICE_DIR_HOVER
, false); /* prefix it */
1351 talk_file(name_mp3_filename
, true);
1355 /* These two functions are called by the USB and shutdown handlers */
1356 void tree_flush(void)
1358 scrobbler_shutdown();
1359 #ifdef HAVE_TAGCACHE
1360 tagcache_shutdown();
1362 playlist_shutdown();
1364 #ifdef HAVE_TC_RAMCACHE
1365 tagcache_unload_ramcache();
1368 #ifdef HAVE_DIRCACHE
1370 int old_val
= global_status
.dircache_size
;
1371 if (global_settings
.dircache
)
1373 global_status
.dircache_size
= dircache_get_cache_size();
1374 # ifdef HAVE_EEPROM_SETTINGS
1381 global_status
.dircache_size
= 0;
1383 if (old_val
!= global_status
.dircache_size
)
1389 void tree_restore(void)
1391 #ifdef HAVE_EEPROM_SETTINGS
1392 firmware_settings
.disk_clean
= false;
1395 #ifdef HAVE_TC_RAMCACHE
1396 remove(TAGCACHE_STATEFILE
);
1399 #ifdef HAVE_DIRCACHE
1400 remove(DIRCACHE_FILE
);
1401 if (global_settings
.dircache
)
1403 /* Print "Scanning disk..." to the display. */
1407 screens
[i
].putsxy((LCD_WIDTH
/2) -
1408 ((strlen(str(LANG_DIRCACHE_BUILDING
)) *
1409 screens
[i
].char_width
)/2),
1410 LCD_HEIGHT
-screens
[i
].char_height
*3,
1411 str(LANG_DIRCACHE_BUILDING
));
1412 gui_textarea_update(&screens
[i
]);
1415 dircache_build(global_status
.dircache_size
);
1417 /* Clean the text when we are done. */
1420 gui_textarea_clear(&screens
[i
]);
1424 #ifdef HAVE_TAGCACHE
1425 tagcache_start_scan();