summaryrefslogtreecommitdiff
path: root/apps/tree.c
diff options
context:
space:
mode:
Diffstat (limited to 'apps/tree.c')
-rw-r--r--apps/tree.c146
1 files changed, 78 insertions, 68 deletions
diff --git a/apps/tree.c b/apps/tree.c
index ba4da816d1..f0f1f0e94e 100644
--- a/apps/tree.c
+++ b/apps/tree.c
@@ -352,9 +352,20 @@ static int tree_get_file_position(char * filename)
352 */ 352 */
353static int update_dir(void) 353static int update_dir(void)
354{ 354{
355 struct gui_synclist * const list = &tree_lists;
356 int show_path_in_browser = global_settings.show_path_in_browser;
355 bool changed = false; 357 bool changed = false;
358
359 const char* title = NULL;/* Must clear the title as the list is reused */
360 int icon = NOICON;
361
356#ifdef HAVE_TAGCACHE 362#ifdef HAVE_TAGCACHE
357 bool id3db = *tc.dirfilter == SHOW_ID3DB; 363 bool id3db = *tc.dirfilter == SHOW_ID3DB;
364#else
365 const bool id3db = false;
366#endif
367
368#ifdef HAVE_TAGCACHE
358 /* Checks for changes */ 369 /* Checks for changes */
359 if (id3db) { 370 if (id3db) {
360 if (tc.currtable != lasttable || 371 if (tc.currtable != lasttable ||
@@ -385,9 +396,7 @@ static int update_dir(void)
385 /* if selected item is undefined */ 396 /* if selected item is undefined */
386 if (tc.selected_item == -1) 397 if (tc.selected_item == -1)
387 { 398 {
388#ifdef HAVE_TAGCACHE
389 if (!id3db) 399 if (!id3db)
390#endif
391 /* use lastfile to determine the selected item */ 400 /* use lastfile to determine the selected item */
392 tc.selected_item = tree_get_file_position(lastfile); 401 tc.selected_item = tree_get_file_position(lastfile);
393 402
@@ -398,31 +407,22 @@ static int update_dir(void)
398 } 407 }
399 if (changed) 408 if (changed)
400 { 409 {
401 if( 410 if( !id3db && tc.dirfull )
402#ifdef HAVE_TAGCACHE
403 !id3db &&
404#endif
405 tc.dirfull )
406 { 411 {
407 splash(HZ, ID2P(LANG_SHOWDIR_BUFFER_FULL)); 412 splash(HZ, ID2P(LANG_SHOWDIR_BUFFER_FULL));
408 } 413 }
409 } 414 }
410 415
411 gui_synclist_init(&tree_lists, &tree_get_filename, &tc, false, 1, NULL); 416 gui_synclist_init(list, &tree_get_filename, &tc, false, 1, NULL);
412 417
413#ifdef HAVE_TAGCACHE 418#ifdef HAVE_TAGCACHE
414 if (id3db) 419 if (id3db)
415 { 420 {
416 if (global_settings.show_path_in_browser == SHOW_PATH_FULL 421 if (show_path_in_browser == SHOW_PATH_FULL
417 || global_settings.show_path_in_browser == SHOW_PATH_CURRENT) 422 || show_path_in_browser == SHOW_PATH_CURRENT)
418 {
419 gui_synclist_set_title(&tree_lists, tagtree_get_title(&tc),
420 filetype_get_icon(ATTR_DIRECTORY));
421 }
422 else
423 { 423 {
424 /* Must clear the title as the list is reused */ 424 title = tagtree_get_title(&tc);
425 gui_synclist_set_title(&tree_lists, NULL, NOICON); 425 icon = filetype_get_icon(ATTR_DIRECTORY);
426 } 426 }
427 } 427 }
428 else 428 else
@@ -430,49 +430,52 @@ static int update_dir(void)
430 { 430 {
431 if (tc.browse && tc.browse->title) 431 if (tc.browse && tc.browse->title)
432 { 432 {
433 int icon = tc.browse->icon; 433 title = tc.browse->title;
434 icon = tc.browse->icon;
434 if (icon == NOICON) 435 if (icon == NOICON)
435 icon = filetype_get_icon(ATTR_DIRECTORY); 436 icon = filetype_get_icon(ATTR_DIRECTORY);
436 gui_synclist_set_title(&tree_lists, tc.browse->title, icon);
437 }
438 else if (global_settings.show_path_in_browser == SHOW_PATH_FULL)
439 {
440 gui_synclist_set_title(&tree_lists, tc.currdir,
441 filetype_get_icon(ATTR_DIRECTORY));
442 } 437 }
443 else if (global_settings.show_path_in_browser == SHOW_PATH_CURRENT) 438 else
444 { 439 {
445 char *title = strrchr(tc.currdir, '/') + 1; 440 if (show_path_in_browser == SHOW_PATH_FULL)
446 if (*title == '\0')
447 { 441 {
448 /* Display "Files" for the root dir */ 442 title = tc.currdir;
449 gui_synclist_set_title(&tree_lists, str(LANG_DIR_BROWSER), 443 icon = filetype_get_icon(ATTR_DIRECTORY);
450 filetype_get_icon(ATTR_DIRECTORY));
451 } 444 }
452 else 445 else if (show_path_in_browser == SHOW_PATH_CURRENT)
453 gui_synclist_set_title(&tree_lists, title, 446 {
454 filetype_get_icon(ATTR_DIRECTORY)); 447 title = strrchr(tc.currdir, '/');
455 } 448 if (title != NULL)
456 else 449 {
457 { 450 title++; /* step past the separator */
458 /* Must clear the title as the list is reused */ 451 if (*title == '\0')
459 gui_synclist_set_title(&tree_lists, NULL, NOICON); 452 {
453 /* Display "Files" for the root dir */
454 title = str(LANG_DIR_BROWSER);
455 }
456 icon = filetype_get_icon(ATTR_DIRECTORY);
457 }
458 }
460 } 459 }
461 } 460 }
462 461
463 gui_synclist_set_nb_items(&tree_lists, tc.filesindir); 462 /* set title and icon, if nothing is set, clear the title
464 gui_synclist_set_icon_callback(&tree_lists, 463 * with NULL and icon as NOICON as the list is reused */
465 global_settings.show_icons?tree_get_fileicon:NULL); 464 gui_synclist_set_title(list, title, icon);
466 gui_synclist_set_voice_callback(&tree_lists, tree_voice_cb); 465
466 gui_synclist_set_nb_items(list, tc.filesindir);
467 gui_synclist_set_icon_callback(list,
468 global_settings.show_icons?tree_get_fileicon:NULL);
469 gui_synclist_set_voice_callback(list, &tree_voice_cb);
467#ifdef HAVE_LCD_COLOR 470#ifdef HAVE_LCD_COLOR
468 gui_synclist_set_color_callback(&tree_lists, &tree_get_filecolor); 471 gui_synclist_set_color_callback(list, &tree_get_filecolor);
469#endif 472#endif
470 if( tc.selected_item >= tc.filesindir) 473 if( tc.selected_item >= tc.filesindir)
471 tc.selected_item=tc.filesindir-1; 474 tc.selected_item=tc.filesindir-1;
472 475
473 gui_synclist_select_item(&tree_lists, tc.selected_item); 476 gui_synclist_select_item(list, tc.selected_item);
474 gui_synclist_draw(&tree_lists); 477 gui_synclist_draw(list);
475 gui_synclist_speak_item(&tree_lists); 478 gui_synclist_speak_item(list);
476 return tc.filesindir; 479 return tc.filesindir;
477} 480}
478 481
@@ -483,13 +486,13 @@ void resume_directory(const char *dir)
483 int ret; 486 int ret;
484#ifdef HAVE_TAGCACHE 487#ifdef HAVE_TAGCACHE
485 bool id3db = *tc.dirfilter == SHOW_ID3DB; 488 bool id3db = *tc.dirfilter == SHOW_ID3DB;
489#else
490 const bool id3db = false;
486#endif 491#endif
487 /* make sure the dirfilter is sane. The only time it should be possible 492 /* make sure the dirfilter is sane. The only time it should be possible
488 * thats its not is when resume playlist is called from a plugin 493 * thats its not is when resume playlist is called from a plugin
489 */ 494 */
490#ifdef HAVE_TAGCACHE
491 if (!id3db) 495 if (!id3db)
492#endif
493 *tc.dirfilter = global_settings.dirfilter; 496 *tc.dirfilter = global_settings.dirfilter;
494 ret = ft_load(&tc, dir); 497 ret = ft_load(&tc, dir);
495 *tc.dirfilter = dirfilter; 498 *tc.dirfilter = dirfilter;
@@ -557,10 +560,9 @@ void set_dirfilter(int l_dirfilter)
557 *tc.dirfilter = l_dirfilter; 560 *tc.dirfilter = l_dirfilter;
558} 561}
559 562
560/* Selects a file and update tree context properly */ 563/* Selects a path + file and update tree context properly */
561void set_current_file(const char *path) 564static void set_current_file_ex(const char *path, const char *filename)
562{ 565{
563 const char *name;
564 int i; 566 int i;
565 567
566#ifdef HAVE_TAGCACHE 568#ifdef HAVE_TAGCACHE
@@ -570,21 +572,27 @@ void set_current_file(const char *path)
570 return; 572 return;
571#endif 573#endif
572 574
573 /* separate directory from filename */ 575 if (!filename) /* path and filename supplied combined */
574 /* gets the directory's name and put it into tc.currdir */
575 name = strrchr(path+1,'/');
576 if (name)
577 { 576 {
578 strmemccpy(tc.currdir, path, name - path + 1); 577 /* separate directory from filename */
579 name++; 578 /* gets the directory's name and put it into tc.currdir */
579 filename = strrchr(path+1,'/');
580 if (filename)
581 {
582 strmemccpy(tc.currdir, path, filename - path + 1);
583 filename++;
584 }
585 else
586 {
587 strcpy(tc.currdir, "/");
588 filename = path+1;
589 }
580 } 590 }
581 else 591 else /* path and filename came in separate */
582 { 592 {
583 strcpy(tc.currdir, "/"); 593 strmemccpy(tc.currdir, path, MAX_PATH);
584 name = path+1;
585 } 594 }
586 595 strmemccpy(lastfile, filename, MAX_PATH);
587 strmemccpy(lastfile, name, MAX_PATH);
588 596
589 597
590 /* If we changed dir we must recalculate the dirlevel 598 /* If we changed dir we must recalculate the dirlevel
@@ -617,6 +625,12 @@ void set_current_file(const char *path)
617 } 625 }
618} 626}
619 627
628/* Selects a file and update tree context properly */
629void set_current_file(const char *path)
630{
631 set_current_file_ex(path, NULL);
632}
633
620 634
621/* main loop, handles key events */ 635/* main loop, handles key events */
622static int dirbrowse(void) 636static int dirbrowse(void)
@@ -981,7 +995,6 @@ static int backup_count = -1;
981int rockbox_browse(struct browse_context *browse) 995int rockbox_browse(struct browse_context *browse)
982{ 996{
983 tc.is_browsing = (browse != NULL); 997 tc.is_browsing = (browse != NULL);
984 static char current[MAX_PATH];
985 int ret_val = 0; 998 int ret_val = 0;
986 int dirfilter = browse->dirfilter; 999 int dirfilter = browse->dirfilter;
987 1000
@@ -1021,9 +1034,7 @@ int rockbox_browse(struct browse_context *browse)
1021 1034
1022 if (browse->selected) 1035 if (browse->selected)
1023 { 1036 {
1024 snprintf(current, sizeof(current), "%s/%s", 1037 set_current_file_ex(browse->root, browse->selected);
1025 browse->root, browse->selected);
1026 set_current_file(current);
1027 /* set_current_file changes dirlevel, change it back */ 1038 /* set_current_file changes dirlevel, change it back */
1028 tc.dirlevel = 0; 1039 tc.dirlevel = 0;
1029 } 1040 }
@@ -1036,8 +1047,7 @@ int rockbox_browse(struct browse_context *browse)
1036 if (dirfilter != SHOW_ID3DB && (browse->flags & BROWSE_DIRFILTER) == 0) 1047 if (dirfilter != SHOW_ID3DB && (browse->flags & BROWSE_DIRFILTER) == 0)
1037 tc.dirfilter = &global_settings.dirfilter; 1048 tc.dirfilter = &global_settings.dirfilter;
1038 tc.browse = browse; 1049 tc.browse = browse;
1039 strmemccpy(current, browse->root, MAX_PATH); 1050 set_current_file(browse->root);
1040 set_current_file(current);
1041 if (browse->flags&BROWSE_RUNFILE) 1051 if (browse->flags&BROWSE_RUNFILE)
1042 ret_val = ft_enter(&tc); 1052 ret_val = ft_enter(&tc);
1043 else 1053 else