irda-app-scene-learn-enter-name.cpp 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. #include "../irda-app.hpp"
  2. #include "gui/modules/text_input.h"
  3. void IrdaAppSceneLearnEnterName::on_enter(IrdaApp* app) {
  4. IrdaAppViewManager* view_manager = app->get_view_manager();
  5. TextInput* text_input = view_manager->get_text_input();
  6. auto transceiver = app->get_transceiver();
  7. auto message = transceiver->get_last_message();
  8. app->set_text_store(
  9. 0,
  10. "%.4s_%0*lX",
  11. irda_get_protocol_name(message->protocol),
  12. irda_get_protocol_command_length(message->protocol),
  13. message->command);
  14. text_input_set_header_text(text_input, "Name the key");
  15. text_input_set_result_callback(
  16. text_input,
  17. IrdaApp::text_input_callback,
  18. app,
  19. app->get_text_store(0),
  20. app->get_text_store_size());
  21. view_manager->switch_to(IrdaAppViewManager::ViewType::TextInput);
  22. }
  23. bool IrdaAppSceneLearnEnterName::on_event(IrdaApp* app, IrdaAppEvent* event) {
  24. bool consumed = false;
  25. if(event->type == IrdaAppEvent::Type::TextEditDone) {
  26. auto remote_manager = app->get_remote_manager();
  27. auto transceiver = app->get_transceiver();
  28. bool result = false;
  29. if(app->get_learn_new_remote()) {
  30. result = remote_manager->add_remote_with_button(
  31. app->get_text_store(0), transceiver->get_last_message());
  32. } else {
  33. result = remote_manager->add_button(
  34. app->get_text_store(0), transceiver->get_last_message());
  35. }
  36. if(!result) {
  37. app->search_and_switch_to_previous_scene(
  38. {IrdaApp::Scene::Start, IrdaApp::Scene::RemoteList});
  39. } else {
  40. app->switch_to_next_scene_without_saving(IrdaApp::Scene::LearnDone);
  41. }
  42. }
  43. return consumed;
  44. }
  45. void IrdaAppSceneLearnEnterName::on_exit(IrdaApp* app) {
  46. }