A modern Music Player Daemon based on Rockbox open source high quality audio player
libadwaita audio rust zig deno mpris rockbox mpd

plugins: disktidy: use UI viewport, limit UI updates

- Show stats when finished
- Keep stats on screen until Cancel or Menu
button is pressed
- Limiting progress updates to 10fps results
in a big speedup

Change-Id: Iebffaead6e1212306edaa42aad925458d13a5f82

authored by

Christian Soffke and committed by
Solomon Peachy
2bf929c7 e3fb4191

+65 -43
+2 -1
apps/plugin.c
··· 862 862 /* for some plugins, the SBS can be left enabled */ 863 863 const char *sepch = strrchr(plugin, PATH_SEPCH); 864 864 bool theme_enabled = sepch && (!strcmp("properties.rock", sepch + 1) || 865 - !strcmp("main_menu_config.rock", sepch + 1)); 865 + !strcmp("main_menu_config.rock", sepch + 1) || 866 + !strcmp("disktidy.rock", sepch + 1)); 866 867 867 868 if (current_plugin_handle) 868 869 {
+51 -37
apps/plugins/disktidy.c
··· 259 259 rb->snprintf(dirs_removed, sizeof(dirs_removed), "%d", 260 260 run_stats.dirs_removed); 261 261 262 - char removed_size[9]; 263 - rb->snprintf(removed_size, sizeof(removed_size), "%d.%d%s", 262 + char removed_size[11]; 263 + rb->snprintf(removed_size, sizeof(removed_size), "(%d.%d%s)", 264 264 (int)rm_size, (int)((rm_size - (int)rm_size) * 100), 265 265 size_units[magnitude]); 266 266 267 - char run_time[9]; 268 - rb->snprintf(run_time, sizeof(run_time), "%02d:%02d:%02d", 267 + char run_time[12]; 268 + rb->snprintf(run_time, sizeof(run_time), "in %02d:%02d:%02d", 269 269 run_stats.run_duration / 3600, run_stats.run_duration / 60, 270 270 run_stats.run_duration % 60); 271 271 ··· 279 279 #endif 280 280 281 281 char* last_run_text[] = { 282 - "Last Run Stats" , "" , "", 283 - "Total Removed: ", total_removed, "", 284 - "Files Removed: ", files_removed, "", 285 - "Dirs Removed: " , dirs_removed , "", 286 - "Removed Size: " , removed_size , "", 287 - "Run Time: " , run_time , "", 288 282 #if CONFIG_RTC 289 - "Run: " , last_run 283 + last_run, "", 290 284 #endif 285 + total_removed, "removed", removed_size, "", 286 + files_removed, run_stats.files_removed == 1 ? "file" : "files,", 287 + dirs_removed , run_stats.dirs_removed == 1 ? "dir" : "dirs", "", 288 + run_time , "", 291 289 }; 292 290 293 291 static struct style_text display_style[] = { 294 - { 0, C_ORANGE | TEXT_CENTER }, 295 - { 3, C_BLUE }, 296 - { 6, C_BLUE }, 297 - { 9, C_BLUE }, 298 - { 12, C_BLUE }, 299 - { 15, C_BLUE }, 300 292 #if CONFIG_RTC 301 - { 18, C_BLUE }, 293 + { 0, TEXT_CENTER }, 302 294 #endif 303 295 LAST_STYLE_ITEM 304 296 }; 305 297 298 + struct viewport vp; 299 + rb->viewport_set_defaults(&vp, SCREEN_MAIN); 300 + 306 301 if (display_text(ARRAYLEN(last_run_text), last_run_text, 307 - display_style, NULL, true)) { 302 + display_style, &vp, false)) { 308 303 return PLUGIN_USB_CONNECTED; 309 304 } 305 + while (true) /* keep info on screen until cancelled */ 306 + { 307 + int button = rb->get_action(CONTEXT_STD, HZ/2); 308 + if (button == ACTION_STD_CANCEL || button == ACTION_STD_MENU) 309 + break; 310 310 311 + if (rb->default_event_handler(button) == SYS_USB_CONNECTED) 312 + return PLUGIN_USB_CONNECTED; 313 + } 311 314 return PLUGIN_OK; 312 315 } 313 316 ··· 337 340 return false; 338 341 } 339 342 340 - static void tidy_lcd_status(const char *name) 343 + static void tidy_lcd_status(const char *name, struct viewport *vp) 341 344 { 342 - /* display status text */ 343 - rb->lcd_clear_display(); 344 - rb->lcd_puts(0, 0, "Working ..."); 345 - rb->lcd_puts(0, 1, name); 346 - rb->lcd_putsf(0, 2, "Cleaned up %d items", 345 + static long next_tick; 346 + 347 + if (TIME_AFTER(next_tick, *rb->current_tick)) 348 + return; 349 + 350 + next_tick = *rb->current_tick + HZ/10; 351 + 352 + struct screen *display = rb->screens[SCREEN_MAIN]; 353 + struct viewport *last_vp = display->set_viewport(vp); 354 + 355 + display->clear_viewport(); 356 + display->puts(0, 0, "Cleaning..."); 357 + display->puts(0, 1, name); 358 + display->putsf(0, 2, "%d items removed", 347 359 run_stats.files_removed + run_stats.dirs_removed); 348 - rb->lcd_update(); 360 + display->update_viewport(); 361 + 362 + display->set_viewport(last_vp); 349 363 } 350 364 351 365 static int tidy_path_append_entry(char *path, struct dirent *entry, int *path_length) ··· 396 410 struct dir_info dinfo; 397 411 struct dirent *entry; 398 412 struct dirinfo info; 413 + struct viewport vp; 414 + rb->viewport_set_defaults(&vp, SCREEN_MAIN); 399 415 DIR *dir, *dir_test; 400 416 /* Set to true when directory and its contents are to be deleted */ 401 417 bool rm_all = false; ··· 424 440 /* Restore path to poped dir */ 425 441 tidy_path_remove_entry(path, dinfo.path_length, path_length); 426 442 dir = dinfo.dir; 427 - tidy_lcd_status(path); 443 + tidy_lcd_status(path, &vp); 428 444 429 445 while ((entry = rb->readdir(dir))) { 430 446 /* Check for user input and usb connect */ ··· 474 490 475 491 if (dir_test) { 476 492 dir = dir_test; 477 - tidy_lcd_status(path); 493 + tidy_lcd_status(path, &vp); 478 494 } 479 495 } 480 496 } ··· 506 522 rm_all_start_depth = dir_stack_size(&dstack); 507 523 } 508 524 509 - tidy_lcd_status(path); 525 + tidy_lcd_status(path, &vp); 510 526 } 511 527 } 512 528 } else { ··· 567 583 568 584 if (status == PLUGIN_OK) 569 585 { 570 - rb->lcd_clear_display(); 571 586 if (user_abort) 572 587 { 573 - rb->splash(HZ, "User aborted"); 574 - rb->lcd_clear_display(); 588 + user_abort = false; 589 + rb->splash(HZ, ID2P(LANG_CANCEL)); 575 590 } 576 - rb->lcd_update(); 577 - rb->splashf(HZ*2, "Cleaned up %d items", 578 - run_stats.files_removed + run_stats.dirs_removed); 579 591 } 580 592 581 593 return status; ··· 666 678 int selection = 0; 667 679 struct simplelist_info list; 668 680 669 - MENUITEM_STRINGLIST(menu, "Disktidy Menu", disktidy_menu_cb, 681 + MENUITEM_STRINGLIST(menu, "Disktidy", disktidy_menu_cb, 670 682 "Start Cleaning", "Files to Clean", "Last Run Stats", 671 683 "Playback Control", "Quit"); 672 684 ··· 675 687 case 0: 676 688 if (tidy_types_selected()) { 677 689 disktidy_status = tidy_do(); 690 + if (disktidy_status == PLUGIN_OK) 691 + disktidy_status = display_run_stats(); 678 692 } else { 679 693 rb->splash(HZ * 2, "Select at least one file type to clean"); 680 694 } ··· 719 733 return; 720 734 721 735 for (unsigned i=0; i<tidy_type_count; i++) 722 - rb->fdprintf(fd, "%s%s%s: %s\n", 736 + rb->fdprintf(fd, "%s%s%s: %s\n", 723 737 tidy_types[i].filestring[0] == '#' ? "\\" : "", 724 738 tidy_types[i].filestring, 725 739 tidy_types[i].directory ? "/" : "",
+12 -5
apps/plugins/lib/display_text.c
··· 31 31 button = rb->button_get(true); 32 32 if ( rb->default_event_handler( button ) == SYS_USB_CONNECTED ) 33 33 return true; 34 - } while( ( button == BUTTON_NONE ) 34 + } while(IS_SYSEVENT(button) || ( button == BUTTON_NONE ) 35 35 || ( button & (BUTTON_REL|BUTTON_REPEAT) ) ); 36 36 return false; 37 37 } ··· 39 39 bool display_text(unsigned short words, char** text, struct style_text* style, 40 40 struct viewport* vp_text, bool wait_key) 41 41 { 42 + bool ret = false; 42 43 int prev_drawmode; 43 44 #ifdef HAVE_LCD_COLOR 44 45 int standard_fgcolor; ··· 52 53 vp_width = vp_text->width; 53 54 vp_height = vp_text->height; 54 55 } 55 - rb->screens[SCREEN_MAIN]->set_viewport(vp_text); 56 + struct viewport *last_vp = rb->screens[SCREEN_MAIN]->set_viewport(vp_text); 56 57 prev_drawmode = rb->lcd_get_drawmode(); 57 58 rb->lcd_set_drawmode(DRMODE_SOLID); 58 59 #ifdef HAVE_LCD_COLOR ··· 80 81 y = MARGIN; 81 82 rb->screens[SCREEN_MAIN]->update_viewport(); 82 83 if (wait_key_press()) 83 - return true; 84 + { 85 + ret = true; 86 + goto cleanup; 87 + } 84 88 rb->screens[SCREEN_MAIN]->clear_viewport(); 85 89 } 86 90 /* no text formatting available */ ··· 132 136 if (wait_key) 133 137 { 134 138 if (wait_key_press()) 135 - return true; 139 + ret = true; 136 140 } 137 - return false; 141 + 142 + cleanup: 143 + rb->screens[SCREEN_MAIN]->set_viewport(last_vp); 144 + return ret; 138 145 }