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