summaryrefslogtreecommitdiff
path: root/apps/tree.c
diff options
context:
space:
mode:
Diffstat (limited to 'apps/tree.c')
-rw-r--r--apps/tree.c237
1 files changed, 71 insertions, 166 deletions
diff --git a/apps/tree.c b/apps/tree.c
index 78fb1db76d..f830e3eb26 100644
--- a/apps/tree.c
+++ b/apps/tree.c
@@ -79,6 +79,7 @@
79#include "textarea.h" 79#include "textarea.h"
80#include "action.h" 80#include "action.h"
81 81
82#include "root_menu.h"
82 83
83#if LCD_DEPTH > 1 84#if LCD_DEPTH > 1
84#include "backdrop.h" 85#include "backdrop.h"
@@ -160,9 +161,10 @@ static int max_files = 0;
160static bool reload_dir = false; 161static bool reload_dir = false;
161 162
162static bool start_wps = false; 163static bool start_wps = false;
163static bool dirbrowse(void);
164static int curr_context = false;/* id3db or tree*/ 164static int curr_context = false;/* id3db or tree*/
165 165
166int dirbrowse(void);
167
166/* 168/*
167 * removes the extension of filename (if it doesn't start with a .) 169 * removes the extension of filename (if it doesn't start with a .)
168 * puts the result in buffer 170 * puts the result in buffer
@@ -272,13 +274,8 @@ void browse_root(void)
272 gui_synclist_init(&tree_lists, &tree_get_filename, &tc, false, 1); 274 gui_synclist_init(&tree_lists, &tree_get_filename, &tc, false, 1);
273 gui_synclist_set_icon_callback(&tree_lists, 275 gui_synclist_set_icon_callback(&tree_lists,
274 global_settings.show_icons?&tree_get_fileicon:NULL); 276 global_settings.show_icons?&tree_get_fileicon:NULL);
275#ifndef SIMULATOR 277 /* not the best place for this call... but... */
276 dirbrowse(); 278 root_menu();
277#else
278 if (!dirbrowse()) {
279 DEBUGF("No filesystem found. Have you forgotten to create it?\n");
280 }
281#endif
282} 279}
283 280
284void tree_get_filetypes(const struct filetype** types, int* count) 281void tree_get_filetypes(const struct filetype** types, int* count)
@@ -478,54 +475,6 @@ void reload_directory(void)
478 reload_dir = true; 475 reload_dir = true;
479} 476}
480 477
481static void start_resume(bool just_powered_on)
482{
483 bool do_resume = false;
484 if ( global_status.resume_index != -1 ) {
485 DEBUGF("Resume index %X offset %X\n",
486 global_status.resume_index,
487 global_status.resume_offset);
488
489#ifdef HAVE_RTC_ALARM
490 if ( rtc_check_alarm_started(true) ) {
491 rtc_enable_alarm(false);
492 do_resume = true;
493 }
494#endif
495
496 /* always resume? */
497 if ( global_settings.resume || ! just_powered_on)
498#ifdef HAVE_HEADPHONE_DETECTION
499 {
500 if ( just_powered_on )
501 {
502 if ( !global_settings.unplug_autoresume
503 || headphones_inserted() )
504 do_resume = true;
505 }
506 else
507 do_resume = true;
508 }
509#else
510 do_resume = true;
511#endif
512
513 if (! do_resume) return;
514
515 if (playlist_resume() != -1)
516 {
517 playlist_start(global_status.resume_index,
518 global_status.resume_offset);
519
520 start_wps = true;
521 }
522 else return;
523 }
524 else if (! just_powered_on) {
525 gui_syncsplash(HZ*2, true, str(LANG_NOTHING_TO_RESUME));
526 }
527}
528
529/* Selects a file and update tree context properly */ 478/* Selects a file and update tree context properly */
530void set_current_file(char *path) 479void set_current_file(char *path)
531{ 480{
@@ -568,10 +517,7 @@ void set_current_file(char *path)
568 tc.selected_item_history[tc.dirlevel] = -1; 517 tc.selected_item_history[tc.dirlevel] = -1;
569 518
570 /* use '/' to calculate dirlevel */ 519 /* use '/' to calculate dirlevel */
571 /* FIXME : strlen(path) : crazy oO better to store it at 520 for (i = 1; path[i] != '\0'; i++)
572 the beginning */
573 int path_len = strlen(path) + 1;
574 for (i = 1; i < path_len; i++)
575 { 521 {
576 if (path[i] == '/') 522 if (path[i] == '/')
577 { 523 {
@@ -580,9 +526,13 @@ void set_current_file(char *path)
580 } 526 }
581 } 527 }
582 } 528 }
529 if (ft_load(&tc, NULL) >= 0)
530 {
531 tc.selected_item = tree_get_file_position(lastfile);
532 }
583} 533}
584 534
585#ifdef HAVE_TAGCACHE 535#if defined(HAVE_TAGCACHE) && defined(HAVE_QUICKSCREEN)
586static bool check_changed_id3mode(bool currmode) 536static bool check_changed_id3mode(bool currmode)
587{ 537{
588 if (currmode != (global_settings.dirfilter == SHOW_ID3DB)) { 538 if (currmode != (global_settings.dirfilter == SHOW_ID3DB)) {
@@ -605,7 +555,7 @@ static bool check_changed_id3mode(bool currmode)
605#endif 555#endif
606 556
607/* main loop, handles key events */ 557/* main loop, handles key events */
608static bool dirbrowse(void) 558int dirbrowse()
609{ 559{
610 int numentries=0; 560 int numentries=0;
611 char buf[MAX_PATH]; 561 char buf[MAX_PATH];
@@ -627,8 +577,8 @@ static bool dirbrowse(void)
627 else 577 else
628#endif 578#endif
629 curr_context=CONTEXT_TREE; 579 curr_context=CONTEXT_TREE;
630 tc.selected_item = 0; 580 if (tc.selected_item < 0)
631 tc.dirlevel=0; 581 tc.selected_item = 0;
632#ifdef HAVE_TAGCACHE 582#ifdef HAVE_TAGCACHE
633 tc.firstpos=0; 583 tc.firstpos=0;
634 lasttable = -1; 584 lasttable = -1;
@@ -636,43 +586,22 @@ static bool dirbrowse(void)
636 lastfirstpos = 0; 586 lastfirstpos = 0;
637#endif 587#endif
638 588
639 if (*tc.dirfilter < NUM_FILTER_MODES) { 589 start_wps = false;
640#ifdef HAVE_RECORDING 590 numentries = update_dir();
641#ifndef SIMULATOR 591 if (numentries == -1)
642 if (global_settings.rec_startup) { 592 return false; /* currdir is not a directory */
643 /* We fake being in the menu structure by calling
644 the appropriate parent when we drop out of each screen */
645#if CONFIG_CODEC == SWCODEC
646 /* Put in a 1 sec pause to slow bootup or the recording codecs
647 won't initialize */
648 sleep(HZ);
649#endif
650 recording_screen(false);
651 rec_menu();
652 main_menu();
653 }
654 else
655#endif
656#endif
657 start_resume(true);
658
659 }
660 /* If we don't need to show the wps, draw the dir */
661 if (!start_wps) {
662 numentries = update_dir();
663 if (numentries == -1)
664 return false; /* currdir is not a directory */
665 593
666 if (*tc.dirfilter > NUM_FILTER_MODES && numentries==0) 594 if (*tc.dirfilter > NUM_FILTER_MODES && numentries==0)
667 { 595 {
668 gui_syncsplash(HZ*2, true, str(LANG_NO_FILES)); 596 gui_syncsplash(HZ*2, true, str(LANG_NO_FILES));
669 return false; /* No files found for rockbox_browser() */ 597 return false; /* No files found for rockbox_browser() */
670 }
671 } 598 }
672 599
673 while(1) { 600 while(1) {
674 struct entry *dircache = tc.dircache; 601 struct entry *dircache = tc.dircache;
675 bool restore = false; 602 bool restore = false;
603 if (tc.dirlevel < 0)
604 tc.dirlevel = 0; /* shouldnt be needed.. this code needs work! */
676#ifdef BOOTFILE 605#ifdef BOOTFILE
677 if (boot_changed) { 606 if (boot_changed) {
678 char *lines[]={str(LANG_BOOT_CHANGED), str(LANG_REBOOT_NOW)}; 607 char *lines[]={str(LANG_BOOT_CHANGED), str(LANG_REBOOT_NOW)};
@@ -715,10 +644,12 @@ static bool dirbrowse(void)
715 exit_func = true; 644 exit_func = true;
716 break; 645 break;
717 } 646 }
718 /* if we are in /, nothing to do */ 647 if ((*tc.dirfilter == SHOW_ID3DB && tc.dirlevel == 0) ||
719 if (tc.dirlevel == 0 && !strcmp(currdir,"/")) 648 ((*tc.dirfilter != SHOW_ID3DB && !strcmp(currdir,"/"))))
720 break; 649 {
721 650 break; /* do nothing */
651 }
652
722#ifdef HAVE_TAGCACHE 653#ifdef HAVE_TAGCACHE
723 if (id3db) 654 if (id3db)
724 tagtree_exit(&tc); 655 tagtree_exit(&tc);
@@ -772,37 +703,17 @@ static bool dirbrowse(void)
772 /* don't enter menu from plugin browser */ 703 /* don't enter menu from plugin browser */
773 if (*tc.dirfilter < NUM_FILTER_MODES) 704 if (*tc.dirfilter < NUM_FILTER_MODES)
774 { 705 {
775 int i; 706 return GO_TO_ROOT;
776 FOR_NB_SCREENS(i)
777 screens[i].stop_scroll();
778 action_signalscreenchange();
779 if (main_menu())
780 reload_dir = true;
781 restore = true;
782
783#ifdef HAVE_TAGCACHE
784 id3db = check_changed_id3mode(id3db);
785 if(id3db)
786 reload_dir = true;
787#endif
788 } 707 }
789 else /* use it as a quick exit instead */ 708 else /* use it as a quick exit instead */
790 exit_func = true; 709 return GO_TO_PREVIOUS;
791 break; 710 break;
792 711
793 case ACTION_TREE_WPS: 712 case ACTION_TREE_WPS:
794 /* don't enter wps from plugin browser etc */ 713 /* don't enter wps from plugin browser etc */
795 if (*tc.dirfilter < NUM_FILTER_MODES) 714 if (*tc.dirfilter < NUM_FILTER_MODES)
796 { 715 {
797 if (audio_status() & AUDIO_STATUS_PLAY) 716 return GO_TO_PREVIOUS_MUSIC;
798 {
799 start_wps=true;
800 }
801 else
802 {
803 start_resume(false);
804 restore = true;
805 }
806 } 717 }
807 break; 718 break;
808#ifdef HAVE_QUICKSCREEN 719#ifdef HAVE_QUICKSCREEN
@@ -869,6 +780,9 @@ static bool dirbrowse(void)
869 } 780 }
870 switch (onplay_result) 781 switch (onplay_result)
871 { 782 {
783 case ONPLAY_MAINMENU:
784 return GO_TO_ROOT;
785
872 case ONPLAY_OK: 786 case ONPLAY_OK:
873 restore = true; 787 restore = true;
874 break; 788 break;
@@ -878,7 +792,7 @@ static bool dirbrowse(void)
878 break; 792 break;
879 793
880 case ONPLAY_START_PLAY: 794 case ONPLAY_START_PLAY:
881 start_wps = true; 795 return GO_TO_WPS;
882 break; 796 break;
883 } 797 }
884 break; 798 break;
@@ -952,37 +866,13 @@ static bool dirbrowse(void)
952 } 866 }
953 break; 867 break;
954 } 868 }
955 869 if (start_wps)
870 return GO_TO_WPS;
956 if ( button ) 871 if ( button )
957 { 872 {
958 ata_spin(); 873 ata_spin();
959 } 874 }
960 875
961 if (start_wps && audio_status() )
962 {
963 int i;
964
965 FOR_NB_SCREENS(i)
966 screens[i].stop_scroll();
967
968 if (gui_wps_show() == SYS_USB_CONNECTED)
969 reload_dir = true;
970#ifdef HAVE_HOTSWAP
971 else
972#ifdef HAVE_TAGCACHE
973 if (!id3db) /* Try reload to catch 'no longer valid' case. */
974#endif
975 reload_dir = true;
976#endif
977#if LCD_DEPTH > 1
978 show_main_backdrop();
979#endif
980#ifdef HAVE_TAGCACHE
981 id3db = check_changed_id3mode(id3db);
982#endif
983 restore = true;
984 start_wps=false;
985 }
986 876
987 check_rescan: 877 check_rescan:
988 /* do we need to rescan dir? */ 878 /* do we need to rescan dir? */
@@ -1016,7 +906,7 @@ static bool dirbrowse(void)
1016 } 906 }
1017 907
1018 if (exit_func) 908 if (exit_func)
1019 break; 909 return GO_TO_PREVIOUS;
1020 910
1021 if (restore || reload_dir) { 911 if (restore || reload_dir) {
1022 /* restore display */ 912 /* restore display */
@@ -1252,24 +1142,39 @@ bool create_playlist(void)
1252 return true; 1142 return true;
1253} 1143}
1254 1144
1255bool rockbox_browse(const char *root, int dirfilter) 1145int rockbox_browse(const char *root, int dirfilter)
1256{ 1146{
1257 static struct tree_context backup; 1147 int ret_val = 0;
1258 int last_context; 1148 int *last_filter = tc.dirfilter;
1259
1260 backup = tc;
1261 reload_dir = true;
1262 memcpy(tc.currdir, root, sizeof(tc.currdir));
1263 start_wps = false;
1264 tc.dirfilter = &dirfilter; 1149 tc.dirfilter = &dirfilter;
1265 last_context = curr_context;
1266 1150
1267 dirbrowse(); 1151 reload_dir = true;
1268 1152 if (dirfilter >= NUM_FILTER_MODES)
1269 tc = backup; 1153 {
1270 curr_context = last_context; 1154 static struct tree_context backup;
1271 1155 int last_context;
1272 return false; 1156
1157 backup = tc;
1158 tc.dirlevel = 0;
1159 memcpy(tc.currdir, root, sizeof(tc.currdir));
1160 start_wps = false;
1161 last_context = curr_context;
1162
1163 ret_val = dirbrowse();
1164 tc = backup;
1165 curr_context = last_context;
1166 }
1167 else
1168 {
1169 static char buf[MAX_PATH];
1170 if (dirfilter != SHOW_ID3DB)
1171 tc.dirfilter = &global_settings.dirfilter;
1172 strcpy(buf,root);
1173 set_current_file(buf);
1174 ret_val = dirbrowse();
1175 }
1176 tc.dirfilter = last_filter;
1177 return ret_val;
1273} 1178}
1274 1179
1275void tree_init(void) 1180void tree_init(void)