storage-settings-scene-format-confirm.c 2.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. #include "../storage-settings.h"
  2. static void
  3. storage_settings_scene_format_confirm_dialog_callback(DialogExResult result, void* context) {
  4. StorageSettings* app = context;
  5. view_dispatcher_send_custom_event(app->view_dispatcher, result);
  6. }
  7. void storage_settings_scene_format_confirm_on_enter(void* context) {
  8. StorageSettings* app = context;
  9. FS_Error sd_status = storage_sd_status(app->fs_api);
  10. DialogEx* dialog_ex = app->dialog_ex;
  11. dialog_ex_set_left_button_text(dialog_ex, "Back");
  12. if(sd_status == FSE_NOT_READY) {
  13. dialog_ex_set_header(dialog_ex, "SD card not mounted", 64, 10, AlignCenter, AlignCenter);
  14. dialog_ex_set_text(
  15. dialog_ex,
  16. "If an SD card is inserted,\r\npull it out and reinsert it",
  17. 64,
  18. 32,
  19. AlignCenter,
  20. AlignCenter);
  21. } else {
  22. dialog_ex_set_right_button_text(dialog_ex, "Format");
  23. dialog_ex_set_header(dialog_ex, "Format SD card?", 64, 10, AlignCenter, AlignCenter);
  24. dialog_ex_set_text(dialog_ex, "All data will be lost", 64, 32, AlignCenter, AlignCenter);
  25. }
  26. dialog_ex_set_context(dialog_ex, app);
  27. dialog_ex_set_result_callback(
  28. dialog_ex, storage_settings_scene_format_confirm_dialog_callback);
  29. view_dispatcher_switch_to_view(app->view_dispatcher, StorageSettingsViewDialogEx);
  30. }
  31. bool storage_settings_scene_format_confirm_on_event(void* context, SceneManagerEvent event) {
  32. StorageSettings* app = context;
  33. bool consumed = false;
  34. if(event.type == SceneManagerEventTypeCustom) {
  35. switch(event.event) {
  36. case DialogExResultLeft:
  37. consumed = scene_manager_previous_scene(app->scene_manager);
  38. break;
  39. case DialogExResultRight:
  40. scene_manager_next_scene(app->scene_manager, StorageSettingsFormatting);
  41. consumed = true;
  42. break;
  43. }
  44. }
  45. return consumed;
  46. }
  47. void storage_settings_scene_format_confirm_on_exit(void* context) {
  48. StorageSettings* app = context;
  49. DialogEx* dialog_ex = app->dialog_ex;
  50. dialog_ex_set_header(dialog_ex, NULL, 0, 0, AlignCenter, AlignCenter);
  51. dialog_ex_set_text(dialog_ex, NULL, 0, 0, AlignCenter, AlignTop);
  52. dialog_ex_set_icon(dialog_ex, 0, 0, NULL);
  53. dialog_ex_set_left_button_text(dialog_ex, NULL);
  54. dialog_ex_set_right_button_text(dialog_ex, NULL);
  55. dialog_ex_set_result_callback(dialog_ex, NULL);
  56. dialog_ex_set_context(dialog_ex, NULL);
  57. }