xremote_scene_save_remote.c 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  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), XREMOTE_APP_EXTENSION, cross_remote_get_name(remote));
  17. text_input_set_validator(text_input, validator_is_file_callback, validator_is_file);
  18. furi_string_free(folder_path);
  19. text_input_set_result_callback(
  20. text_input,
  21. xremote_text_input_callback,
  22. context,
  23. app->text_store[0],
  24. enter_name_length,
  25. false);
  26. view_dispatcher_switch_to_view(app->view_dispatcher, XRemoteViewIdTextInput);
  27. }
  28. bool xremote_scene_save_remote_on_event(void* context, SceneManagerEvent event) {
  29. XRemote* app = context;
  30. CrossRemote* remote = app->cross_remote;
  31. SceneManager* scene_manager = app->scene_manager;
  32. bool consumed = false;
  33. if(event.type == SceneManagerEventTypeCustom) {
  34. bool success = false;
  35. success = cross_remote_save_new(remote, app->text_store[0]);
  36. if(success) {
  37. scene_manager_next_scene(scene_manager, XRemoteSceneMenu);
  38. } else {
  39. scene_manager_search_and_switch_to_previous_scene(scene_manager, XRemoteSceneCreate);
  40. }
  41. consumed = true;
  42. }
  43. return consumed;
  44. }
  45. void xremote_scene_save_remote_on_exit(void* context) {
  46. XRemote* app = context;
  47. TextInput* text_input = app->text_input;
  48. void* validator_context = text_input_get_validator_callback_context(text_input);
  49. text_input_set_validator(text_input, NULL, NULL);
  50. size_t enter_name_length = XREMOTE_MAX_REMOTE_NAME_LENGTH;
  51. strncpy(app->text_store[0], "", enter_name_length);
  52. if(validator_context) {
  53. validator_is_file_free((ValidatorIsFile*)validator_context);
  54. }
  55. }