xremote_scene_save_remote.c 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. #include "../xremote.h"
  2. #include <string.h>
  3. #include <toolbox/path.h>
  4. void xremote_scene_save_remote_on_enter(void* context) {
  5. XRemote* app = context;
  6. CrossRemote* remote = app->cross_remote;
  7. TextInput* text_input = app->text_input;
  8. size_t enter_name_length = 0;
  9. text_input_set_header_text(text_input, "Name the remote");
  10. enter_name_length = XREMOTE_MAX_REMOTE_NAME_LENGTH;
  11. FuriString* folder_path;
  12. folder_path = furi_string_alloc();
  13. //if(furi_string_end_with(app->))
  14. //A lot missing here
  15. ValidatorIsFile* validator_is_file = validator_is_file_alloc_init(
  16. furi_string_get_cstr(folder_path),
  17. XREMOTE_APP_EXTENSION,
  18. xremote_cross_remote_get_name(remote));
  19. text_input_set_validator(text_input, validator_is_file_callback, validator_is_file);
  20. furi_string_free(folder_path);
  21. text_input_set_result_callback(
  22. text_input,
  23. xremote_text_input_callback,
  24. context,
  25. app->text_store[0],
  26. enter_name_length,
  27. false);
  28. view_dispatcher_switch_to_view(app->view_dispatcher, XRemoteViewIdTextInput);
  29. }
  30. bool xremote_scene_save_remote_on_event(void* context, SceneManagerEvent event) {
  31. XRemote* app = context;
  32. CrossRemote* remote = app->cross_remote;
  33. SceneManager* scene_manager = app->scene_manager;
  34. bool consumed = false;
  35. if(event.type == SceneManagerEventTypeCustom) {
  36. bool success = false;
  37. success = xremote_cross_remote_save_new(remote, app->text_store[0]);
  38. if(success) {
  39. scene_manager_next_scene(scene_manager, XRemoteSceneMenu);
  40. } else {
  41. scene_manager_search_and_switch_to_previous_scene(scene_manager, XRemoteSceneCreate);
  42. }
  43. consumed = true;
  44. }
  45. return consumed;
  46. }
  47. void xremote_scene_save_remote_on_exit(void* context) {
  48. XRemote* app = context;
  49. TextInput* text_input = app->text_input;
  50. void* validator_context = text_input_get_validator_callback_context(text_input);
  51. text_input_set_validator(text_input, NULL, NULL);
  52. size_t enter_name_length = XREMOTE_MAX_REMOTE_NAME_LENGTH;
  53. strncpy(app->text_store[0], "", enter_name_length);
  54. if(validator_context) {
  55. validator_is_file_free((ValidatorIsFile*)validator_context);
  56. }
  57. }