storage-settings-scene-sd-info.c 2.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. #include "../storage-settings.h"
  2. static void storage_settings_scene_sd_info_dialog_callback(DialogExResult result, void* context) {
  3. StorageSettings* app = context;
  4. view_dispatcher_send_custom_event(app->view_dispatcher, result);
  5. }
  6. void storage_settings_scene_sd_info_on_enter(void* context) {
  7. StorageSettings* app = context;
  8. SDInfo sd_info;
  9. FS_Error sd_status = storage_sd_info(app->fs_api, &sd_info);
  10. DialogEx* dialog_ex = app->dialog_ex;
  11. dialog_ex_set_context(dialog_ex, app);
  12. dialog_ex_set_result_callback(dialog_ex, storage_settings_scene_sd_info_dialog_callback);
  13. dialog_ex_set_left_button_text(dialog_ex, "Back");
  14. if(sd_status != FSE_OK) {
  15. dialog_ex_set_header(dialog_ex, "SD card not mounted", 64, 10, AlignCenter, AlignCenter);
  16. dialog_ex_set_text(
  17. dialog_ex,
  18. "If an SD card is inserted,\r\npull it out and reinsert it",
  19. 64,
  20. 32,
  21. AlignCenter,
  22. AlignCenter);
  23. } else {
  24. string_printf(
  25. app->text_string,
  26. "Label: %s\nType: %s\n%lu KB total\n%lu KB free",
  27. sd_info.label,
  28. sd_api_get_fs_type_text(sd_info.fs_type),
  29. sd_info.kb_total,
  30. sd_info.kb_free);
  31. dialog_ex_set_text(
  32. dialog_ex, string_get_cstr(app->text_string), 4, 4, AlignLeft, AlignTop);
  33. }
  34. view_dispatcher_switch_to_view(app->view_dispatcher, StorageSettingsViewDialogEx);
  35. }
  36. bool storage_settings_scene_sd_info_on_event(void* context, SceneManagerEvent event) {
  37. StorageSettings* app = context;
  38. bool consumed = false;
  39. if(event.type == SceneManagerEventTypeCustom) {
  40. switch(event.event) {
  41. case DialogExResultLeft:
  42. consumed = scene_manager_previous_scene(app->scene_manager);
  43. break;
  44. case DialogExResultRight:
  45. scene_manager_next_scene(app->scene_manager, StorageSettingsUnmounted);
  46. consumed = true;
  47. break;
  48. }
  49. }
  50. return consumed;
  51. }
  52. void storage_settings_scene_sd_info_on_exit(void* context) {
  53. StorageSettings* app = context;
  54. DialogEx* dialog_ex = app->dialog_ex;
  55. dialog_ex_set_header(dialog_ex, NULL, 0, 0, AlignCenter, AlignCenter);
  56. dialog_ex_set_text(dialog_ex, NULL, 0, 0, AlignCenter, AlignTop);
  57. dialog_ex_set_icon(dialog_ex, 0, 0, NULL);
  58. dialog_ex_set_left_button_text(dialog_ex, NULL);
  59. dialog_ex_set_right_button_text(dialog_ex, NULL);
  60. dialog_ex_set_result_callback(dialog_ex, NULL);
  61. dialog_ex_set_context(dialog_ex, NULL);
  62. string_clean(app->text_string);
  63. }