summaryrefslogtreecommitdiff
path: root/apps/tree.c
diff options
context:
space:
mode:
Diffstat (limited to 'apps/tree.c')
-rw-r--r--apps/tree.c221
1 files changed, 75 insertions, 146 deletions
diff --git a/apps/tree.c b/apps/tree.c
index 8146b52ab2..6a4c97adc1 100644
--- a/apps/tree.c
+++ b/apps/tree.c
@@ -111,9 +111,9 @@ static bool start_wps = false;
111static int curr_context = false;/* id3db or tree*/ 111static int curr_context = false;/* id3db or tree*/
112 112
113static int dirbrowse(void); 113static int dirbrowse(void);
114static int ft_play_filenumber(int pos, int attr);
115static int ft_play_dirname(char* name); 114static int ft_play_dirname(char* name);
116static void ft_play_filename(char *dir, char *file); 115static void ft_play_filename(char *dir, char *file);
116static void say_filetype(int attr);
117 117
118/* 118/*
119 * removes the extension of filename (if it doesn't start with a .) 119 * removes the extension of filename (if it doesn't start with a .)
@@ -216,6 +216,69 @@ static int tree_get_fileicon(int selected_item, void * data)
216 } 216 }
217} 217}
218 218
219static int tree_voice_cb(int selected_item, void * data)
220{
221 struct tree_context * local_tc=(struct tree_context *)data;
222 char *name;
223 int attr=0;
224#ifdef HAVE_TAGCACHE
225 bool id3db = *(local_tc->dirfilter) == SHOW_ID3DB;
226
227 if (id3db)
228 {
229 attr = tagtree_get_attr(local_tc);
230 name = tagtree_get_entry(local_tc, selected_item)->name;
231 }
232 else
233#endif
234 {
235 struct entry* dc = local_tc->dircache;
236 struct entry* e = &dc[selected_item];
237 name = e->name;
238 attr = e->attr;
239 }
240 bool is_dir = (attr & ATTR_DIRECTORY);
241 bool did_clip = false;
242 /* First the .talk clip case */
243 if(is_dir)
244 {
245 if(global_settings.talk_dir_clip)
246 {
247 DEBUGF("Playing directory thumbnail: %s", local_tc->currdir);
248 did_clip = true;
249 if(ft_play_dirname(name) <0)
250 /* failed, not existing */
251 did_clip = false;
252 }
253 } else { /* it's a file */
254 if (global_settings.talk_file_clip && (attr & FILE_ATTR_THUMBNAIL))
255 {
256 did_clip = true;
257 DEBUGF("Playing file thumbnail: %s/%s%s\n",
258 local_tc->currdir, name, file_thumbnail_ext);
259 ft_play_filename(local_tc->currdir, name);
260 }
261 }
262 if(!did_clip)
263 {
264 /* say the number or spell if required or as a fallback */
265 switch (is_dir ? global_settings.talk_dir : global_settings.talk_file)
266 {
267 case 1: /* as numbers */
268 talk_id(is_dir ? VOICE_DIR : VOICE_FILE, false);
269 talk_number(selected_item+1 - (is_dir ? 0 : local_tc->dirsindir),
270 true);
271 if(!is_dir)
272 say_filetype(attr);
273 break;
274 case 2: /* spelled */
275 talk_spell(name, false);
276 break;
277 }
278 }
279 return 0;
280}
281
219bool check_rockboxdir(void) 282bool check_rockboxdir(void)
220{ 283{
221 DIR *dir = opendir(ROCKBOX_DIR); 284 DIR *dir = opendir(ROCKBOX_DIR);
@@ -255,6 +318,7 @@ void tree_gui_init(void)
255 gui_buttonbar_set_display(&tree_buttonbar, &(screens[SCREEN_MAIN]) ); 318 gui_buttonbar_set_display(&tree_buttonbar, &(screens[SCREEN_MAIN]) );
256#endif 319#endif
257 gui_synclist_init(&tree_lists, &tree_get_filename, &tc, false, 1); 320 gui_synclist_init(&tree_lists, &tree_get_filename, &tc, false, 1);
321 gui_synclist_set_voice_callback(&tree_lists, tree_voice_cb);
258 gui_synclist_set_icon_callback(&tree_lists, &tree_get_fileicon); 322 gui_synclist_set_icon_callback(&tree_lists, &tree_get_fileicon);
259#ifdef HAVE_LCD_COLOR 323#ifdef HAVE_LCD_COLOR
260 gui_list_set_color_callback(&tree_lists.gui_list[SCREEN_MAIN], 324 gui_list_set_color_callback(&tree_lists.gui_list[SCREEN_MAIN],
@@ -269,8 +333,6 @@ struct tree_context* tree_get_context(void)
269 return &tc; 333 return &tc;
270} 334}
271 335
272/* talkbox hovering delay, to avoid immediate disk activity */
273#define HOVER_DELAY (HZ/2)
274/* 336/*
275 * Returns the position of a given file in the current directory 337 * Returns the position of a given file in the current directory
276 * returns -1 if not found 338 * returns -1 if not found
@@ -424,6 +486,7 @@ static int update_dir(void)
424 } 486 }
425#endif 487#endif
426 gui_synclist_draw(&tree_lists); 488 gui_synclist_draw(&tree_lists);
489 gui_synclist_speak_item(&tree_lists);
427 gui_syncstatusbar_draw(&statusbars, true); 490 gui_syncstatusbar_draw(&statusbars, true);
428 return tc.filesindir; 491 return tc.filesindir;
429} 492}
@@ -551,14 +614,11 @@ static int dirbrowse()
551{ 614{
552 int numentries=0; 615 int numentries=0;
553 char buf[MAX_PATH]; 616 char buf[MAX_PATH];
554 int lasti = -1;
555 unsigned button, oldbutton; 617 unsigned button, oldbutton;
556 bool reload_root = false; 618 bool reload_root = false;
557 int lastfilter = *tc.dirfilter; 619 int lastfilter = *tc.dirfilter;
558 bool lastsortcase = global_settings.sort_case; 620 bool lastsortcase = global_settings.sort_case;
559 bool need_update = true;
560 bool exit_func = false; 621 bool exit_func = false;
561 long thumbnail_time = -1; /* for delaying a thumbnail */
562 622
563 char* currdir = tc.currdir; /* just a shortcut */ 623 char* currdir = tc.currdir; /* just a shortcut */
564#ifdef HAVE_TAGCACHE 624#ifdef HAVE_TAGCACHE
@@ -580,6 +640,7 @@ static int dirbrowse()
580 640
581 start_wps = false; 641 start_wps = false;
582 numentries = update_dir(); 642 numentries = update_dir();
643 reload_dir = false;
583 if (numentries == -1) 644 if (numentries == -1)
584 return GO_TO_PREVIOUS; /* currdir is not a directory */ 645 return GO_TO_PREVIOUS; /* currdir is not a directory */
585 646
@@ -604,9 +665,10 @@ static int dirbrowse()
604 boot_changed = false; 665 boot_changed = false;
605 } 666 }
606#endif 667#endif
607 button = get_action(CONTEXT_TREE,HZ/5); 668 button = get_action(CONTEXT_TREE,
669 list_do_action_timeout(&tree_lists, HZ/2));
608 oldbutton = button; 670 oldbutton = button;
609 need_update = gui_synclist_do_button(&tree_lists, &button,LIST_WRAP_UNLESS_HELD); 671 gui_synclist_do_button(&tree_lists, &button,LIST_WRAP_UNLESS_HELD);
610 tc.selected_item = gui_synclist_get_sel_pos(&tree_lists); 672 tc.selected_item = gui_synclist_get_sel_pos(&tree_lists);
611 switch ( button ) { 673 switch ( button ) {
612 case ACTION_STD_OK: 674 case ACTION_STD_OK:
@@ -750,57 +812,6 @@ static int dirbrowse()
750 } 812 }
751 813
752 case ACTION_NONE: 814 case ACTION_NONE:
753 if (thumbnail_time != -1 &&
754 TIME_AFTER(current_tick, thumbnail_time))
755 { /* a delayed hovering thumbnail is due now */
756 int res;
757 int attr;
758 char* name;
759
760#ifdef HAVE_TAGCACHE
761 if (id3db)
762 {
763 attr = tagtree_get_attr(&tc);
764 name = tagtree_get_entry(&tc, lasti)->name;
765 }
766 else
767#endif
768 {
769 attr = dircache[lasti].attr;
770 name = dircache[lasti].name;
771 }
772
773 if (attr & ATTR_DIRECTORY)
774 {
775 DEBUGF("Playing directory thumbnail: %s", currdir);
776 res = ft_play_dirname(name);
777 if (res < 0) /* failed, not existing */
778 {
779 /* say the number or spell if required as a fallback */
780 switch (global_settings.talk_dir)
781 {
782 case 1: /* dirs as numbers */
783 talk_id(VOICE_DIR, false);
784 talk_number(lasti+1, true);
785 break;
786
787 case 2: /* dirs spelled */
788 talk_spell(name, false);
789 break;
790 }
791 }
792 }
793 else
794 {
795 DEBUGF("Playing file thumbnail: %s/%s%s\n",
796 currdir, name,
797 file_thumbnail_ext);
798 /* no fallback necessary, we knew in advance
799 that the file exists */
800 ft_play_filename(currdir, name);
801 }
802 thumbnail_time = -1; /* job done */
803 }
804 gui_syncstatusbar_draw(&statusbars, false); 815 gui_syncstatusbar_draw(&statusbars, false);
805 break; 816 break;
806 817
@@ -872,87 +883,12 @@ static int dirbrowse()
872 if (restore || reload_dir) { 883 if (restore || reload_dir) {
873 /* restore display */ 884 /* restore display */
874 numentries = update_dir(); 885 numentries = update_dir();
886 reload_dir = false;
875 if (currdir[1] && (numentries < 0)) 887 if (currdir[1] && (numentries < 0))
876 { /* not in root and reload failed */ 888 { /* not in root and reload failed */
877 reload_root = true; /* try root */ 889 reload_root = true; /* try root */
878 reload_dir = false;
879 goto check_rescan; 890 goto check_rescan;
880 } 891 }
881 need_update = true;
882 reload_dir = false;
883 }
884
885 if(need_update) {
886 need_update=false;
887 if ( numentries > 0 ) {
888 /* Voice the file if changed */
889 if(lasti != tc.selected_item || restore) {
890 int attr;
891 char* name;
892
893 lasti = tc.selected_item;
894 thumbnail_time = -1; /* Cancel whatever we were
895 about to say */
896
897#ifdef HAVE_TAGCACHE
898 if (id3db)
899 {
900 attr = tagtree_get_attr(&tc);
901 name = tagtree_get_entry(&tc, tc.selected_item)->name;
902 }
903 else
904#endif
905 {
906 attr = dircache[tc.selected_item].attr;
907 name = dircache[tc.selected_item].name;
908 }
909
910 /* Directory? */
911 if (attr & ATTR_DIRECTORY)
912 {
913 /* schedule thumbnail playback if required */
914 if (global_settings.talk_dir_clip)
915 thumbnail_time = current_tick + HOVER_DELAY;
916 else
917 {
918 /* talk directly */
919 switch (global_settings.talk_dir)
920 {
921 case 1: /* dirs as numbers */
922 talk_id(VOICE_DIR, false);
923 talk_number(tc.selected_item+1, true);
924 break;
925
926 case 2: /* dirs spelled */
927 talk_spell(name, false);
928 break;
929 }
930 }
931 }
932 else /* file */
933 {
934 /* schedule thumbnail playback if required */
935 if (global_settings.talk_file_clip && (attr & FILE_ATTR_THUMBNAIL))
936 thumbnail_time = current_tick + HOVER_DELAY;
937 else
938 {
939 /* talk directly */
940 switch (global_settings.talk_file)
941 {
942 case 1: /* files as numbers */
943 ft_play_filenumber(
944 tc.selected_item-tc.dirsindir+1,
945 attr & FILE_ATTR_MASK);
946 break;
947
948 case 2: /* files spelled */
949 talk_spell(name, false);
950 break;
951 }
952 }
953 }
954 }
955 }
956 } 892 }
957 } 893 }
958 return true; 894 return true;
@@ -1226,24 +1162,17 @@ void bookmark_play(char *resume_file, int index, int offset, int seed,
1226 start_wps=true; 1162 start_wps=true;
1227} 1163}
1228 1164
1229static int ft_play_filenumber(int pos, int attr) 1165static void say_filetype(int attr)
1230{ 1166{
1231 /* try to find a voice ID for the extension, if known */ 1167 /* try to find a voice ID for the extension, if known */
1232 int j; 1168 int j;
1233 int ext_id = -1; /* default to none */ 1169 attr &= FILE_ATTR_MASK; /* file type */
1234 for (j=0; j<filetypes_count; j++) 1170 for (j=0; j<filetypes_count; j++)
1235 {
1236 if (attr == filetypes[j].tree_attr) 1171 if (attr == filetypes[j].tree_attr)
1237 { 1172 {
1238 ext_id = filetypes[j].voiceclip; 1173 talk_id(filetypes[j].voiceclip, true);
1239 break; 1174 return;
1240 } 1175 }
1241 }
1242
1243 talk_id(VOICE_FILE, false);
1244 talk_number(pos, true);
1245 talk_id(ext_id, true);
1246 return 1;
1247} 1176}
1248 1177
1249static int ft_play_dirname(char* name) 1178static int ft_play_dirname(char* name)