summaryrefslogtreecommitdiff
path: root/apps/tree.c
diff options
context:
space:
mode:
Diffstat (limited to 'apps/tree.c')
-rw-r--r--apps/tree.c119
1 files changed, 73 insertions, 46 deletions
diff --git a/apps/tree.c b/apps/tree.c
index c755c9550a..4deb2890a0 100644
--- a/apps/tree.c
+++ b/apps/tree.c
@@ -78,19 +78,20 @@ static int cursorpos[MAX_DIR_LEVELS];
78static char lastdir[MAX_PATH]; 78static char lastdir[MAX_PATH];
79static char lastfile[MAX_PATH]; 79static char lastfile[MAX_PATH];
80static char currdir[MAX_PATH]; 80static char currdir[MAX_PATH];
81static char currdir_save[MAX_PATH];
81static bool reload_dir = false; 82static bool reload_dir = false;
82static int boot_size = 0; 83static int boot_size = 0;
83static int boot_cluster; 84static int boot_cluster;
84static bool boot_changed = false; 85static bool boot_changed = false;
85 86
86static bool dirbrowse(char *root); 87static bool dirbrowse(char *root, int *dirfilter);
87 88
88void browse_root(void) 89void browse_root(void)
89{ 90{
90#ifndef SIMULATOR 91#ifndef SIMULATOR
91 dirbrowse("/"); 92 dirbrowse("/", &global_settings.dirfilter);
92#else 93#else
93 if (!dirbrowse("/")) { 94 if (!dirbrowse("/", &global_settings.dirfilter)) {
94 DEBUGF("No filesystem found. Have you forgotten to create it?\n"); 95 DEBUGF("No filesystem found. Have you forgotten to create it?\n");
95 } 96 }
96#endif 97#endif
@@ -189,7 +190,7 @@ static int compare(const void* p1, const void* p2)
189 return ( e2->attr & ATTR_DIRECTORY ) - ( e1->attr & ATTR_DIRECTORY ); 190 return ( e2->attr & ATTR_DIRECTORY ) - ( e1->attr & ATTR_DIRECTORY );
190} 191}
191 192
192static void showfileline(int line, int direntry, bool scroll) 193static void showfileline(int line, int direntry, bool scroll, int *dirfilter)
193{ 194{
194 char* name = dircache[direntry].name; 195 char* name = dircache[direntry].name;
195 int xpos = LINE_X; 196 int xpos = LINE_X;
@@ -200,7 +201,7 @@ static void showfileline(int line, int direntry, bool scroll)
200#endif 201#endif
201 202
202 /* if any file filter is on, strip the extension */ 203 /* if any file filter is on, strip the extension */
203 if (global_settings.dirfilter != SHOW_ALL && 204 if (*dirfilter != SHOW_ALL &&
204 !(dircache[direntry].attr & ATTR_DIRECTORY)) 205 !(dircache[direntry].attr & ATTR_DIRECTORY))
205 { 206 {
206 char* dotpos = strrchr(name, '.'); 207 char* dotpos = strrchr(name, '.');
@@ -235,7 +236,7 @@ static void showfileline(int line, int direntry, bool scroll)
235} 236}
236 237
237/* load sorted directory into dircache. returns NULL on failure. */ 238/* load sorted directory into dircache. returns NULL on failure. */
238struct entry* load_and_sort_directory(char *dirname, int dirfilter, 239struct entry* load_and_sort_directory(char *dirname, int *dirfilter,
239 int *num_files, bool *buffer_full) 240 int *num_files, bool *buffer_full)
240{ 241{
241 int i; 242 int i;
@@ -273,7 +274,7 @@ struct entry* load_and_sort_directory(char *dirname, int dirfilter,
273 } 274 }
274 275
275 /* filter out dotfiles and hidden files */ 276 /* filter out dotfiles and hidden files */
276 if (dirfilter != SHOW_ALL && 277 if (*dirfilter != SHOW_ALL &&
277 ((entry->d_name[0]=='.') || 278 ((entry->d_name[0]=='.') ||
278 (entry->attribute & ATTR_HIDDEN))) { 279 (entry->attribute & ATTR_HIDDEN))) {
279 i--; 280 i--;
@@ -322,25 +323,19 @@ struct entry* load_and_sort_directory(char *dirname, int dirfilter,
322 boot_cluster = entry->startcluster; 323 boot_cluster = entry->startcluster;
323 } 324 }
324 325
325 /* filter out all non-playlist files */ 326 /* filter out non-visible files */
326 if ( dirfilter == SHOW_PLAYLIST && 327 if ((*dirfilter == SHOW_PLAYLIST &&
327 (!(dptr->attr & 328 !(dptr->attr & (ATTR_DIRECTORY|TREE_ATTR_M3U))) ||
328 (ATTR_DIRECTORY|TREE_ATTR_M3U))) ) { 329 (*dirfilter == SHOW_MUSIC &&
329 i--; 330 !(dptr->attr & (ATTR_DIRECTORY|TREE_ATTR_MPA|TREE_ATTR_M3U))) ||
330 continue; 331 (*dirfilter == SHOW_SUPPORTED && !(dptr->attr & TREE_ATTR_MASK)) ||
331 } 332 (*dirfilter == SHOW_WPS && !(dptr->attr & TREE_ATTR_WPS)) ||
332 333 (*dirfilter == SHOW_CFG && !(dptr->attr & TREE_ATTR_CFG)) ||
333 /* filter out non-music files */ 334 (*dirfilter == SHOW_LNG && !(dptr->attr & TREE_ATTR_LNG)) ||
334 if ( dirfilter == SHOW_MUSIC && 335 (*dirfilter == SHOW_MOD && !(dptr->attr & TREE_ATTR_MOD)) ||
335 (!(dptr->attr & 336 (*dirfilter == SHOW_FONT && !(dptr->attr & TREE_ATTR_FONT)) ||
336 (ATTR_DIRECTORY|TREE_ATTR_MPA|TREE_ATTR_M3U))) ) { 337 (*dirfilter == SHOW_PLUGINS && !(dptr->attr & TREE_ATTR_ROCK)))
337 i--; 338 {
338 continue;
339 }
340
341 /* filter out non-supported files */
342 if ( dirfilter == SHOW_SUPPORTED &&
343 (!(dptr->attr & TREE_ATTR_MASK)) ) {
344 i--; 339 i--;
345 continue; 340 continue;
346 } 341 }
@@ -363,7 +358,7 @@ struct entry* load_and_sort_directory(char *dirname, int dirfilter,
363 return dircache; 358 return dircache;
364} 359}
365 360
366static int showdir(char *path, int start) 361static int showdir(char *path, int start, int *dirfilter)
367{ 362{
368 int icon_type = 0; 363 int icon_type = 0;
369 int i; 364 int i;
@@ -383,7 +378,7 @@ static int showdir(char *path, int start)
383 378
384 /* new dir? cache it */ 379 /* new dir? cache it */
385 if (strncmp(path,lastdir,sizeof(lastdir)) || reload_dir) { 380 if (strncmp(path,lastdir,sizeof(lastdir)) || reload_dir) {
386 if (!load_and_sort_directory(path, global_settings.dirfilter, 381 if (!load_and_sort_directory(path, dirfilter,
387 &filesindir, &dir_buffer_full)) 382 &filesindir, &dir_buffer_full))
388 return -1; 383 return -1;
389 384
@@ -534,7 +529,7 @@ static int showdir(char *path, int start)
534#endif 529#endif
535 } 530 }
536 531
537 showfileline(i-start, i, false); /* no scroll */ 532 showfileline(i-start, i, false, dirfilter); /* no scroll */
538 } 533 }
539 534
540#ifdef HAVE_LCD_BITMAP 535#ifdef HAVE_LCD_BITMAP
@@ -606,7 +601,7 @@ void resume_directory(char *dir)
606{ 601{
607 bool buffer_full; 602 bool buffer_full;
608 603
609 if (!load_and_sort_directory(dir, global_settings.dirfilter, &filesindir, 604 if (!load_and_sort_directory(dir, &global_settings.dirfilter, &filesindir,
610 &buffer_full)) 605 &buffer_full))
611 return; 606 return;
612 lastdir[0] = 0; 607 lastdir[0] = 0;
@@ -704,7 +699,7 @@ void set_current_file(char *path)
704 } 699 }
705} 700}
706 701
707static bool handle_on(int* ds, int* dc, int numentries, int tree_max_on_screen) 702static bool handle_on(int *ds, int *dc, int numentries, int tree_max_on_screen, int *dirfilter)
708{ 703{
709 bool exit = false; 704 bool exit = false;
710 bool used = false; 705 bool used = false;
@@ -789,7 +784,7 @@ static bool handle_on(int* ds, int* dc, int numentries, int tree_max_on_screen)
789#ifdef HAVE_LCD_BITMAP 784#ifdef HAVE_LCD_BITMAP
790 int xpos,ypos; 785 int xpos,ypos;
791#endif 786#endif
792 showdir(currdir, dirstart); 787 showdir(currdir, dirstart, dirfilter);
793#ifdef HAVE_LCD_BITMAP 788#ifdef HAVE_LCD_BITMAP
794 if (global_settings.invert_cursor) { 789 if (global_settings.invert_cursor) {
795 xpos = lcd_getxmargin(); 790 xpos = lcd_getxmargin();
@@ -808,7 +803,7 @@ static bool handle_on(int* ds, int* dc, int numentries, int tree_max_on_screen)
808 return used; 803 return used;
809} 804}
810 805
811static bool dirbrowse(char *root) 806static bool dirbrowse(char *root, int *dirfilter)
812{ 807{
813 int numentries=0; 808 int numentries=0;
814 char buf[MAX_PATH]; 809 char buf[MAX_PATH];
@@ -817,11 +812,11 @@ static bool dirbrowse(char *root)
817 int button; 812 int button;
818 int tree_max_on_screen; 813 int tree_max_on_screen;
819 bool reload_root = false; 814 bool reload_root = false;
820 int lastfilter = global_settings.dirfilter; 815 int lastfilter = *dirfilter;
821 bool lastsortcase = global_settings.sort_case; 816 bool lastsortcase = global_settings.sort_case;
822 int lastdircursor=-1; 817 int lastdircursor=-1;
823 bool need_update = true; 818 bool need_update = true;
824 819 bool exit_func = false;
825 bool update_all = false; /* set this to true when the whole file list 820 bool update_all = false; /* set this to true when the whole file list
826 has been refreshed on screen */ 821 has been refreshed on screen */
827 822
@@ -839,9 +834,10 @@ static bool dirbrowse(char *root)
839 834
840 memcpy(currdir,root,sizeof(currdir)); 835 memcpy(currdir,root,sizeof(currdir));
841 836
837 if (*dirfilter < NUM_FILTER_MODES)
842 start_resume(true); 838 start_resume(true);
843 839
844 numentries = showdir(currdir, dirstart); 840 numentries = showdir(currdir, dirstart, dirfilter);
845 if (numentries == -1) 841 if (numentries == -1)
846 return false; /* currdir is not a directory */ 842 return false; /* currdir is not a directory */
847 update_all = true; 843 update_all = true;
@@ -899,6 +895,8 @@ static bool dirbrowse(char *root)
899 895
900 restore = true; 896 restore = true;
901 } 897 }
898 if (*dirfilter > NUM_FILTER_MODES)
899 exit_func = true;
902 break; 900 break;
903 901
904#ifdef HAVE_RECORDER_KEYPAD 902#ifdef HAVE_RECORDER_KEYPAD
@@ -1083,6 +1081,8 @@ static bool dirbrowse(char *root)
1083 tree_max_on_screen = (LCD_HEIGHT - MARGIN_Y) / fh; 1081 tree_max_on_screen = (LCD_HEIGHT - MARGIN_Y) / fh;
1084#endif 1082#endif
1085 } 1083 }
1084 else if (*dirfilter > NUM_FILTER_MODES)
1085 exit_func = true;
1086 } 1086 }
1087 restore = true; 1087 restore = true;
1088 break; 1088 break;
@@ -1099,7 +1099,7 @@ static bool dirbrowse(char *root)
1099 else { 1099 else {
1100 if (dirstart) { 1100 if (dirstart) {
1101 dirstart--; 1101 dirstart--;
1102 numentries = showdir(currdir, dirstart); 1102 numentries = showdir(currdir, dirstart, dirfilter);
1103 update_all=true; 1103 update_all=true;
1104 put_cursorxy(CURSOR_X, CURSOR_Y + dircursor, true); 1104 put_cursorxy(CURSOR_X, CURSOR_Y + dircursor, true);
1105 } 1105 }
@@ -1114,7 +1114,7 @@ static bool dirbrowse(char *root)
1114 else { 1114 else {
1115 dirstart = numentries - tree_max_on_screen; 1115 dirstart = numentries - tree_max_on_screen;
1116 dircursor = tree_max_on_screen - 1; 1116 dircursor = tree_max_on_screen - 1;
1117 numentries = showdir(currdir, dirstart); 1117 numentries = showdir(currdir, dirstart, dirfilter);
1118 update_all = true; 1118 update_all = true;
1119 put_cursorxy(CURSOR_X, CURSOR_Y + 1119 put_cursorxy(CURSOR_X, CURSOR_Y +
1120 tree_max_on_screen - 1, true); 1120 tree_max_on_screen - 1, true);
@@ -1138,7 +1138,7 @@ static bool dirbrowse(char *root)
1138 } 1138 }
1139 else { 1139 else {
1140 dirstart++; 1140 dirstart++;
1141 numentries = showdir(currdir, dirstart); 1141 numentries = showdir(currdir, dirstart, dirfilter);
1142 update_all = true; 1142 update_all = true;
1143 put_cursorxy(CURSOR_X, CURSOR_Y + dircursor, true); 1143 put_cursorxy(CURSOR_X, CURSOR_Y + dircursor, true);
1144 } 1144 }
@@ -1151,7 +1151,7 @@ static bool dirbrowse(char *root)
1151 } 1151 }
1152 else { 1152 else {
1153 dirstart = dircursor = 0; 1153 dirstart = dircursor = 0;
1154 numentries = showdir(currdir, dirstart); 1154 numentries = showdir(currdir, dirstart, dirfilter);
1155 update_all=true; 1155 update_all=true;
1156 put_cursorxy(CURSOR_X, CURSOR_Y + dircursor, true); 1156 put_cursorxy(CURSOR_X, CURSOR_Y + dircursor, true);
1157 } 1157 }
@@ -1169,7 +1169,7 @@ static bool dirbrowse(char *root)
1169 1169
1170 case BUTTON_ON: 1170 case BUTTON_ON:
1171 if (handle_on(&dirstart, &dircursor, numentries, 1171 if (handle_on(&dirstart, &dircursor, numentries,
1172 tree_max_on_screen)) 1172 tree_max_on_screen, dirfilter))
1173 { 1173 {
1174 /* start scroll */ 1174 /* start scroll */
1175 restore = true; 1175 restore = true;
@@ -1228,7 +1228,7 @@ static bool dirbrowse(char *root)
1228 1228
1229 /* do we need to rescan dir? */ 1229 /* do we need to rescan dir? */
1230 if (reload_dir || reload_root || 1230 if (reload_dir || reload_root ||
1231 lastfilter != global_settings.dirfilter || 1231 lastfilter != *dirfilter ||
1232 lastsortcase != global_settings.sort_case) 1232 lastsortcase != global_settings.sort_case)
1233 { 1233 {
1234 if ( reload_root ) { 1234 if ( reload_root ) {
@@ -1242,11 +1242,15 @@ static bool dirbrowse(char *root)
1242 dirstart = 0; 1242 dirstart = 0;
1243 lastdir[0] = 0; 1243 lastdir[0] = 0;
1244 } 1244 }
1245 lastfilter = global_settings.dirfilter; 1245
1246 lastfilter = *dirfilter;
1246 lastsortcase = global_settings.sort_case; 1247 lastsortcase = global_settings.sort_case;
1247 restore = true; 1248 restore = true;
1248 } 1249 }
1249 1250
1251 if (exit_func)
1252 break;
1253
1250 if (restore || reload_dir) { 1254 if (restore || reload_dir) {
1251 /* restore display */ 1255 /* restore display */
1252 1256
@@ -1262,7 +1266,7 @@ static bool dirbrowse(char *root)
1262 icon */ 1266 icon */
1263 lcd_setfont(FONT_UI); 1267 lcd_setfont(FONT_UI);
1264#endif 1268#endif
1265 numentries = showdir(currdir, dirstart); 1269 numentries = showdir(currdir, dirstart, dirfilter);
1266 update_all = true; 1270 update_all = true;
1267 put_cursorxy(CURSOR_X, CURSOR_Y + dircursor, true); 1271 put_cursorxy(CURSOR_X, CURSOR_Y + dircursor, true);
1268 1272
@@ -1280,12 +1284,12 @@ static bool dirbrowse(char *root)
1280 /* So if lastdircursor and dircursor differ, and then full 1284 /* So if lastdircursor and dircursor differ, and then full
1281 screen was not refreshed, restore the previous line */ 1285 screen was not refreshed, restore the previous line */
1282 if ((lastdircursor != dircursor) && !update_all ) { 1286 if ((lastdircursor != dircursor) && !update_all ) {
1283 showfileline(lastdircursor, lasti, false); /* no scroll */ 1287 showfileline(lastdircursor, lasti, false, dirfilter); /* no scroll */
1284 } 1288 }
1285 lasti=i; 1289 lasti=i;
1286 lastdircursor=dircursor; 1290 lastdircursor=dircursor;
1287 1291
1288 showfileline(dircursor, i, true); /* scroll please */ 1292 showfileline(dircursor, i, true, dirfilter); /* scroll please */
1289 need_update = true; 1293 need_update = true;
1290 } 1294 }
1291 } 1295 }
@@ -1402,6 +1406,29 @@ bool create_playlist(void)
1402 return true; 1406 return true;
1403} 1407}
1404 1408
1409bool rockbox_browse(char *root, int dirfilter)
1410{
1411 bool rc;
1412 int dircursor_save = dircursor;
1413 int dirstart_save = dirstart;
1414 int dirlevel_save = dirlevel;
1415 int dirpos_save = dirpos[0];
1416 int cursorpos_save = cursorpos[0];
1417
1418 memcpy(currdir_save, currdir, sizeof(currdir));
1419 rc = dirbrowse(root, &dirfilter);
1420 memcpy(currdir, currdir_save, sizeof(currdir));
1421
1422 reload_dir = true;
1423 dirstart = dirstart_save;
1424 cursorpos[0] = cursorpos_save;
1425 dirlevel = dirlevel_save;
1426 dircursor = dircursor_save;
1427 dirpos[0] = dirpos_save;
1428
1429 return false;
1430}
1431
1405void tree_init(void) 1432void tree_init(void)
1406{ 1433{
1407 /* We copy the settings value in case it is changed by the user. We can't 1434 /* We copy the settings value in case it is changed by the user. We can't