Rockbox open source high quality audio player as a Music Player Daemon
mpris rockbox mpd libadwaita audio rust zig deno
2
fork

Configure Feed

Select the types of activity you want to include in your feed.

plugins: Disk Tidy: SBS title & minor display adjustments

- Move header that displays "Cleaning...", or
that shows the last run's date, into SBS
title area, if it exists.
- Left-align everything if SBS title doesn't exist
- Display "Nothing removed" instead of multiple
zeros for items, size, dirs, and files
- Display "Today" instead of the current date
- display "2m 1s" instead of "00:02:01, and
"<1s" instead of "00:00:00"
- "1 items" -> "1 item"

Change-Id: I40302af00d1038adca45a1c6a908af76bd9917cc

+76 -28
+76 -28
apps/plugins/disktidy.c
··· 27 27 #define DEFAULT_FILES PLUGIN_APPS_DATA_DIR "/disktidy.config" 28 28 #define CUSTOM_FILES PLUGIN_APPS_DATA_DIR "/disktidy_custom.config" 29 29 #define LAST_RUN_STATS_FILE PLUGIN_APPS_DATA_DIR "/disktidy.stats" 30 + #define CLEANING_STR "Cleaning..." 30 31 #define DIR_STACK_SIZE 25 31 32 32 33 struct dir_info { ··· 64 65 static bool user_abort; 65 66 static bool tidy_loaded_and_changed = false; 66 67 static bool stats_file_exists = false; 68 + static bool sbs_has_title; 67 69 68 70 static void dir_stack_init(struct dir_stack *dstack) 69 71 { ··· 224 226 225 227 static enum plugin_status display_run_stats(void) 226 228 { 229 + struct viewport vp; 230 + 227 231 if (!load_run_stats()) { 228 232 rb->splash(HZ * 2, "Unable to load last run stats"); 229 233 return PLUGIN_OK; ··· 247 251 magnitude++; 248 252 } 249 253 250 - char total_removed[8]; 251 - rb->snprintf(total_removed, sizeof(total_removed), "%d", 252 - run_stats.files_removed + run_stats.dirs_removed); 254 + char total_removed[8] = "Nothing"; 255 + int num_removed = run_stats.files_removed + run_stats.dirs_removed; 256 + if (num_removed) 257 + rb->snprintf(total_removed, sizeof(total_removed), "%d", num_removed); 253 258 254 259 char files_removed[8]; 255 260 rb->snprintf(files_removed, sizeof(files_removed), "%d", ··· 264 269 (int)rm_size, (int)((rm_size - (int)rm_size) * 100), 265 270 size_units[magnitude]); 266 271 267 - char run_time[12]; 268 - rb->snprintf(run_time, sizeof(run_time), "in %02d:%02d:%02d", 269 - run_stats.run_duration / 3600, run_stats.run_duration / 60, 270 - run_stats.run_duration % 60); 272 + char run_time[12] = "in <1s"; 273 + int s = run_stats.run_duration % 60; 274 + int m = run_stats.run_duration / 60; 275 + int h = run_stats.run_duration / 3600; 276 + if (h) 277 + rb->snprintf(run_time, sizeof(run_time), "in %dh %dm, %ds", h, m, s); 278 + else if (m) 279 + rb->snprintf(run_time, sizeof(run_time), "in %dm %ds", m, s); 280 + else if (s) 281 + rb->snprintf(run_time, sizeof(run_time), "in %ds", s); 271 282 272 283 #if CONFIG_RTC 284 + struct tm tm = *rb->get_time(); 273 285 char last_run[18]; 274 - rb->snprintf(last_run, sizeof(last_run), "%02d:%02d %d/%s/%d", 275 - run_stats.last_run_time.tm_hour, 276 - run_stats.last_run_time.tm_min, run_stats.last_run_time.tm_mday, 277 - months[run_stats.last_run_time.tm_mon], 278 - 2000 + (run_stats.last_run_time.tm_year % 100)); 286 + if (tm.tm_mday == run_stats.last_run_time.tm_mday && 287 + tm.tm_mon == run_stats.last_run_time.tm_mon && 288 + tm.tm_year == run_stats.last_run_time.tm_year) 289 + { 290 + rb->snprintf(last_run, sizeof(last_run), "%02d:%02d Today", 291 + run_stats.last_run_time.tm_hour, 292 + run_stats.last_run_time.tm_min); 293 + } 294 + else 295 + rb->snprintf(last_run, sizeof(last_run), "%02d:%02d %d/%s/%d", 296 + run_stats.last_run_time.tm_hour, 297 + run_stats.last_run_time.tm_min, run_stats.last_run_time.tm_mday, 298 + months[run_stats.last_run_time.tm_mon], 299 + 2000 + (run_stats.last_run_time.tm_year % 100)); 279 300 #endif 280 301 281 302 char* last_run_text[] = { ··· 287 308 dirs_removed , run_stats.dirs_removed == 1 ? "dir" : "dirs", "", 288 309 run_time , "", 289 310 }; 290 - 291 - static struct style_text display_style[] = { 311 + char** text_arr = last_run_text; 312 + int len = ARRAYLEN(last_run_text); 313 + if (!num_removed) 314 + { 315 + /* Hide superfluous zeros if nothing was removed */ 316 + text_arr[len - 9] = ""; 317 + text_arr[len - 8] = run_time; 318 + text_arr[len - 7] = ""; 319 + len -= 6; 320 + } 292 321 #if CONFIG_RTC 293 - { 0, TEXT_CENTER }, 322 + sbs_has_title = rb->sb_set_title_text(last_run, Icon_NOICON, SCREEN_MAIN); 323 + if (sbs_has_title) 324 + { 325 + text_arr += 2; 326 + len -=2; 327 + #else 328 + sbs_has_title = rb->sb_set_title_text("Last Run", Icon_NOICON, SCREEN_MAIN); 329 + if (sbs_has_title) 330 + { 294 331 #endif 295 - LAST_STYLE_ITEM 296 - }; 332 + rb->send_event(GUI_EVENT_ACTIONUPDATE, (void*)1); 333 + } 297 334 298 - struct viewport vp; 299 335 rb->viewport_set_defaults(&vp, SCREEN_MAIN); 300 336 301 - if (display_text(ARRAYLEN(last_run_text), last_run_text, 302 - display_style, &vp, false)) { 337 + if (display_text(len, text_arr, NULL, &vp, false)) 338 + { 303 339 return PLUGIN_USB_CONNECTED; 304 340 } 305 341 while (true) /* keep info on screen until cancelled */ ··· 343 379 static void tidy_lcd_status(const char *name, struct viewport *vp) 344 380 { 345 381 static long next_tick; 382 + int i, num_removed; 383 + struct screen *display; 384 + struct viewport *last_vp; 346 385 347 386 if (TIME_AFTER(next_tick, *rb->current_tick)) 348 387 return; 349 388 350 389 next_tick = *rb->current_tick + HZ/10; 351 390 352 - struct screen *display = rb->screens[SCREEN_MAIN]; 353 - struct viewport *last_vp = display->set_viewport(vp); 354 - 391 + display = rb->screens[SCREEN_MAIN]; 392 + last_vp = display->set_viewport(vp); 355 393 display->clear_viewport(); 356 - display->puts(0, 0, "Cleaning..."); 357 - display->puts(0, 1, name); 358 - display->putsf(0, 2, "%d items removed", 359 - run_stats.files_removed + run_stats.dirs_removed); 360 - display->update_viewport(); 361 394 395 + i = 0; 396 + num_removed = run_stats.files_removed + run_stats.dirs_removed; 397 + if (!sbs_has_title) 398 + display->puts(0, i++, CLEANING_STR); 399 + display->puts(0, i++, name); 400 + if (num_removed) 401 + display->putsf(0, i++, num_removed == 1 ? "%d item removed" : "%d items removed", num_removed); 402 + else 403 + display->puts(0, i++, "Nothing removed"); 404 + 405 + display->update_viewport(); 362 406 display->set_viewport(last_vp); 363 407 } 364 408 ··· 556 600 { 557 601 /* clean disk and display num of items removed */ 558 602 char path[MAX_PATH]; 603 + 604 + sbs_has_title = rb->sb_set_title_text(CLEANING_STR, Icon_NOICON, SCREEN_MAIN); 605 + if (sbs_has_title) 606 + rb->send_event(GUI_EVENT_ACTIONUPDATE, (void*)1); 559 607 560 608 run_stats.files_removed = 0; 561 609 run_stats.dirs_removed = 0;