subghz_scene_delete.c 2.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. #include "../subghz_i.h"
  2. #include "../helpers/subghz_custom_event.h"
  3. void subghz_scene_delete_callback(GuiButtonType result, InputType type, void* context) {
  4. furi_assert(context);
  5. SubGhz* subghz = context;
  6. if((result == GuiButtonTypeRight) && (type == InputTypeShort)) {
  7. view_dispatcher_send_custom_event(subghz->view_dispatcher, SubGhzCustomEventSceneDelete);
  8. }
  9. }
  10. void subghz_scene_delete_on_enter(void* context) {
  11. SubGhz* subghz = context;
  12. FuriString* frequency_str;
  13. FuriString* modulation_str;
  14. FuriString* text;
  15. frequency_str = furi_string_alloc();
  16. modulation_str = furi_string_alloc();
  17. text = furi_string_alloc();
  18. subghz_get_frequency_modulation(subghz, frequency_str, modulation_str);
  19. widget_add_string_element(
  20. subghz->widget,
  21. 78,
  22. 0,
  23. AlignLeft,
  24. AlignTop,
  25. FontSecondary,
  26. furi_string_get_cstr(frequency_str));
  27. widget_add_string_element(
  28. subghz->widget,
  29. 113,
  30. 0,
  31. AlignLeft,
  32. AlignTop,
  33. FontSecondary,
  34. furi_string_get_cstr(modulation_str));
  35. subghz_protocol_decoder_base_get_string(subghz->txrx->decoder_result, text);
  36. widget_add_string_multiline_element(
  37. subghz->widget, 0, 0, AlignLeft, AlignTop, FontSecondary, furi_string_get_cstr(text));
  38. furi_string_free(frequency_str);
  39. furi_string_free(modulation_str);
  40. furi_string_free(text);
  41. widget_add_button_element(
  42. subghz->widget, GuiButtonTypeRight, "Delete", subghz_scene_delete_callback, subghz);
  43. view_dispatcher_switch_to_view(subghz->view_dispatcher, SubGhzViewIdWidget);
  44. }
  45. bool subghz_scene_delete_on_event(void* context, SceneManagerEvent event) {
  46. SubGhz* subghz = context;
  47. if(event.type == SceneManagerEventTypeCustom) {
  48. if(event.event == SubGhzCustomEventSceneDelete) {
  49. furi_string_set(subghz->file_path_tmp, subghz->file_path);
  50. if(subghz_delete_file(subghz)) {
  51. scene_manager_next_scene(subghz->scene_manager, SubGhzSceneDeleteSuccess);
  52. } else {
  53. scene_manager_search_and_switch_to_previous_scene(
  54. subghz->scene_manager, SubGhzSceneStart);
  55. }
  56. return true;
  57. }
  58. }
  59. return false;
  60. }
  61. void subghz_scene_delete_on_exit(void* context) {
  62. SubGhz* subghz = context;
  63. widget_reset(subghz->widget);
  64. }