wifi_marauder_scene_script_confirm_delete.c 2.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  1. #include "../wifi_marauder_app_i.h"
  2. void wifi_marauder_scene_script_confirm_delete_widget_callback(
  3. GuiButtonType result,
  4. InputType type,
  5. void* context) {
  6. WifiMarauderApp* app = context;
  7. if(type == InputTypeShort) {
  8. view_dispatcher_send_custom_event(app->view_dispatcher, result);
  9. }
  10. }
  11. void wifi_marauder_scene_script_confirm_delete_on_enter(void* context) {
  12. WifiMarauderApp* app = context;
  13. widget_add_button_element(
  14. app->widget,
  15. GuiButtonTypeLeft,
  16. "No",
  17. wifi_marauder_scene_script_confirm_delete_widget_callback,
  18. app);
  19. widget_add_button_element(
  20. app->widget,
  21. GuiButtonTypeRight,
  22. "Yes",
  23. wifi_marauder_scene_script_confirm_delete_widget_callback,
  24. app);
  25. widget_add_string_element(
  26. app->widget, 0, 0, AlignLeft, AlignTop, FontPrimary, "Are you sure?");
  27. widget_add_text_box_element(
  28. app->widget,
  29. 0,
  30. 12,
  31. 128,
  32. 38,
  33. AlignCenter,
  34. AlignCenter,
  35. "The script will be\npermanently deleted",
  36. false);
  37. view_dispatcher_switch_to_view(app->view_dispatcher, WifiMarauderAppViewWidget);
  38. }
  39. bool wifi_marauder_scene_script_confirm_delete_on_event(void* context, SceneManagerEvent event) {
  40. WifiMarauderApp* app = context;
  41. bool consumed = false;
  42. if(event.type == SceneManagerEventTypeCustom) {
  43. // get which button press: "Yes" or "No"
  44. if(event.event == GuiButtonTypeRight) {
  45. // Yes
  46. if(app->script != NULL) {
  47. char script_path[256];
  48. snprintf(
  49. script_path,
  50. sizeof(script_path),
  51. "%s/%s.json",
  52. MARAUDER_APP_FOLDER_SCRIPTS,
  53. app->script->name);
  54. storage_simply_remove(app->storage, script_path);
  55. wifi_marauder_script_free(app->script);
  56. app->script = NULL;
  57. DialogMessage* message = dialog_message_alloc();
  58. dialog_message_set_text(message, "Deleted!", 83, 19, AlignLeft, AlignBottom);
  59. dialog_message_set_icon(message, &I_DolphinMafia_119x62, 0, 2);
  60. dialog_message_set_buttons(message, NULL, "Ok", NULL);
  61. dialog_message_show(app->dialogs, message);
  62. dialog_message_free(message);
  63. }
  64. }
  65. scene_manager_previous_scene(app->scene_manager);
  66. consumed = true;
  67. }
  68. return consumed;
  69. }
  70. void wifi_marauder_scene_script_confirm_delete_on_exit(void* context) {
  71. WifiMarauderApp* app = context;
  72. widget_reset(app->widget);
  73. }